什么都不做的装饰器类如下所示:
class NullDecl (object): def __init__ (self, func): self.func = func for name in set(dir(func)) - set(dir(self)): setattr(self, name, getattr(func, name)) def __call__ (self, *args): return self.func (*args)
然后您可以正常应用它:
@NullDecldef myFunc (x,y,z): return (x+y)/z



