1

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.

4
  • What do you mean by "this doesn't appear too prominently"? Does anything appear at all? Commented May 7, 2017 at 8:32
  • Methods appear what I would call prominently. This thing I have annotated with :var appears just under class description as "Variables: bullet list". I wanted them to appear as methods too. Commented May 7, 2017 at 9:11
  • Why do you want them to appear "as methods"? They are not methods. Am I missing something? Commented May 7, 2017 at 9:17
  • They are effectively public members. My mistake, I don't want them to appear as methods, just like methods (or properties, or public attributes). Commented May 7, 2017 at 9:29

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is perfect. Thanks! It even works when I move it to the docstring of the class.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.