Skip to content

Commit a61bf32

Browse files
committed
Add unit test
1 parent 078879e commit a61bf32

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

test-data/unit/check-isinstance.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,3 +1344,11 @@ def f(x: object) -> None:
13441344
reveal_type(b) # E: Revealed type is '__main__.A'
13451345
[builtins fixtures/isinstance.pyi]
13461346
[out]
1347+
1348+
[case testIsInstanceWithTypeVariable]
1349+
from typing import *
1350+
def f(x: Union[int, str], typ: type) -> None:
1351+
if isinstance(x, (typ, int)):
1352+
x + 1 # E: Unsupported operand types for + (likely involving Union)
1353+
[builtins fixtures/isinstancelistset.pyi]
1354+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from typing import builtinclass, Iterable, Iterator, Generic, TypeVar, List, Mapping, overload, Tuple, Set, Union
2+
3+
@builtinclass
4+
class object:
5+
def __init__(self) -> None: pass
6+
7+
@builtinclass
8+
class type:
9+
def __init__(self, x) -> None: pass
10+
11+
class tuple: pass
12+
class function: pass
13+
14+
def isinstance(x: object, t: Union[type, Tuple]) -> bool: pass
15+
16+
@builtinclass
17+
class int:
18+
def __add__(self, x: int) -> int: pass
19+
@builtinclass
20+
class bool(int): pass
21+
@builtinclass
22+
class str:
23+
def __add__(self, x: str) -> str: pass
24+
def __getitem__(self, x: int) -> str: pass
25+
26+
T = TypeVar('T')
27+
KT = TypeVar('KT')
28+
VT = TypeVar('VT')
29+
30+
class list(Iterable[T], Generic[T]):
31+
def __iter__(self) -> Iterator[T]: pass
32+
def __mul__(self, x: int) -> list[T]: pass
33+
def __setitem__(self, x: int, v: T) -> None: pass
34+
def __getitem__(self, x: int) -> T: pass
35+
def __add__(self, x: List[T]) -> T: pass
36+
37+
class dict(Iterable[KT], Mapping[KT, VT], Generic[KT, VT]):
38+
@overload
39+
def __init__(self, **kwargs: VT) -> None: pass
40+
@overload
41+
def __init__(self, arg: Iterable[Tuple[KT, VT]], **kwargs: VT) -> None: pass
42+
def __setitem__(self, k: KT, v: VT) -> None: pass
43+
def __iter__(self) -> Iterator[KT]: pass
44+
def update(self, a: Mapping[KT, VT]) -> None: pass
45+
46+
class set(Iterable[T], Generic[T]):
47+
def __iter__(self) -> Iterator[T]: pass
48+
def add(self, x: T) -> None: pass
49+
def discard(self, x: T) -> None: pass
50+
def update(self, x: Set[T]) -> None: pass

0 commit comments

Comments
 (0)