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

Method write

mypy/metastore.py:113–131  ·  view source on GitHub ↗
(self, name: str, data: bytes, mtime: float | None = None)

Source from the content-addressed store, hash-verified

111 return f.read()
112
113 def write(self, name: str, data: bytes, mtime: float | None = None) -> bool:
114 assert not os.path.isabs(name), "Don't use absolute paths!"
115
116 if not self.cache_dir_prefix:
117 return False
118
119 path = os_path_join(self.cache_dir_prefix, name)
120 tmp_filename = path + "." + random_string()
121 try:
122 os.makedirs(os.path.dirname(path), exist_ok=True)
123 with open(tmp_filename, "wb") as f:
124 f.write(data)
125 os.replace(tmp_filename, path)
126 if mtime is not None:
127 os.utime(path, times=(mtime, mtime))
128
129 except OSError:
130 return False
131 return True
132
133 def remove(self, name: str) -> None:
134 if not self.cache_dir_prefix:

Callers 1

mainFunction · 0.95

Calls 4

os_path_joinFunction · 0.90
random_stringFunction · 0.85
replaceMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected