Repository navigation
Transform the inner expression of StarExpr - #22131
Open
Cherith1222 wants to merge 2 commits into
Open
Cherith1222 wants to merge 2 commits into
Cherith1222 wants to merge 2 commits into
Conversation
Functions using value-constrained type variables are checked as copies made by TreeTransform. visit_star_expr reused the original inner expression, so in '(*result,)' the NameExpr kept pointing at the original Var, which is never inferred because only the copies are checked. That produced a spurious has-type error and an Any tuple. Transform the inner expression and preserve the 'valid' flag. Fixes python#21693. AI-assisted (Cursor). Not yet reviewed by a human.
for more information, see https://pre-commit.ci
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: scipy-stubs (https://github.com/scipy/scipy-stubs)
- tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
|
dibrinsofor
approved these changes
Oct 7, 2026
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.
Summary
Functions that use value-constrained type variables are checked as copies made by
TreeTransform.visit_star_exprreused the original inner expression, so in(*result,)theNameExprstill pointed at the originalVar. That variable is never inferred, because only the copies are checked. The result was a spurious[has-type]error and anAnytuple. The inner expression is now transformed, and thevalidflag is preserved.Fixes #21693.
Test Plan
Before the change, the new test failed. After it, the new test passed.
check-typevar-tuple.testandcheck-typevar-values.testtogether: 212 passed. Resource Sentinel, 1 CPU, 2.5 GiB.Not run: the full mypy suite and mypy_primer.
AI assistance
Drafted with Cursor. The account owner authorized opening this pull request. A human has not reviewed the diff. There is no
Co-authored-by,Reviewed-by, orSigned-off-bytrailer.