Skip to content

Commit 52b6db2

Browse files
authored
Fallback to json if integer exceeds 64-bit range
1 parent f067db4 commit 52b6db2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

mypy/util.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,11 +928,19 @@ def quote_docstring(docstr: str) -> str:
928928
def json_dumps(obj: object, debug: bool = False) -> bytes:
929929
if orjson is not None:
930930
if debug:
931-
return orjson.dumps(obj, option=orjson.OPT_INDENT_2 | orjson.OPT_SORT_KEYS) # type: ignore[no-any-return]
931+
dumps_option = orjson.OPT_INDENT_2 | orjson.OPT_SORT_KEYS
932932
else:
933933
# TODO: If we don't sort keys here, testIncrementalInternalScramble fails
934934
# We should document exactly what is going on there
935-
return orjson.dumps(obj, option=orjson.OPT_SORT_KEYS) # type: ignore[no-any-return]
935+
dumps_option = orjson.OPT_SORT_KEYS
936+
937+
try:
938+
return orjson.dumps(obj, option=dumps_option)
939+
except TypeError as e:
940+
if str(e) == 'Integer exceeds 64-bit range':
941+
# use stdlib json below
942+
pass
943+
raise
936944

937945
if debug:
938946
return json.dumps(obj, indent=2, sort_keys=True).encode("utf-8")

0 commit comments

Comments
 (0)