inherit_docs decorator#

Sometimes, it can be a challenge to make sure that the derived class and all its (inherited or overwritten) methods ihnerit the documentation strings, unless explicitly overwritten.

Let us say we have a documented class A:

class A:
    """Class A doc-string."""

    def __init__(self, a):
        self.a = a

    def method1(self):
        """Class A method doc-string."""
        return self.a - 1

    def method2(self):
        """Class A method doc-string."""
        return self.a + 3

Now, if we derive class B, by decorating it with ubermagutil.inherit_docs we can make sure all doc-strings are ihnerited, unless overwritten explicitly. This is also the case for methods, whose implementation is changed, but doc-string was not specified.

import ubermagutil

class B(A):
    """Class B doc-string."""

    def method1(self):
        return self.a + 1

    def method2(self):
        """New doc-string."""
        return self.a + 9

From blass B, method1 inherits doc-string:

'Class A method doc-string.'

However, doc-string of method2 is overwritten:

'New doc-string.'