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.
|
Follow-up pushed at 8dee2d2 to fix the CI line-number regressions. Root cause: the PR started using nested The follow-up gives synthetic parses an explicit source-line offset and applies it only when copying nested subscript line/end-line positions. Local validation: .venv/bin/python -m pytest -n0 -q mypy/test/testcheck.py::TypeCheckSuite::check-errorcodes.test::testNestedSubscriptWrongArityLineNumber
# 1 passed
.venv/bin/python -m pytest -n0 -q <14 CI-failing node ids>
# 14 passed
uvx black --check mypy/fastparse.py
uvx ruff check mypy/fastparse.py
git diff --check
# all passed |
|
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 ( |
|
Diff from mypy_primer, showing the effect of this PR on open source code: prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/_internal/concurrency/api.py:181: error: "Call" expects no type arguments, but 1 given [type-arg]
+ src/prefect/_internal/concurrency/api.py:183: error: "Call" expects no type arguments, but 1 given [type-arg]
antidote (https://github.com/Finistere/antidote)
- src/antidote/lib/interface_ext/__init__.py:1359: error: "staticmethod" expects 2 type arguments, but 1 given [type-arg]
+ src/antidote/lib/interface_ext/__init__.py:1361: error: "staticmethod" expects 2 type arguments, but 1 given [type-arg]
- src/antidote/lib/interface_ext/__init__.py:1359: error: Missing type arguments for generic type "staticmethod" [type-arg]
+ src/antidote/lib/interface_ext/__init__.py:1361: error: Missing type arguments for generic type "staticmethod" [type-arg]
ibis (https://github.com/ibis-project/ibis)
- ibis/selectors.py:434: error: Variable "ibis.common.collections.frozendict" is not valid as a type [valid-type]
+ ibis/selectors.py:437: error: Variable "ibis.common.collections.frozendict" is not valid as a type [valid-type]
- ibis/selectors.py:434: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
+ ibis/selectors.py:437: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- ibis/expr/types/generic.py:152: error: Function "ibis.expr.types.generic.Value.type" is not valid as a type [valid-type]
+ ibis/expr/types/generic.py:164: error: Function "ibis.expr.types.generic.Value.type" is not valid as a type [valid-type]
- ibis/expr/types/generic.py:152: note: Perhaps you need "Callable[...]" or a callback protocol?
+ ibis/expr/types/generic.py:164: note: Perhaps you need "Callable[...]" or a callback protocol?
- ibis/expr/types/generic.py:170: error: Function "ibis.expr.types.generic.Value.type" is not valid as a type [valid-type]
+ ibis/expr/types/generic.py:171: error: Function "ibis.expr.types.generic.Value.type" is not valid as a type [valid-type]
- ibis/expr/types/generic.py:170: note: Perhaps you need "Callable[...]" or a callback protocol?
+ ibis/expr/types/generic.py:171: note: Perhaps you need "Callable[...]" or a callback protocol?
- ibis/expr/types/temporal.py:428: error: "Value" expects no type arguments, but 1 given [type-arg]
+ ibis/expr/types/temporal.py:431: error: "Value" expects no type arguments, but 1 given [type-arg]
- ibis/expr/types/temporal.py:1161: error: "Value" expects no type arguments, but 1 given [type-arg]
+ ibis/expr/types/temporal.py:1174: error: "Value" expects no type arguments, but 1 given [type-arg]
|
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.