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 167cedf

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

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
@@ -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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.