Skip to content

Commit eca912f

Browse files
committed
Remove file_exists parameter from mypy.parse.parse() calls
1 parent 10e9494 commit eca912f

6 files changed

Lines changed: 21 additions & 31 deletions

File tree

misc/dump-ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def dump(fname: str, python_version: tuple[int, int], quiet: bool = False) -> No
1919
options.python_version = python_version
2020
with open(fname, "rb") as f:
2121
s = f.read()
22-
tree = parse(s, fname, None, errors=Errors(options), options=options, file_exists=True)
22+
tree = parse(s, fname, None, errors=Errors(options), options=options)
2323
if not quiet:
2424
print(tree)
2525

mypy/build.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,9 +1214,7 @@ def parse_file(
12141214
Raise CompileError if there is a parse error.
12151215
"""
12161216
imports_only = False
1217-
file_exists = self.fscache.exists(path)
1218-
if self.workers and file_exists:
1219-
# Currently, we can use the native parser only for actual files.
1217+
if self.workers:
12201218
imports_only = True
12211219
t0 = time.time()
12221220
parse_errors: list[ParseError] = []
@@ -1230,7 +1228,6 @@ def parse_file(
12301228
id,
12311229
self.errors,
12321230
options=options,
1233-
file_exists=file_exists,
12341231
imports_only=imports_only,
12351232
)
12361233
tree._fullname = id

mypy/checkstrformat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ def apply_field_accessors(
587587
module=None,
588588
options=self.chk.options,
589589
errors=temp_errors,
590-
file_exists=False,
591590
)
592591
if temp_errors.is_errors():
593592
self.msg.fail(

mypy/parse.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

mypy/stubgen.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,6 @@ def parse_source_file(mod: StubSource, mypy_options: MypyOptions) -> None:
17501750
module=mod.module,
17511751
errors=errors,
17521752
options=mypy_options,
1753-
file_exists=True,
17541753
)
17551754
mod.ast._fullname = mod.module
17561755
for err in errs:

mypy/test/testparse.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def test_parser(testcase: DataDrivenTestCase) -> None:
6666
module="__main__",
6767
errors=errors,
6868
options=options,
69-
file_exists=False,
7069
)
7170
if errors.is_errors():
7271
errors.raise_error()
@@ -107,7 +106,6 @@ def test_parse_error(testcase: DataDrivenTestCase) -> None:
107106
"__main__",
108107
errors=errors,
109108
options=options,
110-
file_exists=False,
111109
)
112110
if errors.is_errors():
113111
errors.raise_error()

0 commit comments

Comments
 (0)