Skip to content

Latest commit

 

History

History
874 lines (656 loc) · 33.8 KB

File metadata and controls

874 lines (656 loc) · 33.8 KB

What's new in Python 3.16

Editor:TBD

This article explains the new features in Python 3.16, compared to 3.15.

For full details, see the :ref:`changelog <changelog>`.

Note

Prerelease users should be aware that this document is currently in draft form. It will be updated substantially as Python 3.16 moves towards release, so it's worth checking back even after reading earlier versions.

Summary --- release highlights

New features

Other language changes

New modules

  • None yet.

Improved modules

asyncio

codecs

  • On platforms that provide the C library's :manpage:`iconv(3)` function, every encoding known to iconv for which Python has no built-in codec is now available (for example cp1133). Prefixing an encoding name with iconv: forces the iconv-based codec even when a built-in codec of the same name exists. (Contributed by Serhiy Storchaka in :gh:`152997`.)

csv

  • :meth:`csv.Sniffer.sniff` now deduces the dialect by trial parsing instead of heuristics based on matching isolated fragments and on character frequencies, so the result is consistent with how :func:`csv.reader` will parse the sample. It can now detect the escapechar parameter, accepts non-ASCII delimiters in the delimiters argument, no longer misdetects the delimiter when the sample contains delimiter characters inside quoted fields, and no longer takes quadratic time on quoted samples. The results may differ from those of earlier Python versions. (Contributed by Serhiy Storchaka in :gh:`83273`.)

curses

ctypes

encodings

  • Add the utf-7-imap codec, implementing the modified UTF-7 encoding used for international IMAP4 mailbox names (RFC 3501). (Contributed by Serhiy Storchaka in :gh:`66788`.)

gzip

io

imaplib

ipaddress

Add :meth:`~ipaddress.IPv4Network.next_network` and :meth:`~ipaddress.IPv6Network.next_network` methods to find the next nearest network with a specific prefix size.

logging

  • :class:`~logging.handlers.TimedRotatingFileHandler` now uses the creation time instead of the last modification time of an existing log file as the basis for the first rotation after handler creation, if supported by the OS and file system. This allows it to be used in short-running programs that start and end before the rotation interval expires. (Contributed by Iván Márton and Serhiy Storchaka in :gh:`84649`.)

lzma

math

multiprocessing

  • Add the optional buffersize parameter to :meth:`multiprocessing.pool.Pool.imap` and :meth:`multiprocessing.pool.Pool.imap_unordered` to limit the number of submitted tasks whose results have not yet been yielded. If the buffer is full, iteration over the iterables pauses until a result is yielded from the buffer. To fully utilize pool's capacity when using this feature, set buffersize at least to the number of processes in pool (to consume iterable as you go), or even higher (to prefetch the next N=buffersize-processes arguments).

    (Contributed by Oleksandr Baltian in :gh:`136871`.)

os

  • Add :func:`os.pidfd_getfd` for duplicating a file descriptor from another process via a pidfd. Available on Linux 5.6+. (Contributed by Maurycy Pawłowski-Wieroński in :gh:`149464`.)

pydoc

  • Modernize the HTML output of :mod:`pydoc`. The pages generated by the :mod:`pydoc` HTTP server now use semantic HTML5 markup and a new style sheet based on the python-docs-theme used by docs.python.org, with dark mode support. Class members inherited from other classes are collapsed by default. (Contributed by Serhiy Storchaka in :gh:`153906`.)

re

  • :mod:`re` now supports set operations and nested sets in character classes, as described in Unicode Technical Standard #18: set difference ([A--B]), intersection ([A&&B]) and union ([A||B]), where an operand may be a nested set written in square brackets. For example, [a-z--[aeiou]] matches an ASCII lowercase consonant. (Contributed by Serhiy Storchaka in :gh:`152100`.)
  • Regular expressions now support Unicode property escapes \p{...} and \P{...}, which match a character by a Unicode property -- for example \p{Lu} (an uppercase letter), \p{Cased} or \p{ASCII}. See :ref:`the regular expression syntax <re-syntax>` for the supported properties. (Contributed by Serhiy Storchaka in :gh:`95555`.)

shlex

  • Add keyword-only parameter force to :func:`shlex.quote` to force quoting a string, even if it is already safe for a shell without being quoted. (Contributed by Jay Berry in :gh:`148846`.)

symtable

tkinter

xml

  • Add support for multiple multi-byte encodings in the :mod:`XML parser <xml.parsers.expat>`: "cp932", "cp949", "cp950", "Big5", "EUC-JP", "GB2312", "GBK", "johab", and "Shift_JIS". Add partial support (only BMP characters) for multi-byte encodings "Big5-HKSCS", "EUC_JIS-2004", "EUC_JISX0213", "Shift_JIS-2004", "Shift_JISX0213", "utf-8-sig" and non-standard aliases like "UTF8" (without hyphen). The parser now raises :exc:`ValueError` for known unsupported multi-byte encodings such as "ISO-2022-JP" or "raw-unicode-escape" instead of failing later, when encountering non-ASCII data. (Contributed by Serhiy Storchaka in :gh:`62259`.)

zipfile

Optimizations

re

  • Character class escapes (\d, \D, \s, \S, \w and \W) outside a character set, and character sets containing a single such escape (such as [\d] or [^\s]), are now compiled to a single CATEGORY opcode instead of being wrapped in an IN block. This speeds up matching of patterns such as \d+ and reduces the size of the compiled byte code. (Contributed by Serhiy Storchaka in :gh:`152033` and Pieter Eendebak in :gh:`152056`.)

module_name

  • TODO

Removed

annotationlib

array

  • The 'u' format code (:c:type:`wchar_t`) which has been deprecated in documentation since Python 3.3 and at runtime since Python 3.13. Use 'w' format code instead (:c:type:`Py_UCS4`, always 4 bytes).

asyncio

functools

  • Calling the Python implementation of :func:`functools.reduce` with function or sequence as keyword arguments has been deprecated since Python 3.14.

logging

  • Support for custom logging handlers with the strm argument is deprecated and scheduled for removal in Python 3.16. Define handlers with the stream argument instead.

mimetypes

shutil

symtable

sys

sysconfig

tarfile

Deprecated

New deprecations

Porting to Python 3.16

This section lists previously described changes and other bugfixes that may require changes to your code.

Build changes

C API changes

New features

  • TODO

Porting to Python 3.16

Deprecated C APIs

Removed C APIs