MCPcopy
hub / github.com/python/mypy / _load_json_file

Function _load_json_file

mypy/build.py:1838–1869  ·  view source on GitHub ↗

A simple helper to read a JSON file with logging.

(
    file: str, manager: BuildManager, log_success: str, log_error: str
)

Source from the content-addressed store, hash-verified

1836
1837
1838def _load_json_file(
1839 file: str, manager: BuildManager, log_success: str, log_error: str
1840) -> dict[str, Any] | None:
1841 """A simple helper to read a JSON file with logging."""
1842 t0 = time.time()
1843 try:
1844 data = manager.metastore.read(file)
1845 except OSError:
1846 manager.log(log_error + file)
1847 return None
1848 manager.add_stats(metastore_read_time=time.time() - t0)
1849 # Only bother to compute the log message if we are logging it, since it could be big
1850 if manager.verbosity() >= 2:
1851 manager.trace(log_success + data.rstrip().decode())
1852 try:
1853 t1 = time.time()
1854 result = json_loads(data)
1855 manager.add_stats(data_file_load_time=time.time() - t1)
1856 except json.JSONDecodeError:
1857 manager.errors.set_file(file, None, manager.options)
1858 manager.error(
1859 None,
1860 "Error reading JSON file;"
1861 " you likely have a bad cache.\n"
1862 "Try removing the {cache_dir} directory"
1863 " and run mypy again.".format(cache_dir=manager.options.cache_dir),
1864 blocker=True,
1865 )
1866 return None
1867 else:
1868 assert isinstance(result, dict)
1869 return result
1870
1871
1872def _cache_dir_prefix(options: Options) -> str:

Callers 4

read_plugins_snapshotFunction · 0.85
read_deps_cacheFunction · 0.85
find_cache_metaFunction · 0.85
load_treeMethod · 0.85

Calls 12

json_loadsFunction · 0.90
isinstanceFunction · 0.85
add_statsMethod · 0.80
verbosityMethod · 0.80
traceMethod · 0.80
rstripMethod · 0.80
set_fileMethod · 0.80
readMethod · 0.45
logMethod · 0.45
decodeMethod · 0.45
errorMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…