python , "docstring" __doc__ . - , docstring . docstring B.myfunction A.myfunction ( , -, ). ( ), docstring :
def copydoc(fromfunc, sep="\n"):
"""
Decorator: Copy the docstring of `fromfunc`
"""
def _decorator(func):
sourcedoc = fromfunc.__doc__
if func.__doc__ == None:
func.__doc__ = sourcedoc
else:
func.__doc__ = sep.join([sourcedoc, func.__doc__])
return func
return _decorator
class A(object):
def myfunction():
"""Documentation for A."""
pass
class B(A):
@copydoc(A.myfunction)
def myfunction():
"""Extra details for B."""
pass
:
>>> help(B.myfunction)
Help on method myfunction in module __main__:
myfunction() unbound __main__.B method
Documentation for A.
Extra details for B.
, docstring : @copydoc(A.myfunction). , , , , , .
, , : " ", , . , , @copydoc(A). , . ( , , ).