def outer(func): def inner(*args, **kwargs): ret = func(*args, **kwargs) return ret return inner @outer # auth = inner() 一旦加上装饰器,那么当前auth已经变成inner了 def auth(): pass ret = auth()
@装饰器函数
重新定义被装饰函数=装饰器函数(被装饰函数)
@outer # auth = inner() 一旦加上装饰器,那么当前auth已经变成inner了 def auth(): pass
3.3
import functools def outer(func): functools.wraps(func) # inner.__name__ == func.__name__,inner.__doc__ == func.__doc__ def inner(*args, **kwargs): """bbb""" ret = func(*args, **kwargs) return ret return inner @outer # auth = inner() 一旦加上装饰器,那么当前auth已经变成inner了 def auth(): """xxx""" pass ret = auth()