summaryrefslogtreecommitdiffstats
path: root/Doc/whatsnew
diff options
context:
space:
mode:
authorMikhail Golubev <qsolo825@gmail.com>2020-10-07 21:44:31 (GMT)
committerGitHub <noreply@github.com>2020-10-07 21:44:31 (GMT)
commit4f3c25043d651a13c41cffcee703f7d5cb677cc7 (patch)
tree08093971ec6aefd8b762e8da9d20434c09a3c3ae /Doc/whatsnew
parentf90dc36c15d7fee0efaf6d39e97be0bdf2683e93 (diff)
downloadcpython-4f3c25043d651a13c41cffcee703f7d5cb677cc7.zip
cpython-4f3c25043d651a13c41cffcee703f7d5cb677cc7.tar.gz
cpython-4f3c25043d651a13c41cffcee703f7d5cb677cc7.tar.bz2
bpo-41923: PEP 613: Add TypeAlias to typing module (#22532)
This special marker annotation is intended to help in distinguishing proper PEP 484-compliant type aliases from regular top-level variable assignments.
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r--Doc/whatsnew/3.10.rst25
1 files changed, 23 insertions, 2 deletions
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index 2bcdba6..4ada4be 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -99,8 +99,29 @@ in :issue:`38605`.)
* :pep:`618`: The :func:`zip` function now has an optional ``strict`` flag, used
to require that all the iterables have an equal length.
-PEP604: New Type Operator
--------------------------
+PEP 613: TypeAlias Annotation
+-----------------------------
+
+:pep:`484` introduced the concept of type aliases, only requiring them to be
+top-level unannotated assignments. This simplicity sometimes made it difficult
+for type checkers to distinguish between type aliases and ordinary assignments,
+especially when forward references or invalid types were involved. Compare::
+
+ StrCache = 'Cache[str]' # a type alias
+ LOG_PREFIX = 'LOG[DEBUG]' # a module constant
+
+Now the :mod:`typing` module has a special annotation :data:`TypeAlias` to
+declare type aliases more explicitly::
+
+ StrCache: TypeAlias = 'Cache[str]' # a type alias
+ LOG_PREFIX = 'LOG[DEBUG]' # a module constant
+
+See :pep:`613` for more details.
+
+(Contributed by Mikhail Golubev in :issue:`41923`.)
+
+PEP604: New Type Union Operator
+-------------------------------
A new type union operator was introduced which enables the syntax ``X | Y``.
This provides a cleaner way of expressing 'either type X or type Y' instead of