Skip to content

Commit 9e5a998

Browse files
author
hauntsaninja
committed
more edits
1 parent 5bc7167 commit 9e5a998

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

docs/source/kinds_of_types.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ X | Y syntax for Unions
247247
-----------------------
248248

249249
:pep:`604` introduced an alternative way for spelling union types. In Python
250-
3.10 and later, it is possible to write ``Union[int, str]`` as ``int | str``. It
251-
is possible to use this syntax in versions of Python where it isn't supported by
250+
3.10 and later, you can write ``Union[int, str]`` as ``int | str``. It is
251+
possible to use this syntax in versions of Python where it isn't supported by
252252
the runtime with some limitations, see :ref:`runtime_troubles`.
253253

254254
.. code-block:: python

docs/source/runtime_troubles.rst

+12-11
Original file line numberDiff line numberDiff line change
@@ -275,24 +275,25 @@ the built-in collections or those from :py:mod:`collections.abc`
275275
y: dict[int, str]
276276
z: Sequence[str] = x
277277
278+
There is limited support for using this syntax in Python 3.7 and later as well.
278279
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>`.
282283

283-
Using new syntax
284-
----------------
284+
Using X | Y syntax for Unions
285+
-----------------------------
285286

286287
Starting with Python 3.10 (:pep:`604`), you can spell union types as ``x: int |
287288
str``, instead of ``x: typing.Union[int, str]``.
288289

290+
There is limited support for using this syntax in Python 3.7 and later as well.
289291
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>`.
296297

297298
Using new additions to the typing module
298299
----------------------------------------

0 commit comments

Comments
 (0)