Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sphinx autodoc show-inheritance: How to skip undocumented, intermediate bases?

I have a three-layered class structure like this:

class Super(object):
    """This class is documented."""

class Intermediate(Super):
    pass

class Sub(Intermediate):
    """This is also documented."""

My index.rst file looks as follows:

.. automodule:: mymodule
   :show-inheritance:
   :inherited-members:

Sphinx generates a nice API documentation for me. It includes the classes Super and Sub, with the appropriate comments. It does not include Intermediate, because it doesn't have a comment and I did not supply the undoc-members flag. This is because I don't want Intermediate to show up in the documentation.

My problem is this: Because I supply the show-inheritance flag, Sphinx displays the bases for each class; object for Super and Intermediate for Sub. Since Intermediate is undocumented, I do not want it to show up in the list of base classes. Instead, I'd like Sphinx to display the next documented class up in the inheritance tree, Super. In other words: I want Sphinx to display Super, not Intermediate as the base class of Sub.

Does anybody know how to do this?

like image 877
Michael Herrmann Avatar asked Jun 22 '13 20:06

Michael Herrmann


1 Answers

For this peculiar situation, where you want to "hide" the class inheritance, you can use autoclass to document each visible class instead of documenting the whole module.

For instance:

.. currentmodule:: demo

.. autoclass:: Super
   :members:

.. autoclass:: Sub
   :members:

Then you can add the :show-inheritance: flag to show inheritace to the class you want.

Quoting the doc:

The automodule, autoclass and autoexception directives also support a flag option called show-inheritance. When given, a list of base classes will be inserted just below the class signature (when used with automodule, this will be inserted for every class that is documented in the module).

like image 184
Laurent LAPORTE Avatar answered Sep 24 '22 12:09

Laurent LAPORTE