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

Method _find_module_non_stub_helper

mypy/modulefinder.py:346–370  ·  view source on GitHub ↗
(
        self, id: str, pkg_dir: str
    )

Source from the content-addressed store, hash-verified

344 return version >= min_version and (max_version is None or version <= max_version)
345
346 def _find_module_non_stub_helper(
347 self, id: str, pkg_dir: str
348 ) -> OnePackageDir | ModuleNotFoundReason:
349 plausible_match = False
350 dir_path = pkg_dir
351 components = id.split(".")
352 for index, component in enumerate(components):
353 dir_path = os_path_join(dir_path, component)
354 if self.fscache.isfile(os_path_join(dir_path, "py.typed")):
355 return os.path.join(pkg_dir, *components[:-1]), index == 0
356 elif not plausible_match and (
357 self.fscache.isdir(dir_path) or self.fscache.isfile(dir_path + ".py")
358 ):
359 plausible_match = True
360 # If this is not a directory then we can't traverse further into it
361 if not self.fscache.isdir(dir_path):
362 break
363 if plausible_match:
364 if self.options:
365 module_specific_options = self.options.clone_for_module(id)
366 if module_specific_options.follow_untyped_imports:
367 return os.path.join(pkg_dir, *components[:-1]), False
368 return ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS
369 else:
370 return ModuleNotFoundReason.NOT_FOUND
371
372 def _update_ns_ancestors(self, components: list[str], match: tuple[str, bool]) -> None:
373 path, verify = match

Callers 1

_find_moduleMethod · 0.95

Calls 7

os_path_joinFunction · 0.90
enumerateFunction · 0.85
splitMethod · 0.80
clone_for_moduleMethod · 0.80
isfileMethod · 0.45
joinMethod · 0.45
isdirMethod · 0.45

Tested by

no test coverage detected