You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using a decorator to inherit the docstring would be very useful. For example, the decorator's definition would be like this:
fromtypingimportCallable, Literaldefinherit_docstring(func: Callable=None, *, source: Callable=None, style: Literal["numpy", "google"] ="numpy"):
"""Decorator for inherit docstring from other functions."""fromdocstring_inheritanceimportinherit_google_docstring, inherit_numpy_docstringassertsourceisnotNone, "Source function is not given."assertstylein ("numpy", "google"), "Style must be either 'numpy' or 'google'."defwrapper(f):
inherit_func=inherit_numpy_docstringifstyle=="numpy"elseinherit_google_docstringinherit_func(source.__doc__, f)
returnfreturnwrapperiffuncisNoneelsewrapper(func)
With the following usage:
defparent(x, y):
"""Parent summary. Args: x: Description for x. y: Description for y. Notes: Parent notes. """@inherit_docstring(source=parent, style="google")defchild(x, y, z):
""" Args: z: Description for z. Returns: Something. Notes: Child notes. """
The child's docstring is:
>>> print(child.__doc__)
Parent summary.
Args:
x: Description for x.
y: Description for y.
z: Description for z.
Returns:
Something.
Notes:
Child notes.
The text was updated successfully, but these errors were encountered:
Using a decorator to inherit the docstring would be very useful. For example, the decorator's definition would be like this:
With the following usage:
The child's docstring is:
The text was updated successfully, but these errors were encountered: