python - 如何使用 Sphinx 记录特定部分中的成员?

标签 python python-2.7 documentation python-sphinx autodoc

我正在努力弄清楚如何将 Python 类的特定成员的文档放置在 Sphinx 文档的特定部分中,最好同时将其余部分自动记录在另一个部分中。

我有一个Python类

class MyClass(object):

    def funky(self, arg):
        """Some docs."""
        ...

my/module.py 中定义,它按预期工作,我可以使用它来记录而不会出现问题

***************************
MyModule - :mod:`my.module`
***************************

.. automodule:: my.module

.. autoclass:: MyClass
   :members:
   :undoc-members:
   :show-inheritance:

但是当我尝试更好地控制文档的组织时,我无法让事情正常进行。具体来说,我希望将一些成员记录在明确的部分中(此处仅显示一个成员,但会有多个),其余成员作为一个组自动记录。

但是当我尝试这个时,例如

***************************
MyModule - :mod:`my.module`
***************************

To document
===========

Things that are not yet documented.

.. automodule:: my.module

.. autoclass:: MyClass
   :members:
   :undoc-members:
   :show-inheritance:
   :exclude-members: funky

Funky things
------------

Some funky things.

.. automethod:: funky

我明白

WARNING: don't know which module to import for autodocumenting u'funky' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)

但没有变化

.. currentmodule:: my.module
.. class:: MyClass

.. automethod:: funky

.. currentmodule:: my.module

   .. automethod:: funky

等等。带我去任何地方。

如何在 Sphinx 文档的特定位置自动记录类(class)的某些成员?

最佳答案

这有效:

.. currentmodule:: my.module

.. automethod:: MyClass.funky

您可以跳过 .. currentmodule:: 并按如下方式执行:

.. automethod:: my.module.MyClass.funky

第三个选项:

.. currentmodule:: my.module

.. autoclass:: MyClass   

   .. automethod:: funky

关于python - 如何使用 Sphinx 记录特定部分中的成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34010116/

相关文章:

python - 将字典值分配给变量,其中 key == list[element]

r - 链接到 R 中 roxygen2 文档中的其他包

python - 当请求来自远程时, "nice"调试 django 的方法是什么?

android - 在我的 Android 设备上使用 kivy 加载声音

python - numpy中唯一元素的分组索引

Python:kubernetes exec 失败并显示需要升级的消息

haskell 阴谋 : Generate latex haddock documentation

linux - Doxygen 找不到 m2cpp.pl

python - 来自具有频率 python 的数据框的 WordCloud

python - 我想基于上一列添加一个新的 DataFrame 列,以便如果上一列元素与列表值匹配,则更改该值