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
Whenever I use .from_dict() (or .from_json()) it errors out with a NameError, saying that the types haven't been defined, even though it is defined within the TYPE_CHECKING block.
Traceback (most recent call last):
File "/home/bvl/dev/dataclasses_json_bug/main.py", line 16, in <module>
x = Something.from_dict({"thing": 123})
File "/home/bvl/dev/dataclasses_json_bug/.venv/lib/python3.14/site-packages/dataclasses_json/api.py", line 70, in from_dict
return _decode_dataclass(cls, kvs, infer_missing)
File "/home/bvl/dev/dataclasses_json_bug/.venv/lib/python3.14/site-packages/dataclasses_json/core.py", line 166, in _decode_dataclass
types = get_type_hints(cls)
File "/home/bvl/.pyenv/versions/3.14-dev/lib/python3.14/typing.py", line 2432, in get_type_hints
value = _eval_type(value, base_globals, base_locals, base.__type_params__)
File "/home/bvl/.pyenv/versions/3.14-dev/lib/python3.14/typing.py", line 473, in _eval_type
return t._evaluate(globalns, localns, type_params, recursive_guard=recursive_guard)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bvl/.pyenv/versions/3.14-dev/lib/python3.14/typing.py", line 1071, in _evaluate
eval(self.__forward_code__, globalns, locals_to_pass),
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 1, in <module>
NameError: name 'Any' is not defined. Did you mean: 'any'?
Looks like the root cause is with typing.get_type_hints(), which has already been reported, but not touched since 2022: https://bugs.python.org/issue43463
Description
Whenever I use
.from_dict()
(or.from_json()
) it errors out with aNameError
, saying that the types haven't been defined, even though it is defined within theTYPE_CHECKING
block.Looks like the root cause is with
typing.get_type_hints()
, which has already been reported, but not touched since 2022: https://bugs.python.org/issue43463Code snippet that reproduces the issue
Describe the results you expected
Everything imported in the
TYPE_CHECKING
block should be imported when needed, as with.from_dict()
.From the code snippet above, the expected output is:
Python version you are using
Python 3.14.0a0
Environment description
dataclasses-json==0.6.6
marshmallow==3.21.3
mypy-extensions==1.0.0
packaging==24.0
typing-inspect==0.9.0
typing_extensions==4.12.1
The text was updated successfully, but these errors were encountered: