From 711125677e6a0c7f4e11dbf48230cec496147dce Mon Sep 17 00:00:00 2001 From: Fix Bot Date: Tue, 19 May 2026 22:01:51 +0000 Subject: [PATCH] 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 --- mypy/build.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mypy/build.py b/mypy/build.py index 8d5db0bab8df..119e8967f844 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -3211,7 +3211,11 @@ def parse_file(self, *, temporary: bool = False, raw_data: FileRawData | None = # The file was already parsed. return - if raw_data is None: + if raw_data is None and not ( + self.options.native_parser + and self.source is None + and self.manager.fscache.exists(self.xpath, real_only=True) + ): source = self.get_source() else: source = ""