在 Sphinx 文档中*仅*显示文档字符串?
Sphinx 有一个名为 automethod
的功能,可以从方法的文档字符串中提取文档并将其嵌入到文档中。但它不仅嵌入了文档字符串,还嵌入了方法签名(名称+参数)。如何仅嵌入文档字符串(不包括方法签名)?
参考: http://www.sphinx-doc.org/ en/master/usage/extensions/autodoc.html
Sphinx has a feature called automethod
that extracts the documentation from a method's docstring and embeds that into the documentation. But it not only embeds the docstring, but also the method signature (name + arguments). How do I embed only the docstring (excluding the method signature)?
ref: http://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找的是:
根据当前来源< /a> 这应该允许覆盖负责记录方法的类(旧版本的
add_documenter
禁止此类覆盖,但现在明确允许)。当然,让format_args
返回 None 是autodoc
中记录的方式,表示“不用理会签名”。我认为这是执行此任务的干净、架构化的方式,因此比猴子补丁替代方案更可取。如果您需要使用一些旧版本的
sphinx
,但是您可能确实需要monkeypatch(autodoc.MethodDocumenter.format_args=lambda _:None
- eek!-)如果在您的特定部署中可行的话,我建议将 sphinx 升级到当前版本作为更好的方法。I think what you're looking for is:
per the current sources this should allow overriding what class is responsible for documenting methods (older versions of
add_documenter
forbade such overrides, but now they're explicitly allowed). Havingformat_args
return None, of course, is THE documented way inautodoc
to say "don't bother with the signature".I think this is the clean, architected way to perform this task, and, as such, preferable to monkeypatching alternatives. If you need to live with some old versions of
sphinx
however you may indeed have to monkeypatch (autodoc.MethodDocumenter.format_args=lambda _:None
-- eek!-) though I would recommend upgradingsphinx
to the current version as a better approach if at all feasible in your specific deployment.