Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Update utility code to handle C implementations of frozendict (#10902)
Browse files Browse the repository at this point in the history
* update _handle_frozendict to work with c implementations of frozen dict

* add changelog

* add clarifying comment to _handle_frozendict
  • Loading branch information
H-Shay committed Sep 28, 2021
1 parent 8aaa4b7 commit 0f007fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/10902.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update utility code to handle C implementations of frozendict.
8 changes: 7 additions & 1 deletion synapse/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ def _handle_frozendict(obj: Any) -> Dict[Any, Any]:
if type(obj) is frozendict:
# fishing the protected dict out of the object is a bit nasty,
# but we don't really want the overhead of copying the dict.
return obj._dict
try:
return obj._dict
except AttributeError:
# When the C implementation of frozendict is used,
# there isn't a `_dict` attribute with a dict
# so we resort to making a copy of the frozendict
return dict(obj)
raise TypeError(
"Object of type %s is not JSON serializable" % obj.__class__.__name__
)
Expand Down

0 comments on commit 0f007fe

Please sign in to comment.