python装饰器的wraps作用
不加:
from functools import wraps def my_decorator(func): def wper(*args, **kwargs): '''decorator''' print('Calling decorated function...') return func(*args, **kwargs) return wper @my_decorator def example(): """Docstring""" print('Called example function') print(example.__name__, example.__doc__)#wper decorator
加:
from functools import wraps def my_decorator(func): @wraps(func) def wper(*args, **kwargs): '''decorator''' print('Calling decorated function...') return func(*args, **kwargs) return wper @my_decorator def example(): """Docstring""" print('Called example function') print(example.__name__, example.__doc__)#example Docstring
装饰器修复技术