class object def __init__ self func self func func self __name__ func

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class A(object):
def __init__(self, func):
self.func = func
self.__name__ = func.__name__
def __call__(self, *args, **kwargs):
return self.func(*args, **kwargs)
class B(object):
def a(self):
return self.b(0)
@A
def b(self, c):
return c
print B().a()
[mag@frontier:~]% python b.py
Traceback (most recent call last):
File "b.py", line 17, in <module>
print B().a()
File "b.py", line 11, in a
return self.b(0)
File "b.py", line 7, in __call__
return self.func(*args, **kwargs)
TypeError: b() takes exactly 2 arguments (1 given)
[mag@frontier:~]1%