jbasko
jbasko

Reputation: 7330

In Sphinx, document attributes provided via __getattr__

In Python's Sphinx, how do I document attributes that are available thanks to __getattr__?

I have an instance of some config manager that allows accessing any section of the configuration via attribute that matches a section name i.e. config_manager.<section_name>.

For now I document this inside .rst file (but would prefer in code) with something like this:

.. autoclass:: ConfigManager
    :members:
    :var .<section_name>: Access any section of the configuration by its name.

but this doesn't appear too prominently in the docs, even though providing this kind of access is one of the main purposes of that class.

Upvotes: 1

Views: 299

Answers (1)

mzjn
mzjn

Reputation: 50977

You could use the .. attribute:: directive, like this:

.. autoclass:: ConfigManager
    :members:

    .. attribute:: <section_name>

       Access any section of the configuration by its name.

The attributes will appear before the methods (and presented like the methods) in the output.

Upvotes: 1

Related Questions