Python sphinx 如何在Sphinx文档中显示类的继承成员?

Python sphinx 如何在Sphinx文档中显示类的继承成员?,python-sphinx,autodoc,Python Sphinx,Autodoc,我想记录一些类,这些类都是从同一个基类派生的,具有一些公共属性,并且我想对子类中的每个属性重复记录,这样我就可以在一个地方看到一个类的所有属性 例如,我有以下代码: 类基(对象): “”“基类。”“” #:第一个属性 a=int #:第二个属性 b=str 第一个孩子(基本): “”“基础的第一个子项。”“” #:子属性 c=浮动 第二类(基本类): “”“基础的第二个子项。”“” 通过 我有一个问题: .. automodule:: example :members: :show

我想记录一些类,这些类都是从同一个基类派生的,具有一些公共属性,并且我想对子类中的每个属性重复记录,这样我就可以在一个地方看到一个类的所有属性

例如,我有以下代码:

类基(对象):
“”“基类。”“”
#:第一个属性
a=int
#:第二个属性
b=str
第一个孩子(基本):
“”“基础的第一个子项。”“”
#:子属性
c=浮动
第二类(基本类):
“”“基础的第二个子项。”“”
通过
我有一个问题:

.. 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 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"

您需要添加
:继承成员:
选项,引用文档:

对于类和异常,在记录所有成员时,从基类继承的成员将被忽略,除非除了成员之外,您还提供了继承成员标志选项


这对我来说非常好。很难说为什么它对你不起作用,你有没有尝试过升级Sphinx或者使用默认主题,看看它是否能用。这很奇怪:在我上面发布的测试中它能用,但在我的实际项目中它不能用。我真的无法解释为什么,因为conf.py或其他文件中没有实质性的差异。我能想到的唯一区别是,在我的项目中,类是“嵌套的”:
。。autoclass::www.oe.oe_wsme.wstypes.BaseModel
您继承的成员可能没有定义docstring,在这种情况下,请尝试添加“:undoc members:`以及。可能的重复