can do this if we're desperate for the last few %

This commit is contained in:
Shane Smiskol 2024-08-16 01:35:12 -07:00
parent a5e363d8db
commit 18e11ac788
1 changed files with 7 additions and 3 deletions

View File

@ -80,10 +80,14 @@ def asdictref(obj) -> dict[str, Any]:
for field in getattr(obj, _FIELDS): # similar to dataclasses.fields()
ret[field] = _asdictref_inner(getattr(obj, field))
return ret
elif isinstance(obj, (tuple, list)):
return type(obj)(_asdictref_inner(v) for v in obj)
else:
return obj
obj_type = type(obj)
if obj_type is list:
return [_asdictref_inner(v) for v in obj]
elif obj_type is tuple:
return tuple(_asdictref_inner(v) for v in obj)
else:
return obj
return _asdictref_inner(obj)