Skip to content

Avoid eager file read in State.parse_file() when using native parser#21516

Closed
JiwaniZakir wants to merge 1 commit into
python:masterfrom
JiwaniZakir:fix/issue-21514
Closed

Avoid eager file read in State.parse_file() when using native parser#21516
JiwaniZakir wants to merge 1 commit into
python:masterfrom
JiwaniZakir:fix/issue-21514

Conversation

@JiwaniZakir
Copy link
Copy Markdown
Contributor

In State.parse_file() in mypy/build.py, get_source() was called unconditionally when raw_data was None, causing eager file reading in Python even when using the native parser with a single on-disk file in the batch. The fix makes get_source() conditional, skipping it when the native parser is enabled, no source override is present, and the file exists on disk — passing an empty string to parse_file_inner() instead, matching the parallel code path. Run python -m pytest mypy/test/testparse.py mypy/test/testfinegrained.py -x -q to verify.

Fixes #21514

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 python#21514
@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native parser reads file eagerly if there is one file in parse batch

2 participants