小编mar*_*llv的帖子

未显示文档字符串中的继承属性

我正在尝试使用 Sphinx 来记录具有 google 样式文档字符串类的一个基类和 2 个子类。我特别纠结于继承的属性:

class Base(object):
    """Base class.

    Attributes:
         a (int): one attribute
         b (int): another one
    """

    def __init__(self):
        self.a = 3
        self.b = 5

class FirstChild(Base):
    """First Child of Base.

    Attributes:
        c (float): child class attribute
    """

    def __init__(self):
        self.c = 3.1

class SecondChild(Base):
    """Second Child of Base."""
    pass
Run Code Online (Sandbox Code Playgroud)

这是第一个文件:

.. automodule:: my_package.my_module
    :members:
    :undoc-members:
    :show-inheritance:
    :inherited-members:
Run Code Online (Sandbox Code Playgroud)

Sphinx 仅在 Base 类上显示属性 a 和 b。FirstChild中只有c,SecondChild中没有属性,即使有:inherited-members:标签。

有没有办法在子类中显示 a、b 和 c,而不必在 FirstChild/SecondChild 文档字符串中复制/粘贴描述?

谢谢!

python python-sphinx autodoc

5
推荐指数
1
解决办法
761
查看次数

标签 统计

autodoc ×1

python ×1

python-sphinx ×1