dataclasses-json
dataclasses-json copied to clipboard
#341: Fixes for type-parameters without arguments
Closes #341
Changes:
- Updated
tests.entities
andtests.test_collections
to include alternative forms of the same collection types (likebuiltins.list
("builtin") andtyping.List
(~~"generic"~~ "unbound") in addition to the existingtyping.List[TypeA]
) - Added new internal helper class ~~
core._NoArgs
~~utils._NoArgs
and its singleton instance ~~core._NO_ARGS
~~utils._NO_ARGS
- Added new methods ~~
core._extract_args()
~~utils._get_type_args()
and ~~core._extract_type_parameter()
~~utils._get_type_arg_param()
which return eithertp.__args__
value or_NO_ARGS
constant - All "unsafe" usages of
tp.__args__
replaced with the new methods - Added
TypeVar
special case check forcore._decode_dict_keys()
-
Note: This is a special case for Python 3.7 and Python 3.8.
By some reason, "unbound" dicts are counted as having key type parameter to be
TypeVar('KT')
-
Note: This is a special case for Python 3.7 and Python 3.8.
By some reason, "unbound" dicts are counted as having key type parameter to be
- Added
tp.__origin__ == None
special case forutils._get_type_origin()
-
Note: This is a special case for Python 3.6 exclusively.
By some reason, some "unbound" types (
typing.Set
,typing.Tuple
, andtyping.FrozenSet
) are considered to have this field withNone
rather than generating anAttributeError
- Same for
tp.__args__
and dicts
-
Note: This is a special case for Python 3.6 exclusively.
By some reason, some "unbound" types (
Status
- Without the fix, new tests fail on all versions of Python, but fail differently (see report in the comments of #341)
- By now, there are no failures related to the missing
tp.__args__
:- [x] Python 3.6: ~~Decodes "unbound" (but not "builtin") sets, tuples, and frozensets as lists rather than required types~~
- [x] Python 3.7-3.8: ~~Fails to decode "unbound" and "builtin" dicts by trying to instantiate uninstantiatable
typing.Dict
.~~ Was actually caused by the strange structure of dict class nesting in specifically these Python versions, see note above - [x] No longer fails on Python 3.9+
- [x] (New) Python 3.6: ~~Unable to decode "unbound"
typing.Dict
anddict
keys on Python 3.6 exclusively~~
This seems like a pretty solid thing to get into the project so it is working in 3.10 as well :)
Yes I'm sorry I've been MIA... I'll take a look soon!
@lidatong do you have plans to release a new version with this patch in? It will be great if we can get this bug fixed
@lidatong any update on this? Would be great to have a new version released with these features.