我在一个模块中有一些函数,我想在我的文档中将它们分成两组。我有三个文件:
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/