You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I get an error when deserialising Union[Literal, MyClass] but not when deserialising Union[MyClass, Literal].
It seems this error started some time after v0.15.7.
Example:
fromtypingimportUnion, Literalfromdataclassesimportdataclassfromapischemaimportdeserialize@dataclassclassBar:
baz: intdeserialize(Union[Literal["foo"], Bar], {"baz": 1}) # this failsdeserialize(Union[Bar, Literal["foo"]], {"baz": 1}) # this works
Here's the traceback for the the call that fails:
Traceback (most recent call last):
File "/home/kheavey/anchorpy/throwaway.py", line 11, in <module>
deserialize(Union[Literal["foo"], Bar], {"baz": 1})
File "/home/kheavey/anchorpy/.venv/lib/python3.9/site-packages/apischema/utils.py", line 424, in wrapper
return wrapped(*args, **kwargs)
File "/home/kheavey/anchorpy/.venv/lib/python3.9/site-packages/apischema/deserialization/__init__.py", line 912, in deserialize
return deserialization_method(
File "/home/kheavey/anchorpy/.venv/lib/python3.9/site-packages/apischema/deserialization/__init__.py", line 698, in method
return deserialize_alt(data)
File "/home/kheavey/anchorpy/.venv/lib/python3.9/site-packages/apischema/deserialization/__init__.py", line 271, in method
return value_map[data]
TypeError: unhashable type: 'dict'
Here's what value_map and data look like:
(Pdb) value_map
{'foo': 'foo'}
(Pdb) data
{'baz': 1}
The text was updated successfully, but these errors were encountered:
wyfo
linked a pull request
Dec 6, 2021
that will
close
this issue
I get an error when deserialising
Union[Literal, MyClass]
but not when deserialisingUnion[MyClass, Literal]
.It seems this error started some time after v0.15.7.
Example:
Here's the traceback for the the call that fails:
Here's what
value_map
anddata
look like:The text was updated successfully, but these errors were encountered: