Skip to content

Commit 28a9fcd

Browse files
committedMar 9, 2015
Merge branch 'new-typevar-syntax'
Closes #539.
2 parents 84cdb8a + 233f5bd commit 28a9fcd

16 files changed

+94
-89
lines changed
 

‎docs/source/generics.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ as its value. A typical example is a type variable that can only have values
151151
152152
from typing import TypeVar
153153
154-
AnyStr = TypeVar('AnyStr', values=(str, bytes))
154+
AnyStr = TypeVar('AnyStr', str, bytes)
155155
156156
This is actually such a common type variable that ``AnyStr`` is
157157
defined in ``typing`` and we don't need to define it ourselves.
@@ -209,7 +209,7 @@ this is correct for ``concat``, since ``concat`` actually returns a
209209
>>> print(type(ss))
210210
<class 'str'>
211211
212-
You can also use a ``TypeVar`` with ``values`` when defining a generic
213-
class. For example, mypy uses the type ``typing.Pattern[AnyStr]`` for the
214-
return value of ``re.compile``, since regular expressions can be based
215-
on a string or a bytes pattern.
212+
You can also use a ``TypeVar`` with a restricted set of possible
213+
values when defining a generic class. For example, mypy uses the type
214+
``typing.Pattern[AnyStr]`` for the return value of ``re.compile``,
215+
since regular expressions can be based on a string or a bytes pattern.

‎lib-python/3.2/test/test_random.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from typing import Undefined, Any, Dict, List, Callable, Generic, TypeVar
1212

13-
RT = TypeVar('RT', values=(random.Random, random.SystemRandom))
13+
RT = TypeVar('RT', random.Random, random.SystemRandom)
1414

1515
class TestBasicOps(unittest.TestCase, Generic[RT]):
1616
# Superclass with tests common to all generators.

‎lib-typing/2.7/test_typing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_typevar(self):
7373
self.assertIsNone(t.values)
7474

7575
def test_typevar_values(self):
76-
t = TypeVar('t', values=(int, unicode))
76+
t = TypeVar('t', int, unicode)
7777
self.assertEqual(t.name, 't')
7878
self.assertEqual(t.values, (int, unicode))
7979

‎lib-typing/2.7/typing.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,15 @@ def NamedTuple(typename, fields):
183183

184184

185185
class TypeVar(object):
186-
def __init__(self, name, values=None):
186+
def __init__(self, name, *values):
187187
self.name = name
188+
if not values:
189+
values = None
188190
self.values = values
189191

190192

191193
# Predefined type variables.
192-
AnyStr = TypeVar('AnyStr', values=(str, unicode))
194+
AnyStr = TypeVar('AnyStr', str, unicode)
193195

194196

195197
class forwardref(object):

‎lib-typing/3.2/test_typing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_typevar(self):
7171
self.assertIsNone(t.values)
7272

7373
def test_typevar_values(self):
74-
t = TypeVar('t', values=(int, str))
74+
t = TypeVar('t', int, str)
7575
self.assertEqual(t.name, 't')
7676
self.assertEqual(t.values, (int, str))
7777

‎lib-typing/3.2/typing.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,15 @@ def NamedTuple(typename, fields):
183183

184184

185185
class TypeVar:
186-
def __init__(self, name, *, values=None):
186+
def __init__(self, name, *values):
187187
self.name = name
188+
if not values:
189+
values = None
188190
self.values = values
189191

190192

191193
# Predefined type variables.
192-
AnyStr = TypeVar('AnyStr', values=(str, bytes))
194+
AnyStr = TypeVar('AnyStr', str, bytes)
193195

194196

195197
class forwardref:

‎mypy/semanal.py

