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

Method isfile_case

mypy/fscache.py:190–224  ·  view source on GitHub ↗

Return whether path exists and is a file. On case-insensitive filesystems (like Mac or Windows) this returns False if the case of path's last component does not exactly match the case found in the filesystem. We check also the case of other path components up to pre

(self, path: str, prefix: str)

Source from the content-addressed store, hash-verified

188 return stat.S_ISREG(st.st_mode)
189
190 def isfile_case(self, path: str, prefix: str) -> bool:
191 """Return whether path exists and is a file.
192
193 On case-insensitive filesystems (like Mac or Windows) this returns
194 False if the case of path's last component does not exactly match
195 the case found in the filesystem.
196
197 We check also the case of other path components up to prefix.
198 For example, if path is 'user-stubs/pack/mod.pyi' and prefix is 'user-stubs',
199 we check that the case of 'pack' and 'mod.py' matches exactly, 'user-stubs' will be
200 case insensitive on case insensitive filesystems.
201
202 The caller must ensure that prefix is a valid file system prefix of path.
203 """
204 if not self.isfile(path):
205 # Fast path
206 return False
207 if path in self.isfile_case_cache:
208 return self.isfile_case_cache[path]
209 head, tail = os.path.split(path)
210 if not tail:
211 self.isfile_case_cache[path] = False
212 return False
213 try:
214 names = self.listdir(head)
215 # This allows one to check file name case sensitively in
216 # case-insensitive filesystems.
217 res = tail in names
218 except OSError:
219 res = False
220 if res:
221 # Also recursively check the other path components in case sensitive way.
222 res = self.exists_case(head, prefix)
223 self.isfile_case_cache[path] = res
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

Callers 3

_find_moduleMethod · 0.45
verify_moduleFunction · 0.45
highest_init_levelFunction · 0.45

Calls 4

isfileMethod · 0.95
listdirMethod · 0.95
exists_caseMethod · 0.95
splitMethod · 0.80

Tested by

no test coverage detected