Fix nested Concatenate with ellipsis crash#21414
Fix nested Concatenate with ellipsis crash#21414cyphercodes wants to merge 3 commits intopython:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
|
IMO we should disallow from typing import Callable, Concatenate, ParamSpec
P = ParamSpec("P")
f: Callable[Concatenate[Concatenate[int, P], ...], object] # E: Invalid location for ConcatenatePotentially related to #21425. I think this PR currently just duplicates effort. |
|
Updated this PR to address the latest review feedback from @A5rocks:
Local verification:
|
This comment has been minimized.
This comment has been minimized.
|
Updated the expected output for the tuple/ Verification:
|
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
| [case testTuplePassedParameters] | ||
| from typing_extensions import Concatenate | ||
|
|
||
| def c(t: tuple[Concatenate[int, ...]]) -> None: # E: Cannot use "[int, VarArg(Any), KwArg(Any)]" for tuple, only for ParamSpec |
There was a problem hiding this comment.
I think we can remove this old error codepath? I can't imagine a scenario where it's useful...
| and analyzed.flavor == ParamSpecFlavor.BARE | ||
| ): | ||
| if analyzed.prefix.arg_types: | ||
| if not allow_param_spec: |
There was a problem hiding this comment.
I think this can be simpler if you check isinstance for the 2 types up here. Then you can deduplicate the error codepaths.
Fixes #21404.
This rejects a nested
Concatenate[...]when it appears in the prefix arguments of anotherConcatenate, including theConcatenate[Concatenate[...], ...]crash case from the issue. The existing nested-Concatenate error path only handled theParamSpec-prefix form, so the ellipsis form could reachParameters(...)with anotherParametersobject nested inside it.Tests:
pytest -n0 mypy/test/testcheck.py::TypeCheckSuite::check-parameter-specification.test -k testStackedConcatenateIsIllegal -qpytest -n0 mypy/test/testcheck.py::TypeCheckSuite::check-parameter-specification.test -qpython -m mypy --config-file mypy_self_check.ini mypy/typeanal.pypython -m mypy --config-file mypy_self_check.ini -p mypypre-commit run --files mypy/typeanal.py test-data/unit/check-parameter-specification.testgit diff --check