@@ -17,7 +17,6 @@ def parse(
1717 module : str | None ,
1818 errors : Errors ,
1919 options : Options ,
20- file_exists : bool ,
2120 imports_only : bool = False ,
2221) -> tuple [MypyFile , list [ParseError ]]:
2322 """Parse a source file, without doing any semantic analysis.
@@ -28,27 +27,25 @@ def parse(
2827 The python_version (major, minor) option determines the Python syntax variant.
2928 """
3029 if options .native_parser :
31- # Native parser only works with actual files on disk
32- # Fall back to fastparse for in-memory source or non-existent files
33- if file_exists :
34- import mypy .nativeparse
35-
36- ignore_errors = options .ignore_errors or fnam in errors .ignored_files
37- # If errors are ignored, we can drop many function bodies to speed up type checking.
38- strip_function_bodies = ignore_errors and not options .preserve_asts
39- tree , parse_errors , type_ignores = mypy .nativeparse .native_parse (
40- fnam ,
41- options ,
42- skip_function_bodies = strip_function_bodies ,
43- imports_only = imports_only ,
44- )
45- # Convert type ignores list to dict
46- tree .ignored_lines = dict (type_ignores )
47- # Set is_stub based on file extension
48- tree .is_stub = fnam .endswith (".pyi" )
49- # Note: tree.imports is populated directly by native_parse with deserialized
50- # import metadata, so we don't need to collect imports via AST traversal
51- return tree , parse_errors
30+ import mypy .nativeparse
31+
32+ ignore_errors = options .ignore_errors or fnam in errors .ignored_files
33+ # If errors are ignored, we can drop many function bodies to speed up type checking.
34+ strip_function_bodies = ignore_errors and not options .preserve_asts
35+ tree , parse_errors , type_ignores = mypy .nativeparse .native_parse (
36+ fnam ,
37+ options ,
38+ source ,
39+ skip_function_bodies = strip_function_bodies ,
40+ imports_only = imports_only ,
41+ )
42+ # Convert type ignores list to dict
43+ tree .ignored_lines = dict (type_ignores )
44+ # Set is_stub based on file extension
45+ tree .is_stub = fnam .endswith (".pyi" )
46+ # Note: tree.imports is populated directly by native_parse with deserialized
47+ # import metadata, so we don't need to collect imports via AST traversal
48+ return tree , parse_errors
5249 # Fall through to fastparse for non-existent files
5350
5451 assert not imports_only
0 commit comments