/ / Jak mogę pokazać odziedziczonych członków klasy w mojej dokumentacji Sphinx? - python-sfinks, autodoc

Jak mogę pokazać odziedziczonych członków klasy w mojej dokumentacji Sphinx? - python-sphinx, autodoc

Chcę udokumentować niektóre klasy, które wszystkie pochodząz tej samej klasy bazowej z kilkoma typowymi atrybutami i chciałbym powtórzyć dokumentację dla każdego atrybutu w podklasach, tak aby móc zobaczyć wszystkie atrybuty klasy w jednym miejscu.

Na przykład mam ten kod:

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

a ja mam to pierwsze:

.. automodule:: example
:members:
:show-inheritance:

Wynik będzie taki:

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.

Czy istnieje sposób generowania dokumentacji, tak aby klasy potomne miały również odziedziczone atrybuty?

Na przykład:

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"

Odpowiedzi:

3 dla odpowiedzi № 1

Musisz dodać :inherited-members: opcja, cytat z dokumentów:

W przypadku klas i wyjątków elementy dziedziczone z klas bazowych zostaną pominięte podczas dokumentowania wszystkich członków, chyba że oprócz członków zostanie podana opcja flaga odziedziczonych członków.