Python domain customization

python_type_aliases : dict[str, str] = {}

Maps names or dotted names appearing in type annotations in Python signatures to the corresponding fully-qualified name.

For example, to map MyUnqualifiedType to alias_ex.MyUnqualifiedType, add the following to conf.py:

python_type_aliases = {
    "MyUnqualifiedType": "alias_ex.MyUnqualifiedType",
}
Python signature modified by type alias
.. py:function:: foo(x: MyUnqualifiedType) -> str
   :noindex:

   Function description.
foo(x: alias_ex.MyUnqualifiedType) str

Function description.

python_resolve_unqualified_typing : bool = True

Specifies whether to add the following mappings to python_type_aliases:

If python_transform_type_annotations_pep585 is also set to True, then these aliases are additionally subject to that mapping.

python_transform_type_annotations_pep585 : bool = True

Specifies whether to add the following PEP 585 mappings to python_type_aliases:

python_transform_type_annotations_pep604 : bool = True

Converts type annotations involving typing.Optional, typing.Union, and/or typing.Literal to the more concise PEP 604 form.

.. py:function:: foo(x: typing.Optional[int], \
                     y: typing.Union[int, float])
   :noindex:
foo(x: int | None, y: int | float)
python_transform_type_annotations_concise_literal : bool = True

If set to True, converts typing.Literal[a] to a if a is a constant.

This option requires that python_transform_type_annotations_pep604 is also enabled.

.. py:function:: foo(x: typing.Literal[1, 2, "abc"])
   :noindex:

.. py:function:: foo(x: ~typing.Literal[1, 2, "abc"])
   :noindex:
foo(x: 1 | 2 | 'abc')
foo(x: 1 | 2 | 'abc')

Warning

The concise syntax is non-standard and not accepted by Python type checkers.

python_qualify_parameter_ids : bool = True

Specifies whether function parameters should be assigned fully-qualified ids (for cross-linking purposes) of the form <parent-id>.<param-name> based on the id of the parent declaration.

If set to False, instead the shorter unqualified id p-<param-name> is used. This option should only be set to False if each Python declaration is on a separate page.


Last update: Jul 26, 2022