相关疑难解决方法(0)

napoleon 和 autodoc 如何交互记录成员

我注意到 Sphinx 呈现类描述的行为发生了变化。鉴于此代码

# my example happens to be a dataclass, but the behavior for 
# regular classes is the same
@dataclass
class TestClass:
    """This is a test class for dataclasses.

    This is the body of the docstring description.
    """
    var_int: int
    var_str: str
Run Code Online (Sandbox Code Playgroud)

加上一些通用的狮身人面像设置,我大约两年前就得到了这个

文档仅显示文档字符串

现在我得到了这个

文档显示类变量,就像它们在文档字符串中一样

有没有办法告诉 Sphinx 不要将类变量添加到类定义的底部?尤其令人烦恼的是,它假设它们的值为None,只是因为它们没有默认值。


这个问题是在这篇文章的讨论中出现的,其中还包含有关 Sphinx 配置等的评论中的更多上下文。

python python-sphinx autodoc sphinx-napoleon python-dataclasses

3
推荐指数
1
解决办法
2164
查看次数