Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _asdict(obj, encode_json=False):
"""
A re-implementation of `asdict` (based on the original in the `dataclasses`
source) to support arbitrary Collection and Mapping types.
"""
if _is_dataclass_instance(obj):
result = []
for field in fields(obj):
value = _asdict(getattr(obj, field.name), encode_json=encode_json)
result.append((field.name, value))
return _encode_overrides(dict(result), _user_overrides(obj),
encode_json=encode_json)
elif isinstance(obj, Mapping):
return dict((_asdict(k, encode_json=encode_json),
_asdict(v, encode_json=encode_json)) for k, v in
obj.items())
elif isinstance(obj, Collection) and not isinstance(obj, str) and not isinstance(obj, bytes):
return list(_asdict(v, encode_json=encode_json) for v in obj)
else:
return copy.deepcopy(obj)
def _asdict(obj, encode_json=False):
"""
A re-implementation of `asdict` (based on the original in the `dataclasses`
source) to support arbitrary Collection and Mapping types.
"""
if _is_dataclass_instance(obj):
result = []
for field in fields(obj):
value = _asdict(getattr(obj, field.name), encode_json=encode_json)
result.append((field.name, value))
result = _handle_undefined_parameters_safe(cls=obj, kvs=dict(result),
usage="to")
return _encode_overrides(dict(result), _user_overrides(obj),
encode_json=encode_json)
elif isinstance(obj, Mapping):
return dict((_asdict(k, encode_json=encode_json),
_asdict(v, encode_json=encode_json)) for k, v in
obj.items())
elif isinstance(obj, Collection) and not isinstance(obj, str) \
and not isinstance(obj, bytes):
return list(_asdict(v, encode_json=encode_json) for v in obj)