Skip to content

Commit 6fcc3d5

Browse files
committed
Add failing unit test for ininstance with type objects
1 parent 6ea4f4d commit 6fcc3d5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test-data/unit/check-isinstance.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,3 +1354,21 @@ def f(x: Union[int, str], typ: type) -> None:
13541354
else:
13551355
reveal_type(x) # E: Revealed type is 'Union[builtins.int, builtins.str]'
13561356
[builtins fixtures/isinstancelist.pyi]
1357+
1358+
1359+
[case testIsInstanceWithTypeObject]
1360+
from typing import Union, Type
1361+
1362+
class A: pass
1363+
1364+
def f(x: Union[int, A], a: Type[A]) -> None:
1365+
if isinstance(x, a):
1366+
reveal_type(x) # E: Revealed type is '__main__.A'
1367+
elif isinstance(x, int):
1368+
reveal_type(x) # E: Revealed type is 'builtins.int'
1369+
else:
1370+
reveal_type(x) # E: Revealed type is '__main__.A'
1371+
reveal_type(x) # E: Revealed type is 'Union[builtins.int, __main__.A]'
1372+
1373+
[builtins fixtures/isinstancelist.pyi]
1374+

0 commit comments

Comments
 (0)