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

Commit 07b3168

Browse files
author
David Robertson
committed
Use new canonicaljson serisalistion hook
From matrix-org/python-canonicaljson#59
1 parent 3537e5c commit 07b3168

File tree

3 files changed

+14
-86
lines changed

3 files changed

+14
-86
lines changed

Diff for: poetry.lock

+4-82
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pyproject.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,8 @@ jsonschema = ">=3.0.0"
158158
immutabledict = ">=2.0"
159159
# We require 2.1.0 or higher for type hints. Previous guard was >= 1.1.0
160160
unpaddedbase64 = ">=2.1.0"
161-
# We require 1.5.0 to work around an issue when running against the C implementation of
162-
# frozendict: https://github.com/matrix-org/python-canonicaljson/issues/36
163-
canonicaljson = "^1.5.0"
161+
# We require 2.0.0 for immutabledict support.
162+
canonicaljson = "^2.0.0"
164163
# we use the type definitions added in signedjson 1.1.
165164
signedjson = "^1.1.0"
166165
# validating SSL certs for IP addresses requires service_identity 18.1.

Diff for: synapse/__init__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import json
2121
import os
2222
import sys
23+
from typing import Any, Dict
2324

2425
from synapse.util.rust import check_rust_lib_up_to_date
2526
from synapse.util.stringutils import strtobool
@@ -63,9 +64,15 @@
6364

6465
# Use the standard library json implementation instead of simplejson.
6566
try:
66-
from canonicaljson import set_json_library
67+
from canonicaljson import register_preserialisation_callback, set_json_library
68+
from immutabledict import immutabledict
6769

6870
set_json_library(json)
71+
72+
def _immutabledict_cb(d: immutabledict) -> Dict[str, Any]:
73+
return d._dict
74+
75+
register_preserialisation_callback(immutabledict, _immutabledict_cb)
6976
except ImportError:
7077
pass
7178

0 commit comments

Comments
 (0)