diff --git a/mypy/treetransform.py b/mypy/treetransform.py index f33cba1e3c7a..2c1ce2b19a73 100644 --- a/mypy/treetransform.py +++ b/mypy/treetransform.py @@ -450,7 +450,9 @@ def visit_match_stmt(self, o: MatchStmt) -> MatchStmt: ) def visit_star_expr(self, node: StarExpr) -> StarExpr: - return StarExpr(node.expr) + new = StarExpr(self.expr(node.expr)) + new.valid = node.valid + return new def visit_int_expr(self, node: IntExpr) -> IntExpr: return IntExpr(node.value) diff --git a/test-data/unit/check-typevar-tuple.test b/test-data/unit/check-typevar-tuple.test index 6d8c69a147a3..655a89d8cc81 100644 --- a/test-data/unit/check-typevar-tuple.test +++ b/test-data/unit/check-typevar-tuple.test @@ -3255,3 +3255,21 @@ class K(Base): class Base: ... reveal_type(K.q) # N: Revealed type is "builtins.list[tuple[builtins.bool, builtins.int, builtins.str]]" [builtins fixtures/tuple.pyi] + +[case testUnpackTypeVarTupleInFunctionWithConstrainedTypeVar] +from typing import Generic, TypeVar, Tuple +from typing_extensions import TypeVarTuple, Unpack + +T = TypeVar("T") +P = TypeVar("P", int, str) +Ts = TypeVarTuple("Ts") + +class Container(Generic[T, P]): + def foo(self) -> T: ... + +def f(container: Container[Tuple[Unpack[Ts]], P]) -> None: + result = container.foo() + reveal_type(result) # N: Revealed type is "tuple[Unpack[Ts`-1]]" + y = (*result,) + reveal_type(y) # N: Revealed type is "tuple[Unpack[Ts`-1]]" +[builtins fixtures/tuple.pyi]