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

Commit 0f007fe

Browse files
authored
Update utility code to handle C implementations of frozendict (#10902)
* update _handle_frozendict to work with c implementations of frozen dict * add changelog * add clarifying comment to _handle_frozendict
1 parent 8aaa4b7 commit 0f007fe

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

changelog.d/10902.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update utility code to handle C implementations of frozendict.

synapse/util/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ def _handle_frozendict(obj: Any) -> Dict[Any, Any]:
5050
if type(obj) is frozendict:
5151
# fishing the protected dict out of the object is a bit nasty,
5252
# but we don't really want the overhead of copying the dict.
53-
return obj._dict
53+
try:
54+
return obj._dict
55+
except AttributeError:
56+
# When the C implementation of frozendict is used,
57+
# there isn't a `_dict` attribute with a dict
58+
# so we resort to making a copy of the frozendict
59+
return dict(obj)
5460
raise TypeError(
5561
"Object of type %s is not JSON serializable" % obj.__class__.__name__
5662
)

0 commit comments

Comments
 (0)