MCPcopy
hub / github.com/python/mypy / parse_source_file

Function parse_source_file

mypy/stubgen.py:1736–1761  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1734
1735
1736def 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
1764def generate_asts_for_modules(

Callers 1

Calls 6

is_blockersMethod · 0.95
new_messagesMethod · 0.95
ErrorsClass · 0.90
exitMethod · 0.80
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…