Use nested subscript line numbers in fastparse#21500
Use nested subscript line numbers in fastparse#21500Sean-Kenneth-Doherty wants to merge 3 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
|
I pushed follow-up commit The follow-up keeps normal source annotations at offset 0 and passes Fresh local validation on the updated head:
The refreshed GitHub Actions matrix is running now. |
|
Follow-up after the first CI run exposed line-number regressions in synthetic type parses:
The refreshed GitHub Actions matrix is still running on the current head ( |

Fixes #21480
When fastparse converts a type annotation subscript into an
UnboundType, it used the outer annotation line captured whenTypeConverterwas created. For nested multi-line subscripts, that made wrong-arity errors point at the outer annotation instead of the nested offending subscript.Use the AST subscript node's own line number for real source annotations while preserving source offsets for annotations parsed out of type comments. This matches the native parser behavior for nested annotations without collapsing type-comment errors to line 1.
Verification:
PATH=.venv/bin:$PATH .venv/bin/python runtests.py testNestedSubscriptWrongArityLineNumber testClassVarTooManyArguments testInvalidNumberOfGenericArgsInTypeDeclPATH=.venv/bin:$PATH .venv/bin/python runtests.py testInvalidNumberOfGenericArgsInUndefinedArg testInvalidNumberOfGenericArgsInNestedBlock testInvalidNumberOfGenericArgsInTupleType testInvalidNumberOfGenericArgsInFunctionType testInvalidFunctionType testInvalidOptionalType testClassVarInClassVarPATH=.venv/bin:$PATH .venv/bin/python runtests.py testPreviousErrorInMethodSemanalPass3PATH=.venv/bin:$PATH .venv/bin/python runtests.py testTypeCommentNestedSubscriptWrongArityLineNumber testNestedSubscriptWrongArityLineNumber testClassVarTooManyArgumentspython3.11andpython3.12: nested source annotations report line 3 while parsed type comments report relative line 1TMPDIR=/home/sean/.cache/codex-tmp/go-build GOTMPDIR=/home/sean/.cache/codex-tmp/go-build PATH=.venv/bin:$PATH .venv/bin/pre-commit run --files mypy/fastparse.py test-data/unit/check-errorcodes.test.venv/bin/python -m compileall -q mypy/fastparse.pyTMPDIR=/home/sean/.cache/codex-tmp/go-build GOTMPDIR=/home/sean/.cache/codex-tmp/go-build PATH=.venv/bin:$PATH .venv/bin/python -m mypy --config-file mypy_self_check.ini --no-incremental mypy/fastparse.pyNote: the full local self-check over
-p mypy -p mypycwas attempted but did not complete in a useful time locally after a long silent low-CPU run, so I replaced it with the narrower parser-file self-check plus the failing fixture coverage above.