Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport PR #12278 on branch v3.0.0-doc (Document inheriting docstrings) #12290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions doc/devel/documenting_mpl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,29 @@ definition. There are some some manual hacks in this case, violating the
"single entry point" requirement above -- see the ``docstring.interpd.update``
calls in `matplotlib.patches`.


Inheriting docstrings
---------------------

If a subclass overrides a method but does not change the semantics, we can
reuse the parent docstring for the method of the child class. Python does this
automatically, if the subclass method does not have a docstring.

Use a plain comment `# docstring inherited` to denote the intention to reuse
the parent docstring. That way we do not accidentially create a docstring in
the future::

class A:
def foo():
"""The parent docstring."""
pass

class B(A):
def foo():
# docstring inherited
pass


.. _docstring-adding-figures:

Adding figures
Expand Down