【问题标题】:Why Sphinx do not autodoc module variables?为什么 Sphinx 不自动生成模块变量?
【发布时间】:2015-08-01 16:11:29
【问题描述】:

我想要自动记录模块变量,但它不起作用。文档中缺少所有变量...我该如何解决这个问题,所以 autodoc 会列出每个模块变量?

mypackage/__init__.py

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

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

还有文档图片:

【问题讨论】:

  • 下划线的模块被 Python 最佳实践视为内部模块,我猜 autodoc 默认情况下不会记录它们。您可以查看 Sphinx 文档以获取此选项或明确设置 __all__ 以告知您要导出的模块变量。
  • 我试过了,但没有运气。我认为这是一个错误......

标签: python-sphinx autodoc


【解决方案1】:

使用:special-members:

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

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

【讨论】:

  • 我已经在 conf.py 文件中这样做了...autodoc_default_flags = ['members','special-members','private-members','undoc-members'] 并且因为我看到了类私有和特殊我知道这已经有效,但不适用于模块私有...也许有 python版本差异?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-07
  • 1970-01-01
  • 2015-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多