Skip to content

Report nested subscript arity errors at the right line in old parser - #22045

Open
Dextheking1 wants to merge 2 commits into
python:masterfrom
Dextheking1:fix/21480-nested-subscript-line
Open

Dextheking1 wants to merge 2 commits into
python:masterfrom
Dextheking1:fix/21480-nested-subscript-line

Conversation

@Dextheking1

@Dextheking1 Dextheking1 commented Sep 24, 2026 •

Copy link
Copy Markdown

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:

def foo() -> dict[
    str,
    dict[int, int, int],
]: ...

Old parser said line 1, native parser says line 3. Now both say line 3.

TypeConverter.visit_Subscript uses the subscript's own source line for the UnboundType. Type comments and string annotations keep the old behavior through a new is_fragment flag, since nodes parsed from those fragments only have fragment-relative line numbers.

Added testColumnNestedSubscriptArityErrorLine_old_parser to check-columns.test. It fails before the fix (error at the outer line) and passes after. Full testcheck/testparse/testsemanal run: 9030 passed.

Dextheking1 and others added 2 commits September 24, 2026 23:06
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.
@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. ✅

@Dextheking1
Dextheking1 marked this pull request as ready for review September 24, 2026 23:46
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.

fastparse and native parser assign different line numbers to nested subscripts in multi-line type annotations

1 participant