So I have a method in a class and I have another separate function (i.e., outside the class) that want to reuse the docstring of that method. I tried something like __doc__ = <Class Name>.<Method Name>.__doc__
under the separate function but that does not work. Thus, is there a way to do so?
Asked
Active
Viewed 1,244 times
1

John M.
- 825
- 1
- 10
- 22
-
`other_function.__doc__ = ...`, or maybe even `@functools.wraps`. But are you really sure they should use the same doc? – zvone Oct 08 '18 at 00:11
2 Answers
1
Even this is a case, I'd use a manual copy of a docstring. Class or function could be moved around or separated to different projects. Moreso, reading a function below goesn't give me any idea what it's doing.
Please, consult with PEP-8, PEP-257 and PEP-20 for more information why this behavior is discoraged.
def myfunc():
...
myfunc.__doc__ = other_obj.__doc__

Eir Nym
- 1,515
- 19
- 30