From 260dfbc5adf2f7df8643ed3dd90741fd66d6c066 Mon Sep 17 00:00:00 2001 From: Peter Schutt Date: Wed, 11 Oct 2023 13:01:41 +1000 Subject: [PATCH] Handle where `Annotated` has unhashable metadata. Closes #565 --- msgspec/inspect.py | 7 ++++++- tests/test_inspect.py | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/msgspec/inspect.py b/msgspec/inspect.py index d7820187..df8d2c05 100644 --- a/msgspec/inspect.py +++ b/msgspec/inspect.py @@ -619,7 +619,12 @@ def _origin_args_metadata(t): # Strip wrappers (Annotated, NewType, Final) until we hit a concrete type metadata = [] while True: - origin = _CONCRETE_TYPES.get(t) + try: + origin = _CONCRETE_TYPES.get(t) + except TypeError: + # t is not hashable + origin = None + if origin is not None: args = None break diff --git a/tests/test_inspect.py b/tests/test_inspect.py index e1c9dc0c..cd83040b 100644 --- a/tests/test_inspect.py +++ b/tests/test_inspect.py @@ -765,6 +765,13 @@ def test_metadata(): ) +def test_inspect_with_unhashable_metadata(): + + typ = Annotated[int, {"unhashable"}] + + assert mi.type_info(typ) == mi.IntType() + + def test_multi_type_info(): class Example(msgspec.Struct): x: int