[3.9] bpo-42345: Add whatsnew and versionchanged for typing.Literal in 3.9 (GH-23386) by miss-islington · Pull Request #23411 · python/cpython
Notable changes in Python 3.9.1 ===============================
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 respect 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`.)