如何在我的 Sphinx 文档中显示 class 的继承成员?

How can I show inherited members of a class in my Sphinx documentation?

我想记录一些 classes,它们都派生自相同的基础 class,具有一些共同的属性,我想重复子 [=27= 中的每个属性的文档]es,这样我就可以在一个地方看到 class 的所有属性。

例如我有这个代码:

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

我有第一个:

.. automodule:: example
   :members:
   :show-inheritance:

输出将是这样的:

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.

有没有办法生成文档,使子 class 也具有继承的属性?

例如:

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"

您需要添加 :inherited-members: 选项,引用文档:

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.