Repository navigation
Fix TypeVarTuple subscript with defaulted ParamSpec - #22574
Open
Sudhakar7J wants to merge 2 commits into
Open
Sudhakar7J wants to merge 2 commits into
Sudhakar7J wants to merge 2 commits into
Conversation
When a TypeVarTuple is followed by a ParamSpec with a default, allow the ParamSpec argument to be omitted and only consume a trailing argument as the ParamSpec when it is a valid ParamSpec argument. This fixes incorrect splitting that produced 'Can only replace ParamSpec...' errors and Any fallbacks. Fixes python#22375
This comment has been minimized.
This comment has been minimized.
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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 #22375
This fixes type argument splitting for generic types that include a
TypeVarTuplefollowed by a defaultedParamSpec(PEP 696). When a defaultedParamSpecsuffix argument was omitted, mypy split arguments by fixed prefix/suffix counts and incorrectly assigned a regular type argument to theParamSpec, producingCan only replace ParamSpec...and degrading inferred types toAny.The fix detects omitted defaulted suffix variables in variadic generic splitting and only consumes a trailing optional
ParamSpecargument when it is a validParamSpecargument (ParamSpec, parameter list/Parameters,.../Any-like, orUnboundType). The normalized arguments are then used for instance validation/fixing, type alias instantiation, and callable type application.AI assistance: I used an AI coding assistant to help investigate the issue and draft the patch/tests; I reviewed the behavior, ran targeted tests, and verified the reported reproduction.