Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b63b04b

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

File tree

Expand file treeCollapse file tree

1 file changed

+23
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-0
lines changed

‎doc/devel/documenting_mpl.rst

Copy file name to clipboardExpand all lines: doc/devel/documenting_mpl.rst
+23Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.