gpt4 book ai didi

python - 是否可以针对特定功能覆盖 Sphinx autodoc?

转载 作者:太空狗 更新时间:2023-10-29 18:00:31 24 4
gpt4 key购买 nike

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

是否可以覆盖特定函数的 autodoc 输出?

最佳答案

可以使用 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 而不是 autofunction

补充2

也可以通过将签名作为函数文档字符串的第一行来覆盖签名。参见 this answer了解详情。

关于python - 是否可以针对特定功能覆盖 Sphinx autodoc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5365684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com