@@ -8,7 +8,7 @@ Status: Draft
8
8
Type: Standards Track
9
9
Content-Type: text/x-rst
10
10
Created: 29-Sep-2014
11
- Post-History:
11
+ Post-History:
12
12
Resolution:
13
13
14
14
@@ -85,25 +85,21 @@ elements. Example::
85
85
def notify_by_email(employees: Set[Employee], overrides: Mapping[str, str]): ...
86
86
87
87
Generics can be parametrized by using a new factory available in
88
- ``collections.abc`` called ``Var ``. Example::
88
+ ``collections.abc`` called ``TypeVar ``. Example::
89
89
90
- T = Var ('T') # Declare type variable
90
+ T = TypeVar ('T') # Declare type variable
91
91
92
92
def first(l: Sequence[T]) -> T: # Generic function
93
93
return l[0]
94
94
95
- .. FIXME: Maybe rename Var to TypeVar to avoid confusion with simple
96
- variables and a possible future syntax of the form
97
- var name: type = value
98
-
99
95
In this case the contract is that the returning value is consistent with
100
96
the elements held by the collection.
101
97
102
- ``Var `` supports constraining parametric types to classes with any of
98
+ ``TypeVar `` supports constraining parametric types to classes with any of
103
99
the specified bases. Example::
104
100
105
- X = Var ('X')
106
- Y = Var ('Y', Iterable[X])
101
+ X = TypeVar ('X')
102
+ Y = TypeVar ('Y', Iterable[X])
107
103
108
104
def filter(rule: Callable[[X], bool], input: Y) -> Y:
109
105
...
@@ -201,8 +197,8 @@ complex cases, a comment of the following format may be used::
201
197
202
198
x = [] # type: List[Employee]
203
199
204
- If type hinting proves useful in general, a variable typing in syntax may
205
- be provided in a future Python version.
200
+ If type hinting proves useful in general, a syntax for typing variables
201
+ may be provided in a future Python version.
206
202
207
203
208
204
Explicit raised exceptions
@@ -246,7 +242,7 @@ new members are defined:
246
242
247
243
* Union
248
244
249
- * Var
245
+ * TypeVar
250
246
251
247
All available abstract base classes are importable:
252
248
@@ -295,7 +291,7 @@ All available abstract base classes are importable:
295
291
296
292
The following helper types are also provided by the ``typing`` module:
297
293
298
- * AnyStr, equivalent to ``Var ('AnyStr', str, bytes)``
294
+ * AnyStr, equivalent to ``TypeVar ('AnyStr', str, bytes)``
299
295
300
296
* Match and Pattern, types of ``re.match()`` and ``re.compile()`` results
301
297
0 commit comments