|
|
|
@ -66,15 +66,7 @@ def is_dataclass(obj): |
|
|
|
|
return hasattr(obj, _FIELDS) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def asdictref(obj) -> dict[str, Any]: |
|
|
|
|
""" |
|
|
|
|
Similar to dataclasses.asdict without recursive type checking and copy.deepcopy |
|
|
|
|
Note that the resulting dict will contain references to the original struct as a result |
|
|
|
|
""" |
|
|
|
|
if not is_dataclass(obj): |
|
|
|
|
raise TypeError("asdictref() should be called on dataclass instances") |
|
|
|
|
|
|
|
|
|
def _asdictref_inner(obj) -> dict[str, Any] | Any: |
|
|
|
|
def _asdictref_inner(obj) -> dict[str, Any] | Any: |
|
|
|
|
if is_dataclass(obj): |
|
|
|
|
ret = {} |
|
|
|
|
for field in getattr(obj, _FIELDS): # similar to dataclasses.fields() |
|
|
|
@ -85,6 +77,15 @@ def asdictref(obj) -> dict[str, Any]: |
|
|
|
|
else: |
|
|
|
|
return obj |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def asdictref(obj) -> dict[str, Any]: |
|
|
|
|
""" |
|
|
|
|
Similar to dataclasses.asdict without recursive type checking and copy.deepcopy |
|
|
|
|
Note that the resulting dict will contain references to the original struct as a result |
|
|
|
|
""" |
|
|
|
|
if not is_dataclass(obj): |
|
|
|
|
raise TypeError("asdictref() should be called on dataclass instances") |
|
|
|
|
|
|
|
|
|
return _asdictref_inner(obj) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|