Skip to content

Commit

Permalink
feat: comment from review
Browse files Browse the repository at this point in the history
  • Loading branch information
PJCampi committed Jun 5, 2024
1 parent 7e19a59 commit 5927478
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions dataclasses_json/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,8 @@ def _decode_generic(type_, value, infer_missing):

# get the constructor if using corresponding generic type in `typing`
# otherwise fallback on constructing using type_ itself
try:
materialize_type = _get_type_cons(type_)
except (TypeError, AttributeError):
materialize_type = type_

# map abstract collection to concrete implementation
materialize_type = collections_abc_type_to_implementation_type.get(materialize_type, materialize_type)

res = materialize_type(xs)
collection_type = _resolve_collection_type_to_decode_to(type_)
res = collection_type(xs)
elif _is_generic_dataclass(type_):
origin = _get_type_origin(type_)
res = _decode_dataclass(origin, value, infer_missing)
Expand Down Expand Up @@ -417,6 +410,16 @@ def handle_pep0673(pre_0673_hint: str) -> Union[Type, str]:
return list(_decode_type(type_args, x, infer_missing) for x in xs)


def _resolve_collection_type_to_decode_to(type_):
try:
collection_type = _get_type_cons(type_)
except (TypeError, AttributeError):
collection_type = type_

# map abstract collection to concrete implementation
return collections_abc_type_to_implementation_type.get(collection_type, collection_type)


def _asdict(obj, encode_json=False):
"""
A re-implementation of `asdict` (based on the original in the `dataclasses`
Expand Down

0 comments on commit 5927478

Please sign in to comment.