+12-17
Original file line numberDiff line numberDiff line change
@@ -968,11 +968,14 @@ def process_typevar_declaration(self, s: AssignmentStmt) -> None:
968968
if len(call.args) < 1:
969969
self.fail("Too few arguments for TypeVar()", s)
970970
return
971-
if len(call.args) > 2:
972-
self.fail("Too many arguments for TypeVar()", s)
973-
return
974-
if call.arg_kinds not in ([ARG_POS], [ARG_POS, ARG_NAMED]):
975-
self.fail("Unexpected arguments to TypeVar()", s)
971+
if call.arg_kinds != [ARG_POS] * len(call.arg_kinds):
972+
if call.arg_kinds == [ARG_POS, ARG_NAMED] and call.arg_names[1] == 'values':
973+
# Probably using obsolete syntax with values=(...). Explain the current syntax.
974+
self.fail("TypeVar 'values' argument not supported", s)
975+
self.fail("Use TypeVar('T', t, ...) instead of TypeVar('T', values=(t, ...))",
976+
s)
977+
else:
978+
self.fail("Unexpected arguments to TypeVar()", s)
976979
return
977980
if not isinstance(call.args[0], StrExpr):
978981
self.fail("TypeVar() expects a string literal argument", s)
@@ -988,19 +991,11 @@ def process_typevar_declaration(self, s: AssignmentStmt) -> None:
988991
else:
989992
self.fail("Cannot redefine '%s' as a type variable" % name, s)
990993
return
991-
if len(call.args) == 2:
992-
# Analyze values=(...) argument.
993-
if call.arg_names[1] != 'values':
994-
self.fail("Unexpected keyword argument '{}' to TypeVar()".
995-
format(call.arg_names[1]), s)
996-
return
997-
expr = call.args[1]
998-
if isinstance(expr, TupleExpr):
999-
values = self.analyze_types(expr.items)
1000-
else:
1001-
self.fail('The values argument must be a tuple literal', s)
1002-
return
994+
if len(call.args) > 1:
995+
# Analyze enumeration of type variable values.
996+
values = self.analyze_types(call.args[1:])
1003997
else:
998+
# Type variables can refer to an arbitrary type.
1004999
values = []
10051000
# Yes, it's a valid type variable definition! Add it to the symbol table.
10061001
node = self.lookup(name, s)

‎mypy/test/data/check-generics.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ a = '' # E: Incompatible types in assignment (expression has type "str", variabl
793793

794794
[case testSubtypingWithGenericFunctionUsingTypevarWithValues]
795795
from typing import TypeVar, Callable
796-
T = TypeVar('T', values=(int, str))
796+
T = TypeVar('T', int, str)
797797
def f(x: T) -> T: pass
798798
def g1(f: Callable[[str], str]) -> None: pass
799799
g1(f)

‎mypy/test/data/check-typevar-values.test

+41-41
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
[case testCallGenericFunctionWithTypeVarValueRestriction]
55
from typing import TypeVar
6-
T = TypeVar('T', values=(int, str))
6+
T = TypeVar('T', int, str)
77
def f(x: T) -> None: pass
88
f(1)
99
f('x')
1010
f(object()) # E: Type argument 1 of "f" has incompatible value "object"
1111

1212
[case testCallGenericFunctionWithTypeVarValueRestrictionUsingContext]
1313
from typing import TypeVar, List
14-
T = TypeVar('T', values=(int, str))
14+
T = TypeVar('T', int, str)
1515
def f(x: T) -> List[T]: pass
1616
i = [1]
1717
s = ['x']
@@ -23,22 +23,22 @@ o = f(1) # E: Type argument 1 of "f" has incompatible value "object"
2323

2424
[case testCallGenericFunctionWithTypeVarValueRestrictionAndAnyArgs]
2525
from typing import TypeVar, Any
26-
T = TypeVar('T', values=(int, str))
26+
T = TypeVar('T', int, str)
2727
def f(x: T) -> None: pass
2828
f(Any(object()))
2929
[out]
3030

3131
[case testCallGenericFunctionWithTypeVarValueRestrictionInDynamicFunc]
3232
from typing import TypeVar, Any
33-
T = TypeVar('T', values=(int, str))
33+
T = TypeVar('T', int, str)
3434
def f(x: T) -> None: pass
3535
def g():
3636
f(object())
3737
[out]
3838

3939
[case testCallGenericFunctionWithTypeVarValueRestrictionUsingSubtype]
4040
from typing import TypeVar
41-
T = TypeVar('T', values=(int, str))
41+
T = TypeVar('T', int, str)
4242
def f(x: T) -> None: pass
4343
class S(str): pass
4444
f(S())
@@ -50,7 +50,7 @@ class A:
5050
def f(self, x: int) -> A: return self
5151
class B:
5252
def f(self, x: int) -> B: return self
53-
AB = TypeVar('AB', values=(A, B))
53+
AB = TypeVar('AB', A, B)
5454
def f(x: AB) -> AB:
5555
x = x.f(1)
5656
return x.f(1)
@@ -63,7 +63,7 @@ class A:
6363
class B:
6464
def f(self) -> A: return A()
6565
def g(self) -> B: return B()
66-
AB = TypeVar('AB', values=(A, B))
66+
AB = TypeVar('AB', A, B)
6767
def f(x: AB) -> AB:
6868
return x.f() # Error
6969
def g(x: AB) -> AB:
@@ -82,7 +82,7 @@ class A:
8282
class B:
8383
def f(self) -> B: return self
8484
def g(self) -> B: return B()
85-
AB = TypeVar('AB', values=(A, B))
85+
AB = TypeVar('AB', A, B)
8686
def f(x: AB) -> AB:
8787
y = x
8888
if y:
@@ -94,7 +94,7 @@ main: In function "f":
9494

9595
[case testTypeApplicationAndTypeVarValues]
9696
from typing import TypeVar, List
97-
T = TypeVar('T', values=(int, str))
97+
T = TypeVar('T', int, str)
9898
def f(x: T) -> List[T]:
9999
return List[T]()
100100
def g(x: T) -> List[T]:
@@ -105,7 +105,7 @@ main: In function "g":
105105

106106
[case testTypeDeclaredBasedOnTypeVarWithValues]
107107
from typing import TypeVar, Undefined
108-
T = TypeVar('T', values=(int, str))
108+
T = TypeVar('T', int, str)
109109
def f(x: T) -> T:
110110
a = Undefined(T)
111111
b = None # type: T
@@ -118,7 +118,7 @@ main: In function "f":
118118

119119
[case testIsinstanceAndTypeVarValues]
120120
from typing import TypeVar
121-
T = TypeVar('T', values=(int, str))
121+
T = TypeVar('T', int, str)
122122
def f(x: T) -> T:
123123
if isinstance(x, int):
124124
return 2
@@ -135,7 +135,7 @@ main: In function "h":
135135

136136
[case testIsinstanceAndTypeVarValues2]
137137
from typing import TypeVar
138-
T = TypeVar('T', values=(int, str))
138+
T = TypeVar('T', int, str)
139139
def f(x: T) -> T:
140140
if isinstance(x, int):
141141
return 2
@@ -153,7 +153,7 @@ main: In function "g":
153153

154154
[case testIsinstanceAndTypeVarValues3]
155155
from typing import TypeVar
156-
T = TypeVar('T', values=(int, str))
156+
T = TypeVar('T', int, str)
157157
def f(x: T) -> T:
158158
if isinstance(x, int):
159159
y = 1
@@ -164,7 +164,7 @@ def f(x: T) -> T:
164164

165165
[case testIsinstanceAndTypeVarValues4]
166166
from typing import TypeVar
167-
T = TypeVar('T', values=(int, str))
167+
T = TypeVar('T', int, str)
168168
def f(x: T) -> T:
169169
if isinstance(x, int):
170170
y = 1
@@ -177,7 +177,7 @@ main: In function "f":
177177

178178
[case testIsinstanceAndTypeVarValues5]
179179
from typing import TypeVar
180-
T = TypeVar('T', values=(int, str))
180+
T = TypeVar('T', int, str)
181181
def f(x: T) -> T:
182182
if isinstance(x, int):
183183
y = object()
@@ -192,7 +192,7 @@ main: In function "f":
192192
from typing import TypeVar, Undefined
193193
class A: pass
194194
class B: pass
195-
T = TypeVar('T', values=(A, B))
195+
T = TypeVar('T', A, B)
196196
def f(x: T) -> None:
197197
y = x
198198
if isinstance(x, A):
@@ -204,7 +204,7 @@ def f(x: T) -> None:
204204
x = B()
205205
x = y
206206
x.foo() # E: "B" has no attribute "foo"
207-
S = TypeVar('S', values=(int, str))
207+
S = TypeVar('S', int, str)
208208
def g(x: S) -> None:
209209
y = x
210210
if isinstance(x, int):
@@ -216,7 +216,7 @@ main: In function "f":
216216
[case testIsinstanceWithUserDefinedTypeAndTypeVarValues2]
217217
from typing import TypeVar, Undefined
218218
class S(str): pass
219-
T = TypeVar('T', values=(S, int))
219+
T = TypeVar('T', S, int)
220220
def f(x: T) -> None:
221221
y = x
222222
if isinstance(x, S):
@@ -234,7 +234,7 @@ main: In function "f":
234234

235235
[case testTypeVarValuesAndNestedCalls]
236236
from typing import TypeVar
237-
T = TypeVar('T', values=(int, str))
237+
T = TypeVar('T', int, str)
238238
def f(m: T) -> int: pass
239239
def h(x: int) -> int: pass
240240
def g(a: T) -> None:
@@ -243,7 +243,7 @@ def g(a: T) -> None:
243243

244244
[case testGenericTypeWithTypevarValues]
245245
from typing import TypeVar, Generic, Undefined, Any
246-
X = TypeVar('X', values=(int, str))
246+
X = TypeVar('X', int, str)
247247
class A(Generic[X]): pass
248248
a = Undefined(A[int])
249249
b = Undefined(A[str])
@@ -252,7 +252,7 @@ c = Undefined(A[Any])
252252

253253
[case testGenericTypeWithTypevarValuesAndTypeApplication]
254254
from typing import TypeVar, Generic, Undefined, Any
255-
X = TypeVar('X', values=(int, str))
255+
X = TypeVar('X', int, str)
256256
class A(Generic[X]): pass
257257
A[int]()
258258
A[str]()
@@ -261,7 +261,7 @@ A[object]() # E: Type argument 1 of "A" has incompatible value "object"
261261

262262
[case testConstructGenericTypeWithTypevarValuesAndTypeInference]
263263
from typing import TypeVar, Generic, Any
264-
X = TypeVar('X', values=(int, str))
264+
X = TypeVar('X', int, str)
265265
class A(Generic[X]):
266266
def __init__(self, x: X) -> None: pass
267267
A(1)
@@ -272,8 +272,8 @@ A(object()) # E: Type argument 1 of "A" has incompatible value "object"
272272
[case testGenericTypeWithTypevarValuesAndTypevarArgument]
273273
from typing import TypeVar, Generic, Undefined
274274
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)
277277
Z = TypeVar('Z')
278278
class D(Generic[X]):
279279
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"
291291

292292
[case testGenericTypeWithTypevarValuesAndSubtypePromotion]
293293
from typing import TypeVar, Generic, Undefined
294-
X = TypeVar('X', values=(int, str))
294+
X = TypeVar('X', int, str)
295295
class S(str): pass
296296
class C(Generic[X]):
297297
def __init__(self, x: X) -> None: pass
@@ -311,7 +311,7 @@ class B:
311311
def f(self, x: int) -> None: pass
312312
def g(self, x: str) -> None: pass
313313
def h(self, x: int) -> None: pass
314-
X = TypeVar('X', values=(A, B))
314+
X = TypeVar('X', A, B)
315315
class C(Generic[X]):
316316
def f(self, x: X) -> None:
317317
x.f(1)
@@ -322,7 +322,7 @@ main: In member "f" of class "C":
322322

