python - 在 Sphinx 中避免来自父级的文档字符串

标签 python python-sphinx docstring

我将 Sphinx 用于自动文档,但我发现它默认将父类文档字符串附加到我的文档字符串的方式很烦人。

结果是,对于每个继承自 unittest.TestCase 的文档化测试类,我得到了文档字符串 “创建一个类的实例,该实例将在执行时使用指定的测试方法. 如果实例没有具有指定名称的方法,则引发 ValueError。” 附加。所以这两句话一遍又一遍地在我的测试文档中乱扔垃圾。

如何阻止 Sphinx 从父级中提取文档字符串?

最佳答案

有一个 setting :

autodoc_inherit_docstrings

This value controls the docstrings inheritance. If set to True the docstring for classes or methods, if not explicitly set, is inherited form (sic) parents.

The default is True.

New in version 1.7.

尽管要小心使用 - 此设置似乎会破坏我在文档字符串中调用的指令。

关于python - 在 Sphinx 中避免来自父级的文档字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16518834/

相关文章:

python - 在 python 中是否有更简单的方法来编写 6 个嵌套的 for 循环?

Python Chain getattr 作为字符串

python-sphinx - 无效 "requirements_file": path docs/requirements. txt不存在

python-sphinx - 格式化 sphinx 表格单元格中的文本

python - Sphinx 和 Docstrings 中的 reStructuredText : single vs. 双反引号或反引号差异

python - 在类方法文档字符串中使用字符串格式

python - 使用准备好的数据进行 Sci-kit 分类

python - 将 python 的 dict 功能扩展到用户创建的类

python - autodoc 和明确指定的实例属性的问题

python - docstring max line-length 是否与正常的 PEP8 标准不同?