Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError on nested Annotated types where the inner type has unhashable metadata #417

Merged
merged 2 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

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

# Release 4.12.0 (May 23, 2024)

Expand Down
8 changes: 8 additions & 0 deletions src/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4769,6 +4769,14 @@ def test_annotated_in_other_types(self):
X = List[Annotated[T, 5]]
self.assertEqual(X[int], List[Annotated[int, 5]])

def test_nested_annotated_with_unhashable_metadata(self):
X = Annotated[
List[Annotated[str, {"unhashable_metadata"}]],
"metadata"
]
self.assertEqual(X.__origin__, List[Annotated[str, {"unhashable_metadata"}]])
self.assertEqual(X.__metadata__, ("metadata",))


class GetTypeHintsTests(BaseTestCase):
def test_get_type_hints(self):
Expand Down
4 changes: 2 additions & 2 deletions src/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2958,9 +2958,9 @@ def _has_generic_or_protocol_as_origin() -> bool:
except AttributeError:
return False # err on the side of leniency
else:
return frame.f_locals.get("origin") in {
return frame.f_locals.get("origin") in (
typing.Generic, Protocol, typing.Protocol
}
)


_TYPEVARTUPLE_TYPES = {TypeVarTuple, getattr(typing, "TypeVarTuple", None)}
Expand Down
Loading