我想记录一些类,这些类都派生自具有一些公共属性的同一基类,并且我想重复子类中每个属性的文档,以便我可以在一个位置看到一个类的所有属性。
例如我有这样的代码:
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"
您需要添加:inherited-members:
选项,引用文档:
对于类和异常,在记录所有成员时将从基类继承的成员将被忽略,除非除了成员之外还提供了herited-members 标志选项。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)