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

Method read

mypy/fscache.py:265–290  ·  view source on GitHub ↗
(self, path: str)

Source from the content-addressed store, hash-verified

263 return True
264
265 def read(self, path: str) -> bytes:
266 if path in self.read_cache:
267 return self.read_cache[path]
268 if path in self.read_error_cache:
269 raise self.read_error_cache[path]
270
271 # Need to stat first so that the contents of file are from no
272 # earlier instant than the mtime reported by self.stat().
273 self.stat_or_none(path)
274
275 dirname, basename = os.path.split(path)
276 dirname = os.path.normpath(dirname)
277 # Check the fake cache.
278 if basename == "__init__.py" and dirname in self.fake_package_cache:
279 data = b""
280 else:
281 try:
282 with open(path, "rb") as f:
283 data = f.read()
284 except OSError as err:
285 self.read_error_cache[path] = err
286 raise
287
288 self.read_cache[path] = data
289 self.hash_cache[path] = hash_digest(data)
290 return data
291
292 def hash_digest(self, path: str) -> str:
293 if path not in self.hash_cache:

Callers 1

hash_digestMethod · 0.95

Calls 3

stat_or_noneMethod · 0.95
hash_digestFunction · 0.90
splitMethod · 0.80

Tested by

no test coverage detected