Inherited attributes in docstring not displayed

半城伤御伤魂 提交于 2019-12-10 17:23:23

问题


I'm trying to use Sphinx to document one base class and 2 child classes with google style docstring classes. I'm particularly stuggling with inherited attributes:

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

Here is the rst file:

.. automodule:: my_package.my_module
    :members:
    :undoc-members:
    :show-inheritance:
    :inherited-members:

Sphinx displays attributes a and b only on class Base. In FirstChild, there is only c, and no attribute in SecondChild, even with the :inherited-members: tag.

Is there a way to have a, b and c displayed in the child classes without having to copy/paste descriptions in FirstChild/SecondChild docstrings ?

Thanks!

来源:https://stackoverflow.com/questions/47309392/inherited-attributes-in-docstring-not-displayed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!