Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 986
eepp Avatar asked Dec 06 '14 22:12

eepp


People also ask

What does Sphinx Autodoc do?

autodoc imports the modules to be documented. If any modules have side effects on import, these will be executed by autodoc when sphinx-build is run. If you document scripts (as opposed to library modules), make sure their main routine is protected by a if __name__ == '__main__' condition.

What is Sphinx Apidoc?

sphinx-apidoc is a tool for automatic generation of Sphinx sources that, using the autodoc extension, document a whole package in the style of other automatic API documentation tools. MODULE_PATH is the path to a Python package to document, and OUTPUT_PATH is the directory where the generated sources are placed.


1 Answers

Try:

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

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

like image 100
Ethan Koenig Avatar answered Sep 29 '22 11:09

Ethan Koenig