323323
[case testAttributeInGenericTypeWithTypevarValues1]
324324
from typing import TypeVar, Generic, Undefined
325-
X = TypeVar('X', values=(int, str))
325+
X = TypeVar('X', int, str)
326326
class C(Generic[X]):
327327
x = Undefined(X)
328328
def f(self, x: X) -> None:
@@ -333,7 +333,7 @@ main: In member "f" of class "C":
333333

334334
[case testAttributeInGenericTypeWithTypevarValues2]
335335
from typing import TypeVar, Generic, Undefined
336-
X = TypeVar('X', values=(int, str))
336+
X = TypeVar('X', int, str)
337337
class C(Generic[X]):
338338
x = Undefined(X)
339339
cn = C[int]()
@@ -345,7 +345,7 @@ cs.x = 1 # E: Incompatible types in assignment (expression has type "int", varia
345345

346346
[case testInferredAttributeInGenericClassBodyWithTypevarValues]
347347
from typing import TypeVar, Generic, Undefined
348-
X = TypeVar('X', values=(int, str))
348+
X = TypeVar('X', int, str)
349349
class C(Generic[X]):
350350
x = 1
351351
C.x = 1
@@ -357,8 +357,8 @@ class A:
357357
def f(self, x: int) -> None: pass
358358
class B:
359359
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)
362362
class C(Generic[X, Y]):
363363
def f(self, x: X, y: Y) -> None:
364364
x.f(y)
@@ -371,8 +371,8 @@ main, line 10: Argument 1 to "f" of "B" has incompatible type "int"; expected "s
371371
from typing import TypeVar, Generic, Undefined
372372
class A: pass
373373
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)
376376
class C(Generic[X, Y]): pass
377377
a = Undefined(C[A, int])
378378
b = Undefined(C[B, str])
@@ -383,8 +383,8 @@ c = Undefined(C[A, A]) # E: Invalid type argument value for "C"
383383
from typing import TypeVar
384384
class A: pass
385385
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)
388388
def f(x: X, y: Y) -> None: pass
389389
f(A(), '')
390390
f(B(), 1)
@@ -394,7 +394,7 @@ f(1, 1) # E: Type argument 1 of "f" has incompatible value "int"
394394
[case testGenericFunctionWithNormalAndRestrictedTypevar]
395395
from typing import TypeVar, Generic, Undefined
396396
X = TypeVar('X')
397-
Y = TypeVar('Y', values=(int, str))
397+
Y = TypeVar('Y', int, str)
398398
class C(Generic[Y]):
399399
def __init__(self, y: Y) -> None: pass
400400
def f(x: X, y: Y, z: int) -> None:
@@ -413,7 +413,7 @@ main, line 11: "str" has no attribute "foo"
413413

414414
[case testTypeVarWithValueInferredFromObjectReturnTypeContext]
415415
from typing import TypeVar
416-
T = TypeVar('T', values=(int, str))
416+
T = TypeVar('T', int, str)
417417
def c1(x: object) -> None: pass
418418
def c2(x: int) -> None: pass
419419
def c3(x: str) -> None: pass
@@ -426,7 +426,7 @@ c3(g(1)) # E: Argument 1 to "c3" has incompatible type "int"; expected "str"
426426

