2024-06-21 13:12:57 -05:00
|
|
|
|
.. _ext-autodoc:
|
|
|
|
|
|
2008-03-12 16:37:22 -05:00
|
|
|
|
:mod:`sphinx.ext.autodoc` -- Include documentation from docstrings
|
|
|
|
|
==================================================================
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. py:module:: sphinx.ext.autodoc
|
2008-03-12 16:37:22 -05:00
|
|
|
|
:synopsis: Include documentation from docstrings.
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
|
|
|
|
.. index:: pair: automatic; documentation
|
|
|
|
|
single: docstring
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
This extension can import the modules you are documenting,
|
|
|
|
|
and pull in documentation from docstrings in a semi-automatic way.
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2014-03-05 00:45:45 -06:00
|
|
|
|
.. warning::
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
:mod:`~sphinx.ext.autodoc` **imports** the modules to be documented.
|
|
|
|
|
If any modules have side effects on import,
|
|
|
|
|
these will be executed by ``autodoc`` when :program:`sphinx-build` is run.
|
2014-03-05 00:45:45 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
If you document scripts (as opposed to library modules),
|
|
|
|
|
make sure that the main routine is protected by
|
|
|
|
|
an ``if __name__ == '__main__'`` condition.
|
2014-03-05 00:45:45 -06:00
|
|
|
|
|
2008-03-14 18:35:08 -05:00
|
|
|
|
For this to work, the docstrings must of course be written in correct
|
2024-10-01 08:15:24 -05:00
|
|
|
|
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.
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2014-01-19 12:43:54 -06:00
|
|
|
|
If you prefer `NumPy`_ or `Google`_ style docstrings over reStructuredText,
|
|
|
|
|
you can also enable the :mod:`napoleon <sphinx.ext.napoleon>` extension.
|
2024-10-01 08:15:24 -05:00
|
|
|
|
:mod:`!napoleon` is a preprocessor that converts docstrings
|
|
|
|
|
to correct reStructuredText before ``autodoc`` processes them.
|
2014-01-19 12:43:54 -06:00
|
|
|
|
|
2024-03-25 05:39:05 -05:00
|
|
|
|
.. _Google: https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings
|
2021-07-08 15:34:25 -05:00
|
|
|
|
.. _NumPy: https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard
|
2014-01-19 12:43:54 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
|
2024-06-17 04:58:55 -05:00
|
|
|
|
Getting started
|
|
|
|
|
---------------
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
|
2024-06-17 04:58:55 -05:00
|
|
|
|
Setup
|
2024-10-01 08:15:24 -05:00
|
|
|
|
^^^^^
|
|
|
|
|
|
|
|
|
|
Activate the plugin by adding ``'sphinx.ext.autodoc'`` to
|
|
|
|
|
the :confval:`extensions` list in :file:`conf.py`:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
2024-06-17 04:58:55 -05:00
|
|
|
|
|
|
|
|
|
extensions = [
|
|
|
|
|
...
|
|
|
|
|
'sphinx.ext.autodoc',
|
|
|
|
|
]
|
2018-08-26 09:29:00 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
|
2024-06-12 04:43:33 -05:00
|
|
|
|
Ensuring the code can be imported
|
2024-10-01 08:15:24 -05:00
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2024-06-12 04:43:33 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
:mod:`~sphinx.ext.autodoc` analyses the code and docstrings
|
|
|
|
|
by introspection after **importing the modules**.
|
|
|
|
|
For importing to work, you have to make sure that your modules can be found
|
|
|
|
|
by Sphinx and that dependencies can be resolved
|
|
|
|
|
(if your module does ``import foo``, but ``foo`` is not available
|
|
|
|
|
in the python environment that Sphinx runs in, your module import will fail).
|
2024-06-12 04:43:33 -05:00
|
|
|
|
|
|
|
|
|
There are two ways to ensure this:
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
1. Use an environment that contains your package and Sphinx.
|
|
|
|
|
This can e.g. be your local development environment (with an editable install),
|
|
|
|
|
or an environment in CI in which you install Sphinx and your package.
|
|
|
|
|
The regular installation process ensures that your package can be found
|
|
|
|
|
by Sphinx and that all dependencies are available.
|
2024-06-12 04:43:33 -05:00
|
|
|
|
|
|
|
|
|
2. It is alternatively possible to patch the Sphinx run so that it can operate
|
2024-10-01 08:15:24 -05:00
|
|
|
|
directly on the sources;
|
|
|
|
|
e.g. if you want to be able to do a Sphinx build from a source checkout.
|
|
|
|
|
|
|
|
|
|
* Patch :data:`sys.path` in :file:`conf.py` to include your source path.
|
|
|
|
|
For example if you have a repository structure with :file:`doc/conf.py`
|
|
|
|
|
and your package is at :file:`src/my_package`,
|
|
|
|
|
then you should add the following to your :file:`conf.py`.
|
2024-06-12 04:43:33 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
from pathlib import Path
|
2024-06-12 04:43:33 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
sys.path.insert(0, str(Path('..', 'src').resolve()))
|
2024-06-12 04:43:33 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
* To cope with missing dependencies, specify the missing modules in
|
|
|
|
|
the :confval:`autodoc_mock_imports` setting.
|
2024-06-12 04:43:33 -05:00
|
|
|
|
|
|
|
|
|
|
2024-06-17 04:58:55 -05:00
|
|
|
|
Usage
|
2024-10-01 08:15:24 -05:00
|
|
|
|
^^^^^
|
2024-06-17 04:58:55 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
You can now use the :ref:`autodoc-directives` to add formatted documentation
|
|
|
|
|
for Python code elements like functions, classes, modules, etc.
|
|
|
|
|
For example, to document the function ``io.open()``,
|
|
|
|
|
reading its signature and docstring from the source file, you'd write:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
2024-06-17 04:58:55 -05:00
|
|
|
|
|
|
|
|
|
.. autofunction:: io.open
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
You can also document whole classes or even modules automatically,
|
|
|
|
|
using member options for the auto directives, like:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
2024-06-17 04:58:55 -05:00
|
|
|
|
|
|
|
|
|
.. automodule:: io
|
|
|
|
|
:members:
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. tip::
|
|
|
|
|
As a hint to autodoc extension, you can put a ``::`` separator
|
|
|
|
|
between the module name and the object name
|
|
|
|
|
to let autodoc know the correct module, if it is ambiguous:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autoclass:: module.name::Noodle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Marking objects as public or private
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
* autodoc considers a member private if its docstring contains
|
|
|
|
|
``:meta private:`` in its :ref:`info-field-lists`.
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
def my_function(my_arg, my_other_arg):
|
|
|
|
|
"""blah blah blah
|
|
|
|
|
|
|
|
|
|
:meta private:
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 3.0
|
|
|
|
|
|
|
|
|
|
* autodoc considers a member public if its docstring contains
|
|
|
|
|
``:meta public:`` in its :ref:`info-field-lists`, even if it starts with
|
|
|
|
|
an underscore.
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
def _my_function(my_arg, my_other_arg):
|
|
|
|
|
"""blah blah blah
|
|
|
|
|
|
|
|
|
|
:meta public:
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 3.1
|
|
|
|
|
|
|
|
|
|
* autodoc considers a variable member does not have any default value if its
|
|
|
|
|
docstring contains ``:meta hide-value:`` in its :ref:`info-field-lists`.
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
var1 = None #: :meta hide-value:
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 3.5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _doc-comment:
|
|
|
|
|
|
|
|
|
|
Doc comments and docstrings
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
Python has no built-in support for docstrings for
|
|
|
|
|
module data members or class attributes.
|
|
|
|
|
To allow documenting these, ``autodoc`` recognises a special format of
|
|
|
|
|
:ref:`comment <python:comments>` called a 'doc comment' or 'documentation comment'.
|
|
|
|
|
|
|
|
|
|
These comments start with a colon and an optional space character,
|
|
|
|
|
``'#:'`` or ``'#: '``.
|
|
|
|
|
To be recognised, the comments must appear either on the same line
|
|
|
|
|
as the variable or on one or more lines before the variable.
|
|
|
|
|
Multi-line doc-comments must always appear on the lines before the
|
|
|
|
|
variable's definition.
|
|
|
|
|
|
|
|
|
|
For example, all three of the following variables have valid doc-comments:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
egg_and_spam = 1.50 #: A simple meal
|
|
|
|
|
|
|
|
|
|
#: Spam! Lovely spam! Lovely spam!
|
|
|
|
|
egg_bacon_sausage_and_spam = 2.49
|
|
|
|
|
|
|
|
|
|
#: Truly gourmet cuisine for madam; Lobster Thermidor
|
|
|
|
|
#: aux Crevettes with a mornay sauce garnished with
|
|
|
|
|
#: truffle pate, brandy and a fried egg on top and spam.
|
|
|
|
|
lobster_thermidor = 35.00
|
|
|
|
|
|
|
|
|
|
Alternatively, ``autodoc`` can recognise a docstring
|
|
|
|
|
on the line immediately following the definition.
|
|
|
|
|
|
|
|
|
|
In the the following class definition,
|
|
|
|
|
all attributes have documentation recognised by ``autodoc``:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
class Foo:
|
|
|
|
|
"""Docstring for class Foo."""
|
|
|
|
|
|
|
|
|
|
#: Doc comment for class attribute Foo.bar.
|
|
|
|
|
#: It can have multiple lines.
|
|
|
|
|
bar = 1
|
|
|
|
|
|
|
|
|
|
flox = 1.5 #: Doc comment for Foo.flox. One line only.
|
|
|
|
|
|
|
|
|
|
baz = 2
|
|
|
|
|
"""Docstring for class attribute Foo.baz."""
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
#: Doc comment for instance attribute qux.
|
|
|
|
|
self.qux = 3
|
|
|
|
|
|
|
|
|
|
self.spam = 4
|
|
|
|
|
"""Docstring for instance attribute spam."""
|
|
|
|
|
|
|
|
|
|
|
2024-06-17 04:58:55 -05:00
|
|
|
|
.. _autodoc-directives:
|
2024-06-12 04:43:33 -05:00
|
|
|
|
|
2018-08-26 09:29:00 -05:00
|
|
|
|
Directives
|
|
|
|
|
----------
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
:mod:`autodoc` provides several directives that are versions of
|
|
|
|
|
the usual :rst:dir:`py:module`, :rst:dir:`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
|
|
|
|
|
:rst:dir:`py:module`, :rst:dir:`py:class` etc. directive.
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Just as :rst:dir:`py:class` respects the current
|
|
|
|
|
:rst:dir:`py:module`, :rst:dir:`autoclass` will also do so.
|
|
|
|
|
Likewise, :rst:dir:`automethod` will respect the current :rst:dir:`py:class`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Default directive options
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
To make any of the options described below the default,
|
|
|
|
|
use the :confval:`autodoc_default_options` dictionary in :file:`conf.py`.
|
|
|
|
|
|
|
|
|
|
If using defaults for the ``:members:``, ``:exclude-members:``,
|
|
|
|
|
``:private-members:``, or ``:special-members:`` options,
|
|
|
|
|
setting the option on a directive will override the default.
|
|
|
|
|
Instead, to extend the default list with the per-directive option,
|
|
|
|
|
the list may be prepended with a plus sign (``+``),
|
|
|
|
|
as follows:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autoclass:: Noodle
|
|
|
|
|
:members: eat
|
|
|
|
|
:private-members: +_spicy, _garlickly
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. tip::
|
|
|
|
|
If using :confval:`autodoc_default_options`,
|
|
|
|
|
the defaults can be disabled per-directive with the negated form,
|
|
|
|
|
:samp:`:no-{option}:` as an option of the directive
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. automodule:: foo
|
|
|
|
|
:no-undoc-members:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Automatically document modules
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
|
.. rst:directive:: automodule
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Document a module.
|
|
|
|
|
By default, the directive only inserts the docstring of the module itself:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. automodule:: noodles
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
will produce source like this:
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. py:module:: noodles
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
The noodles module.
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
The directive can also contain content of its own,
|
|
|
|
|
which will be inserted into the resulting non-auto directive source
|
|
|
|
|
after the docstring (but before any automatic member documentation).
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2008-06-17 04:24:11 -05:00
|
|
|
|
Therefore, you can also mix automatic and non-automatic member documentation,
|
2024-10-01 08:15:24 -05:00
|
|
|
|
as follows:
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. automodule:: noodles
|
|
|
|
|
:members: Noodle
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. py:function:: boiled_noodle(time=10)
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Create a noodle that has been boiled for *time* minutes.
|
2008-05-23 08:57:48 -05:00
|
|
|
|
|
2021-03-06 03:57:18 -06:00
|
|
|
|
.. rubric:: Options
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:option:: no-index
|
|
|
|
|
:type:
|
|
|
|
|
|
|
|
|
|
Do not generate an index entry for the documented module
|
|
|
|
|
or any auto-documented members.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 0.4
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: platform: platforms
|
|
|
|
|
:type: comma separated list
|
|
|
|
|
|
|
|
|
|
Indicate platforms on which the module is available.
|
|
|
|
|
This is identical to :rst:dir:`py:module`'s ``:platform:`` option.
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: synopsis: purpose
|
|
|
|
|
:type: text
|
|
|
|
|
|
|
|
|
|
A sentence describing the module's purpose.
|
|
|
|
|
This is identical to :rst:dir:`py:module`'s ``:synopsis:`` option.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 0.5
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: deprecated
|
|
|
|
|
:type:
|
|
|
|
|
|
|
|
|
|
Mark a module as deprecated.
|
|
|
|
|
This is identical to :rst:dir:`py:module`'s ``:deprecated:`` option.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 0.5
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: ignore-module-all
|
|
|
|
|
:type: no value
|
|
|
|
|
|
|
|
|
|
Do not use ``__all__`` when analysing the module to document.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 1.7
|
|
|
|
|
|
|
|
|
|
.. rubric:: Options for selecting members to document
|
|
|
|
|
|
2021-03-06 03:57:18 -06:00
|
|
|
|
.. rst:directive:option:: members
|
|
|
|
|
:type: no value or comma separated list
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Generate automatic documentation for all members of the target module:
|
2009-01-10 15:18:18 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. automodule:: noodles
|
|
|
|
|
:members:
|
2009-09-09 11:26:59 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
By default, ``autodoc`` only includes public members
|
|
|
|
|
with a docstring or :ref:`doc-comment <doc-comment>` (``#:``).
|
|
|
|
|
If ``__all__`` exists, it will be used to define which members are public,
|
|
|
|
|
unless the ``:ignore-module-all:`` option is set.
|
2009-09-09 11:26:59 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
To only document certain members, an explicit comma-separated list
|
|
|
|
|
may be used as the argument to ``:members:``:
|
2008-05-23 08:57:48 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2009-09-09 11:26:59 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. automodule:: noodles
|
|
|
|
|
:members: Noodle
|
2010-08-05 11:59:04 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:option:: exclude-members
|
|
|
|
|
:type: comma separated list
|
2021-03-06 03:57:18 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Exclude the given names from the members to document.
|
|
|
|
|
For example:
|
2008-05-23 08:57:48 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2008-05-23 08:57:48 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. automodule:: noodles
|
|
|
|
|
:members:
|
|
|
|
|
:exclude-members: NoodleBase
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 0.6
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: imported-members
|
2021-03-06 04:08:23 -06:00
|
|
|
|
:type: no value
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
To prevent documentation of imported classes or functions,
|
|
|
|
|
in an :rst:dir:`!automodule` directive with the ``members`` option set,
|
|
|
|
|
only module members where the ``__module__`` attribute is equal
|
|
|
|
|
to the module name given to ``automodule`` will be documented.
|
2021-03-06 04:08:23 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Set the ``imported-members`` option if you want to prevent this behavior
|
|
|
|
|
and document all available members.
|
|
|
|
|
|
|
|
|
|
Note that attributes from imported modules will not be documented,
|
|
|
|
|
because attribute documentation is discovered by
|
|
|
|
|
parsing the source file of the current module.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 1.2
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: undoc-members
|
|
|
|
|
:type:
|
|
|
|
|
|
|
|
|
|
Generate automatic documentation for members of the target module
|
|
|
|
|
that don't have a docstring or doc-comment.
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. automodule:: noodles
|
|
|
|
|
:members:
|
|
|
|
|
:undoc-members:
|
2021-03-06 04:08:23 -06:00
|
|
|
|
|
2021-03-06 04:10:16 -06:00
|
|
|
|
.. rst:directive:option:: private-members
|
|
|
|
|
:type: no value or comma separated list
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Generate automatic documentation for private members of the target module.
|
|
|
|
|
This includes names with a leading underscore (e.g. ``_private``)
|
|
|
|
|
and those members explicitly marked as private with ``:meta private:``.
|
2021-03-06 04:10:16 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2021-03-06 04:10:16 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. automodule:: noodles
|
|
|
|
|
:members:
|
|
|
|
|
:private-members:
|
2021-03-06 04:10:16 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
To only document certain private members, an explicit comma-separated list
|
|
|
|
|
may be used as the argument to ``:private-members:``:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. automodule:: noodles
|
|
|
|
|
:members:
|
|
|
|
|
:private-members: _spicy, _garlickly
|
2021-03-06 04:10:16 -06:00
|
|
|
|
|
|
|
|
|
.. versionadded:: 1.1
|
|
|
|
|
.. versionchanged:: 3.2
|
2024-10-01 08:15:24 -05:00
|
|
|
|
The option can now take a comma-separated list of arguments.
|
2021-03-06 04:10:16 -06:00
|
|
|
|
|
2021-03-06 04:12:10 -06:00
|
|
|
|
.. rst:directive:option:: special-members
|
|
|
|
|
:type: no value or comma separated list
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Generate automatic documentation for special members of the target module,
|
|
|
|
|
also known as :ref:`"dunder" names <python:specialnames>`.
|
|
|
|
|
This includes all names enclosed with a double-underscore,
|
|
|
|
|
e.g. ``__special__``:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
2021-03-06 04:12:10 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. automodule:: my.Class
|
|
|
|
|
:members:
|
|
|
|
|
:special-members:
|
2021-03-06 04:12:10 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
To only document certain special members, an explicit comma-separated list
|
|
|
|
|
may be used as the argument to ``:special-members:``:
|
2021-03-06 04:12:10 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. automodule:: noodles
|
|
|
|
|
:members:
|
|
|
|
|
:special-members: __version__
|
2021-03-06 04:12:10 -06:00
|
|
|
|
|
2021-03-06 06:19:26 -06:00
|
|
|
|
.. versionadded:: 1.1
|
2021-03-06 04:12:10 -06:00
|
|
|
|
|
2021-03-06 06:19:26 -06:00
|
|
|
|
.. versionchanged:: 1.2
|
2024-10-01 08:15:24 -05:00
|
|
|
|
The option can now take a comma-separated list of arguments.
|
2021-03-06 04:12:10 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rubric:: Options for documented members
|
2021-03-06 03:57:18 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:option:: member-order
|
|
|
|
|
:type: alphabetical, bysource, or groupwise
|
2018-08-18 03:40:38 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Choose the ordering of automatically documented members
|
|
|
|
|
(default: ``alphabetical``).
|
|
|
|
|
This overrides the :confval:`autodoc_member_order` setting.
|
2018-08-18 03:40:38 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
* ``alphabetical``:
|
|
|
|
|
Use simple alphabetical order.
|
|
|
|
|
* ``groupwise``:
|
|
|
|
|
Group by object type (class, function, etc),
|
|
|
|
|
use alphabetical order within groups.
|
|
|
|
|
* ``bysource``:
|
|
|
|
|
Use the order of objects in the module's source.
|
|
|
|
|
The ``__all__`` variable can be used to override this order.
|
2018-08-18 03:40:38 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Note that for source order, the module must be a Python module with the
|
|
|
|
|
source code available.
|
2018-08-18 03:40:38 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. versionadded:: 0.6
|
|
|
|
|
.. versionchanged:: 1.0
|
|
|
|
|
Support the ``'bysource'`` option.
|
2021-02-01 03:28:01 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:option:: show-inheritance
|
|
|
|
|
:type: no value
|
2021-02-01 03:28:01 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Enable the ``:show-inheritance:`` option for all members of the module,
|
|
|
|
|
if ``:members:`` is enabled.
|
2021-02-01 03:28:01 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. versionadded:: 0.4
|
2010-03-14 13:46:54 -05:00
|
|
|
|
|
2019-12-31 23:40:13 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Automatically document classes or exceptions
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2019-12-31 23:40:13 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:: autoclass
|
|
|
|
|
autoexception
|
2019-12-31 23:40:13 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Document a class.
|
|
|
|
|
For exception classes, prefer ``autoexception``.
|
|
|
|
|
By default, the directive only inserts the docstring of the class itself:
|
2019-12-31 23:40:13 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2019-12-31 23:40:13 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. autoclass:: noodles.Noodle
|
2020-04-13 09:55:07 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
will produce source like this:
|
2020-04-13 09:55:07 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2020-04-13 09:55:07 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. py:class:: Noodle
|
2020-04-13 09:55:07 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
The Noodle class's docstring.
|
2020-04-13 09:55:07 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
The directive can also contain content of its own,
|
|
|
|
|
which will be inserted into the resulting non-auto directive source
|
|
|
|
|
after the docstring (but before any automatic member documentation).
|
2020-12-24 23:28:28 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Therefore, you can also mix automatic and non-automatic member documentation,
|
|
|
|
|
as follows:
|
2020-12-24 23:28:28 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2020-12-24 23:28:28 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. autoclass:: noodles.Noodle
|
|
|
|
|
:members: eat, slurp
|
2020-12-24 23:28:28 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. py:method:: boil(time=10)
|
2008-05-06 13:07:17 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Boil the noodle for *time* minutes.
|
2008-05-06 13:07:17 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rubric:: Advanced usage
|
2008-05-06 13:07:17 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
* It is possible to override the signature for explicitly documented
|
|
|
|
|
callable objects (functions, methods, classes) with the regular syntax
|
|
|
|
|
that will override the signature gained from introspection:
|
2019-11-30 02:21:21 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2019-12-22 01:05:45 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. autoclass:: noodles.Noodle(type)
|
2019-12-22 01:05:45 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. automethod:: eat(persona)
|
2022-04-02 11:42:16 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
This is useful if the signature from the method is hidden by a decorator.
|
2009-09-09 12:10:24 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. versionadded:: 0.4
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rubric:: Options
|
2019-11-30 02:21:21 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:option:: no-index
|
|
|
|
|
:type:
|
2019-11-30 02:21:21 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Do not generate an index entry for the documented class
|
|
|
|
|
or any auto-documented members.
|
2022-04-02 11:42:16 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. versionadded:: 0.4
|
2022-04-02 11:42:16 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:option:: class-doc-from
|
|
|
|
|
:type: class, init, or both
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Select which docstring will be used for the main body of the directive.
|
|
|
|
|
This overrides the global value of :confval:`autoclass_content`.
|
|
|
|
|
The possible values are:
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
* ``class``:
|
|
|
|
|
Only use the class's docstring.
|
|
|
|
|
The :meth:`!__init__` method can be separately documented
|
|
|
|
|
using the ``:members:`` option or :rst:dir:`automethod`.
|
|
|
|
|
* ``init``:
|
|
|
|
|
Only use the docstring of the :meth:`!__init__` method.
|
|
|
|
|
* ``both``
|
|
|
|
|
Use both, appending the docstring of the :meth:`!__init__` method
|
|
|
|
|
to the class's docstring.
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
If the :meth:`!__init__` method doesn't exist or has a blank docstring,
|
|
|
|
|
``autodoc`` will attempt to use the :meth:`!__new__` method's docstring,
|
|
|
|
|
if it exists and is not blank.
|
2008-06-17 04:24:11 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. versionadded:: 4.1
|
2008-06-17 04:24:11 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rubric:: Options for selecting members to document
|
2008-06-17 04:24:11 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:option:: members
|
|
|
|
|
:type: no value or comma separated list
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Generate automatic documentation for all members of the target class:
|
2008-06-22 12:58:05 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autoclass:: noodles.Noodle
|
|
|
|
|
:members:
|
|
|
|
|
|
|
|
|
|
By default, ``autodoc`` only includes public members
|
|
|
|
|
with a docstring or :ref:`doc-comment <doc-comment>` (``#:``)
|
|
|
|
|
that are attributes of the target class (i.e. not inherited).
|
|
|
|
|
|
|
|
|
|
To only document certain members, an explicit comma-separated list
|
|
|
|
|
may be used as the argument to ``:members:``:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autoclass:: noodles.Noodle
|
|
|
|
|
:members: eat, slurp
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: exclude-members
|
|
|
|
|
:type: comma separated list
|
|
|
|
|
|
|
|
|
|
Exclude the given names from the members to document.
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autoclass:: noodles.Noodle
|
|
|
|
|
:members:
|
|
|
|
|
:exclude-members: prepare
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 0.6
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: inherited-members
|
|
|
|
|
:type: comma separated list
|
|
|
|
|
|
|
|
|
|
To generate automatic documentation for members inherited
|
|
|
|
|
from base classes, use the ``:inherited-members:`` option:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autoclass:: noodles.Noodle
|
|
|
|
|
:members:
|
|
|
|
|
:inherited-members:
|
|
|
|
|
|
|
|
|
|
This can be combined with the ``:undoc-members:`` option to generate
|
|
|
|
|
automatic documentation for *all* available members of the class.
|
|
|
|
|
|
|
|
|
|
The members of classes listed in the argument to ``:inherited-members:``
|
|
|
|
|
are excluded from the automatic documentation.
|
|
|
|
|
This defaults to :py:class:`python:object` if no argument is provided,
|
|
|
|
|
meaning that members of the ``object`` class are not documented.
|
|
|
|
|
To include these, use ``None`` as the argument.
|
|
|
|
|
|
|
|
|
|
For example; If your class ``MyList`` is derived from ``list`` class and
|
|
|
|
|
you don't want to document ``list.__len__()``, you should specify a
|
|
|
|
|
option ``:inherited-members: list`` to avoid special members of list
|
|
|
|
|
class.
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
Should any of the inherited members use a format other than
|
|
|
|
|
reStructuredText for their docstrings,
|
|
|
|
|
there may be markup warnings or errors.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 0.3
|
|
|
|
|
|
|
|
|
|
.. versionchanged:: 3.0
|
|
|
|
|
``:inherited-members:`` now takes the name of a base class
|
|
|
|
|
to exclude as an argument.
|
|
|
|
|
|
|
|
|
|
.. versionchanged:: 5.0
|
|
|
|
|
A comma separated list of base class names can be used.
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: undoc-members
|
|
|
|
|
:type: no value
|
|
|
|
|
|
|
|
|
|
Generate automatic documentation for members of the target class
|
|
|
|
|
that don't have a docstring or doc-comment.
|
|
|
|
|
For example:
|
2008-06-22 12:58:05 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2008-07-08 09:45:44 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. autoclass:: noodles.Noodle
|
|
|
|
|
:members:
|
|
|
|
|
:undoc-members:
|
2008-07-08 09:45:44 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:option:: private-members
|
|
|
|
|
:type: no value or comma separated list
|
|
|
|
|
|
|
|
|
|
Generate automatic documentation for private members of the target class.
|
|
|
|
|
This includes names with a leading underscore (e.g. ``_private``)
|
|
|
|
|
and those members explicitly marked as private with ``:meta private:``.
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autoclass:: noodles.Noodle
|
|
|
|
|
:members:
|
|
|
|
|
:private-members:
|
|
|
|
|
|
|
|
|
|
To only document certain private members, an explicit comma-separated list
|
|
|
|
|
may be used as the argument to ``:private-members:``:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autoclass:: noodles.Noodle
|
|
|
|
|
:members:
|
|
|
|
|
:private-members: _spicy, _garlickly
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 1.1
|
|
|
|
|
.. versionchanged:: 3.2
|
|
|
|
|
The option can now take arguments.
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: special-members
|
|
|
|
|
:type: no value or comma separated list
|
|
|
|
|
|
|
|
|
|
Generate automatic documentation for special members of the target class,
|
|
|
|
|
also known as :ref:`"dunder" names <python:specialnames>`.
|
|
|
|
|
This includes all names enclosed with a double-underscore,
|
|
|
|
|
e.g. ``__special__``:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autoclass:: noodles.Noodle
|
|
|
|
|
:members:
|
|
|
|
|
:special-members:
|
|
|
|
|
|
|
|
|
|
To only document certain special members, an explicit comma-separated list
|
|
|
|
|
may be used as the argument to ``:special-members:``:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autoclass:: noodles.Noodle
|
|
|
|
|
:members:
|
|
|
|
|
:special-members: __init__, __name__
|
2009-02-27 08:48:41 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. versionadded:: 1.1
|
|
|
|
|
|
|
|
|
|
.. versionchanged:: 1.2
|
|
|
|
|
The option can now take a comma-separated list of arguments.
|
2009-02-27 08:48:41 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rubric:: Options for documented members
|
2009-03-15 17:52:48 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:option:: member-order
|
|
|
|
|
:type: alphabetical, bysource, or groupwise
|
2009-03-15 17:52:48 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Choose the ordering of automatically documented members
|
|
|
|
|
(default: ``alphabetical``).
|
|
|
|
|
This overrides the :confval:`autodoc_member_order` setting.
|
2013-04-20 06:58:18 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
* ``'alphabetical'``:
|
|
|
|
|
Use simple alphabetical order.
|
|
|
|
|
* ``'groupwise'``:
|
|
|
|
|
Group by object type (class, function, etc),
|
|
|
|
|
use alphabetical order within groups.
|
|
|
|
|
* ``'bysource'``:
|
|
|
|
|
Use the order of objects in the module's source.
|
|
|
|
|
The ``__all__`` variable can be used to override this order.
|
2008-04-13 03:09:07 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Note that for source order, the module must be a Python module with the
|
|
|
|
|
source code available.
|
2013-10-23 03:36:45 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. versionadded:: 0.6
|
|
|
|
|
.. versionchanged:: 1.0
|
|
|
|
|
Support the ``'bysource'`` option.
|
2014-01-19 03:34:52 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:option:: show-inheritance
|
|
|
|
|
:type: no value
|
2020-06-21 09:28:03 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Insert the class's base classes after the class signature.
|
2020-06-21 09:28:03 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. versionadded:: 0.4
|
2021-05-01 00:50:46 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
|
|
|
|
|
Automatically document function-like objects
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
|
.. rst:directive:: autofunction
|
2011-01-03 14:48:37 -06:00
|
|
|
|
automethod
|
2021-07-23 09:10:45 -05:00
|
|
|
|
autoproperty
|
2024-10-01 08:15:24 -05:00
|
|
|
|
autodecorator
|
|
|
|
|
|
|
|
|
|
Document a function, method, property, or decorator.
|
|
|
|
|
By default, the directive only inserts the docstring of the function itself:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autofunction:: noodles.average_noodle
|
|
|
|
|
|
|
|
|
|
will produce source like this:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. py:function:: noodles.average_noodle
|
|
|
|
|
|
|
|
|
|
The average_noodle function's docstring.
|
|
|
|
|
|
|
|
|
|
The directive can also contain content of its own,
|
|
|
|
|
which will be inserted into the resulting non-auto directive source
|
|
|
|
|
after the docstring.
|
|
|
|
|
|
|
|
|
|
Therefore, you can also mix automatic and non-automatic documentation,
|
|
|
|
|
as follows:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autofunction:: noodles.average_noodle
|
|
|
|
|
|
|
|
|
|
.. note:: For more flexibility, use the :py:class:`!Noodle` class.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 2.0
|
|
|
|
|
:rst:dir:`autodecorator`.
|
|
|
|
|
.. versionadded:: 2.1
|
|
|
|
|
:rst:dir:`autoproperty`.
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
If you document decorated functions or methods,
|
|
|
|
|
keep in mind that ``autodoc`` retrieves its docstrings
|
|
|
|
|
by importing the module and inspecting the ``__doc__`` attribute
|
|
|
|
|
of the given function or method.
|
|
|
|
|
That means that if a decorator replaces the decorated function with another,
|
|
|
|
|
it must copy the original ``__doc__`` to the new function.
|
|
|
|
|
|
|
|
|
|
.. rubric:: Advanced usage
|
|
|
|
|
|
|
|
|
|
* It is possible to override the signature for explicitly documented
|
|
|
|
|
callable objects (functions, methods, classes) with the regular syntax
|
|
|
|
|
that will override the signature gained from introspection:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autoclass:: Noodle(type)
|
|
|
|
|
|
|
|
|
|
.. automethod:: eat(persona)
|
|
|
|
|
|
|
|
|
|
This is useful if the signature from the method is hidden by a decorator.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 0.4
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rubric:: Options
|
2013-01-22 10:58:47 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:option:: no-index
|
|
|
|
|
:type:
|
2013-01-22 10:58:47 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Do not generate an index entry for the documented function.
|
2013-02-27 09:38:55 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. versionadded:: 0.4
|
2013-02-27 09:38:55 -06:00
|
|
|
|
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Automatically document attributes or data
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2019-06-29 04:43:30 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rst:directive:: autodata
|
|
|
|
|
autoattribute
|
2020-09-18 14:16:07 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Document a module level variable or constant ('data') or class attribute.
|
|
|
|
|
By default, the directive only inserts the docstring of the variable itself:
|
2020-09-18 14:16:07 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2020-09-18 14:16:07 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. autodata:: noodles.FLOUR_TYPE
|
2011-01-15 08:40:59 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
will produce source like this:
|
2009-01-05 17:28:29 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2009-01-05 17:28:29 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. py:data:: noodles.FLOUR_TYPE
|
2009-01-05 17:28:29 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
The FLOUR_TYPE constant's docstring.
|
2011-01-15 08:40:59 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
The directive can also contain content of its own,
|
|
|
|
|
which will be inserted into the resulting non-auto directive source
|
|
|
|
|
after the docstring.
|
2011-01-03 14:48:37 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Therefore, you can also mix automatic and non-automatic member documentation,
|
|
|
|
|
as follows:
|
2011-01-03 14:48:37 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
|
|
|
|
|
|
|
|
|
.. autodata:: noodles.FLOUR_TYPE
|
|
|
|
|
|
|
|
|
|
.. hint:: Cooking time can vary by which flour type is used.
|
2009-01-05 17:28:29 -06:00
|
|
|
|
|
|
|
|
|
.. versionchanged:: 0.6
|
2024-10-01 08:15:24 -05:00
|
|
|
|
:rst:dir:`autodata` and :rst:dir:`autoattribute`
|
|
|
|
|
can now extract docstrings.
|
2011-01-15 08:40:59 -06:00
|
|
|
|
.. versionchanged:: 1.1
|
2024-10-01 08:15:24 -05:00
|
|
|
|
Doc-comments are now allowed on the same line of an assignment.
|
2013-01-22 10:58:47 -06:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. rubric:: Options
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: no-index
|
|
|
|
|
:type:
|
|
|
|
|
|
|
|
|
|
Do not generate an index entry for the documented class
|
|
|
|
|
or any auto-documented members.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 0.4
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: annotation: value
|
|
|
|
|
:type: string
|
2008-07-04 09:27:25 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. versionadded:: 1.2
|
|
|
|
|
|
|
|
|
|
By default, ``autodoc`` attempts to obtain the type annotation
|
|
|
|
|
and value of the variable by introspection,
|
|
|
|
|
displaying it after the variable's name.
|
|
|
|
|
To override this, a custom string for the variable's value
|
|
|
|
|
may be used as the argument to ``annotation``.
|
|
|
|
|
|
|
|
|
|
For example, if the runtime value of ``FILE_MODE`` is ``0o755``,
|
|
|
|
|
the displayed value will be ``493`` (as ``oct(493) == '0o755'``).
|
|
|
|
|
This can be fixed by setting ``:annotation: = 0o755``.
|
|
|
|
|
|
|
|
|
|
If ``annotation`` is used without arguments,
|
|
|
|
|
no value or type hint will be shown for the variable.
|
|
|
|
|
|
|
|
|
|
.. rst:directive:option:: no-value
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 3.4
|
|
|
|
|
|
|
|
|
|
To display the type hint of the variable without a value,
|
|
|
|
|
use the ``no-value`` option.
|
|
|
|
|
If both the ``annotation`` and ``no-value`` options are used,
|
|
|
|
|
``no-value`` has no effect.
|
2008-07-04 09:27:25 -05:00
|
|
|
|
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2018-08-26 09:29:00 -05:00
|
|
|
|
Configuration
|
|
|
|
|
-------------
|
|
|
|
|
|
2019-02-26 10:09:43 -06:00
|
|
|
|
There are also config values that you can set:
|
2008-03-14 18:35:08 -05:00
|
|
|
|
|
2008-05-04 04:37:37 -05:00
|
|
|
|
.. confval:: autoclass_content
|
|
|
|
|
|
|
|
|
|
This value selects what content will be inserted into the main body of an
|
2010-04-17 03:39:51 -05:00
|
|
|
|
:rst:dir:`autoclass` directive. The possible values are:
|
2008-05-04 04:37:37 -05:00
|
|
|
|
|
|
|
|
|
``"class"``
|
|
|
|
|
Only the class' docstring is inserted. This is the default. You can
|
2010-08-05 06:39:23 -05:00
|
|
|
|
still document ``__init__`` as a separate method using
|
|
|
|
|
:rst:dir:`automethod` or the ``members`` option to :rst:dir:`autoclass`.
|
2008-05-04 04:37:37 -05:00
|
|
|
|
``"both"``
|
|
|
|
|
Both the class' and the ``__init__`` method's docstring are concatenated
|
|
|
|
|
and inserted.
|
|
|
|
|
``"init"``
|
|
|
|
|
Only the ``__init__`` method's docstring is inserted.
|
|
|
|
|
|
2008-05-04 12:57:11 -05:00
|
|
|
|
.. versionadded:: 0.3
|
2008-06-22 16:02:50 -05:00
|
|
|
|
|
2016-02-05 12:09:43 -06:00
|
|
|
|
If the class has no ``__init__`` method or if the ``__init__`` method's
|
|
|
|
|
docstring is empty, but the class has a ``__new__`` method's docstring,
|
|
|
|
|
it is used instead.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 1.4
|
|
|
|
|
|
2020-04-13 11:57:43 -05:00
|
|
|
|
.. confval:: autodoc_class_signature
|
|
|
|
|
|
2021-08-25 16:42:27 -05:00
|
|
|
|
This value selects how the signature will be displayed for the class defined
|
2020-04-13 11:57:43 -05:00
|
|
|
|
by :rst:dir:`autoclass` directive. The possible values are:
|
|
|
|
|
|
|
|
|
|
``"mixed"``
|
|
|
|
|
Display the signature with the class name.
|
|
|
|
|
``"separated"``
|
|
|
|
|
Display the signature as a method.
|
|
|
|
|
|
|
|
|
|
The default is ``"mixed"``.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 4.1
|
|
|
|
|
|
2009-02-27 08:48:41 -06:00
|
|
|
|
.. confval:: autodoc_member_order
|
|
|
|
|
|
|
|
|
|
This value selects if automatically documented members are sorted
|
2010-02-28 04:39:13 -06:00
|
|
|
|
alphabetical (value ``'alphabetical'``), by member type (value
|
|
|
|
|
``'groupwise'``) or by source order (value ``'bysource'``). The default is
|
|
|
|
|
alphabetical.
|
|
|
|
|
|
|
|
|
|
Note that for source order, the module must be a Python module with the
|
|
|
|
|
source code available.
|
2009-02-27 08:48:41 -06:00
|
|
|
|
|
|
|
|
|
.. versionadded:: 0.6
|
2010-02-28 04:39:13 -06:00
|
|
|
|
.. versionchanged:: 1.0
|
|
|
|
|
Support for ``'bysource'``.
|
2009-02-27 08:48:41 -06:00
|
|
|
|
|
2010-02-21 15:16:06 -06:00
|
|
|
|
.. confval:: autodoc_default_flags
|
|
|
|
|
|
|
|
|
|
This value is a list of autodoc directive flags that should be automatically
|
|
|
|
|
applied to all autodoc directives. The supported flags are ``'members'``,
|
2011-01-03 14:56:41 -06:00
|
|
|
|
``'undoc-members'``, ``'private-members'``, ``'special-members'``,
|
2019-04-14 15:47:50 -05:00
|
|
|
|
``'inherited-members'``, ``'show-inheritance'``, ``'ignore-module-all'``
|
|
|
|
|
and ``'exclude-members'``.
|
2010-02-21 15:16:06 -06:00
|
|
|
|
|
2018-08-18 03:40:38 -05:00
|
|
|
|
.. versionadded:: 1.0
|
2010-02-21 15:16:06 -06:00
|
|
|
|
|
2018-08-18 03:40:38 -05:00
|
|
|
|
.. deprecated:: 1.8
|
2010-02-21 15:16:06 -06:00
|
|
|
|
|
2018-08-18 03:40:38 -05:00
|
|
|
|
Integrated into :confval:`autodoc_default_options`.
|
2010-02-21 15:16:06 -06:00
|
|
|
|
|
2018-08-18 03:40:38 -05:00
|
|
|
|
.. confval:: autodoc_default_options
|
2018-08-08 10:26:11 -05:00
|
|
|
|
|
2018-08-18 03:40:38 -05:00
|
|
|
|
The default options for autodoc directives. They are applied to all autodoc
|
2018-08-21 21:08:33 -05:00
|
|
|
|
directives automatically. It must be a dictionary which maps option names
|
2024-10-01 08:15:24 -05:00
|
|
|
|
to the values. For example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
2018-08-08 10:26:11 -05:00
|
|
|
|
|
2018-08-18 03:40:38 -05:00
|
|
|
|
autodoc_default_options = {
|
|
|
|
|
'members': 'var1, var2',
|
|
|
|
|
'member-order': 'bysource',
|
|
|
|
|
'special-members': '__init__',
|
2019-02-10 11:03:09 -06:00
|
|
|
|
'undoc-members': True,
|
2018-08-18 03:40:38 -05:00
|
|
|
|
'exclude-members': '__weakref__'
|
|
|
|
|
}
|
2018-08-08 10:26:11 -05:00
|
|
|
|
|
2019-02-10 11:03:09 -06:00
|
|
|
|
Setting ``None`` or ``True`` to the value is equivalent to giving only the
|
|
|
|
|
option name to the directives.
|
2010-02-21 15:16:06 -06:00
|
|
|
|
|
2018-10-14 19:19:03 -05:00
|
|
|
|
The supported options are ``'members'``, ``'member-order'``,
|
|
|
|
|
``'undoc-members'``, ``'private-members'``, ``'special-members'``,
|
2019-04-14 15:47:50 -05:00
|
|
|
|
``'inherited-members'``, ``'show-inheritance'``, ``'ignore-module-all'``,
|
2022-01-30 10:38:12 -06:00
|
|
|
|
``'imported-members'``, ``'exclude-members'``, ``'class-doc-from'`` and
|
|
|
|
|
``'no-value'``.
|
2018-08-08 10:26:11 -05:00
|
|
|
|
|
2018-08-18 03:40:38 -05:00
|
|
|
|
.. versionadded:: 1.8
|
2018-08-08 10:26:11 -05:00
|
|
|
|
|
2019-02-10 11:03:09 -06:00
|
|
|
|
.. versionchanged:: 2.0
|
|
|
|
|
Accepts ``True`` as a value.
|
|
|
|
|
|
2019-04-14 15:47:50 -05:00
|
|
|
|
.. versionchanged:: 2.1
|
|
|
|
|
Added ``'imported-members'``.
|
|
|
|
|
|
2021-05-01 00:50:46 -05:00
|
|
|
|
.. versionchanged:: 4.1
|
|
|
|
|
Added ``'class-doc-from'``.
|
|
|
|
|
|
2022-01-30 10:38:12 -06:00
|
|
|
|
.. versionchanged:: 4.5
|
2022-02-06 00:30:54 -06:00
|
|
|
|
Added ``'no-value'``.
|
2022-01-30 10:38:12 -06:00
|
|
|
|
|
2011-01-03 15:51:33 -06:00
|
|
|
|
.. confval:: autodoc_docstring_signature
|
|
|
|
|
|
|
|
|
|
Functions imported from C modules cannot be introspected, and therefore the
|
|
|
|
|
signature for such functions cannot be automatically determined. However, it
|
2011-01-03 16:50:30 -06:00
|
|
|
|
is an often-used convention to put the signature into the first line of the
|
|
|
|
|
function's docstring.
|
2011-01-03 15:51:33 -06:00
|
|
|
|
|
|
|
|
|
If this boolean value is set to ``True`` (which is the default), autodoc will
|
|
|
|
|
look at the first line of the docstring for functions and methods, and if it
|
|
|
|
|
looks like a signature, use the line as the signature and remove it from the
|
|
|
|
|
docstring content.
|
|
|
|
|
|
2021-02-06 11:57:02 -06:00
|
|
|
|
autodoc will continue to look for multiple signature lines,
|
|
|
|
|
stopping at the first line that does not look like a signature.
|
|
|
|
|
This is useful for declaring overloaded function signatures.
|
2020-05-29 23:15:19 -05:00
|
|
|
|
|
2011-01-03 15:51:33 -06:00
|
|
|
|
.. versionadded:: 1.1
|
2020-05-29 23:15:19 -05:00
|
|
|
|
.. versionchanged:: 3.1
|
|
|
|
|
|
|
|
|
|
Support overloaded signatures
|
2011-01-03 15:51:33 -06:00
|
|
|
|
|
2021-02-06 11:57:02 -06:00
|
|
|
|
.. versionchanged:: 4.0
|
|
|
|
|
|
|
|
|
|
Overloaded signatures do not need to be separated by a backslash
|
|
|
|
|
|
2013-10-23 03:36:45 -05:00
|
|
|
|
.. confval:: autodoc_mock_imports
|
|
|
|
|
|
|
|
|
|
This value contains a list of modules to be mocked up. This is useful when
|
|
|
|
|
some external dependencies are not met at build time and break the building
|
2016-09-16 07:29:32 -05:00
|
|
|
|
process. You may only specify the root package of the dependencies
|
2018-06-12 22:54:35 -05:00
|
|
|
|
themselves and omit the sub-modules:
|
2016-09-16 07:29:32 -05:00
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
autodoc_mock_imports = ["django"]
|
|
|
|
|
|
|
|
|
|
Will mock all imports under the ``django`` package.
|
2013-10-23 03:36:45 -05:00
|
|
|
|
|
2014-01-19 03:34:52 -06:00
|
|
|
|
.. versionadded:: 1.3
|
|
|
|
|
|
2017-04-19 02:28:56 -05:00
|
|
|
|
.. versionchanged:: 1.6
|
|
|
|
|
This config value only requires to declare the top-level modules that
|
|
|
|
|
should be mocked.
|
2008-06-22 16:02:50 -05:00
|
|
|
|
|
2019-05-25 10:20:44 -05:00
|
|
|
|
.. confval:: autodoc_typehints
|
|
|
|
|
|
2021-04-14 16:41:25 -05:00
|
|
|
|
This value controls how to represent typehints. The setting takes the
|
2019-05-25 10:20:44 -05:00
|
|
|
|
following values:
|
|
|
|
|
|
2021-04-03 12:14:22 -05:00
|
|
|
|
* ``'signature'`` -- Show typehints in the signature (default)
|
|
|
|
|
* ``'description'`` -- Show typehints as content of the function or method
|
|
|
|
|
The typehints of overloaded functions or methods will still be represented
|
|
|
|
|
in the signature.
|
2019-05-25 10:20:44 -05:00
|
|
|
|
* ``'none'`` -- Do not show typehints
|
2021-04-03 12:14:22 -05:00
|
|
|
|
* ``'both'`` -- Show typehints in the signature and as content of
|
|
|
|
|
the function or method
|
|
|
|
|
|
|
|
|
|
Overloaded functions or methods will not have typehints included in the
|
|
|
|
|
description because it is impossible to accurately represent all possible
|
|
|
|
|
overloads as a list of parameters.
|
2019-05-25 10:20:44 -05:00
|
|
|
|
|
2019-11-28 08:31:08 -06:00
|
|
|
|
.. versionadded:: 2.1
|
2020-03-06 22:19:37 -06:00
|
|
|
|
.. versionadded:: 3.0
|
|
|
|
|
|
|
|
|
|
New option ``'description'`` is added.
|
2019-05-25 10:20:44 -05:00
|
|
|
|
|
2021-05-11 10:04:43 -05:00
|
|
|
|
.. versionadded:: 4.1
|
2021-04-03 12:14:22 -05:00
|
|
|
|
|
|
|
|
|
New option ``'both'`` is added.
|
|
|
|
|
|
2020-12-14 16:38:37 -06:00
|
|
|
|
.. confval:: autodoc_typehints_description_target
|
|
|
|
|
|
|
|
|
|
This value controls whether the types of undocumented parameters and return
|
|
|
|
|
values are documented when ``autodoc_typehints`` is set to ``description``.
|
|
|
|
|
|
|
|
|
|
The default value is ``"all"``, meaning that types are documented for all
|
|
|
|
|
parameters and return values, whether they are documented or not.
|
|
|
|
|
|
|
|
|
|
When set to ``"documented"``, types will only be documented for a parameter
|
|
|
|
|
or a return value that is already documented by the docstring.
|
|
|
|
|
|
2022-04-03 08:42:44 -05:00
|
|
|
|
With ``"documented_params"``, parameter types will only be annotated if the
|
|
|
|
|
parameter is documented in the docstring. The return type is always
|
|
|
|
|
annotated (except if it is ``None``).
|
2021-11-29 12:55:58 -06:00
|
|
|
|
|
2020-12-14 16:38:37 -06:00
|
|
|
|
.. versionadded:: 4.0
|
|
|
|
|
|
2022-04-03 08:42:44 -05:00
|
|
|
|
.. versionadded:: 5.0
|
2021-11-29 12:55:58 -06:00
|
|
|
|
|
2022-04-03 08:42:44 -05:00
|
|
|
|
New option ``'documented_params'`` is added.
|
2021-11-29 12:55:58 -06:00
|
|
|
|
|
2020-07-26 02:05:14 -05:00
|
|
|
|
.. confval:: autodoc_type_aliases
|
|
|
|
|
|
|
|
|
|
A dictionary for users defined `type aliases`__ that maps a type name to the
|
|
|
|
|
full-qualified object name. It is used to keep type aliases not evaluated in
|
|
|
|
|
the document. Defaults to empty (``{}``).
|
|
|
|
|
|
2022-03-26 11:46:22 -05:00
|
|
|
|
The type aliases are only available if your program enables :pep:`Postponed
|
|
|
|
|
Evaluation of Annotations (PEP 563) <563>` feature via ``from __future__ import
|
2020-07-26 02:05:14 -05:00
|
|
|
|
annotations``.
|
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
For example, there is code using a type alias:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
2020-07-26 02:05:14 -05:00
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
AliasType = Union[List[Dict[Tuple[int, str], Set[int]]], Tuple[str, List[str]]]
|
|
|
|
|
|
|
|
|
|
def f() -> AliasType:
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
If ``autodoc_type_aliases`` is not set, autodoc will generate internal mark-up
|
2024-10-01 08:15:24 -05:00
|
|
|
|
from this code as following:
|
2020-07-26 02:05:14 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. code-block:: rst
|
2020-07-26 02:05:14 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. py:function:: f() -> Union[List[Dict[Tuple[int, str], Set[int]]], Tuple[str, List[str]]]
|
|
|
|
|
|
|
|
|
|
...
|
2020-07-26 02:05:14 -05:00
|
|
|
|
|
|
|
|
|
If you set ``autodoc_type_aliases`` as
|
2020-12-27 23:24:19 -06:00
|
|
|
|
``{'AliasType': 'your.module.AliasType'}``, it generates the following document
|
2024-10-01 08:15:24 -05:00
|
|
|
|
internally:
|
|
|
|
|
|
|
|
|
|
.. code-block:: rst
|
2020-07-26 02:05:14 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
.. py:function:: f() -> your.module.AliasType:
|
2020-07-26 02:05:14 -05:00
|
|
|
|
|
2024-10-01 08:15:24 -05:00
|
|
|
|
...
|
2020-07-26 02:05:14 -05:00
|
|
|
|
|
|
|
|
|
.. __: https://mypy.readthedocs.io/en/latest/kinds_of_types.html#type-aliases
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
|
2021-12-23 19:14:19 -06:00
|
|
|
|
.. confval:: autodoc_typehints_format
|
2021-12-02 10:28:10 -06:00
|
|
|
|
|
2021-12-23 19:14:19 -06:00
|
|
|
|
This value controls the format of typehints. The setting takes the
|
|
|
|
|
following values:
|
|
|
|
|
|
|
|
|
|
* ``'fully-qualified'`` -- Show the module name and its name of typehints
|
|
|
|
|
* ``'short'`` -- Suppress the leading module names of the typehints
|
2024-07-10 15:43:14 -05:00
|
|
|
|
(e.g. ``io.StringIO`` -> ``StringIO``) (default)
|
2021-12-02 10:28:10 -06:00
|
|
|
|
|
|
|
|
|
.. versionadded:: 4.4
|
|
|
|
|
|
2022-01-01 04:37:42 -06:00
|
|
|
|
.. versionchanged:: 5.0
|
|
|
|
|
|
|
|
|
|
The default setting was changed to ``'short'``
|
|
|
|
|
|
2021-01-27 10:57:46 -06:00
|
|
|
|
.. confval:: autodoc_preserve_defaults
|
|
|
|
|
|
|
|
|
|
If True, the default argument values of functions will be not evaluated on
|
|
|
|
|
generating document. It preserves them as is in the source code.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 4.0
|
|
|
|
|
|
|
|
|
|
Added as an experimental feature. This will be integrated into autodoc core
|
|
|
|
|
in the future.
|
|
|
|
|
|
2017-07-15 05:27:04 -05:00
|
|
|
|
.. confval:: autodoc_warningiserror
|
|
|
|
|
|
2024-07-24 09:14:54 -05:00
|
|
|
|
This value controls the behavior of :option:`sphinx-build --fail-on-warning`
|
|
|
|
|
during importing modules.
|
2018-12-25 12:10:25 -06:00
|
|
|
|
If ``False`` is given, autodoc forcedly suppresses the error if the imported
|
2017-07-15 05:27:04 -05:00
|
|
|
|
module emits warnings. By default, ``True``.
|
|
|
|
|
|
2024-08-13 11:12:42 -05:00
|
|
|
|
.. versionchanged:: 8.1
|
|
|
|
|
This option now has no effect as :option:`!--fail-on-warning`
|
|
|
|
|
no longer exits early.
|
|
|
|
|
|
2017-08-18 03:51:24 -05:00
|
|
|
|
.. confval:: autodoc_inherit_docstrings
|
|
|
|
|
|
|
|
|
|
This value controls the docstrings inheritance.
|
2018-02-21 14:04:54 -06:00
|
|
|
|
If set to True the docstring for classes or methods, if not explicitly set,
|
2020-08-11 11:05:00 -05:00
|
|
|
|
is inherited from parents.
|
2017-08-18 03:51:24 -05:00
|
|
|
|
|
|
|
|
|
The default is ``True``.
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 1.7
|
|
|
|
|
|
2018-08-26 09:29:00 -05:00
|
|
|
|
.. confval:: suppress_warnings
|
2023-07-28 16:30:26 -05:00
|
|
|
|
:no-index:
|
2018-08-26 09:29:00 -05:00
|
|
|
|
|
|
|
|
|
:mod:`autodoc` supports to suppress warning messages via
|
|
|
|
|
:confval:`suppress_warnings`. It allows following warnings types in
|
|
|
|
|
addition:
|
|
|
|
|
|
|
|
|
|
* autodoc
|
|
|
|
|
* autodoc.import_object
|
|
|
|
|
|
2018-06-08 11:27:13 -05:00
|
|
|
|
|
2008-06-22 16:02:50 -05:00
|
|
|
|
Docstring preprocessing
|
|
|
|
|
-----------------------
|
|
|
|
|
|
2008-07-29 13:30:23 -05:00
|
|
|
|
autodoc provides the following additional events:
|
2008-06-22 16:02:50 -05:00
|
|
|
|
|
|
|
|
|
.. event:: autodoc-process-docstring (app, what, name, obj, options, lines)
|
|
|
|
|
|
2008-07-29 13:30:23 -05:00
|
|
|
|
.. versionadded:: 0.4
|
|
|
|
|
|
2008-06-22 16:02:50 -05:00
|
|
|
|
Emitted when autodoc has read and processed a docstring. *lines* is a list
|
|
|
|
|
of strings -- the lines of the processed docstring -- that the event handler
|
|
|
|
|
can modify **in place** to change what Sphinx puts into the output.
|
|
|
|
|
|
|
|
|
|
:param app: the Sphinx application object
|
|
|
|
|
:param what: the type of the object which the docstring belongs to (one of
|
|
|
|
|
``"module"``, ``"class"``, ``"exception"``, ``"function"``, ``"method"``,
|
|
|
|
|
``"attribute"``)
|
|
|
|
|
:param name: the fully qualified name of the object
|
|
|
|
|
:param obj: the object itself
|
|
|
|
|
:param options: the options given to the directive: an object with attributes
|
|
|
|
|
``inherited_members``, ``undoc_members``, ``show_inheritance`` and
|
2023-07-28 16:30:26 -05:00
|
|
|
|
``no-index`` that are true if the flag option of same name was given to the
|
2008-06-22 16:02:50 -05:00
|
|
|
|
auto directive
|
|
|
|
|
:param lines: the lines of the docstring, see above
|
|
|
|
|
|
2020-01-12 22:16:59 -06:00
|
|
|
|
.. event:: autodoc-before-process-signature (app, obj, bound_method)
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 2.4
|
|
|
|
|
|
|
|
|
|
Emitted before autodoc formats a signature for an object. The event handler
|
|
|
|
|
can modify an object to change its signature.
|
|
|
|
|
|
|
|
|
|
:param app: the Sphinx application object
|
|
|
|
|
:param obj: the object itself
|
|
|
|
|
:param bound_method: a boolean indicates an object is bound method or not
|
|
|
|
|
|
2008-07-29 13:30:23 -05:00
|
|
|
|
.. event:: autodoc-process-signature (app, what, name, obj, options, signature, return_annotation)
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 0.5
|
|
|
|
|
|
|
|
|
|
Emitted when autodoc has formatted a signature for an object. The event
|
|
|
|
|
handler can return a new tuple ``(signature, return_annotation)`` to change
|
|
|
|
|
what Sphinx puts into the output.
|
|
|
|
|
|
|
|
|
|
:param app: the Sphinx application object
|
|
|
|
|
:param what: the type of the object which the docstring belongs to (one of
|
|
|
|
|
``"module"``, ``"class"``, ``"exception"``, ``"function"``, ``"method"``,
|
|
|
|
|
``"attribute"``)
|
|
|
|
|
:param name: the fully qualified name of the object
|
|
|
|
|
:param obj: the object itself
|
|
|
|
|
:param options: the options given to the directive: an object with attributes
|
|
|
|
|
``inherited_members``, ``undoc_members``, ``show_inheritance`` and
|
2023-07-28 16:30:26 -05:00
|
|
|
|
``no-index`` that are true if the flag option of same name was given to the
|
2008-07-29 13:30:23 -05:00
|
|
|
|
auto directive
|
|
|
|
|
:param signature: function signature, as a string of the form
|
2014-06-18 10:53:25 -05:00
|
|
|
|
``"(parameter_1, parameter_2)"``, or ``None`` if introspection didn't
|
|
|
|
|
succeed and signature wasn't specified in the directive.
|
2008-07-29 13:30:23 -05:00
|
|
|
|
:param return_annotation: function return annotation as a string of the form
|
|
|
|
|
``" -> annotation"``, or ``None`` if there is no return annotation
|
2008-06-22 16:02:50 -05:00
|
|
|
|
|
|
|
|
|
The :mod:`sphinx.ext.autodoc` module provides factory functions for commonly
|
2008-07-29 13:30:23 -05:00
|
|
|
|
needed docstring processing in event :event:`autodoc-process-docstring`:
|
2008-06-22 16:02:50 -05:00
|
|
|
|
|
|
|
|
|
.. autofunction:: cut_lines
|
|
|
|
|
.. autofunction:: between
|
2008-11-02 14:04:24 -06:00
|
|
|
|
|
2021-05-15 10:35:03 -05:00
|
|
|
|
.. event:: autodoc-process-bases (app, name, obj, options, bases)
|
|
|
|
|
|
|
|
|
|
Emitted when autodoc has read and processed a class to determine the
|
|
|
|
|
base-classes. *bases* is a list of classes that the event handler can
|
|
|
|
|
modify **in place** to change what Sphinx puts into the output. It's
|
|
|
|
|
emitted only if ``show-inheritance`` option given.
|
|
|
|
|
|
|
|
|
|
:param app: the Sphinx application object
|
|
|
|
|
:param name: the fully qualified name of the object
|
|
|
|
|
:param obj: the object itself
|
|
|
|
|
:param options: the options given to the class directive
|
|
|
|
|
:param bases: the list of base classes signature. see above.
|
|
|
|
|
|
2021-09-22 20:54:54 -05:00
|
|
|
|
.. versionadded:: 4.1
|
|
|
|
|
.. versionchanged:: 4.3
|
|
|
|
|
|
2024-07-14 00:00:08 -05:00
|
|
|
|
``bases`` can contain a string as a base class name.
|
|
|
|
|
It will be processed as reStructuredText.
|
2021-09-22 20:54:54 -05:00
|
|
|
|
|
2008-11-02 14:04:24 -06:00
|
|
|
|
|
|
|
|
|
Skipping members
|
|
|
|
|
----------------
|
|
|
|
|
|
|
|
|
|
autodoc allows the user to define a custom method for determining whether a
|
|
|
|
|
member should be included in the documentation by using the following event:
|
|
|
|
|
|
|
|
|
|
.. event:: autodoc-skip-member (app, what, name, obj, skip, options)
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 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``.
|
|
|
|
|
|
2016-11-23 12:45:39 -06:00
|
|
|
|
If more than one enabled extension handles the ``autodoc-skip-member``
|
|
|
|
|
event, autodoc will use the first non-``None`` value returned by a handler.
|
|
|
|
|
Handlers should return ``None`` to fall back to the skipping behavior of
|
|
|
|
|
autodoc and other enabled extensions.
|
|
|
|
|
|
2008-11-02 14:04:24 -06:00
|
|
|
|
:param app: the Sphinx application object
|
|
|
|
|
:param what: the type of the object which the docstring belongs to (one of
|
|
|
|
|
``"module"``, ``"class"``, ``"exception"``, ``"function"``, ``"method"``,
|
|
|
|
|
``"attribute"``)
|
|
|
|
|
:param name: the fully qualified name of the object
|
|
|
|
|
:param obj: the object itself
|
2014-06-18 10:53:25 -05:00
|
|
|
|
:param skip: a boolean indicating if autodoc will skip this member if the
|
|
|
|
|
user handler does not override the decision
|
2008-11-02 14:04:24 -06:00
|
|
|
|
:param options: the options given to the directive: an object with attributes
|
|
|
|
|
``inherited_members``, ``undoc_members``, ``show_inheritance`` and
|
2023-07-28 16:30:26 -05:00
|
|
|
|
``no-index`` that are true if the flag option of same name was given to the
|
2008-11-02 14:04:24 -06:00
|
|
|
|
auto directive
|