Report nested subscript arity errors at the right line in old parser - #22045
Open
Dextheking1 wants to merge 2 commits into
Open
Dextheking1 wants to merge 2 commits into
Dextheking1 wants to merge 2 commits into
Conversation
The old parser pinned every type node to the outer annotation line, so arity errors in nested subscripts were reported at the wrong line. Use the subscript's own source line instead, matching the native parser. Type comments and string annotations keep the outer line, since their nodes only have fragment-relative positions. Fixes python#21480.
for more information, see https://pre-commit.ci
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Dextheking1
marked this pull request as ready for review
September 24, 2026 23:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21480.
The old parser pinned every type node to the outer annotation line, so an arity error in a nested subscript was reported at the wrong line:
Old parser said line 1, native parser says line 3. Now both say line 3.
TypeConverter.visit_Subscriptuses the subscript's own source line for theUnboundType. Type comments and string annotations keep the old behavior through a newis_fragmentflag, since nodes parsed from those fragments only have fragment-relative line numbers.Added
testColumnNestedSubscriptArityErrorLine_old_parserto check-columns.test. It fails before the fix (error at the outer line) and passes after. Full testcheck/testparse/testsemanal run: 9030 passed.