@@ -1228,68 +1228,76 @@ x, y = g(z) # E: Argument 1 to "g" has incompatible type "int"; expected "Tuple[
12281228[out]
12291229
12301230[case testFixedTupleJoinVarTuple]
1231- from typing import Tuple
1231+ from typing import Tuple, TypeVar
12321232
12331233class A: pass
12341234class B(A): pass
12351235
12361236fixtup: Tuple[B, B]
12371237
1238+ T = TypeVar("T")
1239+ def join(x: T, y: T) -> T: ...
1240+
12381241vartup_b: Tuple[B, ...]
1239- reveal_type(fixtup if int() else vartup_b) # N: Revealed type is "builtins.tuple[__main__.B, ...]"
1240- reveal_type(vartup_b if int() else fixtup) # N: Revealed type is "builtins.tuple[__main__.B, ...]"
1242+ reveal_type(join( fixtup, vartup_b) ) # N: Revealed type is "builtins.tuple[__main__.B, ...]"
1243+ reveal_type(join( vartup_b, fixtup) ) # N: Revealed type is "builtins.tuple[__main__.B, ...]"
12411244
12421245vartup_a: Tuple[A, ...]
1243- reveal_type(fixtup if int() else vartup_a) # N: Revealed type is "builtins.tuple[__main__.A, ...]"
1244- reveal_type(vartup_a if int() else fixtup) # N: Revealed type is "builtins.tuple[__main__.A, ...]"
1245-
1246+ reveal_type(join(fixtup, vartup_a)) # N: Revealed type is "builtins.tuple[__main__.A, ...]"
1247+ reveal_type(join(vartup_a, fixtup)) # N: Revealed type is "builtins.tuple[__main__.A, ...]"
12461248
12471249[builtins fixtures/tuple.pyi]
12481250[out]
12491251
12501252[case testFixedTupleJoinList]
1251- from typing import Tuple, List
1253+ from typing import Tuple, List, TypeVar
12521254
12531255class A: pass
12541256class B(A): pass
12551257
12561258fixtup: Tuple[B, B]
12571259
1260+ T = TypeVar("T")
1261+ def join(x: T, y: T) -> T: ...
1262+
12581263lst_b: List[B]
1259- reveal_type(fixtup if int() else lst_b) # N: Revealed type is "typing.Sequence[__main__.B]"
1260- reveal_type(lst_b if int() else fixtup) # N: Revealed type is "typing.Sequence[__main__.B]"
1264+ reveal_type(join( fixtup, lst_b) ) # N: Revealed type is "typing.Sequence[__main__.B]"
1265+ reveal_type(join( lst_b, fixtup) ) # N: Revealed type is "typing.Sequence[__main__.B]"
12611266
12621267lst_a: List[A]
1263- reveal_type(fixtup if int() else lst_a) # N: Revealed type is "typing.Sequence[__main__.A]"
1264- reveal_type(lst_a if int() else fixtup) # N: Revealed type is "typing.Sequence[__main__.A]"
1268+ reveal_type(join( fixtup, lst_a) ) # N: Revealed type is "typing.Sequence[__main__.A]"
1269+ reveal_type(join( lst_a, fixtup) ) # N: Revealed type is "typing.Sequence[__main__.A]"
12651270
12661271[builtins fixtures/tuple.pyi]
12671272[out]
12681273
12691274[case testEmptyTupleJoin]
1270- from typing import Tuple, List
1275+ from typing import Tuple, List, TypeVar
12711276
12721277class A: pass
12731278
12741279empty = ()
12751280
1281+ T = TypeVar("T")
1282+ def join(x: T, y: T) -> T: ...
1283+
12761284fixtup: Tuple[A]
1277- reveal_type(fixtup if int() else empty) # N: Revealed type is "builtins.tuple[__main__.A, ...]"
1278- reveal_type(empty if int() else fixtup) # N: Revealed type is "builtins.tuple[__main__.A, ...]"
1285+ reveal_type(join( fixtup, empty) ) # N: Revealed type is "builtins.tuple[__main__.A, ...]"
1286+ reveal_type(join( empty, fixtup) ) # N: Revealed type is "builtins.tuple[__main__.A, ...]"
12791287
12801288vartup: Tuple[A, ...]
1281- reveal_type(empty if int() else vartup) # N: Revealed type is "builtins.tuple[__main__.A, ...]"
1282- reveal_type(vartup if int() else empty) # N: Revealed type is "builtins.tuple[__main__.A, ...]"
1289+ reveal_type(join( vartup, empty) ) # N: Revealed type is "builtins.tuple[__main__.A, ...]"
1290+ reveal_type(join( empty, vartup) ) # N: Revealed type is "builtins.tuple[__main__.A, ...]"
12831291
12841292lst: List[A]
1285- reveal_type(empty if int() else lst) # N: Revealed type is "typing.Sequence[__main__.A]"
1286- reveal_type(lst if int() else empty) # N: Revealed type is "typing.Sequence[__main__.A]"
1293+ reveal_type(join( empty, lst) ) # N: Revealed type is "typing.Sequence[__main__.A]"
1294+ reveal_type(join( lst, empty) ) # N: Revealed type is "typing.Sequence[__main__.A]"
12871295
12881296[builtins fixtures/tuple.pyi]
12891297[out]
12901298
12911299[case testTupleSubclassJoin]
1292- from typing import Tuple, NamedTuple
1300+ from typing import Tuple, NamedTuple, TypeVar
12931301
12941302class NTup(NamedTuple):
12951303 a: bool
@@ -1302,32 +1310,38 @@ ntup: NTup
13021310subtup: SubTuple
13031311vartup: SubVarTuple
13041312
1305- reveal_type(ntup if int() else vartup) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1306- reveal_type(subtup if int() else vartup) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1313+ T = TypeVar("T")
1314+ def join(x: T, y: T) -> T: ...
1315+
1316+ reveal_type(join(ntup, vartup)) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1317+ reveal_type(join(subtup, vartup)) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
13071318
13081319[builtins fixtures/tuple.pyi]
13091320[out]
13101321
13111322[case testTupleJoinIrregular]
1312- from typing import Tuple
1323+ from typing import Tuple, TypeVar
13131324
13141325tup1: Tuple[bool, int]
13151326tup2: Tuple[bool]
13161327
1317- reveal_type(tup1 if int() else tup2) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1318- reveal_type(tup2 if int() else tup1) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1328+ T = TypeVar("T")
1329+ def join(x: T, y: T) -> T: ...
1330+
1331+ reveal_type(join(tup1, tup2)) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1332+ reveal_type(join(tup2, tup1)) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
13191333
1320- reveal_type(tup1 if int() else ( )) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1321- reveal_type(() if int() else tup1) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1334+ reveal_type(join( tup1, () )) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1335+ reveal_type(join((), tup1) ) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
13221336
1323- reveal_type(tup2 if int() else ( )) # N: Revealed type is "builtins.tuple[builtins.bool, ...]"
1324- reveal_type(() if int() else tup2) # N: Revealed type is "builtins.tuple[builtins.bool, ...]"
1337+ reveal_type(join( tup2, () )) # N: Revealed type is "builtins.tuple[builtins.bool, ...]"
1338+ reveal_type(join((), tup2) ) # N: Revealed type is "builtins.tuple[builtins.bool, ...]"
13251339
13261340[builtins fixtures/tuple.pyi]
13271341[out]
13281342
13291343[case testTupleSubclassJoinIrregular]
1330- from typing import Tuple, NamedTuple
1344+ from typing import Tuple, NamedTuple, TypeVar
13311345
13321346class NTup1(NamedTuple):
13331347 a: bool
@@ -1342,14 +1356,17 @@ tup1: NTup1
13421356tup2: NTup2
13431357subtup: SubTuple
13441358
1345- reveal_type(tup1 if int() else tup2) # N: Revealed type is "builtins.tuple[builtins.bool, ...]"
1346- reveal_type(tup2 if int() else tup1) # N: Revealed type is "builtins.tuple[builtins.bool, ...]"
1359+ T = TypeVar("T")
1360+ def join(x: T, y: T) -> T: ...
1361+
1362+ reveal_type(join(tup1, tup2)) # N: Revealed type is "builtins.tuple[builtins.bool, ...]"
1363+ reveal_type(join(tup2, tup1)) # N: Revealed type is "builtins.tuple[builtins.bool, ...]"
13471364
1348- reveal_type(tup1 if int() else subtup) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1349- reveal_type(subtup if int() else tup1) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1365+ reveal_type(join( tup1, subtup) ) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1366+ reveal_type(join( subtup, tup1) ) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
13501367
1351- reveal_type(tup2 if int() else subtup) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1352- reveal_type(subtup if int() else tup2) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1368+ reveal_type(join( tup2, subtup) ) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
1369+ reveal_type(join( subtup, tup2) ) # N: Revealed type is "builtins.tuple[builtins.int, ...]"
13531370
13541371[builtins fixtures/tuple.pyi]
13551372[out]
0 commit comments