Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
440 views
in Technique[技术] by (71.8m points)

python - How to document nested classes with Sphinx's autodoc?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...