Skip to content

Commit

Permalink
Improve data class serialization to dict
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Nov 19, 2024
1 parent d0551e2 commit 26de23d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions fido2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,10 @@ def __getitem__(self, key):
serialize = f.metadata.get("serialize")
if serialize:
return serialize(value)
if isinstance(value, _DataClassMapping):
if isinstance(value, Mapping) and not isinstance(value, dict):
return dict(value)
if isinstance(value, list) and all(
isinstance(v, _DataClassMapping) for v in value
):
return [dict(v) for v in value]
if isinstance(value, Sequence) and all(isinstance(v, Mapping) for v in value):
return [v if isinstance(v, dict) else dict(v) for v in value]
return value

@classmethod
Expand Down

0 comments on commit 26de23d

Please sign in to comment.