forked from python/mypy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.py
More file actions
34 lines (29 loc) · 1.24 KB
/
parse.py
File metadata and controls
34 lines (29 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from typing import Union, Optional
from mypy.errors import Errors
from mypy.options import Options
from mypy.nodes import MypyFile
def parse(source: Union[str, bytes],
fnam: str,
module: Optional[str],
errors: Optional[Errors],
options: Options) -> MypyFile:
"""Parse a source file, without doing any semantic analysis.
Return the parse tree. If errors is not provided, raise ParseError
on failure. Otherwise, use the errors object to report parse errors.
The python_version (major, minor) option determines the Python syntax variant.
"""
is_stub_file = fnam.endswith('.pyi')
if options.python_version[0] >= 3 or is_stub_file:
import mypy.fastparse
return mypy.fastparse.parse(source,
fnam=fnam,
module=module,
errors=errors,
options=options)
else:
import mypy.fastparse2
return mypy.fastparse2.parse(source,
fnam=fnam,
module=module,
errors=errors,
options=options)