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

Skip to content

Commit 167cedf

Browse files
meeseeksmachinetimhoffm
authored andcommitted
Backport PR #12278: Document inheriting docstrings (#12290)
1 parent 71c1a9e commit 167cedf

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

doc/devel/documenting_mpl.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,29 @@ definition. There are some some manual hacks in this case, violating the
632632
"single entry point" requirement above -- see the ``docstring.interpd.update``
633633
calls in `matplotlib.patches`.
634634

635+
636+
Inheriting docstrings
637+
---------------------
638+
639+
If a subclass overrides a method but does not change the semantics, we can
640+
reuse the parent docstring for the method of the child class. Python does this
641+
automatically, if the subclass method does not have a docstring.
642+
643+
Use a plain comment `# docstring inherited` to denote the intention to reuse
644+
the parent docstring. That way we do not accidentially create a docstring in
645+
the future::
646+
647+
class A:
648+
def foo():
649+
"""The parent docstring."""
650+
pass
651+
652+
class B(A):
653+
def foo():
654+
# docstring inherited
655+
pass
656+
657+
635658
.. _docstring-adding-figures:
636659

637660
Adding figures

0 commit comments

Comments
 (0)