Use mypy to parse (and optionally analyze) source files.
(
py_modules: list[StubSource], parse_only: bool, mypy_options: MypyOptions, verbose: bool
)
| 1762 | |
| 1763 | |
| 1764 | def 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 | |
| 1791 | def generate_stub_for_py_module( |
no test coverage detected
searching dependent graphs…