我想记录一些类,这些类都来自同一个基类,并带有一些共同的属性,我想重复子类中每个属性的文档,这样我就可以在一个单元中看到一个类的所有属性的地方。
例如,我有这个代码:
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 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"
答案 0 :(得分:7)
您需要添加{{1}}选项,引用文档:
对于类和异常,除了成员之外,在记录所有成员时将忽略从基类继承的成员,除非您提供inherited-members标志选项。