相关疑难解决方法(0)

如何使用Sphinx的autodoc来记录类的__init __(self)方法?

默认情况下,Sphinx不会为__init __(self)生成文档.我尝试过以下方法:

.. automodule:: mymodule
    :members:
Run Code Online (Sandbox Code Playgroud)

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

在conf.py中,设置以下内容只会将__init __(self)docstring附加到类docstring(Sphinx autodoc文档似乎同意这是预期的行为,但没有提到我正在尝试解决的问题):

autoclass_content = 'both'
Run Code Online (Sandbox Code Playgroud)

python python-sphinx autodoc

88
推荐指数
4
解决办法
3万
查看次数

是否应该在类和__init__ docstrings中记录哪些内容?

我没有找到关于应该在类和__init__文档字符串中记录什么的最佳实践.有时我发现构造函数参数已经在docstring类中记录,有时会在__init__docstring 中描述.我更喜欢在类docstring中描述构造,因为这是您在创建新实例时调用的内容.但是应该在__init__docstring方法中记录什么呢?


编辑:

我知道google styleguidegoogle docstring样式示例,但两者都没有回答我的问题.文档字符串样式的例子确实说

__init__方法可以记录在类级别docstring中,也可以记录在__init__方法本身的docstring中.任何一种形式都是可以接受的,但这两种形式不应混合.选择一种约定来记录__init__方法并与之保持一致.

但是如果我选择将__init__函数的docstring 放入类级docstring中,那么__init__docstring 应该包含什么?

python docstring code-documentation

24
推荐指数
5
解决办法
5126
查看次数