From 3f0b1e5b511cede8eb2721514511f1816c125f1a Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 17 Apr 2025 08:53:27 -0700 Subject: [PATCH] Add back _AnnotatedAlias Fixes #586 --- src/test_typing_extensions.py | 5 +++++ src/typing_extensions.py | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/test_typing_extensions.py b/src/test_typing_extensions.py index a6948951..095505aa 100644 --- a/src/test_typing_extensions.py +++ b/src/test_typing_extensions.py @@ -5251,6 +5251,11 @@ def test_nested_annotated_with_unhashable_metadata(self): self.assertEqual(X.__origin__, List[Annotated[str, {"unhashable_metadata"}]]) self.assertEqual(X.__metadata__, ("metadata",)) + def test_compatibility(self): + # Test that the _AnnotatedAlias compatibility alias works + self.assertTrue(hasattr(typing_extensions, "_AnnotatedAlias")) + self.assertIs(typing_extensions._AnnotatedAlias, typing._AnnotatedAlias) + class GetTypeHintsTests(BaseTestCase): def test_get_type_hints(self): diff --git a/src/typing_extensions.py b/src/typing_extensions.py index f8b2f76e..1c968f72 100644 --- a/src/typing_extensions.py +++ b/src/typing_extensions.py @@ -4095,7 +4095,7 @@ def evaluate_forward_ref( ) -# Aliases for items that have always been in typing. +# Aliases for items that are in typing in all supported versions. # Explicitly assign these (rather than using `from typing import *` at the top), # so that we get a CI error if one of these is deleted from typing.py # in a future version of Python @@ -4136,3 +4136,6 @@ def evaluate_forward_ref( cast = typing.cast no_type_check = typing.no_type_check no_type_check_decorator = typing.no_type_check_decorator +# This is private, but it was defined by typing_extensions for a long time +# and some users rely on it. +_AnnotatedAlias = typing._AnnotatedAlias