5

I want to have automatic documentation for module variables, but it just not work. All variables is missing in the doc... How can I fix this, so autodoc will list every module variable?

mypackage/__init__.py:

class __init__:
    test = 'test'
    _test = '_test'
    __test = '__test'
    __test__ = '__test__'

__author__ = 'author'
__email__ = 'author_email'
__description__ = 'description'
__version__ = 'version'

And docs image:

enter image description here

mzjn
  • 48,958
  • 13
  • 128
  • 248
  • Modules by underscore are considered module internal by Python best practices and autodoc does not document them by default, I guess. You can check Sphinx documentation for option for this or explicitly set `__all__` to tell what module variables you are exporting. – Mikko Ohtamaa Aug 01 '15 at 18:20
  • I tried but no luck with that. I think this is a bug... –  Aug 01 '15 at 19:58

2 Answers2

0

Use :special-members:

.. autoclass:: my.Class
   :members:
   :private-members:
   :special-members:

http://sphinx-doc.org/ext/autodoc.html

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • 1
    I have allready did this in conf.py file... `autodoc_default_flags = ['members','special-members','private-members','undoc-members']` and because I see class privates and specijal I know this allready works, but not for module privates... Maybe there is python version diference? –  Aug 01 '15 at 21:02
0

I have been reading many posts about this and It took some time before I finally got it working. I know it is a old post but I still hope my code helps somebody else. Automodule does support it but for some reason it does not like comments above the variable which always has been my preferred way of commenting.

config.py:

my_var = None
"""
This is my variable
"""

# This is not found because Sphinx does not like comments above variables
my_var_not_found = None

.rst file:

.. automodule:: config
   :special-members:

HTML result:

config.my_var = None
     This is my variable