From d972ba0c2a9db49970e2161b4ee7b47638a43a4e Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Wed, 26 Sep 2018 03:27:22 +0200 Subject: [PATCH] Backport PR #12278: Document inheriting docstrings --- doc/devel/documenting_mpl.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/doc/devel/documenting_mpl.rst b/doc/devel/documenting_mpl.rst index e41c6630be6f..1778c2851fff 100644 --- a/doc/devel/documenting_mpl.rst +++ b/doc/devel/documenting_mpl.rst @@ -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