Skip to content

Commit 7111256

Browse files
author
Fix Bot
committed
Avoid eager file read in State.parse_file() when using native parser
When there was only one file in a parse batch, State.parse_file() was called directly and invoked get_source() unconditionally, reading the file eagerly in Python. This is unnecessary for on-disk files with the native parser, which reads files itself in Rust. The fix skips get_source() in that case, matching the behavior of the parallel path. Fixes #21514
1 parent b44b2ca commit 7111256

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

mypy/build.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3211,7 +3211,11 @@ def parse_file(self, *, temporary: bool = False, raw_data: FileRawData | None =
32113211
# The file was already parsed.
32123212
return
32133213

3214-
if raw_data is None:
3214+
if raw_data is None and not (
3215+
self.options.native_parser
3216+
and self.source is None
3217+
and self.manager.fscache.exists(self.xpath, real_only=True)
3218+
):
32153219
source = self.get_source()
32163220
else:
32173221
source = ""

0 commit comments

Comments
 (0)