我注意到 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