Skip to content

Commit f02c757

Browse files
committed
test
1 parent 99e2688 commit f02c757

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

test-data/unit/check-generics.test

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
-- --------------------
33

44

5-
[case testGenericMethodReturnType]
65
from typing import TypeVar, Generic
6+
[case testGenericMethodReturnType]
77
T = TypeVar('T')
88
a: A[B]
99
b: B
@@ -3563,3 +3563,53 @@ def foo(x: T):
35633563
reveal_type(C) # N: Revealed type is "Overload(def [T, S] (x: builtins.int, y: S`-1) -> __main__.C[__main__.Int[S`-1]], def [T, S] (x: builtins.str, y: S`-1) -> __main__.C[__main__.Str[S`-1]])"
35643564
reveal_type(C(0, x)) # N: Revealed type is "__main__.C[__main__.Int[T`-1]]"
35653565
reveal_type(C("yes", x)) # N: Revealed type is "__main__.C[__main__.Str[T`-1]]"
3566+
3567+
[case testDeterminismFromJoinOrderingInSolver]
3568+
# Used to fail non-deterministically
3569+
# https://github.com/python/mypy/issues/19121
3570+
from __future__ import annotations
3571+
from typing import Generic, Iterable, Iterator, Self, TypeVar
3572+
3573+
_T1 = TypeVar("_T1")
3574+
_T2 = TypeVar("_T2")
3575+
_T3 = TypeVar("_T3")
3576+
_T_co = TypeVar("_T_co", covariant=True)
3577+
3578+
class Base(Iterable[_T1]):
3579+
def __iter__(self) -> Iterator[_T1]: ...
3580+
class A(Base[_T1]): ...
3581+
class B(Base[_T1]): ...
3582+
class C(Base[_T1]): ...
3583+
class D(Base[_T1]): ...
3584+
class E(Base[_T1]): ...
3585+
3586+
class zip2(Generic[_T_co]):
3587+
def __new__(
3588+
cls,
3589+
iter1: Iterable[_T1],
3590+
iter2: Iterable[_T2],
3591+
iter3: Iterable[_T3],
3592+
) -> zip2[tuple[_T1, _T2, _T3]]: ...
3593+
def __iter__(self) -> Self: ...
3594+
def __next__(self) -> _T_co: ...
3595+
3596+
def draw(
3597+
colors1: A[str] | B[str] | C[int] | D[int | str],
3598+
colors2: A[str] | B[str] | C[int] | D[int | str],
3599+
colors3: A[str] | B[str] | C[int] | D[int | str],
3600+
) -> None:
3601+
for c1, c2, c3 in zip2(colors1, colors2, colors3):
3602+
reveal_type(c1) # N: Revealed type is "Union[builtins.int, builtins.str]"
3603+
reveal_type(c2) # N: Revealed type is "Union[builtins.int, builtins.str]"
3604+
reveal_type(c3) # N: Revealed type is "Union[builtins.int, builtins.str]"
3605+
3606+
def draw_again(
3607+
colors1: B[str] | A[int | str] | C[str] | E[int] | D[int],
3608+
colors2: B[str] | A[int | str] | C[str] | E[int] | D[int],
3609+
colors3: B[str] | A[int | str] | C[str] | E[int] | D[int],
3610+
) -> None:
3611+
for c1, c2, c3 in zip2(colors1, colors2, colors3):
3612+
reveal_type(c1) # N: Revealed type is "Union[builtins.int, builtins.str]"
3613+
reveal_type(c2) # N: Revealed type is "Union[builtins.int, builtins.str]"
3614+
reveal_type(c3) # N: Revealed type is "Union[builtins.int, builtins.str]"
3615+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)