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

Method exists_case

mypy/fscache.py:226–248  ·  view source on GitHub ↗

Return whether path exists - checking path components in case sensitive fashion, up to prefix.

(self, path: str, prefix: str)

Source from the content-addressed store, hash-verified

224 return res
225
226 def exists_case(self, path: str, prefix: str) -> bool:
227 """Return whether path exists - checking path components in case sensitive
228 fashion, up to prefix.
229 """
230 if path in self.exists_case_cache:
231 return self.exists_case_cache[path]
232 head, tail = os.path.split(path)
233 if not head.startswith(prefix) or not tail:
234 # Only perform the check for paths under prefix.
235 self.exists_case_cache[path] = True
236 return True
237 try:
238 names = self.listdir(head)
239 # This allows one to check file name case sensitively in
240 # case-insensitive filesystems.
241 res = tail in names
242 except OSError:
243 res = False
244 if res:
245 # Also recursively check other path components.
246 res = self.exists_case(head, prefix)
247 self.exists_case_cache[path] = res
248 return res
249
250 def isdir(self, path: str) -> bool:
251 st = self.stat_or_none(path)

Callers 2

isfile_caseMethod · 0.95
_find_moduleMethod · 0.80

Calls 3

listdirMethod · 0.95
splitMethod · 0.80
startswithMethod · 0.45

Tested by

no test coverage detected