@@ -1261,3 +1261,50 @@ def g() -> None:
1261
1261
def foo(): ...
1262
1262
foo()
1263
1263
[builtins fixtures/dict.pyi]
1264
+
1265
+
1266
+ [case testNarrowingWithTupleOfTypes]
1267
+ from typing import Tuple, Type
1268
+
1269
+ class Base: ...
1270
+
1271
+ class Impl1(Base): ...
1272
+ class Impl2(Base): ...
1273
+
1274
+ impls: Tuple[Type[Base], ...] = (Impl1, Impl2)
1275
+ some: object
1276
+
1277
+ if isinstance(some, impls):
1278
+ reveal_type(some) # N: Revealed type is "__main__.Base"
1279
+ else:
1280
+ reveal_type(some) # N: Revealed type is "builtins.object"
1281
+
1282
+ raw: Tuple[type, ...]
1283
+ if isinstance(some, raw):
1284
+ reveal_type(some) # N: Revealed type is "builtins.object"
1285
+ else:
1286
+ reveal_type(some) # N: Revealed type is "builtins.object"
1287
+ [builtins fixtures/dict.pyi]
1288
+
1289
+
1290
+ [case testNarrowingWithTupleOfTypesPy310Plus]
1291
+ # flags: --python-version 3.10
1292
+ class Base: ...
1293
+
1294
+ class Impl1(Base): ...
1295
+ class Impl2(Base): ...
1296
+
1297
+ some: int | Base
1298
+
1299
+ impls: tuple[type[Base], ...] = (Impl1, Impl2)
1300
+ if isinstance(some, impls):
1301
+ reveal_type(some) # N: Revealed type is "__main__.Base"
1302
+ else:
1303
+ reveal_type(some) # N: Revealed type is "Union[builtins.int, __main__.Base]"
1304
+
1305
+ raw: tuple[type, ...]
1306
+ if isinstance(some, raw):
1307
+ reveal_type(some) # N: Revealed type is "Union[builtins.int, __main__.Base]"
1308
+ else:
1309
+ reveal_type(some) # N: Revealed type is "Union[builtins.int, __main__.Base]"
1310
+ [builtins fixtures/dict.pyi]
0 commit comments