427427
[case testTypeVarWithValueInferredFromObjectReturnTypeContext2]
428428
from typing import TypeVar
429-
T = TypeVar('T', values=(int, str))
429+
T = TypeVar('T', int, str)
430430
class ss(str): pass
431431
def c(x: ss) -> None: pass
432432
def g(x: T) -> T: pass
@@ -444,7 +444,7 @@ main, line 7: Argument 1 to "c" has incompatible type "int"; expected "ss"
444444
[case testTypevarValuesSpecialCase1]
445445
from typing import TypeVar, Generic
446446
from abc import abstractmethod
447-
T = TypeVar('T', values=(int, str))
447+
T = TypeVar('T', int, str)
448448
class A(Generic[T]):
449449
@abstractmethod
450450
def f(self) -> 'A[T]': pass
@@ -460,14 +460,14 @@ main: In class "C":
460460

461461
[case testDefaultArgumentValueInGenericClassWithTypevarValues]
462462
from typing import TypeVar, Generic
463-
T = TypeVar('T', values=(int, str))
463+
T = TypeVar('T', int, str)
464464
class C(Generic[T]):
465465
def f(self, x: int = None) -> None: pass
466466

467467
[case testTypevarValuesWithOverloadedFunctionSpecialCase]
468468
from typing import TypeVar, overload, Callable
469469

470-
T = TypeVar('T', values=(int, str))
470+
T = TypeVar('T', int, str)
471471
def f(x: T) -> None:
472472
y = m(g, x)
473473
x = y

‎mypy/test/data/pythoneval.test

+3-3
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ if isinstance(x, tuple):
337337

338338
[case testTypevarValues]
339339
from typing import TypeVar
340-
T = TypeVar('T', values=(str, bytes))
340+
T = TypeVar('T', str, bytes)
341341
def f(x: T) -> T:
342342
if isinstance(x, str):
343343
return 'foo'
@@ -425,8 +425,8 @@ b'xx'
425425
[case testMultipleTypevarsWithValues]
426426
from typing import TypeVar
427427

428-
T = TypeVar('T', values=(int, str))
429-
S = TypeVar('S', values=(int, str))
428+
T = TypeVar('T', int, str)
429+
S = TypeVar('S', int, str)
430430

431431
def f(t: T, s: S) -> None:
432432
t + s

‎mypy/test/data/semanal-errors.test

+12-6
Original file line numberDiff line numberDiff line change
@@ -1082,18 +1082,24 @@ a = TypeVar() # E: Too few arguments for TypeVar()
10821082
b = TypeVar(x='b') # E: Unexpected arguments to TypeVar()
10831083
c = TypeVar(1) # E: TypeVar() expects a string literal argument
10841084
d = TypeVar('D') # E: Unexpected TypeVar() argument value
1085-
e = TypeVar('e', values=(int, str), x=1) # E: Too many arguments for TypeVar()
1086-
f = TypeVar('f', (int, str)) # E: Unexpected arguments to TypeVar()
1087-
g = TypeVar('g', x=(int, str)) # E: Unexpected keyword argument 'x' to TypeVar()
1085+
e = TypeVar('e', int, str, x=1) # E: Unexpected arguments to TypeVar()
1086+
f = TypeVar('f', (int, str)) # E: Type expected
1087+
g = TypeVar('g', x=(int, str)) # E: Unexpected arguments to TypeVar()
10881088
[out]
10891089

10901090
[case testInvalidTypevarValues]
10911091
from typing import TypeVar
1092-
a = TypeVar('a', values=int) # E: The values argument must be a tuple literal
1093-
b = TypeVar('b', values=(int)) # E: The values argument must be a tuple literal
1094-
c = TypeVar('c', values=(int, 2)) # E: Type expected
1092+
b = TypeVar('b', *[int]) # E: Unexpected arguments to TypeVar()
1093+
c = TypeVar('c', int, 2) # E: Type expected
10951094
[out]
10961095

