@@ -275,24 +275,25 @@ the built-in collections or those from :py:mod:`collections.abc`
275
275
y: dict[int , str ]
276
276
z: Sequence[str ] = x
277
277
278
+ There is limited support for using this syntax in Python 3.7 and later as well.
278
279
If you use ``from __future__ import annotations ``, mypy will understand this
279
- syntax in Python 3.7 and later. However, since this will not be supported by the
280
- Python interpreter at runtime, make sure you're aware of the caveats mentioned
281
- in the notes at :ref: `future annotations import<future-annotations> `.
280
+ syntax in annotations. However, since this will not be supported by the Python
281
+ interpreter at runtime, make sure you're aware of the caveats mentioned in the
282
+ notes at :ref: `future annotations import<future-annotations> `.
282
283
283
- Using new syntax
284
- ----------------
284
+ Using X | Y syntax for Unions
285
+ -----------------------------
285
286
286
287
Starting with Python 3.10 (:pep: `604 `), you can spell union types as ``x: int |
287
288
str ``, instead of ``x: typing.Union[int, str] ``.
288
289
290
+ There is limited support for using this syntax in Python 3.7 and later as well.
289
291
If you use ``from __future__ import annotations ``, mypy will understand this
290
- syntax in Python 3.7 and later. However, since this will not be supported by the
291
- Python interpreter at runtime (if evaluated, ``int | str `` will raise
292
- ``TypeError: unsupported operand type(s) for |: 'type' and 'type' ``), make sure
293
- you're aware of the caveats mentioned in the notes at :ref: `future annotations
294
- import<future-annotations>`. You can also use the new syntax in string literal
295
- types or type comments.
292
+ syntax in annotations, string literal types, type comments and stub files.
293
+ However, since this will not be supported by the Python interpreter at runtime
294
+ (if evaluated, ``int | str `` will raise ``TypeError: unsupported operand type(s)
295
+ for |: 'type' and 'type' ``), make sure you're aware of the caveats mentioned in
296
+ the notes at :ref: `future annotations import<future-annotations> `.
296
297
297
298
Using new additions to the typing module
298
299
----------------------------------------
0 commit comments