我想记录一些从同一个基类派生的类,这些类有一些共同的属性,我希望在子类中为每个属性重复记录文档,以便我可以在一个地方查看一个类的所有属性。
例如,我有以下代码:
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
我有这个rst文件:
.. 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"