Python 3.10
Python 3.10
Python 3.10.0 (final) was released on the 4 October 2021. The Features for 3.10 are defined in PEP 619 and a detailed description of the changes can be found in What’s New in Python 3.10.
| New syntax features | Status | |
|---|---|---|
| PEP 634 | Structural Pattern Matching: Specification | |
| PEP 635 | Structural Pattern Matching: Motivation and Rationale | |
| PEP 636 | Structural Pattern Matching: Tutorial | |
| bpo-12782 | Parenthesized context managers are now officially allowed | |
| New features in the standard library | ||
| PEP 618 | Add Optional Length-Checking To zip | |
| Interpreter improvements | ||
| PEP 626 | Precise line numbers for debugging and other tools | |
| New typing features | ||
| PEP 604 | Allow writing union types as X | Y |
| PEP 613 | Explicit Type Aliases | |
| PEP 612 | Parameter Specification Variables | |
| Important deprecations, removals or restrictions | ||
| PEP 644 | Require OpenSSL 1.1.1 or newer | |
| PEP 632 | Deprecate distutils module. | Not relevant |
| PEP 623 | Deprecate and prepare for the removal of the wstr member in PyUnicodeObject. | Not relevant |
| PEP 624 | Remove Py_UNICODE encoder APIs | Not relevant |
| PEP 597 | Add optional EncodingWarning |
Other Language Changes:
The int type has a new method int.bit_count(), returning thenumber of ones in the binary expansion of a given integer, also known as the population count. | |
|---|---|
| The views returned by dict.keys(), dict.values() and dict.items() now all have a mapping attribute that gives atypes.MappingProxyType object wrapping the original dictionary. | |
PEP 618: The zip() function now has an optional strict flag, usedto require that all the iterables have an equal length. | |
| Builtin and extension functions that take integer arguments no longer accept Decimals, Fractions and other objects that can be converted to integers only with a loss (e.g. that have the int() method but do not have the index() method). | |
If object.__ipow__() returns NotImplemented, the operator willcorrectly fall back to object.__pow__() and object.__rpow__() as expected. | |
| Assignment expressions can now be used unparenthesized within set literals and set comprehensions, as well as in sequence indexes (but not slices). | |
Functions have a new __builtins__ attribute which is used to look forbuiltin symbols when a function is executed, instead of looking into __globals__['__builtins__']. The attribute is initialized from__globals__["__builtins__"] if it exists, else from the current builtins. | |
Two new builtin functions – aiter() and anext() have been addedto provide asynchronous counterparts to iter() and next(), respectively. | |
| Static methods (@staticmethod) and class methods (@classmethod) now inherit the method attributes ( __module__, __name__, __qualname__, __doc__,__annotations__) and have a new __wrapped__ attribute.Moreover, static methods are now callable as regular functions. | |
Annotations for complex targets (everything beside simple name targetsdefined by PEP 526) no longer cause any runtime effects with from __future__ import annotations. | |
| Class and module objects now lazy-create empty annotations dicts on demand. The annotations dicts are stored in the object’s __dict__ forbackwards compatibility. This improves the best practices for working with __annotations__. | |
Annotations consist of yield, yield from, await or named expressionsare now forbidden under from __future__ import annotations due to their sideeffects. | |
Usage of unbound variables, super() and other expressions that mightalter the processing of symbol table as annotations are now rendered effectless under from __future__ import annotations. | |
| Hashes of NaN values of both float type and decimal.Decimal type now depend on object identity. Formerly, they always hashed to 0 even though NaN values are not equal to one another.This caused potentially quadratic runtime behavior due to excessive hash collisions when creating dictionaries and sets containing multiple NaNs. | |
| A SyntaxError (instead of a NameError) will be raised when deleting the __debug__ constant. | |
SyntaxError exceptions now have end_lineno andend_offset attributes. They will be None if not determined. |
Changes to built-in modules:
| asyncio | |
|---|---|
Add missing connect_accepted_socket()method. | |
| array | |
| The index() method of array.array now has optional start and stop parameters. | |
| gc | |
| Add audit hooks for gc.get_objects(), gc.get_referrers() and gc.get_referents(). | |
| hashlib | |
| The hashlib module requires OpenSSL 1.1.1 or newer. | |
| The hashlib module has preliminary support for OpenSSL 3.0.0. | |
| The pure-Python fallback of pbkdf2_hmac() is deprecated. In the future PBKDF2-HMAC will only be available when Python has been built with OpenSSL support. | |
| os | |
| Add os.cpu_count() support for VxWorks RTOS. | |
Add a new function os.eventfd() and related helpers to wrap theeventfd2 syscall on Linux. | |
Add os.splice() that allows to move data between two filedescriptors without copying between kernel address space and user address space, where one of the file descriptors must refer to a pipe. | |
Add O_EVTONLY, O_FSYNC, O_SYMLINKand O_NOFOLLOW_ANY for macOS. | |
| platform | |
Add platform.freedesktop_os_release() to retrieve operation systemidentification from freedesktop.org os-release standard file. | |
| socket | |
| The exception socket.timeout is now an alias of TimeoutError. | |
Add option to create MPTCP sockets with IPPROTO_MPTCP. | |
Add IP_RECVTOS option to receive the type of service (ToS) or DSCP/ECN fields. | |
| ssl | |
| The ssl module requires OpenSSL 1.1.1 or newer. | |
The ssl module has preliminary support for OpenSSL 3.0.0 and new optionOP_IGNORE_UNEXPECTED_EOF. | |
| Deprecated function and use of deprecated constants now result in a DeprecationWarning. ssl.SSLContext.options has OP_NO_SSLv2 and OP_NO_SSLv3 set by default and therefore cannot warn about setting the flag again. | |
| The ssl module now has more secure default settings. Ciphers without forward secrecy or SHA-1 MAC are disabled by default. Security level 2 prohibits weak RSA, DH, and ECC keys with less than 112 bits of security. SSLContext defaults to minimum protocol version TLS 1.2. Settings are based on Hynek Schlawack’s research. | |
| The deprecated protocols SSL 3.0, TLS 1.0, and TLS 1.1 are no longer officially supported. Python does not block them actively. However OpenSSL build options, distro configurations, vendor patches, and cipher suites may prevent a successful handshake. | |
| Add a timeout parameter to the ssl.get_server_certificate() function. | |
| The ssl module uses heap-types and multi-phase initialization. | |
A new verify flag VERIFY_X509_PARTIAL_CHAIN has been added. | |
| sys | |
Add sys.orig_argv attribute: the list of the original command linearguments passed to the Python executable. | |
Add sys.stdlib_module_names, containing the list of the standard librarymodule names. | |
| _thread | |
| _thread.interrupt_main() now takes an optional signal number to simulate (the default is still signal.SIGINT). |
Notes
The structural pattern matching feature is discussed in issue #7847.
