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/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 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 = {