Skip to content

Commit 8dfcf3c

Browse files
authored
Fix TypeError on nested Annotated types where the inner type has unhashable metadata (#417)
1 parent d76f591 commit 8dfcf3c

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
- Preliminary changes for compatibility with the draft implementation
44
of PEP 649 in Python 3.14.
5+
- Fix regression in v4.12.0 where nested `Annotated` types would cause
6+
`TypeError` to be raised if the nested `Annotated` type had unhashable
7+
metadata.
58

69
# Release 4.12.0 (May 23, 2024)
710

src/test_typing_extensions.py

+8
Original file line numberDiff line numberDiff line change
@@ -4769,6 +4769,14 @@ def test_annotated_in_other_types(self):
47694769
X = List[Annotated[T, 5]]
47704770
self.assertEqual(X[int], List[Annotated[int, 5]])
47714771

4772+
def test_nested_annotated_with_unhashable_metadata(self):
4773+
X = Annotated[
4774+
List[Annotated[str, {"unhashable_metadata"}]],
4775+
"metadata"
4776+
]
4777+
self.assertEqual(X.__origin__, List[Annotated[str, {"unhashable_metadata"}]])
4778+
self.assertEqual(X.__metadata__, ("metadata",))
4779+
47724780

47734781
class GetTypeHintsTests(BaseTestCase):
47744782
def test_get_type_hints(self):

src/typing_extensions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2958,9 +2958,9 @@ def _has_generic_or_protocol_as_origin() -> bool:
29582958
except AttributeError:
29592959
return False # err on the side of leniency
29602960
else:
2961-
return frame.f_locals.get("origin") in {
2961+
return frame.f_locals.get("origin") in (
29622962
typing.Generic, Protocol, typing.Protocol
2963-
}
2963+
)
29642964

29652965

29662966
_TYPEVARTUPLE_TYPES = {TypeVarTuple, getattr(typing, "TypeVarTuple", None)}

0 commit comments

Comments
 (0)