summaryrefslogtreecommitdiff
path: root/Doc/whatsnew/3.10.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/whatsnew/3.10.rst')
-rw-r--r--Doc/whatsnew/3.10.rst99
1 files changed, 99 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index 1228f26954..738ef974e7 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -70,6 +70,23 @@ Summary -- Release highlights
New Features
============
+.. _whatsnew310-pep563:
+
+PEP 563: Postponed Evaluation of Annotations Becomes Default
+------------------------------------------------------------
+
+In Python 3.7, postponed evaluation of annotations was added,
+to be enabled with a ``from __future__ import annotations``
+directive. In 3.10 this became the default behavior, even
+without that future directive. With this being default, all
+annotations stored in :attr:`__annotations__` will be strings.
+If needed, annotations can be resolved at runtime using
+:func:`typing.get_type_hints`. See :pep:`563` for a full
+description. Also, the :func:`inspect.signature` will try to
+resolve types from now on, and when it fails it will fall back to
+showing the string annotations. (Contributed by Batuhan Taskaya
+in :issue:`38605`.)
+
* The :class:`int` type has a new method :meth:`int.bit_count`, returning the
number of ones in the binary expansion of a given integer, also known
as the population count. (Contributed by Niklas Fiekas in :issue:`29882`.)
@@ -82,6 +99,50 @@ New Features
* :pep:`618`: The :func:`zip` function now has an optional ``strict`` flag, used
to require that all the iterables have an equal length.
+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
+using :data:`typing.Union`, especially in type hints (annotations).
+
+In previous versions of Python, to apply a type hint for functions accepting
+arguments of multiple types, :data:`typing.Union` was used::
+
+ def square(number: Union[int, float]) -> Union[int, float]:
+ return number ** 2
+
+
+Now, type hints can be written in a more succinct manner::
+
+ def square(number: int | float) -> int | float:
+ return number ** 2
+
+
+See :pep:`604` for more details.
+
+(Contributed by Maggie Moss and Philippe Prados in :issue:`41428`.)
Other Language Changes
======================
@@ -109,6 +170,12 @@ base64
Add :func:`base64.b32hexencode` and :func:`base64.b32hexdecode` to support the
Base32 Encoding with Extended Hex Alphabet.
+codecs
+------
+
+Add a :func:`codecs.unregister` function to unregister a codec search function.
+(Contributed by Hai Shi in :issue:`41842`.)
+
curses
------
@@ -119,6 +186,11 @@ by :func:`curses.color_content`, :func:`curses.init_color`,
support is provided by the underlying ncurses library.
(Contributed by Jeffrey Kintscher and Hans Petter Jansson in :issue:`36982`.)
+encodings
+---------
+:func:`encodings.normalize_encoding` now ignores non-ASCII characters.
+(Contributed by Hai Shi in :issue:`39337`.)
+
glob
----
@@ -188,6 +260,12 @@ Deprecated
Removed
=======
+* Removed special methods ``__int__``, ``__float__``, ``__floordiv__``,
+ ``__mod__``, ``__divmod__``, ``__rfloordiv__``, ``__rmod__`` and
+ ``__rdivmod__`` of the :class:`complex` class. They always raised
+ a :exc:`TypeError`.
+ (Contributed by Serhiy Storchaka in :issue:`41974`.)
+
* The ``ParserBase.error()`` method from the private and undocumented ``_markupbase``
module has been removed. :class:`html.parser.HTMLParser` is the only subclass of
``ParserBase`` and its ``error()`` implementation has already been removed in
@@ -237,6 +315,14 @@ New Features
:class:`datetime.time` objects.
(Contributed by Zackery Spytz in :issue:`30155`.)
+* Add a :c:func:`PyCodec_Unregister` function to unregister a codec
+ search function.
+ (Contributed by Hai Shi in :issue:`41842`.)
+
+* The :c:func:`PyIter_Send` function was added to allow
+ sending value into iterator without raising ``StopIteration`` exception.
+ (Contributed by Vladimir Matveev in :issue:`41756`.)
+
Porting to Python 3.10
----------------------
@@ -289,6 +375,14 @@ Porting to Python 3.10
Unicode object without initial data.
(Contributed by Inada Naoki in :issue:`36346`.)
+Deprecated
+----------
+
+* The ``PyUnicode_InternImmortal()`` function is now deprecated
+ and will be removed in Python 3.12: use :c:func:`PyUnicode_InternInPlace`
+ instead.
+ (Contributed by Victor Stinner in :issue:`41692`.)
+
Removed
-------
@@ -324,3 +418,8 @@ Removed
* Removed ``_Py_CheckRecursionLimit`` variable: it has been replaced by
``ceval.recursion_limit`` of the :c:type:`PyInterpreterState` structure.
(Contributed by Victor Stinner in :issue:`41834`.)
+
+* Removed undocumented macros ``Py_ALLOW_RECURSION`` and
+ ``Py_END_ALLOW_RECURSION`` and the ``recursion_critical`` field of the
+ :c:type:`PyInterpreterState` structure.
+ (Contributed by Serhiy Storchaka in :issue:`41936`.)