diff options
author | kj <28750310+Fidget-Spinner@users.noreply.github.com> | 2020-11-19 04:44:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-19 04:44:24 (GMT) |
commit | 4687338d0ed46e1f5f5060536becf8a96496bae7 (patch) | |
tree | 160afde4e5231ff61a3eb556708418c71bf8ba5c /Doc/whatsnew | |
parent | a85fefe71b3bf56b1b3e72e752e0f962c3b0b487 (diff) | |
download | cpython-4687338d0ed46e1f5f5060536becf8a96496bae7.zip cpython-4687338d0ed46e1f5f5060536becf8a96496bae7.tar.gz cpython-4687338d0ed46e1f5f5060536becf8a96496bae7.tar.bz2 |
bpo-42345: Add whatsnew for typing.Literal in 3.10 (GH-23385)
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/3.10.rst | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 9559441..ad0ec4d 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -300,6 +300,32 @@ and :data:`types.NotImplementedType` classes, providing a new set of types readily interpretable by type checkers. (Contributed by Bas van Beek in :issue:`41810`.) +typing +------ + +The behavior of :class:`typing.Literal` was changed to conform with :pep:`586` +and to match the behavior of static type checkers specified in the PEP. + +1. ``Literal`` now de-duplicates parameters. +2. Equality comparisons between ``Literal`` objects are now order independent. +3. ``Literal`` comparisons now respects types. For example, + ``Literal[0] == Literal[False]`` previously evaluated to ``True``. It is + now ``False``. To support this change, the internally used type cache now + supports differentiating types. +4. ``Literal`` objects will now raise a :exc:`TypeError` exception during + equality comparisons if one of their parameters are not :term:`immutable`. + Note that declaring ``Literal`` with mutable parameters will not throw + an error:: + + >>> from typing import Literal + >>> Literal[{0}] + >>> Literal[{0}] == Literal[{False}] + Traceback (most recent call last): + File "<stdin>", line 1, in <module> + TypeError: unhashable type: 'set' + +(Contributed by Yurii Karabas in :issue:`42345`.) + unittest -------- |