T1是一個decorator class
用到class A func, 傳進來的arg中,會少了class A self參數
請問有人可以解釋原因嗎?
code
===========================
class T1(object):
def __init__(self, func):
self.func = func
def __call__(self, *arg, **kw):
print('T1:', locals())
# T1: {'self': <__main__.T1 object at 0x7f28e2787c70>, 'arg': (), 'kw': {}}
return self.func(*arg, **kw)
class A(object):
@T1
def func(self):
pass
a = A()
a.func() # missing 1 required positional argument: 'self'
============================