From bd4d821618f8b1fb42e472036d46f00527cd4d95 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Mon, 5 May 2025 17:33:04 -0500 Subject: [PATCH 1/2] Render typing_extensions.TypeAlias like other type aliases Signed-off-by: Brad Keryan --- autoapi/_astroid_utils.py | 2 ++ autoapi/_objects.py | 6 +++++- autoapi/_parser.py | 6 +++++- tests/python/pep695/example/example.py | 4 ++++ tests/python/test_pyintegration.py | 12 ++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/autoapi/_astroid_utils.py b/autoapi/_astroid_utils.py index ea353d20..fd2586d0 100644 --- a/autoapi/_astroid_utils.py +++ b/autoapi/_astroid_utils.py @@ -522,6 +522,8 @@ def _resolve_annotation(annotation: astroid.nodes.NodeNG) -> str: if resolved.startswith("typing."): return resolved[len("typing.") :] + if resolved.startswith("typing_extensions."): + return resolved[len("typing_extensions.") :] # Sphinx is capable of linking anything in the same module # without needing a fully qualified path. diff --git a/autoapi/_objects.py b/autoapi/_objects.py index 99e0b12e..3137f18c 100644 --- a/autoapi/_objects.py +++ b/autoapi/_objects.py @@ -352,7 +352,11 @@ def __init__(self, *args, **kwargs): """ def is_type_alias(self): - return self.annotation in ("TypeAlias", "typing.TypeAlias") + return self.annotation in ( + "TypeAlias", + "typing.TypeAlias", + "typing_extensions.TypeAlias", + ) class PythonAttribute(PythonData): diff --git a/autoapi/_parser.py b/autoapi/_parser.py index 0460e92f..5053b545 100644 --- a/autoapi/_parser.py +++ b/autoapi/_parser.py @@ -90,7 +90,11 @@ def _parse_assign(self, node): value_node = assign_value[1] annotation = _astroid_utils.get_assign_annotation(node) - if annotation in ("TypeAlias", "typing.TypeAlias"): + if annotation in ( + "TypeAlias", + "typing.TypeAlias", + "typing_extensions.TypeAlias", + ): value = node.value.as_string() elif isinstance( value_node, astroid.nodes.ClassDef diff --git a/tests/python/pep695/example/example.py b/tests/python/pep695/example/example.py index 7d2c648c..e42a4836 100644 --- a/tests/python/pep695/example/example.py +++ b/tests/python/pep695/example/example.py @@ -1,4 +1,8 @@ from typing import TypeAlias +import typing +import typing_extensions MyTypeAliasA: TypeAlias = tuple[str, int] type MyTypeAliasB = tuple[str, int] +MyTypeAliasC: typing.TypeAlias = tuple[str, int] +MyTypeAliasD: typing_extensions.TypeAlias = tuple[str, int] diff --git a/tests/python/test_pyintegration.py b/tests/python/test_pyintegration.py index b45b2ae5..32a77f84 100644 --- a/tests/python/test_pyintegration.py +++ b/tests/python/test_pyintegration.py @@ -756,6 +756,18 @@ def test_integration(self, parse): value = properties[1].text assert value == " = tuple[str, int]" + alias = example_file.find(id="example.MyTypeAliasC") + properties = alias.find_all(class_="property") + assert len(properties) == 2 + value = properties[1].text + assert value == " = tuple[str, int]" + + alias = example_file.find(id="example.MyTypeAliasD") + properties = alias.find_all(class_="property") + assert len(properties) == 2 + value = properties[1].text + assert value == " = tuple[str, int]" + def test_napoleon_integration_loaded(builder, parse): confoverrides = { From 609d3adabbd5783ee7e23deff936cd2b61598a51 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Fri, 27 Jun 2025 21:28:07 -0500 Subject: [PATCH 2/2] Update changelog Signed-off-by: Brad Keryan --- docs/changes/520.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/520.bugfix.rst diff --git a/docs/changes/520.bugfix.rst b/docs/changes/520.bugfix.rst new file mode 100644 index 00000000..d17da4c1 --- /dev/null +++ b/docs/changes/520.bugfix.rst @@ -0,0 +1 @@ +Render typing_extensions.TypeAlias like other type aliases