Parse a source file. On success, store AST in the corresponding attribute of the stub source. If there are syntax errors, print them and exit.
(mod: StubSource, mypy_options: MypyOptions)
| 1734 | |
| 1735 | |
| 1736 | def parse_source_file(mod: StubSource, mypy_options: MypyOptions) -> None: |
| 1737 | """Parse a source file. |
| 1738 | |
| 1739 | On success, store AST in the corresponding attribute of the stub source. |
| 1740 | If there are syntax errors, print them and exit. |
| 1741 | """ |
| 1742 | assert mod.path is not None, "Not found module was not skipped" |
| 1743 | with open(mod.path, "rb") as f: |
| 1744 | data = f.read() |
| 1745 | source = mypy.util.decode_python_encoding(data) |
| 1746 | errors = Errors(mypy_options) |
| 1747 | mod.ast = mypy.parse.parse( |
| 1748 | source, |
| 1749 | fnam=mod.path, |
| 1750 | module=mod.module, |
| 1751 | errors=errors, |
| 1752 | options=mypy_options, |
| 1753 | file_exists=True, |
| 1754 | eager=True, |
| 1755 | ) |
| 1756 | mod.ast._fullname = mod.module |
| 1757 | if errors.is_blockers(): |
| 1758 | # Syntax error! |
| 1759 | for m in errors.new_messages(): |
| 1760 | sys.stderr.write(f"{m}\n") |
| 1761 | sys.exit(1) |
| 1762 | |
| 1763 | |
| 1764 | def generate_asts_for_modules( |
no test coverage detected
searching dependent graphs…