解决方法:使用funtools中的装饰器wraps装饰的内部包裹函数,可以制定将原函数的某些属性更新到包裹函数上面。
from functools import wraps, update_wrapper,WRAPPER_ASSIGNMENTS, WRAPPER_UPDATES
def mydecorator(func):
@wraps(func)
def wrapper(*args, **kargs):
'''wrapper function'''
print('In wrapper')
func(*args, **kargs)
# update_wrapper(wrapper, func)
return wrapper
@mydecorator
def example():
'''example function'''
print('In example')
print(example.__name__, example.__doc__)