Skip to content

Commit

Permalink
Handle where Annotated has unhashable metadata.
Browse files Browse the repository at this point in the history
Closes #565
  • Loading branch information
peterschutt authored and jcrist committed Oct 11, 2023
1 parent 05125a8 commit 260dfbc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion msgspec/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 260dfbc

Please sign in to comment.