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 2d0cd4f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions dataclasses_json/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,8 @@ def _decode_generic(type_, value, infer_missing):
else:
xs = _decode_items(_get_type_arg_param(type_, 0), 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 +408,18 @@ 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_):
# get the constructor if using corresponding generic type in `typing`
# otherwise fallback on constructing using type_ itself
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 2d0cd4f

Please sign in to comment.