2

Say I have documented a variable in a Python module, like so:

some_random_name = 'whatever'
"""The random whatever variable"""

Can I include autodocs for that single variable in my .rst file, without also dragging in the module __doc__ string and generating documentation output for that too?

I have tried

.. automodule: themodule
   :members: some_random_name

but that both drags in the __doc__ string and does not show autodocs for some_random_name.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Prof. Falken
  • 24,226
  • 19
  • 100
  • 173

1 Answers1

2

I cannot reproduce the problem with documenting the module attribute. It works for me. Do you by any chance have an __all__ variable in your module whose value does not include some_random_name? Sphinx considers __all__ when looking for members.

The module docstring can be removed by intercepting the autodoc-process-docstring event. Here is a demonstration (add the code to conf.py):

import inspect

def remove_mod_docstring(app, what, name, obj, options, lines):
    """Erase module docstring in-place"""  
    if inspect.ismodule(obj):
        for i in xrange(len(lines)):
            lines[i] = ''

def setup(app):
    app.connect('autodoc-process-docstring', remove_mod_docstring)
mzjn
  • 48,958
  • 13
  • 128
  • 248