| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
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
The note uses result, index = container.foo(). That assignment does not report [has-type] after the StarExpr transform. A variadic tuple still needs a star target, and both names are Any. AI-assisted (Cursor).
…-transform # Conflicts: # test-data/unit/check-typevar-tuple.test
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #21693.
(*result,) can report a spurious [has-type] error when that function is also generic over a value-constrained type variable. TypeChecker.expand_typevars copies the function once per constraint value (mypy/checker.py). Each copy is what gets checked (self.accept(item.body)). TypeTransformVisitor gives locals new Var nodes, and a copied NameExpr points at the new Var.
TransformVisitor.visit_star_expr used to return StarExpr(node.expr). The inner expression was the original node. In y = (*result,), that name still pointed at the original Var, which this copied check does not infer. Issue #21693 reports Cannot determine type of "result" and types y as tuple[Any, ...]. The inner expression is now passed through self.expr, so the copied star uses the copied variable.
StarExpr.__init__ sets valid to False. Semantic analysis sets it to True when the star is allowed, including inside a tuple. The transform assigns node.valid onto the new node so the copy keeps that flag.
The new case is testUnpackTypeVarTupleInFunctionWithConstrainedTypeVar in test-data/unit/check-typevar-tuple.test. P is constrained to int and str, the container result is Tuple[Unpack[Ts]], and the case stars it: y = (*result,). Both reveal_type lines expect tuple[Unpack[Ts`-1]], and the case records no [has-type] error. The issue note result, index = container.foo() is not in this test.
The pre-commit.ci commit only adds the missing final newline in that test file.
On 2026-10-08, gh pr view for head b0c7abbb0ed32aaf73e94a054f106357765981ca showed 24 check runs, all success, latest completion 2026-10-07T08:09:26Z. The pre-commit.ci status was success.
Drafted with Cursor.
Cherith reviewed this diff and confirmed it with the person who helped draft it.