Skip to content

Commit 4cda52d

Browse files
authored
Include tuple fallback in constraints built from tuple types (#19100)
Fixes #19093.
1 parent ed88d82 commit 4cda52d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

mypy/constraints.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,11 @@ def visit_tuple_type(self, template: TupleType) -> list[Constraint]:
13351335
res.extend(
13361336
infer_constraints(template_items[i], actual_items[i], self.direction)
13371337
)
1338+
res.extend(
1339+
infer_constraints(
1340+
template.partial_fallback, actual.partial_fallback, self.direction
1341+
)
1342+
)
13381343
return res
13391344
elif isinstance(actual, AnyType):
13401345
return self.infer_against_any(template.items, actual)

test-data/unit/check-typevar-tuple.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,3 +2628,19 @@ def fn(f: Callable[[*tuple[T]], int]) -> Callable[[*tuple[T]], int]: ...
26282628
def test(*args: Unpack[tuple[T]]) -> int: ...
26292629
reveal_type(fn(test)) # N: Revealed type is "def [T] (T`1) -> builtins.int"
26302630
[builtins fixtures/tuple.pyi]
2631+
2632+
[case testConstraintsIncludeTupleFallback]
2633+
from typing import Generic, TypeVar
2634+
from typing_extensions import TypeVarTuple, Unpack
2635+
2636+
T = TypeVar("T")
2637+
Ts = TypeVarTuple("Ts")
2638+
_FT = TypeVar("_FT", bound=type)
2639+
2640+
def identity(smth: _FT) -> _FT:
2641+
return smth
2642+
2643+
@identity
2644+
class S(tuple[Unpack[Ts]], Generic[T, Unpack[Ts]]):
2645+
def f(self, x: T, /) -> T: ...
2646+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)