您如何能够在装饰器前添加函数docstring?
def g(func):
someOtherDocString = "That is great"
def wrap(*args, **kwargs):
func(*args, **kwargs)
return wrap
@g
def f():
""" This is awesome """
结果:
>>>help(f)
Help on function f in module __main__:
f()
That is great
That is awesome
非常感谢所有帮助。
答案 0 :(得分:5)
你尝试过魔法__doc__
:
from functools import wraps
def g(func):
func.__doc__ = "That is great" + func.__doc__
@wraps(func)
def wrap(*args, **kwargs):
return func(*args, **kwargs)
return wrap