Honor transform_source with the native parser - #22008
Dextheking1 wants to merge 1 commit into
Conversation
The native (Rust) parser path in mypy/parse.py silently ignored options.transform_source: the transform was only applied in the old-parser branch. Additionally, with the native parser the source was never read in the first place during (parallel) builds, since State.requires_read() did not account for the transform. Apply the transform up front in parse() so both parsers honor it, and make requires_read() return True when a transform is configured, so the source is read (and then transformed) before the native parser sees it. Fixes python#21222
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
The only failing check is This is unrelated to the change here. The PR only touches I checked: the py314t job is not in the required set for merging (the check's |
Fixes #21222 (the
transform_sourcehalf).The issue reports two things broken under parallel checking. The shadow-file half was already handled —
requires_read()checks the shadow map and works in threaded and--num-workersbuilds. The genuinely broken half isoptions.transform_source: the native parser path skipped it (it was only applied on the old-parser path), and the parallel build passedsource=None, so the parser read the untransformed file from disk.This applies the transform before dispatching to the native parser, and makes
requires_read()force a source read when a transform is configured.Tests: new
TransformSourceSuiteinmypy/test/testparse.pycovering the native parser, the old parser, and a parallel build. The native-parser cases fail without the fix; all pass with it. Fulltestparsesuite (249 passed, 75 skipped) and shadow-relatedtestcheck(13 passed) green.Disclosure: I used an LLM assistant while developing this fix.