/
check-typevar-unbound.test
72 lines (49 loc) · 1.37 KB
/
check-typevar-unbound.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
[case testUnboundTypeVar]
from typing import TypeVar
T = TypeVar('T')
def f() -> T: # E: A function returning TypeVar should receive at least one argument containing the same TypeVar
...
f()
U = TypeVar('U', bound=int)
def g() -> U: # E: A function returning TypeVar should receive at least one argument containing the same TypeVar \
# N: Consider using the upper bound "int" instead
...
V = TypeVar('V', int, str)
# TODO: this should also give an error
def h() -> V:
...
[case testInnerFunctionTypeVar]
from typing import TypeVar
T = TypeVar('T')
def g(a: T) -> T:
def f() -> T:
...
return f()
[case testUnboundIterableOfTypeVars]
from typing import Iterable, TypeVar
T = TypeVar('T')
def f() -> Iterable[T]:
...
f()
[case testBoundTypeVar]
from typing import TypeVar
T = TypeVar('T')
def f(a: T, b: T, c: int) -> T:
...
[case testNestedBoundTypeVar]
from typing import Callable, List, Union, Tuple, TypeVar
T = TypeVar('T')
def f(a: Union[int, T], b: str) -> T:
...
def g(a: Callable[..., T], b: str) -> T:
...
def h(a: List[Union[Callable[..., T]]]) -> T:
...
def j(a: List[Union[Callable[..., Tuple[T, T]], int]]) -> T:
...
[builtins fixtures/tuple.pyi]
[case testUnboundedTypevarUnpacking]
from typing import TypeVar
T = TypeVar("T")
def f(t: T) -> None:
a, *b = t # E: "object" object is not iterable