1096+
[case testObsoleteTypevarValuesSyntax]
1097+
from typing import TypeVar
1098+
a = TypeVar('a', values=(int, str))
1099+
[out]
1100+
main, line 2: TypeVar 'values' argument not supported
1101+
main, line 2: Use TypeVar('T', t, ...) instead of TypeVar('T', values=(t, ...))
1102+
10971103
[case testLocalTypevarScope]
10981104
from typing import TypeVar
10991105
def f() -> None:

‎mypy/test/data/semanal-types.test

+4-4
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,8 @@ MypyFile:1(
12931293

12941294
[case testTypevarWithValues]
12951295
from typing import TypeVar, Any
1296-
T = TypeVar('T', values=(int, str))
1297-
S = TypeVar('S', values=(Any, int, str))
1296+
T = TypeVar('T', int, str)
1297+
S = TypeVar('S', Any, int, str)
12981298
[out]
12991299
MypyFile:1(
13001300
ImportFrom:1(typing, [TypeVar : TypeVar, Any : Any])
@@ -1314,7 +1314,7 @@ MypyFile:1(
13141314

13151315
[case testGenericFunctionWithValueSet]
13161316
from typing import TypeVar
1317-
T = TypeVar('T', values=(int, str))
1317+
T = TypeVar('T', int, str)
13181318
def f(x: T) -> T: pass
13191319
[out]
13201320
MypyFile:1(
@@ -1335,7 +1335,7 @@ MypyFile:1(
13351335

13361336
[case testGenericClassWithValueSet]
13371337
from typing import TypeVar, Generic
1338-
T = TypeVar('T', values=(int, str))
1338+
T = TypeVar('T', int, str)
13391339
class C(Generic[T]): pass
13401340
[out]
13411341
MypyFile:1(

‎mypy/test/data/typexport-basic.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ MemberExpr(10) : def [1:B, -1:builtins.object] (self: A[B], y: builtins.object)
10331033
[case testTypeVariableWithValueRestriction]
10341034
## NameExpr
10351035
from typing import TypeVar
1036-
T = TypeVar('T', values=(int, str))
1036+
T = TypeVar('T', int, str)
10371037
def f(x: T) -> None: pass
10381038
f(1)
10391039
f('x')
@@ -1044,7 +1044,7 @@ NameExpr(6) : def [-1:builtins.str] (x: builtins.str)
10441044
[case testTypeVariableWithValueRestrictionAndSubtype]
10451045
## NameExpr|CallExpr
10461046
from typing import TypeVar, Undefined
1047-
T = TypeVar('T', values=(int, str))
1047+
T = TypeVar('T', int, str)
10481048
def f(x: T) -> T: pass
10491049
class S(str): pass
10501050
s = Undefined # type: S

‎stubs/2.7/typing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __getitem__(self, typeargs): pass
3232
Set = TypeAlias(object)
3333

3434
# Predefined type variables.
35-
AnyStr = TypeVar('AnyStr', values=(str, unicode))
35+
AnyStr = TypeVar('AnyStr', str, unicode)
3636

3737
# Abstract base classes.
3838

‎stubs/3.2/builtins.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def callable(o: object) -> bool: pass
636636
def chr(code: int) -> str: pass
637637
def delattr(o: Any, name: str) -> None: pass
638638
def dir(o: object = None) -> List[str]: pass
639-
_N = TypeVar('_N', values=(int, float))
639+
_N = TypeVar('_N', int, float)
640640
def divmod(a: _N, b: _N) -> Tuple[_N, _N]: pass
641641
def eval(source: str, globals: Dict[str, Any] = None,
642642
locals: Mapping[str, Any] = None) -> Any: pass # TODO code object as source

‎stubs/3.2/typing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __getitem__(self, typeargs): pass
3232
Set = TypeAlias(object)
3333

3434
# Predefined type variables.
35-
AnyStr = TypeVar('AnyStr', values=(str, bytes))
35+
AnyStr = TypeVar('AnyStr', str, bytes)
3636

3737
# Abstract base classes.
3838

0 commit comments

Comments
 (0)
Please sign in to comment.