@@ -1228,68 +1228,76 @@ x, y = g(z) # E: Argument 1 to "g" has incompatible type "int"; expected "Tuple[
1228
1228
[out]
1229
1229
1230
1230
[case testFixedTupleJoinVarTuple]
1231
- from typing import Tuple
1231
+ from typing import Tuple, TypeVar
1232
1232
1233
1233
class A: pass
1234
1234
class B(A): pass
1235
1235
1236
1236
fixtup: Tuple[B, B]
1237
1237
1238
+ T = TypeVar("T")
1239
+ def join(x: T, y: T) -> T: ...
1240
+
1238
1241
vartup_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, ...]"
1241
1244
1242
1245
vartup_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, ...]"
1246
1248
1247
1249
[builtins fixtures/tuple.pyi]
1248
1250
[out]
1249
1251
1250
1252
[case testFixedTupleJoinList]
1251
- from typing import Tuple, List
1253
+ from typing import Tuple, List, TypeVar
1252
1254
1253
1255
class A: pass
1254
1256
class B(A): pass
1255
1257
1256
1258
fixtup: Tuple[B, B]
1257
1259
1260
+ T = TypeVar("T")
1261
+ def join(x: T, y: T) -> T: ...
1262
+
1258
1263
lst_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]"
1261
1266
1262
1267
lst_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]"
1265
1270
1266
1271
[builtins fixtures/tuple.pyi]
1267
1272
[out]
1268
1273
1269
1274
[case testEmptyTupleJoin]
1270
- from typing import Tuple, List
1275
+ from typing import Tuple, List, TypeVar
1271
1276
1272
1277
class A: pass
1273
1278
1274
1279
empty = ()
1275
1280
1281
+ T = TypeVar("T")
1282
+ def join(x: T, y: T) -> T: ...
1283
+
1276
1284
fixtup: 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, ...]"
1279
1287
1280
1288
vartup: 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, ...]"
1283
1291
1284
1292
lst: 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]"
1287
1295
1288
1296
[builtins fixtures/tuple.pyi]
1289
1297
[out]
1290
1298
1291
1299
[case testTupleSubclassJoin]
1292
- from typing import Tuple, NamedTuple
1300
+ from typing import Tuple, NamedTuple, TypeVar
1293
1301
1294
1302
class NTup(NamedTuple):
1295
1303
a: bool
@@ -1302,32 +1310,38 @@ ntup: NTup
1302
1310
subtup: SubTuple
1303
1311
vartup: SubVarTuple
1304
1312
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, ...]"
1307
1318
1308
1319
[builtins fixtures/tuple.pyi]
1309
1320
[out]
1310
1321
1311
1322
[case testTupleJoinIrregular]
1312
- from typing import Tuple
1323
+ from typing import Tuple, TypeVar
1313
1324
1314
1325
tup1: Tuple[bool, int]
1315
1326
tup2: Tuple[bool]
1316
1327
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, ...]"
1319
1333
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, ...]"
1322
1336
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, ...]"
1325
1339
1326
1340
[builtins fixtures/tuple.pyi]
1327
1341
[out]
1328
1342
1329
1343
[case testTupleSubclassJoinIrregular]
1330
- from typing import Tuple, NamedTuple
1344
+ from typing import Tuple, NamedTuple, TypeVar
1331
1345
1332
1346
class NTup1(NamedTuple):
1333
1347
a: bool
@@ -1342,14 +1356,17 @@ tup1: NTup1
1342
1356
tup2: NTup2
1343
1357
subtup: SubTuple
1344
1358
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, ...]"
1347
1364
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, ...]"
1350
1367
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, ...]"
1353
1370
1354
1371
[builtins fixtures/tuple.pyi]
1355
1372
[out]
0 commit comments