I want to document some classes which all derive from the same base class with some common attributes and I would like to repeat the documentation for every attribute in the subclasses, so that I can see all the attributes for a class in a single place.
So for instance I have this code:
class Base(object):
    """Base class."""
    #: First attribute
    a = int
    #: Second attribute
    b = str
class FirstChild(Base):
    """First Child of Base."""
    #: Child attribute
    c = float
class SecondChild(Base):
    """Second Child of Base."""
    pass
and I have this rst:
.. automodule:: example
   :members:
   :show-inheritance:
The output will be like this:
class class example.Base
   Bases: "object"
   Base class.
   a
      First attribute
      alias of "int"
   b
      Second attribute
      alias of "str"
class class example.FirstChild
   Bases: "example.Base"
   First Child of Base.
   c
      Child attribute
      alias of "float"
class class example.SecondChild
   Bases: "example.Base"
   Second Child of Base.
Is there a way to generate documentation such that the child classes will also have the inherited attributes?
For instance:
class class example.FirstChild
   Bases: "example.Base"
   First Child of Base.
   a
      First attribute
      alias of "int"
   b
      Second attribute
      alias of "str"
   c
      Child attribute
      alias of "float"
class class example.SecondChild
   Bases: "example.Base"
   Second Child of Base.
   a
      First attribute
      alias of "int"
   b
      Second attribute
      alias of "str"
autodoc provides several directives that are versions of the usual py:module , py:class and so forth. On parsing time, they import the corresponding module and extract the docstring of the given objects, inserting them into the page source under a suitable py:module , py:class etc. directive.
You need to add the :inherited-members: option, quote from the docs:
For classes and exceptions, members inherited from base classes will be left out when documenting all members, unless you give the inherited-members flag option, in addition to members.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With