相关疑难解决方法(0)

继承Python类继承中的docstrings

我正在尝试在Python中进行一些类继承.我希望每个班级和继承的班级都有良好的文档字符串.所以我认为对于继承的类,我希望它:

  • 继承基类docstring
  • 可能会将相关的额外文档附加到docstring

在类继承情况下是否有任何(可能是优雅或pythonic)方式进行此类文档字符串操作?多重继承怎么样?

python documentation inheritance

88
推荐指数
6
解决办法
2万
查看次数

如何在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
Run Code Online (Sandbox Code Playgroud)

我有这个第一个:

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

输出将如下所示:

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 …
Run Code Online (Sandbox Code Playgroud)

python-sphinx autodoc

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