本文介绍了如何在我的Sphinx文档中显示类的继承成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想记录一些类,这些类都派生自具有一些公共属性的同一基类,并且我想重复子类中每个属性的文档,以便我可以在一个位置查看类的所有属性。

例如,我有这样的代码:

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:选项,引用自文档:

这篇关于如何在我的Sphinx文档中显示类的继承成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 16:00