@@ -808,6 +808,84 @@ b = (1, 'x')
808808a = (0, *b, '')
809809[builtins fixtures/tuple.pyi]
810810
811+ [case testTupleMeetTupleAny]
812+ # flags: --hide-error-context
813+ from typing import Union, Tuple
814+ class A: pass
815+ class B: pass
816+
817+ def f(x: Union[B, Tuple[A, A]]) -> None:
818+ if isinstance(x, tuple):
819+ reveal_type(x) # E: Revealed type is 'Tuple[__main__.A, __main__.A]'
820+ else:
821+ reveal_type(x) # E: Revealed type is '__main__.B'
822+
823+ def g(x: Union[str, Tuple[str, str]]) -> None:
824+ if isinstance(x, tuple):
825+ reveal_type(x) # E: Revealed type is 'Tuple[builtins.str, builtins.str]'
826+ else:
827+ reveal_type(x) # E: Revealed type is 'builtins.str'
828+
829+ [builtins fixtures/tuple.pyi]
830+ [out]
831+
832+ [case testTupleMeetTUpleAnyComplex]
833+ # flags: --hide-error-context
834+ from typing import Tuple, Union
835+
836+ Pair = Tuple[int, int]
837+ Variant = Union[int, Pair]
838+ def tuplify(v: Variant) -> None:
839+ reveal_type(v) # E: Revealed type is 'Union[builtins.int, Tuple[builtins.int, builtins.int]]'
840+ if not isinstance(v, tuple):
841+ reveal_type(v) # E: Revealed type is 'builtins.int'
842+ v = (v, v)
843+ reveal_type(v) # E: Revealed type is 'Tuple[builtins.int, builtins.int]'
844+ reveal_type(v) # E: Revealed type is 'Tuple[builtins.int, builtins.int]'
845+ reveal_type(v[0]) # E: Revealed type is 'builtins.int'
846+
847+ Pair2 = Tuple[int, str]
848+ Variant2 = Union[int, Pair2]
849+ def tuplify2(v: Variant2) -> None:
850+ if isinstance(v, tuple):
851+ reveal_type(v) # E: Revealed type is 'Tuple[builtins.int, builtins.str]'
852+ else:
853+ reveal_type(v) # E: Revealed type is 'builtins.int'
854+ [builtins fixtures/tuple.pyi]
855+ [out]
856+
857+ [case testTupleMeetTupleAnyAfter]
858+ # flags: --hide-error-context
859+ from typing import Tuple, Union
860+
861+ def good(blah: Union[Tuple[int, int], int]) -> None:
862+ reveal_type(blah) # E: Revealed type is 'Union[Tuple[builtins.int, builtins.int], builtins.int]'
863+ if isinstance(blah, tuple):
864+ reveal_type(blah) # E: Revealed type is 'Tuple[builtins.int, builtins.int]'
865+ reveal_type(blah) # E: Revealed type is 'Union[Tuple[builtins.int, builtins.int], builtins.int]'
866+ [builtins fixtures/tuple.pyi]
867+ [out]
868+
869+ [case testTupleMeetTupleVariable]
870+ from typing import Tuple, TypeVar, Generic, Union
871+ T = TypeVar('T')
872+
873+ class A: pass
874+ class B1(A): pass
875+ class B2(A): pass
876+ class C: pass
877+
878+ x = None # type: Tuple[A, ...]
879+ y = None # type: Tuple[Union[B1, C], Union[B2, C]]
880+
881+ def g(x: T) -> Tuple[T, T]:
882+ return (x, x)
883+
884+ z = 1
885+ x, y = g(z) # E: Argument 1 to "g" has incompatible type "int"; expected "Tuple[B1, B2]"
886+ [builtins fixtures/tuple.pyi]
887+ [out]
888+
811889[case testTupleWithUndersizedContext]
812890a = ([1], 'x')
813891a = ([], 'x', 1) # E: Incompatible types in assignment (expression has type "Tuple[List[int], str, int]", variable has type "Tuple[List[int], str]")
0 commit comments