当前位置: 首页 > 文档资料 > Sphinx 中文文档 >

sphinx.ext.autodoc – Include documentation from docstrings

优质
小牛编辑
127浏览
2023-12-01

This extension can import the modules you are documenting, and pull in documentation from docstrings in a semi-automatic way.

Note

For Sphinx (actually, the Python interpreter that executes Sphinx) to find your module, it must be importable. That means that the module or the package must be in one of the directories on sys.path – adapt your sys.path in the configuration file accordingly.

For this to work, the docstrings must of course be written in correct reStructuredText. You can then use all of the usual Sphinx markup in the docstrings, and it will end up correctly in the documentation. Together with hand-written documentation, this technique eases the pain of having to maintain two locations for documentation, while at the same time avoiding auto-generated-looking pure API documentation.

autodoc provides several directives that are versions of the usual py:module, py:class and so forth. On parsing time, they import the corresponding module and extract the docstring of the given objects, inserting them into the page source under a suitable py:module, py:class etc. directive.

Note

Just as py:class respects the current py:module,

New in version 0.5.

Emitted when autodoc has to decide whether a member should be included in the documentation. The member is excluded if a handler returns True. It is included if the handler returns False.

Parameters:
  • app – the Sphinx application object
  • what – the type of the object which the docstring belongs to (one of "module", "class", "exception", "function", "method", "attribute")
  • name – the fully qualified name of the object
  • obj – the object itself
  • skip – a boolean indicating if autodoc will skip this member if the user handler does not override the decision
  • options – the options given to the directive: an object with attributes inherited_members, undoc_members, show_inheritance and noindex that are true if the flag option of same name was given to the auto directive