parse.py 778 B

12345678910111213141516171819202122
  1. from __future__ import annotations
  2. from mypy.errors import Errors
  3. from mypy.nodes import MypyFile
  4. from mypy.options import Options
  5. def parse(
  6. source: str | bytes, fnam: str, module: str | None, errors: Errors | None, options: Options
  7. ) -> MypyFile:
  8. """Parse a source file, without doing any semantic analysis.
  9. Return the parse tree. If errors is not provided, raise ParseError
  10. on failure. Otherwise, use the errors object to report parse errors.
  11. The python_version (major, minor) option determines the Python syntax variant.
  12. """
  13. if options.transform_source is not None:
  14. source = options.transform_source(source)
  15. import mypy.fastparse
  16. return mypy.fastparse.parse(source, fnam=fnam, module=module, errors=errors, options=options)