Skip to content

Commit 50b0860

Browse files
committed
Remove file_exists parameter from mypy.parse.parse() calls
1 parent 2e793ae commit 50b0860

6 files changed

Lines changed: 17 additions & 27 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,13 +1282,12 @@ def parse_file(
12821282
12831283
Raise CompileError if there is a parse error.
12841284
"""
1285-
file_exists = self.fscache.exists(path, real_only=True)
12861285
t0 = time.time()
12871286
if raw_data:
12881287
# If possible, deserialize from known binary data instead of parsing from scratch.
12891288
tree = load_from_raw(path, id, raw_data, self.errors, options)
12901289
else:
1291-
tree = parse(source, path, id, self.errors, options=options, file_exists=file_exists)
1290+
tree = parse(source, path, id, self.errors, options=options)
12921291
tree._fullname = id
12931292
if self.stats_enabled:
12941293
with self.stats_lock:

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
eager=True,
592591
)
593592
if temp_errors.is_errors():

mypy/parse.py

Lines changed: 15 additions & 20 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
eager: bool = False,
2221
) -> MypyFile:
2322
"""Parse a source file, without doing any semantic analysis.
@@ -29,25 +28,21 @@ def parse(
2928
the parse errors, use eager=True.
3029
"""
3130
if options.native_parser:
32-
# Native parser only works with actual files on disk
33-
# Fall back to fastparse for in-memory source or non-existent files
34-
if file_exists:
35-
import mypy.nativeparse
36-
37-
ignore_errors = options.ignore_errors or fnam in errors.ignored_files
38-
# If errors are ignored, we can drop many function bodies to speed up type checking.
39-
strip_function_bodies = ignore_errors and not options.preserve_asts
40-
tree, _, _ = mypy.nativeparse.native_parse(
41-
fnam, options, skip_function_bodies=strip_function_bodies
42-
)
43-
# Set is_stub based on file extension
44-
tree.is_stub = fnam.endswith(".pyi")
45-
# Note: tree.imports is populated directly by load_from_raw() with deserialized
46-
# import metadata, so we don't need to collect imports via AST traversal
47-
if eager and tree.raw_data is not None:
48-
tree = load_from_raw(fnam, module, tree.raw_data, errors, options)
49-
return tree
50-
# Fall through to fastparse for non-existent files
31+
import mypy.nativeparse
32+
33+
ignore_errors = options.ignore_errors or fnam in errors.ignored_files
34+
# If errors are ignored, we can drop many function bodies to speed up type checking.
35+
strip_function_bodies = ignore_errors and not options.preserve_asts
36+
tree, _, _ = mypy.nativeparse.native_parse(
37+
fnam, options, source, skip_function_bodies=strip_function_bodies
38+
)
39+
# Set is_stub based on file extension
40+
tree.is_stub = fnam.endswith(".pyi")
41+
# Note: tree.imports is populated directly by load_from_raw() with deserialized
42+
# import metadata, so we don't need to collect imports via AST traversal
43+
if eager and tree.raw_data is not None:
44+
tree = load_from_raw(fnam, module, tree.raw_data, errors, options)
45+
return tree
5146

5247
if options.transform_source is not None:
5348
source = options.transform_source(source)

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
eager=True,
17551754
)
17561755
mod.ast._fullname = mod.module

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
eager=True,
7170
)
7271
if errors.is_errors():
@@ -108,7 +107,6 @@ def test_parse_error(testcase: DataDrivenTestCase) -> None:
108107
"__main__",
109108
errors=errors,
110109
options=options,
111-
file_exists=False,
112110
eager=True,
113111
)
114112
if errors.is_errors():

0 commit comments

Comments
 (0)