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

Skip to content

Commit b63b04b

Browse files
meeseeksmachinetimhoffm
authored andcommitted
Backport PR #12278: Document inheriting docstrings (#12289)
1 parent 1815263 commit b63b04b

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
@@ -630,6 +630,29 @@ definition. There are some some manual hacks in this case, violating the
630630
"single entry point" requirement above -- see the ``docstring.interpd.update``
631631
calls in `matplotlib.patches`.
632632

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

635658
Adding figures

0 commit comments

Comments
 (0)