MCPcopy
hub / github.com/python/mypy / _can_find_module_in_parent_dir

Method _can_find_module_in_parent_dir

mypy/modulefinder.py:380–396  ·  view source on GitHub ↗

Test if a module can be found by checking the parent directories of the current working directory.

(self, id: str)

Source from the content-addressed store, hash-verified

378 path = os.path.dirname(path)
379
380 def _can_find_module_in_parent_dir(self, id: str) -> bool:
381 """Test if a module can be found by checking the parent directories
382 of the current working directory.
383 """
384 working_dir = os.getcwd()
385 parent_search = FindModuleCache(
386 SearchPaths((), (), (), ()),
387 self.fscache,
388 self.options,
389 stdlib_py_versions=self.stdlib_py_versions,
390 )
391 while any(is_init_file(file) for file in os.listdir(working_dir)):
392 working_dir = os.path.dirname(working_dir)
393 parent_search.search_paths = SearchPaths((working_dir,), (), (), ())
394 if not isinstance(parent_search._find_module(id, False)[0], ModuleNotFoundReason):
395 return True
396 return False
397
398 def _find_module(self, id: str, use_typeshed: bool) -> tuple[ModuleSearchResult, bool]:
399 """Try to find a module in all available sources.

Callers 1

find_moduleMethod · 0.95

Calls 7

_find_moduleMethod · 0.95
FindModuleCacheClass · 0.85
SearchPathsClass · 0.85
anyFunction · 0.85
is_init_fileFunction · 0.85
isinstanceFunction · 0.85
listdirMethod · 0.45

Tested by

no test coverage detected