How to document nested classes with Sphinx's autodoc?

▼魔方 西西 提交于 2019-11-28 05:36:52

问题


Is there any way to document a nested class with Sphinx's autodoc plugin?

In:

class A:
    class B:
    """
    class B's documentation.
    """

    # ...

I want to use autoclass or something similar in my .rst file to document A.B specifically.

I tried:

.. currentmodule:: package.module

.. autoclass:: A.B

and

.. autoclass:: package.module.A.B

without success:

/path/to/file.rst:280: WARNING: autodoc: failed to import class 'B' from module 'package.module.A'; the following exception was raised:

...

Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/sphinx/ext/autodoc.py", line 335, in import_object
    __import__(self.modname)
ImportError: No module named 'package.module.A'; 'package.module' is not a package

Of course A is not a module; it seems like autoclass is considering anything before the last . as packages and modules.


回答1:


Try:

.. autoclass:: package.module::A.B

Source: https://groups.google.com/forum/#!topic/sphinx-users/IL5V7HR1ZYE



来源:https://stackoverflow.com/questions/27337534/how-to-document-nested-classes-with-sphinxs-autodoc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!