[Python-checkins] bpo-46120: State that `|` is preferred over `Union` (GH-30222)

gpshead webhook-mailer at python.org
Fri Dec 24 16:36:39 EST 2021


https://github.com/python/cpython/commit/1b30660c3b40da557050948ac8635f2dc50c4ee2
commit: 1b30660c3b40da557050948ac8635f2dc50c4ee2
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: gpshead <greg at krypto.org>
date: 2021-12-24T13:36:09-08:00
summary:

bpo-46120: State that `|` is preferred over `Union` (GH-30222)

Co-authored-by: Éric <merwok at netwok.org>
Co-authored-by: Guido van Rossum <gvanrossum at gmail.com>

files:
A Misc/NEWS.d/next/Documentation/2021-12-21-12-45-57.bpo-46120.PE0DmJ.rst
M Doc/library/typing.rst

diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 727941b57b547..08b59d84246f8 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -625,7 +625,7 @@ These can be used as types in annotations using ``[]``, each having a unique syn
 
    Union type; ``Union[X, Y]`` is equivalent to ``X | Y`` and means either X or Y.
 
-   To define a union, use e.g. ``Union[int, str]`` or the shorthand ``int | str``.  Details:
+   To define a union, use e.g. ``Union[int, str]`` or the shorthand ``int | str``. Using that shorthand is recommended. Details:
 
    * The arguments must be types and there must be at least one.
 
diff --git a/Misc/NEWS.d/next/Documentation/2021-12-21-12-45-57.bpo-46120.PE0DmJ.rst b/Misc/NEWS.d/next/Documentation/2021-12-21-12-45-57.bpo-46120.PE0DmJ.rst
new file mode 100644
index 0000000000000..17f67472e2ab0
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2021-12-21-12-45-57.bpo-46120.PE0DmJ.rst
@@ -0,0 +1 @@
+State that ``|`` is preferred for readability over ``Union`` in the :mod:`typing` docs.



More information about the Python-checkins mailing list