Skip to content

Commit e1dc0db

Browse files
bpo-42345: Add whatsnew and versionchanged for typing.Literal in 3.9 (pythonGH-23386)
* Whatsnew entry in 3.9 same as the one in 3.10. * versionchanged for typing.Literal docs Needs backport to 3.9.
1 parent 1b54077 commit e1dc0db

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Doc/library/typing.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,12 @@ These can be used as types in annotations using ``[]``, each having a unique syn
674674

675675
.. versionadded:: 3.8
676676

677+
.. versionchanged:: 3.9.1
678+
``Literal`` now de-duplicates parameters. Equality comparison of
679+
``Literal`` objects are no longer order dependent. ``Literal`` objects
680+
will now raise a :exc:`TypeError` exception during equality comparisons
681+
if one of their parameters are not :term:`immutable`.
682+
677683
.. data:: ClassVar
678684

679685
Special type construct to mark class variables.

Doc/whatsnew/3.9.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,3 +1454,32 @@ Removed
14541454
``PyNullImporter_Type``, ``PyCmpWrapper_Type``, ``PySortWrapper_Type``,
14551455
``PyNoArgsFunction``.
14561456
(Contributed by Pablo Galindo Salgado in :issue:`39372`.)
1457+
1458+
Notable changes in Python 3.9.1
1459+
===============================
1460+
1461+
typing
1462+
------
1463+
1464+
The behavior of :class:`typing.Literal` was changed to conform with :pep:`586`
1465+
and to match the behavior of static type checkers specified in the PEP.
1466+
1467+
1. ``Literal`` now de-duplicates parameters.
1468+
2. Equality comparisons between ``Literal`` objects are now order independent.
1469+
3. ``Literal`` comparisons now respect types. For example,
1470+
``Literal[0] == Literal[False]`` previously evaluated to ``True``. It is
1471+
now ``False``. To support this change, the internally used type cache now
1472+
supports differentiating types.
1473+
4. ``Literal`` objects will now raise a :exc:`TypeError` exception during
1474+
equality comparisons if one of their parameters are not :term:`immutable`.
1475+
Note that declaring ``Literal`` with mutable parameters will not throw
1476+
an error::
1477+
1478+
>>> from typing import Literal
1479+
>>> Literal[{0}]
1480+
>>> Literal[{0}] == Literal[{False}]
1481+
Traceback (most recent call last):
1482+
File "<stdin>", line 1, in <module>
1483+
TypeError: unhashable type: 'set'
1484+
1485+
(Contributed by Yurii Karabas in :issue:`42345`.)

0 commit comments

Comments
 (0)