diff options
author | Adam Turner <9087854+AA-Turner@users.noreply.github.com> | 2023-04-05 13:07:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-05 13:07:25 +0100 |
commit | 4a3febb69a124300f1481fc33b44a5672f24e0fa (patch) | |
tree | 10defdc4bcc3d606604cab9dae3ca445ba74685b /doc | |
parent | 609b2f2650dfea191e688ce6238ba567da551052 (diff) | |
download | sphinx-git-4a3febb69a124300f1481fc33b44a5672f24e0fa.tar.gz |
Add an option for displaying short ``Literal`` types (#11109)
The new ``python_display_short_literal_types`` configuration option
for the ``py`` domain controls display of PEP 586 ``Literal`` types.
The 'short' format is inspired by PEP 604, using the bitwise OR operator
to distinguish the possible legal values for the argument.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/usage/configuration.rst | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index fb5a7615c..c92e468f1 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -2936,6 +2936,36 @@ Options for the C++ domain Options for the Python domain ----------------------------- +.. confval:: python_display_short_literal_types + + This value controls how :py:data:`~typing.Literal` types are displayed. + The setting is a boolean, default ``False``. + + Examples + ~~~~~~~~ + + The examples below use the following :rst:dir:`py:function` directive: + + .. code:: reStructuredText + + .. py:function:: serve_food(item: Literal["egg", "spam", "lobster thermidor"]) -> None + + When ``False``, :py:data:`~typing.Literal` types display as per standard + Python syntax, i.e.: + + .. code:: python + + serve_food(item: Literal["egg", "spam", "lobster thermidor"]) -> None + + When ``True``, :py:data:`~typing.Literal` types display with a short, + :PEP:`604`-inspired syntax, i.e.: + + .. code:: python + + serve_food(item: "egg" | "spam" | "lobster thermidor") -> None + + .. versionadded:: 6.2 + .. confval:: python_use_unqualified_type_names If true, suppress the module name of the python reference if it can be |