@@ -260,9 +260,9 @@ hinting, use the following:
260
260
261
261
* a ``@no_type_checks`` decorator on classes and functions
262
262
263
- * a ``# type: ignore`` comment on arbitrary lines
263
+ * a ``''' type: ignore''' `` string literal on arbitrary lines
264
264
265
- .. FIXME: should we have a module-wide comment as well?
265
+ .. FIXME: should we have a module-wide string literals as well?
266
266
267
267
268
268
Type Hints on Local and Global Variables
@@ -272,14 +272,16 @@ No first-class syntax support for explicitly marking variables as being
272
272
of a specific type is added by this PEP. To help with type inference in
273
273
complex cases, a comment of the following format may be used::
274
274
275
- x = [] # type: List[Employee]
275
+ '''type: List[Employee]'''
276
+ x = []
276
277
277
278
In the case where type information for a local variable is needed before
278
279
if was declared, an ``Undefined`` placeholder might be used::
279
280
280
281
from typing import Undefined
281
-
282
- x = Undefined # type: List[Employee]
282
+
283
+ '''type: List[Employee]'''
284
+ x = Undefined
283
285
y = Undefined(int)
284
286
285
287
If type hinting proves useful in general, a syntax for typing variables
@@ -327,9 +329,12 @@ generics and union types:
327
329
* TypeVar, used as ``X = TypeVar('X', Type1, Type2, Type3)`` or simply
328
330
``Y = TypeVar('Y')``
329
331
330
- * Undefined, used as ``local_variable = Undefined # type: List[int]`` or
331
- ``local_variable = Undefined(List[int])`` (the latter being slower
332
- during runtime)
332
+ * Undefined, used as ``local_variable = Undefined(List[int])`` or::
333
+
334
+ '''type: List[int]'''
335
+ local_variable = Undefined
336
+
337
+ (the former being slower during runtime)
333
338
334
339
* Callable, used as ``Callable[[Arg1Type, Arg2Type], ReturnType]``
335
340
0 commit comments