4
def __init__(self, name, bases, namespace):
5
"""Create a new class."""
8
self.__namespace__ = namespace
10
"""Create a new instance."""
14
def __init__(self, klass):
15
self.__klass__ = klass
16
def __getattr__(self, name):
18
value = self.__klass__.__namespace__[name]
20
raise AttributeError(name)
21
if type(value) is not types.FunctionType:
23
return BoundMethod(value, self)
26
def __init__(self, function, instance):
27
self.function = function
28
self.instance = instance
29
def __call__(self, *args):
30
print("calling", self.function, "for", self.instance, "with", args)
31
return self.function(self.instance, *args)
33
Trace = Tracing('Trace', (), {})
35
class MyTracedClass(Trace):
41
aninstance = MyTracedClass()
43
aninstance.method1(10)
45
print(aninstance.method2())