3
3
4
4
[case testCallGenericFunctionWithTypeVarValueRestriction]
5
5
from typing import TypeVar
6
- T = TypeVar('T', values=( int, str) )
6
+ T = TypeVar('T', int, str)
7
7
def f(x: T) -> None: pass
8
8
f(1)
9
9
f('x')
10
10
f(object()) # E: Type argument 1 of "f" has incompatible value "object"
11
11
12
12
[case testCallGenericFunctionWithTypeVarValueRestrictionUsingContext]
13
13
from typing import TypeVar, List
14
- T = TypeVar('T', values=( int, str) )
14
+ T = TypeVar('T', int, str)
15
15
def f(x: T) -> List[T]: pass
16
16
i = [1]
17
17
s = ['x']
@@ -23,22 +23,22 @@ o = f(1) # E: Type argument 1 of "f" has incompatible value "object"
23
23
24
24
[case testCallGenericFunctionWithTypeVarValueRestrictionAndAnyArgs]
25
25
from typing import TypeVar, Any
26
- T = TypeVar('T', values=( int, str) )
26
+ T = TypeVar('T', int, str)
27
27
def f(x: T) -> None: pass
28
28
f(Any(object()))
29
29
[out]
30
30
31
31
[case testCallGenericFunctionWithTypeVarValueRestrictionInDynamicFunc]
32
32
from typing import TypeVar, Any
33
- T = TypeVar('T', values=( int, str) )
33
+ T = TypeVar('T', int, str)
34
34
def f(x: T) -> None: pass
35
35
def g():
36
36
f(object())
37
37
[out]
38
38
39
39
[case testCallGenericFunctionWithTypeVarValueRestrictionUsingSubtype]
40
40
from typing import TypeVar
41
- T = TypeVar('T', values=( int, str) )
41
+ T = TypeVar('T', int, str)
42
42
def f(x: T) -> None: pass
43
43
class S(str): pass
44
44
f(S())
@@ -50,7 +50,7 @@ class A:
50
50
def f(self, x: int) -> A: return self
51
51
class B:
52
52
def f(self, x: int) -> B: return self
53
- AB = TypeVar('AB', values=( A, B) )
53
+ AB = TypeVar('AB', A, B)
54
54
def f(x: AB) -> AB:
55
55
x = x.f(1)
56
56
return x.f(1)
@@ -63,7 +63,7 @@ class A:
63
63
class B:
64
64
def f(self) -> A: return A()
65
65
def g(self) -> B: return B()
66
- AB = TypeVar('AB', values=( A, B) )
66
+ AB = TypeVar('AB', A, B)
67
67
def f(x: AB) -> AB:
68
68
return x.f() # Error
69
69
def g(x: AB) -> AB:
@@ -82,7 +82,7 @@ class A:
82
82
class B:
83
83
def f(self) -> B: return self
84
84
def g(self) -> B: return B()
85
- AB = TypeVar('AB', values=( A, B) )
85
+ AB = TypeVar('AB', A, B)
86
86
def f(x: AB) -> AB:
87
87
y = x
88
88
if y:
@@ -94,7 +94,7 @@ main: In function "f":
94
94
95
95
[case testTypeApplicationAndTypeVarValues]
96
96
from typing import TypeVar, List
97
- T = TypeVar('T', values=( int, str) )
97
+ T = TypeVar('T', int, str)
98
98
def f(x: T) -> List[T]:
99
99
return List[T]()
100
100
def g(x: T) -> List[T]:
@@ -105,7 +105,7 @@ main: In function "g":
105
105
106
106
[case testTypeDeclaredBasedOnTypeVarWithValues]
107
107
from typing import TypeVar, Undefined
108
- T = TypeVar('T', values=( int, str) )
108
+ T = TypeVar('T', int, str)
109
109
def f(x: T) -> T:
110
110
a = Undefined(T)
111
111
b = None # type: T
@@ -118,7 +118,7 @@ main: In function "f":
118
118
119
119
[case testIsinstanceAndTypeVarValues]
120
120
from typing import TypeVar
121
- T = TypeVar('T', values=( int, str) )
121
+ T = TypeVar('T', int, str)
122
122
def f(x: T) -> T:
123
123
if isinstance(x, int):
124
124
return 2
@@ -135,7 +135,7 @@ main: In function "h":
135
135
136
136
[case testIsinstanceAndTypeVarValues2]
137
137
from typing import TypeVar
138
- T = TypeVar('T', values=( int, str) )
138
+ T = TypeVar('T', int, str)
139
139
def f(x: T) -> T:
140
140
if isinstance(x, int):
141
141
return 2
@@ -153,7 +153,7 @@ main: In function "g":
153
153
154
154
[case testIsinstanceAndTypeVarValues3]
155
155
from typing import TypeVar
156
- T = TypeVar('T', values=( int, str) )
156
+ T = TypeVar('T', int, str)
157
157
def f(x: T) -> T:
158
158
if isinstance(x, int):
159
159
y = 1
@@ -164,7 +164,7 @@ def f(x: T) -> T:
164
164
165
165
[case testIsinstanceAndTypeVarValues4]
166
166
from typing import TypeVar
167
- T = TypeVar('T', values=( int, str) )
167
+ T = TypeVar('T', int, str)
168
168
def f(x: T) -> T:
169
169
if isinstance(x, int):
170
170
y = 1
@@ -177,7 +177,7 @@ main: In function "f":
177
177
178
178
[case testIsinstanceAndTypeVarValues5]
179
179
from typing import TypeVar
180
- T = TypeVar('T', values=( int, str) )
180
+ T = TypeVar('T', int, str)
181
181
def f(x: T) -> T:
182
182
if isinstance(x, int):
183
183
y = object()
@@ -192,7 +192,7 @@ main: In function "f":
192
192
from typing import TypeVar, Undefined
193
193
class A: pass
194
194
class B: pass
195
- T = TypeVar('T', values=( A, B) )
195
+ T = TypeVar('T', A, B)
196
196
def f(x: T) -> None:
197
197
y = x
198
198
if isinstance(x, A):
@@ -204,7 +204,7 @@ def f(x: T) -> None:
204
204
x = B()
205
205
x = y
206
206
x.foo() # E: "B" has no attribute "foo"
207
- S = TypeVar('S', values=( int, str) )
207
+ S = TypeVar('S', int, str)
208
208
def g(x: S) -> None:
209
209
y = x
210
210
if isinstance(x, int):
@@ -216,7 +216,7 @@ main: In function "f":
216
216
[case testIsinstanceWithUserDefinedTypeAndTypeVarValues2]
217
217
from typing import TypeVar, Undefined
218
218
class S(str): pass
219
- T = TypeVar('T', values=( S, int) )
219
+ T = TypeVar('T', S, int)
220
220
def f(x: T) -> None:
221
221
y = x
222
222
if isinstance(x, S):
@@ -234,7 +234,7 @@ main: In function "f":
234
234
235
235
[case testTypeVarValuesAndNestedCalls]
236
236
from typing import TypeVar
237
- T = TypeVar('T', values=( int, str) )
237
+ T = TypeVar('T', int, str)
238
238
def f(m: T) -> int: pass
239
239
def h(x: int) -> int: pass
240
240
def g(a: T) -> None:
@@ -243,7 +243,7 @@ def g(a: T) -> None:
243
243
244
244
[case testGenericTypeWithTypevarValues]
245
245
from typing import TypeVar, Generic, Undefined, Any
246
- X = TypeVar('X', values=( int, str) )
246
+ X = TypeVar('X', int, str)
247
247
class A(Generic[X]): pass
248
248
a = Undefined(A[int])
249
249
b = Undefined(A[str])
@@ -252,7 +252,7 @@ c = Undefined(A[Any])
252
252
253
253
[case testGenericTypeWithTypevarValuesAndTypeApplication]
254
254
from typing import TypeVar, Generic, Undefined, Any
255
- X = TypeVar('X', values=( int, str) )
255
+ X = TypeVar('X', int, str)
256
256
class A(Generic[X]): pass
257
257
A[int]()
258
258
A[str]()
@@ -261,7 +261,7 @@ A[object]() # E: Type argument 1 of "A" has incompatible value "object"
261
261
262
262
[case testConstructGenericTypeWithTypevarValuesAndTypeInference]
263
263
from typing import TypeVar, Generic, Any
264
- X = TypeVar('X', values=( int, str) )
264
+ X = TypeVar('X', int, str)
265
265
class A(Generic[X]):
266
266
def __init__(self, x: X) -> None: pass
267
267
A(1)
@@ -272,8 +272,8 @@ A(object()) # E: Type argument 1 of "A" has incompatible value "object"
272
272
[case testGenericTypeWithTypevarValuesAndTypevarArgument]
273
273
from typing import TypeVar, Generic, Undefined
274
274
class C: pass
275
- X = TypeVar('X', values=( int, str) )
276
- Y = TypeVar('Y', values=( int, C) )
275
+ X = TypeVar('X', int, str)
276
+ Y = TypeVar('Y', int, C)
277
277
Z = TypeVar('Z')
278
278
class D(Generic[X]):
279
279
def __init__(self, x: X) -> None: pass
@@ -291,7 +291,7 @@ main, line 13: Type variable "Z" not valid as type argument value for "D"
291
291
292
292
[case testGenericTypeWithTypevarValuesAndSubtypePromotion]
293
293
from typing import TypeVar, Generic, Undefined
294
- X = TypeVar('X', values=( int, str) )
294
+ X = TypeVar('X', int, str)
295
295
class S(str): pass
296
296
class C(Generic[X]):
297
297
def __init__(self, x: X) -> None: pass
@@ -311,7 +311,7 @@ class B:
311
311
def f(self, x: int) -> None: pass
312
312
def g(self, x: str) -> None: pass
313
313
def h(self, x: int) -> None: pass
314
- X = TypeVar('X', values=( A, B) )
314
+ X = TypeVar('X', A, B)
315
315
class C(Generic[X]):
316
316
def f(self, x: X) -> None:
317
317
x.f(1)
@@ -322,7 +322,7 @@ main: In member "f" of class "C":
322
322
323
323
[case testAttributeInGenericTypeWithTypevarValues1]
324
324
from typing import TypeVar, Generic, Undefined
325
- X = TypeVar('X', values=( int, str) )
325
+ X = TypeVar('X', int, str)
326
326
class C(Generic[X]):
327
327
x = Undefined(X)
328
328
def f(self, x: X) -> None:
@@ -333,7 +333,7 @@ main: In member "f" of class "C":
333
333
334
334
[case testAttributeInGenericTypeWithTypevarValues2]
335
335
from typing import TypeVar, Generic, Undefined
336
- X = TypeVar('X', values=( int, str) )
336
+ X = TypeVar('X', int, str)
337
337
class C(Generic[X]):
338
338
x = Undefined(X)
339
339
cn = C[int]()
@@ -345,7 +345,7 @@ cs.x = 1 # E: Incompatible types in assignment (expression has type "int", varia
345
345
346
346
[case testInferredAttributeInGenericClassBodyWithTypevarValues]
347
347
from typing import TypeVar, Generic, Undefined
348
- X = TypeVar('X', values=( int, str) )
348
+ X = TypeVar('X', int, str)
349
349
class C(Generic[X]):
350
350
x = 1
351
351
C.x = 1
@@ -357,8 +357,8 @@ class A:
357
357
def f(self, x: int) -> None: pass
358
358
class B:
359
359
def f(self, x: str) -> None: pass
360
- X = TypeVar('X', values=( A, B) )
361
- Y = TypeVar('Y', values=( int, str) )
360
+ X = TypeVar('X', A, B)
361
+ Y = TypeVar('Y', int, str)
362
362
class C(Generic[X, Y]):
363
363
def f(self, x: X, y: Y) -> None:
364
364
x.f(y)
@@ -371,8 +371,8 @@ main, line 10: Argument 1 to "f" of "B" has incompatible type "int"; expected "s
371
371
from typing import TypeVar, Generic, Undefined
372
372
class A: pass
373
373
class B: pass
374
- X = TypeVar('X', values=( A, B) )
375
- Y = TypeVar('Y', values=( int, str) )
374
+ X = TypeVar('X', A, B)
375
+ Y = TypeVar('Y', int, str)
376
376
class C(Generic[X, Y]): pass
377
377
a = Undefined(C[A, int])
378
378
b = Undefined(C[B, str])
@@ -383,8 +383,8 @@ c = Undefined(C[A, A]) # E: Invalid type argument value for "C"
383
383
from typing import TypeVar
384
384
class A: pass
385
385
class B: pass
386
- X = TypeVar('X', values=( A, B) )
387
- Y = TypeVar('Y', values=( int, str) )
386
+ X = TypeVar('X', A, B)
387
+ Y = TypeVar('Y', int, str)
388
388
def f(x: X, y: Y) -> None: pass
389
389
f(A(), '')
390
390
f(B(), 1)
@@ -394,7 +394,7 @@ f(1, 1) # E: Type argument 1 of "f" has incompatible value "int"
394
394
[case testGenericFunctionWithNormalAndRestrictedTypevar]
395
395
from typing import TypeVar, Generic, Undefined
396
396
X = TypeVar('X')
397
- Y = TypeVar('Y', values=( int, str) )
397
+ Y = TypeVar('Y', int, str)
398
398
class C(Generic[Y]):
399
399
def __init__(self, y: Y) -> None: pass
400
400
def f(x: X, y: Y, z: int) -> None:
@@ -413,7 +413,7 @@ main, line 11: "str" has no attribute "foo"
413
413
414
414
[case testTypeVarWithValueInferredFromObjectReturnTypeContext]
415
415
from typing import TypeVar
416
- T = TypeVar('T', values=( int, str) )
416
+ T = TypeVar('T', int, str)
417
417
def c1(x: object) -> None: pass
418
418
def c2(x: int) -> None: pass
419
419
def c3(x: str) -> None: pass
@@ -426,7 +426,7 @@ c3(g(1)) # E: Argument 1 to "c3" has incompatible type "int"; expected "str"
426
426
427
427
[case testTypeVarWithValueInferredFromObjectReturnTypeContext2]
428
428
from typing import TypeVar
429
- T = TypeVar('T', values=( int, str) )
429
+ T = TypeVar('T', int, str)
430
430
class ss(str): pass
431
431
def c(x: ss) -> None: pass
432
432
def g(x: T) -> T: pass
@@ -444,7 +444,7 @@ main, line 7: Argument 1 to "c" has incompatible type "int"; expected "ss"
444
444
[case testTypevarValuesSpecialCase1]
445
445
from typing import TypeVar, Generic
446
446
from abc import abstractmethod
447
- T = TypeVar('T', values=( int, str) )
447
+ T = TypeVar('T', int, str)
448
448
class A(Generic[T]):
449
449
@abstractmethod
450
450
def f(self) -> 'A[T]': pass
@@ -460,14 +460,14 @@ main: In class "C":
460
460
461
461
[case testDefaultArgumentValueInGenericClassWithTypevarValues]
462
462
from typing import TypeVar, Generic
463
- T = TypeVar('T', values=( int, str) )
463
+ T = TypeVar('T', int, str)
464
464
class C(Generic[T]):
465
465
def f(self, x: int = None) -> None: pass
466
466
467
467
[case testTypevarValuesWithOverloadedFunctionSpecialCase]
468
468
from typing import TypeVar, overload, Callable
469
469
470
- T = TypeVar('T', values=( int, str) )
470
+ T = TypeVar('T', int, str)
471
471
def f(x: T) -> None:
472
472
y = m(g, x)
473
473
x = y
0 commit comments