python - Sphinx with autodoc "duplicate object description"将成员分组到单独文件时发出警告

标签 python python-sphinx restructuredtext autodoc

我在一个模块中有一些函数,我想在我的文档中将它们分成两组。我有三个文件:

my_mod.rst

my_mod
======
.. automodule:: my_mod
   :no-members:

.. toctree::
   :maxdepth: 1

   my_mod/group1
   my_mod/group2

group1.rst

group1
======

.. automodule:: my_mod
   :members: add, subtract

group2.rst

group2
======

.. automodule:: my_mod
   :members: multiply, divide

我必须在每个中使用 .. automodule::my_mod。在 my_mod.rst 中,它显示模块文档字符串,并在其他文件中识别我想要显示的 :members:。但是,这会在生成 HTML 文件时导致多个错误,例如:

/pathto/my_mymod.rst:2: WARNING: duplicate object description of my_mod, other instance in my_mod/group1, use :noindex: for one of them

不过,如果我添加 :noindex:,我将无法再从文档的其他地方链接到这些函数,因此这不是我的解决方案。

我能否在不丢失任何功能的情况下避免这些错误消息?此外,这似乎如我所愿地工作(错误消息除外),但是多次引用同一模块是否存在任何潜在的陷阱?

最佳答案

另一种方法是使用autofunction

group1
======

.. currentmodule:: my_mod

.. autofunction:: add
.. autofunction:: subtract

group2
======

.. currentmodule:: my_mod

.. autofunction:: multiply
.. autofunction:: divide

关于python - Sphinx with autodoc "duplicate object description"将成员分组到单独文件时发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61374995/

相关文章:

python-sphinx - 单独的sphinx构建目录和源目录用于版本控制

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

Emacs 在 rst-mode 中复制 org-mode 的 M-RET 功能

python-sphinx - 在 Sphinx 文档中重用 RST 中的文本

python - Sublime Text : "The system cannot find the file specified" error

python - Pandas 表示跨多个列

pdf - sphinx用latexpdf删除我pdf中的章节标题?

python-sphinx - 如何在python-sphinx中创建方程末尾的数字?

python - Supervisord 无法启动 Tornado 服务器

python - 报告实验室错误 : 'Table' object has no attribute '_colpositions'