Re: [問題] decorator class in a class

作者: lycantrope (阿寬)   2022-11-18 15:14:52
※ 引述《tsaiminghan (nahgnimiast)》之銘言:
: class T1(object):
: def __init__(self, func):
: self.func = func
: def __call__(self, *arg, **kw):
: print('T1:', locals())
: return self.func(*arg, **kw)
: def T2(func):
: def wrapper(*arg, **kw):
: print(locals())
: return func(*arg, **kw)
: return wrapper
講錯還請高手指正
@T1
def F():
pass
把decorator還原:
def F():
pass
F = T1(F)
F已經變成有implement call的 T1 class instance
所以在呼叫F(),locals()會帶有self
作者: tsaiminghan (tsaiminghan)   2022-11-18 15:51:00
抱歉,我沒說清楚對於F函式,T1, T2使用上都沒有問題有問題的是class A中使用T1傳進來的arg中,函少class A的self

Links booklink

Contact Us: admin [ a t ] ucptt.com