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

标签 python python-sphinx autodoc

我正在使用 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/

相关文章:

python - 如何在 Python 中重新加载环境变量?

python - 根据各个对应元素的比率或基于第三个列表对 Python 中的 2 个列表进行排序

python - pandas - 使用指定的开始日期、结束日期和粒度对数据框重新采样

python - 开始为 Django 应用程序编写文档

matlab - matlab 中 sphinx 的继承图

python-sphinx - 如何使用 sphinx 分配案例的标签中心?

clojure - 如何从 leiningen 项目中排除 jars?

python - 根据输入执行查找时出现问题

python - 覆盖 sphinx 的 autodoc 中的函数声明

python - 为什么 CPython 不将 `sphinx.autodoc` 用于标准库?