Skip to content

Commit

Permalink
simplify to_dict
Browse files Browse the repository at this point in the history
Signed-off-by: Zhiyuan Chen <[email protected]>
  • Loading branch information
ZhiyuanChen committed May 18, 2023
1 parent ed563b3 commit 1afcf45
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions chanfig/flat_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,14 @@ def to_dict(obj: Any) -> Mapping[str, Any]: # pylint: disable=R0911

if isinstance(obj, FlatDict):
return {k: to_dict(v) for k, v in obj.items()}
if isinstance(obj, dict):
return obj
if isinstance(obj, Variable):
return obj.value
if isinstance(obj, list):
return [to_dict(v) for v in obj] # type: ignore
if isinstance(obj, tuple):
return tuple(to_dict(v) for v in obj) # type: ignore
if isinstance(obj, set):
return {to_dict(v) for v in obj} # type: ignore
if isinstance(obj, Variable):
return to_dict(obj.value)
if isinstance(obj, (int, float, str, bool, type(None))):
return obj # type: ignore
return obj.value
return obj


Expand Down

0 comments on commit 1afcf45

Please sign in to comment.