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

Function find_module_paths_using_imports

mypy/stubgen.py:1607–1637  ·  view source on GitHub ↗

Find path and runtime value of __all__ (if possible) for modules and packages. This function uses runtime Python imports to get the information.

(
    modules: list[str], packages: list[str], verbose: bool, quiet: bool
)

Source from the content-addressed store, hash-verified

1605
1606
1607def find_module_paths_using_imports(
1608 modules: list[str], packages: list[str], verbose: bool, quiet: bool
1609) -> tuple[list[StubSource], list[StubSource]]:
1610 """Find path and runtime value of __all__ (if possible) for modules and packages.
1611
1612 This function uses runtime Python imports to get the information.
1613 """
1614 with ModuleInspect() as inspect:
1615 py_modules: list[StubSource] = []
1616 c_modules: list[StubSource] = []
1617 found = list(walk_packages(inspect, packages, verbose))
1618 modules = modules + found
1619 modules = [
1620 mod for mod in modules if not is_non_library_module(mod)
1621 ] # We don't want to run any tests or scripts
1622 for mod in modules:
1623 try:
1624 result = find_module_path_and_all_py3(inspect, mod, verbose)
1625 except CantImport as e:
1626 tb = traceback.format_exc()
1627 if verbose:
1628 sys.stderr.write(tb)
1629 if not quiet:
1630 report_missing(mod, e.message, tb)
1631 continue
1632 if not result:
1633 c_modules.append(StubSource(mod))
1634 else:
1635 path, runtime_all = result
1636 py_modules.append(StubSource(mod, path, runtime_all))
1637 return py_modules, c_modules
1638
1639
1640def is_non_library_module(module: str) -> bool:

Callers 1

collect_build_targetsFunction · 0.85

Calls 9

ModuleInspectClass · 0.90
walk_packagesFunction · 0.90
report_missingFunction · 0.90
listClass · 0.85
is_non_library_moduleFunction · 0.85
StubSourceClass · 0.85
appendMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…