Skip to content

Commit 260dfbc

Browse files
peterschuttjcrist
authored andcommitted
Handle where Annotated has unhashable metadata.
Closes #565
1 parent 05125a8 commit 260dfbc

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎msgspec/inspect.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,12 @@ def _origin_args_metadata(t):
619619
# Strip wrappers (Annotated, NewType, Final) until we hit a concrete type
620620
metadata = []
621621
while True:
622-
origin = _CONCRETE_TYPES.get(t)
622+
try:
623+
origin = _CONCRETE_TYPES.get(t)
624+
except TypeError:
625+
# t is not hashable
626+
origin = None
627+
623628
if origin is not None:
624629
args = None
625630
break

‎tests/test_inspect.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,13 @@ def test_metadata():
765765
)
766766

767767

768+
def test_inspect_with_unhashable_metadata():
769+
770+
typ = Annotated[int, {"unhashable"}]
771+
772+
assert mi.type_info(typ) == mi.IntType()
773+
774+
768775
def test_multi_type_info():
769776
class Example(msgspec.Struct):
770777
x: int

0 commit comments

Comments
 (0)