Skip to content

Commit

Permalink
Add support for Python type parameter lists
Browse files Browse the repository at this point in the history
Sphinx has partial support for type parameter lists: they are supported
by the Python domain in signatures, but are not supported by autodoc.

This adds the following support:

- Sphinx Python domain for type parameter fields in docstrings, with
  sphinx.ext.napoleon support as well.

- Support for type parameters as Sphinx objects, with cross-linking, like
  the existing support for function parameters as Sphinx objects.

- Support in apigen for PEP 695 type parameters, and for displaying
  pre-PEP 695 separately-defined TypeVar types as PEP 695 type parameters.
  • Loading branch information
jbms committed Jul 10, 2024
1 parent d50317c commit 447de0e
Show file tree
Hide file tree
Showing 7 changed files with 709 additions and 72 deletions.
17 changes: 16 additions & 1 deletion sphinx_immaterial/apidoc/object_description_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,22 @@ def format_object_description_tooltip(
("py:property", {"toc_icon_class": "alias", "toc_icon_text": "P"}),
("py:attribute", {"toc_icon_class": "alias", "toc_icon_text": "A"}),
("py:data", {"toc_icon_class": "alias", "toc_icon_text": "V"}),
("py:parameter", {"toc_icon_class": "sub-data", "toc_icon_text": "p"}),
(
"py:parameter",
{
"toc_icon_class": "sub-data",
"toc_icon_text": "p",
"generate_synopses": "first_sentence",
},
),
(
"py:typeParameter",
{
"toc_icon_class": "alias",
"toc_icon_text": "T",
"generate_synopses": "first_sentence",
},
),
("c:member", {"toc_icon_class": "alias", "toc_icon_text": "V"}),
("c:var", {"toc_icon_class": "alias", "toc_icon_text": "V"}),
("c:function", {"toc_icon_class": "procedure", "toc_icon_text": "F"}),
Expand Down
1 change: 0 additions & 1 deletion sphinx_immaterial/apidoc/object_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def _make_section_from_field(
source: docutils.nodes.field,
) -> Optional[docutils.nodes.section]:
fieldname = cast(docutils.nodes.field_name, source[0])
fieldbody = cast(docutils.nodes.field_body, source[1])
ids = fieldname["ids"]
if not ids:
# Not indexed
Expand Down
Loading

0 comments on commit 447de0e

Please sign in to comment.