Skip to content

Commit

Permalink
fix namespace.to_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
bendichter committed Apr 17, 2024
1 parent 37b11ec commit 5ca55d4
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tools/schemacode/bidsschematools/types/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,17 @@ def __init__(self, *args, **kwargs):
self._properties = dict(*args, **kwargs)

def to_dict(self) -> dict:
ret = {}
for key, val in self._properties.items():
if isinstance(val, Namespace):
val = val.to_dict()
ret[key] = val
return ret

def _to_dict(obj):
if isinstance(obj, Namespace):
return {k: _to_dict(v) for k, v in obj._properties.items()}
if isinstance(obj, list):
return [_to_dict(v) for v in obj]
if isinstance(obj, dict):
return {k: _to_dict(v) for k, v in obj.items()}
return obj

return _to_dict(self)

def __deepcopy__(self, memo):
return self.build(self.to_dict())
Expand Down

0 comments on commit 5ca55d4

Please sign in to comment.