MCPcopy Create free account
hub / github.com/python/mypy / generate_asts_for_modules

Function generate_asts_for_modules

mypy/stubgen.py:1764–1788  ·  view source on GitHub ↗

Use mypy to parse (and optionally analyze) source files.

(
    py_modules: list[StubSource], parse_only: bool, mypy_options: MypyOptions, verbose: bool
)

Source from the content-addressed store, hash-verified

1762
1763
1764def generate_asts_for_modules(
1765 py_modules: list[StubSource], parse_only: bool, mypy_options: MypyOptions, verbose: bool
1766) -> None:
1767 """Use mypy to parse (and optionally analyze) source files."""
1768 if not py_modules:
1769 return # Nothing to do here, but there may be C modules
1770 if verbose:
1771 print(f"Processing {len(py_modules)} files...")
1772 if parse_only:
1773 for mod in py_modules:
1774 parse_source_file(mod, mypy_options)
1775 return
1776 # Perform full semantic analysis of the source set.
1777 try:
1778 res = build([module.source for module in py_modules], mypy_options)
1779 except CompileError as e:
1780 raise SystemExit(f"Critical error during semantic analysis: {e}") from e
1781
1782 for mod in py_modules:
1783 mod.ast = res.graph[mod.module].tree
1784 # Use statically inferred __all__ if there is no runtime one.
1785 if mod.runtime_all is None:
1786 mod_names = res.manager.semantic_analyzer.modules[mod.module].names
1787 if "__all__" in mod_names:
1788 mod.runtime_all = [name for name, sym in mod_names.items() if sym.module_public]
1789
1790
1791def generate_stub_for_py_module(

Callers 1

generate_stubsFunction · 0.85

Calls 5

buildFunction · 0.90
printFunction · 0.85
lenFunction · 0.85
parse_source_fileFunction · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…