Kji*_*jir 5 python-sphinx autodoc
我想记录一些类,这些类都是从具有一些公共属性的相同基类派生的,我想重复子类中每个属性的文档,以便我可以在一个地方看到类的所有属性.
所以例如我有这个代码:
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
Run Code Online (Sandbox Code Playgroud)
我有这个第一个:
.. automodule:: example
:members:
:show-inheritance:
Run Code Online (Sandbox Code Playgroud)
输出将如下所示:
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.
Run Code Online (Sandbox Code Playgroud)
有没有办法生成文档,以便子类也具有继承属性?
例如:
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"
Run Code Online (Sandbox Code Playgroud)
您需要添加:inherited-members:
选项,引用文档:
对于类和异常,除了成员之外,在记录所有成员时将忽略从基类继承的成员,除非您提供inherited-members标志选项.