Skip to content

Commit 6ec7306

Browse files
committed
Refactor orjson packer to use functools.partial.
1 parent 9b331e2 commit 6ec7306

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

jupyter_client/session.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,11 @@ def json_unpacker(s: str | bytes) -> t.Any:
132132
_default_packer_unpacker = "json", "json"
133133
_default_pack_unpack = (json_packer, json_unpacker)
134134
else:
135+
import functools
135136

136-
def orjson_packer(obj: t.Any) -> bytes:
137-
"""Convert a json object to a bytes using orjson with a fallback to json_packer."""
138-
try:
139-
return orjson.dumps(
140-
obj, default=json_default, option=orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z
141-
)
142-
except (TypeError, ValueError):
143-
return json_packer(obj)
144-
137+
orjson_packer = functools.partial(
138+
orjson.dumps, default=json_default, option=orjson.OPT_NAIVE_UTC | orjson.OPT_UTC_Z
139+
)
145140
orjson_unpacker = orjson.loads
146141
_default_packer_unpacker = "orjson", "orjson"
147142
_default_pack_unpack = (orjson_packer, orjson_unpacker)

0 commit comments

Comments
 (0)