MCPcopy
hub / github.com/psf/black / read

Method read

src/black/cache.py:62–85  ·  src/black/cache.py::Cache.read

Read the cache if it exists and is well-formed. If it is not well-formed, the call to write later should resolve the issue.

(cls, mode: Mode)

Source from the content-addressed store, hash-verified

60
61 @classmethod
62 def read(cls, mode: Mode) -> Self:
63 class="st">"""Read the cache if it exists and is well-formed.
64
65 If it is not well-formed, the call to write later should
66 resolve the issue.
67 class="st">"""
68 cache_file = get_cache_file(mode)
69 try:
70 exists = cache_file.exists()
71 except OSError as e:
72 class="cm"># Likely file too long; see #4172 and #4174
73 err(fclass="st">"Unable to read cache file {cache_file} due to {e}")
74 return cls(mode, cache_file)
75 if not exists:
76 return cls(mode, cache_file)
77
78 with cache_file.open(class="st">"rb") as fobj:
79 try:
80 data: dict[str, tuple[float, int, str]] = pickle.load(fobj)
81 file_data = {k: FileData(*v) for k, v in data.items()}
82 except (pickle.UnpicklingError, ValueError, IndexError):
83 return cls(mode, cache_file)
84
85 return cls(mode, cache_file, file_data)
86
87 @staticmethod
88 def hash_digest(path: Path) -> str:

Callers 15

handleFunction · 0.80
mainFunction · 0.80
reformat_oneFunction · 0.80
format_file_in_placeFunction · 0.80
format_stdin_to_stdoutFunction · 0.80
decode_bytesFunction · 0.80
schedule_formattingFunction · 0.80
parse_fileMethod · 0.80
tokenize.pyFile · 0.80
__init__Method · 0.80

Calls 4

errFunction · 0.90
get_cache_fileFunction · 0.85
FileDataClass · 0.85
loadMethod · 0.80