是否可以覆盖 Sphinx autodoc 的特定功能?

发布于 2024-10-24 03:34:30 字数 179 浏览 8 评论 0原文

我正在使用 Sphinx 的 autodoc 插件自动记录一组模块。我有一个接受 *args 的函数,我想重写文档以显示稍微好一点的 funcname(arg1[, arg2[, ...]]) Python stdlib 文档使用的样式。

是否可以覆盖特定函数的自动文档输出?

I'm using Sphinx's autodoc plugin to automatically document a set of modules. I have a function that accepts *args, and I'd like to override the documentation to show the slightly nicer funcname(arg1[, arg2[, ...]]) style that the Python stdlib docs use.

Is it possible to override the autodoc output for a specific function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

是伱的 2024-10-31 03:34:30

可以使用 autofunction 覆盖签名:

.. automodule:: yourmodule
   :members:
   :exclude-members: funcname

.. autofunction:: funcname(arg1[, arg2[, ...]])

但是,具有覆盖签名的函数不会与使用 automodule 引入的其他函数一起排序。对每个函数使用显式的 autofunction 指令可以解决这个问题:

.. autofunction:: firstfunc

.. autofunction:: funcname(arg1[, arg2[, ...]])

.. autofunction:: thirdfunc

添加

您还可以附加到文档字符串:

.. autofunction:: funcname(arg1[, arg2[, ...]])

   Extra documentation here.  

要覆盖签名和文档字符串,请使用 function而不是自动函数

添加 2

还可以通过将签名作为函数文档字符串的第一行来覆盖签名。有关详细信息,请参阅此答案

It is possible to override a signature by using autofunction:

.. automodule:: yourmodule
   :members:
   :exclude-members: funcname

.. autofunction:: funcname(arg1[, arg2[, ...]])

However, the function with the overridden signature is not sorted with the other functions pulled in with automodule. Using explicit autofunction directives for every function works around that:

.. autofunction:: firstfunc

.. autofunction:: funcname(arg1[, arg2[, ...]])

.. autofunction:: thirdfunc

Addition

You can also append to the docstring:

.. autofunction:: funcname(arg1[, arg2[, ...]])

   Extra documentation here.  

To override both signature and docstring, use function instead of autofunction.

Addition 2

The signature can also be overridden by having a signature as the first line of the function docstring. See this answer for details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文