Sphinx autodoc show-inheritance:如何跳过无证的中间基础?

Mic*_*ann 9 python python-2.7 python-sphinx

我有一个三层的类结构,如下所示:

class Super(object):
    """This class is documented."""

class Intermediate(Super):
    pass

class Sub(Intermediate):
    """This is also documented."""
Run Code Online (Sandbox Code Playgroud)

我的index.rst文件如下:

.. automodule:: mymodule
   :show-inheritance:
   :inherited-members:
Run Code Online (Sandbox Code Playgroud)

Sphinx为我生成了一个很好的API文档.它包括类SuperSub适当的注释.它不包括Intermediate,因为它没有评论,我没有提供undoc-members标志.这是因为我不想Intermediate出现在文档中.

我的问题是:因为我提供了show-inheritance标志,Sphinx显示每个类的基础; object对于SuperIntermediateSub.由于Intermediate没有文档,我不希望它出现在基类列表中.相反,我希望Sphinx在继承树中显示下一个记录的类,Super.换句话说:我希望Sphinx能够显示Super,而不是Intermediate作为基类Sub.

有人知道怎么做这个吗?

Lau*_*RTE 3

对于这种特殊的情况,如果你想“隐藏”类继承,你可以使用autoclass文档记录每个可见的类,而不是记录整个模块。

例如:

.. currentmodule:: demo

.. autoclass:: Super
   :members:

.. autoclass:: Sub
   :members:
Run Code Online (Sandbox Code Playgroud)

然后你可以添加:show-inheritance:标志以显示对所需类的继承。

引用文档:

automodule、autoclass 和 autoexception 指令还支持名为 show-inheritance 的标志选项。当给出时,基类列表将被插入到类签名的正下方(当与自动模块一起使用时,这将为模块中记录的每个类插入)。