MCPcopy Index your code
hub / github.com/python/mypy / json_dumps

Function json_dumps

mypy/util.py:945–964  ·  view source on GitHub ↗
(obj: object, debug: bool = False)

Source from the content-addressed store, hash-verified

943
944
945def json_dumps(obj: object, debug: bool = False) -> bytes:
946 if orjson is not None:
947 if debug:
948 dumps_option = orjson.OPT_INDENT_2 | orjson.OPT_SORT_KEYS
949 else:
950 # TODO: If we don't sort keys here, testIncrementalInternalScramble fails
951 # We should document exactly what is going on there
952 dumps_option = orjson.OPT_SORT_KEYS
953
954 try:
955 return orjson.dumps(obj, option=dumps_option) # type: ignore[no-any-return]
956 except TypeError as e:
957 if str(e) != "Integer exceeds 64-bit range":
958 raise
959
960 if debug:
961 return json.dumps(obj, indent=2, sort_keys=True).encode("utf-8")
962 else:
963 # See above for sort_keys comment
964 return json.dumps(obj, sort_keys=True, separators=(",", ":")).encode("utf-8")
965
966
967def json_loads(data: bytes) -> Any:

Callers 12

deps_to_jsonFunction · 0.90
write_deps_cacheFunction · 0.90
write_plugins_snapshotFunction · 0.90
find_cache_metaFunction · 0.90
write_cacheFunction · 0.90
write_cache_metaFunction · 0.90
write_cache_meta_exFunction · 0.90
apply_diffFunction · 0.90
encode_for_diffFunction · 0.90
mainFunction · 0.90
write_cacheFunction · 0.90

Calls 3

strClass · 0.85
dumpsMethod · 0.80
encodeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…