bpo-42345: Add whatsnew and versionchanged for typing.Literal in 3.9 (GH-23386)

* Whatsnew entry in 3.9 same as the one in 3.10.
* versionchanged for typing.Literal docs

Needs backport to 3.9.
(cherry picked from commit e1dc0db8c7)

Co-authored-by: kj <28750310+Fidget-Spinner@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2020-11-19 09:59:10 -08:00 committed by GitHub
parent 2acd9d0c6c
commit 1051ca4d97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View file

@ -655,6 +655,12 @@ These can be used as types in annotations using ``[]``, each having a unique syn
.. versionadded:: 3.8 .. versionadded:: 3.8
.. versionchanged:: 3.9.1
``Literal`` now de-duplicates parameters. Equality comparison of
``Literal`` objects are no longer order dependent. ``Literal`` objects
will now raise a :exc:`TypeError` exception during equality comparisons
if one of their parameters are not :term:`immutable`.
.. data:: ClassVar .. data:: ClassVar
Special type construct to mark class variables. Special type construct to mark class variables.

View file

@ -1454,3 +1454,32 @@ Removed
``PyNullImporter_Type``, ``PyCmpWrapper_Type``, ``PySortWrapper_Type``, ``PyNullImporter_Type``, ``PyCmpWrapper_Type``, ``PySortWrapper_Type``,
``PyNoArgsFunction``. ``PyNoArgsFunction``.
(Contributed by Pablo Galindo Salgado in :issue:`39372`.) (Contributed by Pablo Galindo Salgado in :issue:`39372`.)
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`.)