| 1 |
|
| 2 |
**************************** |
| 3 |
What's New In Python 3.13 |
| 4 |
**************************** |
| 5 |
|
| 6 |
:Editors: Adam Turner and Thomas Wouters |
| 7 |
|
| 8 |
.. Rules for maintenance: |
| 9 |
|
| 10 |
* Anyone can add text to this document. Do not spend very much time |
| 11 |
on the wording of your changes, because your text will probably |
| 12 |
get rewritten to some degree. |
| 13 |
|
| 14 |
* The maintainer will go through Misc/NEWS periodically and add |
| 15 |
changes; it's therefore more important to add your changes to |
| 16 |
Misc/NEWS than to this file. |
| 17 |
|
| 18 |
* This is not a complete list of every single change; completeness |
| 19 |
is the purpose of Misc/NEWS. Some changes I consider too small |
| 20 |
or esoteric to include. If such a change is added to the text, |
| 21 |
I'll just remove it. (This is another reason you shouldn't spend |
| 22 |
too much time on writing your addition.) |
| 23 |
|
| 24 |
* If you want to draw your new text to the attention of the |
| 25 |
maintainer, add 'XXX' to the beginning of the paragraph or |
| 26 |
section. |
| 27 |
|
| 28 |
* It's OK to just add a fragmentary note about a change. For |
| 29 |
example: "XXX Describe the transmogrify() function added to the |
| 30 |
socket module." The maintainer will research the change and |
| 31 |
write the necessary text. |
| 32 |
|
| 33 |
* You can comment out your additions if you like, but it's not |
| 34 |
necessary (especially when a final release is some months away). |
| 35 |
|
| 36 |
* Credit the author of a patch or bugfix. Just the name is |
| 37 |
sufficient; the e-mail address isn't necessary. |
| 38 |
|
| 39 |
* It's helpful to add the issue number as a comment: |
| 40 |
|
| 41 |
XXX Describe the transmogrify() function added to the socket |
| 42 |
module. |
| 43 |
(Contributed by P.Y. Developer in :gh:`12345`.) |
| 44 |
|
| 45 |
This saves the maintainer the effort of going through the VCS log |
| 46 |
when researching a change. |
| 47 |
|
| 48 |
This article explains the new features in Python 3.13, compared to 3.12. |
| 49 |
Python 3.13 was released on October 7, 2024. |
| 50 |
For full details, see the :ref:`changelog <changelog>`. |
| 51 |
|
| 52 |
.. seealso:: |
| 53 |
|
| 54 |
:pep:`719` -- Python 3.13 Release Schedule |
| 55 |
|
| 56 |
|
| 57 |
Summary -- Release Highlights |
| 58 |
============================= |
| 59 |
|
| 60 |
.. This section singles out the most important changes in Python 3.13. |
| 61 |
Brevity is key. |
| 62 |
|
| 63 |
Python 3.13 is a stable release of the Python programming |
| 64 |
language, with a mix of changes to the language, the implementation |
| 65 |
and the standard library. |
| 66 |
The biggest changes include a new `interactive interpreter |
| 67 |
<whatsnew313-better-interactive-interpreter_>`_, |
| 68 |
experimental support for running in a `free-threaded mode |
| 69 |
<whatsnew313-free-threaded-cpython_>`_ (:pep:`703`), |
| 70 |
and a `Just-In-Time compiler <whatsnew313-jit-compiler_>`_ (:pep:`744`). |
| 71 |
|
| 72 |
Error messages continue to improve, with tracebacks now highlighted in color |
| 73 |
by default. The :func:`locals` builtin now has :ref:`defined semantics |
| 74 |
<whatsnew313-locals-semantics>` for changing the returned mapping, |
| 75 |
and type parameters now support default values. |
| 76 |
|
| 77 |
The library changes contain removal of deprecated APIs and modules, |
| 78 |
as well as the usual improvements in user-friendliness and correctness. |
| 79 |
Several legacy standard library modules have now `been removed |
| 80 |
<whatsnew313-pep594_>`_ following their deprecation in Python 3.11 (:pep:`594`). |
| 81 |
|
| 82 |
This article doesn't attempt to provide a complete specification |
| 83 |
of all new features, but instead gives a convenient overview. |
| 84 |
For full details refer to the documentation, |
| 85 |
such as the :ref:`Library Reference <library-index>` |
| 86 |
and :ref:`Language Reference <reference-index>`. |
| 87 |
To understand the complete implementation and design rationale for a change, |
| 88 |
refer to the PEP for a particular new feature; |
| 89 |
but note that PEPs usually are not kept up-to-date |
| 90 |
once a feature has been fully implemented. |
| 91 |
See `Porting to Python 3.13`_ for guidance on upgrading from |
| 92 |
earlier versions of Python. |
| 93 |
|
| 94 |
-------------- |
| 95 |
|
| 96 |
.. PEP-sized items next. |
| 97 |
|
| 98 |
Interpreter improvements: |
| 99 |
|
| 100 |
* A greatly improved :ref:`interactive interpreter |
| 101 |
<whatsnew313-better-interactive-interpreter>` and |
| 102 |
:ref:`improved error messages <whatsnew313-improved-error-messages>`. |
| 103 |
* :pep:`667`: The :func:`locals` builtin now has |
| 104 |
:ref:`defined semantics <whatsnew313-locals-semantics>` when mutating the |
| 105 |
returned mapping. Python debuggers and similar tools may now more reliably |
| 106 |
update local variables in optimized scopes even during concurrent code |
| 107 |
execution. |
| 108 |
* :pep:`703`: CPython 3.13 has experimental support for running with the |
| 109 |
:term:`global interpreter lock` disabled. See :ref:`Free-threaded CPython |
| 110 |
<whatsnew313-free-threaded-cpython>` for more details. |
| 111 |
* :pep:`744`: A basic :ref:`JIT compiler <whatsnew313-jit-compiler>` was added. |
| 112 |
It is currently disabled by default (though we may turn it on later). |
| 113 |
Performance improvements are modest -- we expect to improve this |
| 114 |
over the next few releases. |
| 115 |
* Color support in the new :ref:`interactive interpreter |
| 116 |
<whatsnew313-better-interactive-interpreter>`, |
| 117 |
as well as in :ref:`tracebacks <whatsnew313-improved-error-messages>` |
| 118 |
and :ref:`doctest <whatsnew313-doctest>` output. |
| 119 |
This can be disabled through the :envvar:`PYTHON_COLORS` and |NO_COLOR|_ |
| 120 |
environment variables. |
| 121 |
|
| 122 |
Python data model improvements: |
| 123 |
|
| 124 |
* :attr:`~type.__static_attributes__` stores the names of attributes accessed |
| 125 |
through ``self.X`` in any function in a class body. |
| 126 |
* :attr:`~type.__firstlineno__` records the first line number of a class |
| 127 |
definition. |
| 128 |
|
| 129 |
Significant improvements in the standard library: |
| 130 |
|
| 131 |
* Add a new :exc:`PythonFinalizationError` exception, raised when an operation |
| 132 |
is blocked during :term:`finalization <interpreter shutdown>`. |
| 133 |
* The :mod:`argparse` module now supports deprecating command-line options, |
| 134 |
positional arguments, and subcommands. |
| 135 |
* The new functions :func:`base64.z85encode` and :func:`base64.z85decode` |
| 136 |
support encoding and decoding `Z85 data`_. |
| 137 |
* The :mod:`copy` module now has a :func:`copy.replace` function, |
| 138 |
with support for many builtin types and any class defining |
| 139 |
the :func:`~object.__replace__` method. |
| 140 |
* The new :mod:`dbm.sqlite3` module is now the default :mod:`dbm` backend. |
| 141 |
* The :mod:`os` module has a :ref:`suite of new functions <os-timerfd>` |
| 142 |
for working with Linux's timer notification file descriptors. |
| 143 |
* The :mod:`random` module now has a :ref:`command-line interface <random-cli>`. |
| 144 |
|
| 145 |
Security improvements: |
| 146 |
|
| 147 |
* :func:`ssl.create_default_context` sets :data:`ssl.VERIFY_X509_PARTIAL_CHAIN` |
| 148 |
and :data:`ssl.VERIFY_X509_STRICT` as default flags. |
| 149 |
|
| 150 |
C API improvements: |
| 151 |
|
| 152 |
* The :c:data:`Py_mod_gil` slot is now used to indicate that |
| 153 |
an extension module supports running with the :term:`GIL` disabled. |
| 154 |
* The :doc:`PyTime C API </c-api/time>` has been added, |
| 155 |
providing access to system clocks. |
| 156 |
* :c:type:`PyMutex` is a new lightweight mutex that occupies a single byte. |
| 157 |
* There is a new :ref:`suite of functions <c-api-monitoring>` |
| 158 |
for generating :pep:`669` monitoring events in the C API. |
| 159 |
|
| 160 |
New typing features: |
| 161 |
|
| 162 |
* :pep:`696`: Type parameters (:data:`typing.TypeVar`, :data:`typing.ParamSpec`, |
| 163 |
and :data:`typing.TypeVarTuple`) now support defaults. |
| 164 |
* :pep:`702`: The new :func:`warnings.deprecated` decorator adds support |
| 165 |
for marking deprecations in the type system and at runtime. |
| 166 |
* :pep:`705`: :data:`typing.ReadOnly` can be used to mark an item of a |
| 167 |
:class:`typing.TypedDict` as read-only for type checkers. |
| 168 |
* :pep:`742`: :data:`typing.TypeIs` provides more intuitive |
| 169 |
type narrowing behavior, as an alternative to :data:`typing.TypeGuard`. |
| 170 |
|
| 171 |
Platform support: |
| 172 |
|
| 173 |
* :pep:`730`: Apple's iOS is now an :ref:`officially supported platform |
| 174 |
<whatsnew313-platform-support>`, at :pep:`tier 3 <11#tier-3>`. |
| 175 |
* :pep:`738`: Android is now an :ref:`officially supported platform |
| 176 |
<whatsnew313-platform-support>`, at :pep:`tier 3 <11#tier-3>`. |
| 177 |
* ``wasm32-wasi`` is now supported as a :pep:`tier 2 <11#tier-2>` platform. |
| 178 |
* ``wasm32-emscripten`` is no longer an officially supported platform. |
| 179 |
|
| 180 |
Important removals: |
| 181 |
|
| 182 |
* :ref:`PEP 594 <whatsnew313-pep594>`: The remaining 19 "dead batteries" |
| 183 |
(legacy stdlib modules) have been removed from the standard library: |
| 184 |
:mod:`!aifc`, :mod:`!audioop`, :mod:`!cgi`, :mod:`!cgitb`, :mod:`!chunk`, |
| 185 |
:mod:`!crypt`, :mod:`!imghdr`, :mod:`!mailcap`, :mod:`!msilib`, :mod:`!nis`, |
| 186 |
:mod:`!nntplib`, :mod:`!ossaudiodev`, :mod:`!pipes`, :mod:`!sndhdr`, |
| 187 |
:mod:`!spwd`, :mod:`!sunau`, :mod:`!telnetlib`, :mod:`!uu` and :mod:`!xdrlib`. |
| 188 |
* Remove the :program:`2to3` tool and :mod:`!lib2to3` module |
| 189 |
(deprecated in Python 3.11). |
| 190 |
* Remove the :mod:`!tkinter.tix` module (deprecated in Python 3.6). |
| 191 |
* Remove the :func:`!locale.resetlocale` function. |
| 192 |
* Remove the :mod:`!typing.io` and :mod:`!typing.re` namespaces. |
| 193 |
* Remove chained :class:`classmethod` descriptors. |
| 194 |
|
| 195 |
Release schedule changes: |
| 196 |
|
| 197 |
:pep:`602` ("Annual Release Cycle for Python") has been updated |
| 198 |
to extend the full support ('bugfix') period for new releases to two years. |
| 199 |
This updated policy means that: |
| 200 |
|
| 201 |
* Python 3.9--3.12 have one and a half years of full support, |
| 202 |
followed by three and a half years of security fixes. |
| 203 |
* Python 3.13 and later have two years of full support, |
| 204 |
followed by three years of security fixes. |
| 205 |
|
| 206 |
|
| 207 |
New Features |
| 208 |
============ |
| 209 |
|
| 210 |
|
| 211 |
.. _whatsnew313-better-interactive-interpreter: |
| 212 |
|
| 213 |
A better interactive interpreter |
| 214 |
-------------------------------- |
| 215 |
|
| 216 |
Python now uses a new :term:`interactive` shell by default, based on code |
| 217 |
from the `PyPy project`_. |
| 218 |
When the user starts the :term:`REPL` from an interactive terminal, |
| 219 |
the following new features are now supported: |
| 220 |
|
| 221 |
* Multiline editing with history preservation. |
| 222 |
* Direct support for REPL-specific commands like :kbd:`help`, :kbd:`exit`, |
| 223 |
and :kbd:`quit`, without the need to call them as functions. |
| 224 |
* Prompts and tracebacks with :ref:`color enabled by default |
| 225 |
<using-on-controlling-color>`. |
| 226 |
* Interactive help browsing using :kbd:`F1` with a separate command |
| 227 |
history. |
| 228 |
* History browsing using :kbd:`F2` that skips output as well as the |
| 229 |
:term:`>>>` and :term:`...` prompts. |
| 230 |
* "Paste mode" with :kbd:`F3` that makes pasting larger blocks of code |
| 231 |
easier (press :kbd:`F3` again to return to the regular prompt). |
| 232 |
|
| 233 |
To disable the new interactive shell, |
| 234 |
set the :envvar:`PYTHON_BASIC_REPL` environment variable. |
| 235 |
For more on interactive mode, see :ref:`tut-interac`. |
| 236 |
|
| 237 |
(Contributed by Pablo Galindo Salgado, Łukasz Langa, and |
| 238 |
Lysandros Nikolaou in :gh:`111201` based on code from the PyPy project. |
| 239 |
Windows support contributed by Dino Viehland and Anthony Shaw.) |
| 240 |
|
| 241 |
.. _`PyPy project`: https://pypy.org/ |
| 242 |
|
| 243 |
|
| 244 |
.. _whatsnew313-improved-error-messages: |
| 245 |
|
| 246 |
Improved error messages |
| 247 |
----------------------- |
| 248 |
|
| 249 |
* The interpreter now uses color by default when displaying tracebacks in the |
| 250 |
terminal. This feature :ref:`can be controlled <using-on-controlling-color>` |
| 251 |
via the new :envvar:`PYTHON_COLORS` environment variable as well as |
| 252 |
the canonical |NO_COLOR|_ and |FORCE_COLOR|_ environment variables. |
| 253 |
(Contributed by Pablo Galindo Salgado in :gh:`112730`.) |
| 254 |
|
| 255 |
* A common mistake is to write a script with the same name as a |
| 256 |
standard library module. When this results in errors, we now |
| 257 |
display a more helpful error message: |
| 258 |
|
| 259 |
.. code-block:: pytb |
| 260 |
|
| 261 |
$ python random.py |
| 262 |
Traceback (most recent call last): |
| 263 |
File "/home/me/random.py", line 1, in <module> |
| 264 |
import random |
| 265 |
File "/home/me/random.py", line 3, in <module> |
| 266 |
print(random.randint(5)) |
| 267 |
^^^^^^^^^^^^^^ |
| 268 |
AttributeError: module 'random' has no attribute 'randint' (consider renaming '/home/me/random.py' since it has the same name as the standard library module named 'random' and prevents importing that standard library module) |
| 269 |
|
| 270 |
Similarly, if a script has the same name as a third-party |
| 271 |
module that it attempts to import and this results in errors, |
| 272 |
we also display a more helpful error message: |
| 273 |
|
| 274 |
.. code-block:: pytb |
| 275 |
|
| 276 |
$ python numpy.py |
| 277 |
Traceback (most recent call last): |
| 278 |
File "/home/me/numpy.py", line 1, in <module> |
| 279 |
import numpy as np |
| 280 |
File "/home/me/numpy.py", line 3, in <module> |
| 281 |
np.array([1, 2, 3]) |
| 282 |
^^^^^^^^ |
| 283 |
AttributeError: module 'numpy' has no attribute 'array' (consider renaming '/home/me/numpy.py' if it has the same name as a library you intended to import) |
| 284 |
|
| 285 |
(Contributed by Shantanu Jain in :gh:`95754`.) |
| 286 |
|
| 287 |
* The error message now tries to suggest the correct keyword argument |
| 288 |
when an incorrect keyword argument is passed to a function. |
| 289 |
|
| 290 |
.. code-block:: pycon |
| 291 |
|
| 292 |
>>> "Better error messages!".split(max_split=1) |
| 293 |
Traceback (most recent call last): |
| 294 |
File "<python-input-0>", line 1, in <module> |
| 295 |
"Better error messages!".split(max_split=1) |
| 296 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ |
| 297 |
TypeError: split() got an unexpected keyword argument 'max_split'. Did you mean 'maxsplit'? |
| 298 |
|
| 299 |
(Contributed by Pablo Galindo Salgado and Shantanu Jain in :gh:`107944`.) |
| 300 |
|
| 301 |
|
| 302 |
.. _whatsnew313-free-threaded-cpython: |
| 303 |
|
| 304 |
Free-threaded CPython |
| 305 |
--------------------- |
| 306 |
|
| 307 |
CPython now has experimental support for running in a free-threaded mode, |
| 308 |
with the :term:`global interpreter lock` (GIL) disabled. |
| 309 |
This is an experimental feature and therefore is not enabled by default. |
| 310 |
The free-threaded mode requires a different executable, |
| 311 |
usually called ``python3.13t`` or ``python3.13t.exe``. |
| 312 |
Pre-built binaries marked as *free-threaded* can be installed as part of |
| 313 |
the official :ref:`Windows <install-freethreaded-windows>` |
| 314 |
and :ref:`macOS <install-freethreaded-macos>` installers, |
| 315 |
or CPython can be built from source with the :option:`--disable-gil` option. |
| 316 |
|
| 317 |
Free-threaded execution allows for full utilization of the available |
| 318 |
processing power by running threads in parallel on available CPU cores. |
| 319 |
While not all software will benefit from this automatically, programs |
| 320 |
designed with threading in mind will run faster on multi-core hardware. |
| 321 |
**The free-threaded mode is experimental** and work is ongoing to improve it: |
| 322 |
expect some bugs and a substantial single-threaded performance hit. |
| 323 |
Free-threaded builds of CPython support optionally running with the GIL |
| 324 |
enabled at runtime using the environment variable :envvar:`PYTHON_GIL` or |
| 325 |
the command-line option :option:`-X gil=1`. |
| 326 |
|
| 327 |
To check if the current interpreter supports free-threading, :option:`python -VV <-V>` |
| 328 |
and :data:`sys.version` contain "experimental free-threading build". |
| 329 |
The new :func:`!sys._is_gil_enabled` function can be used to check whether |
| 330 |
the GIL is actually disabled in the running process. |
| 331 |
|
| 332 |
C-API extension modules need to be built specifically for the free-threaded |
| 333 |
build. Extensions that support running with the :term:`GIL` disabled should |
| 334 |
use the :c:data:`Py_mod_gil` slot. Extensions using single-phase init should |
| 335 |
use :c:func:`PyUnstable_Module_SetGIL` to indicate whether they support |
| 336 |
running with the GIL disabled. Importing C extensions that don't use these |
| 337 |
mechanisms will cause the GIL to be enabled, unless the GIL was explicitly |
| 338 |
disabled with the :envvar:`PYTHON_GIL` environment variable or the |
| 339 |
:option:`-X gil=0` option. |
| 340 |
pip 24.1 or newer is required to install packages with C extensions in the |
| 341 |
free-threaded build. |
| 342 |
|
| 343 |
This work was made possible thanks to many individuals and |
| 344 |
organizations, including the large community of contributors to Python |
| 345 |
and third-party projects to test and enable free-threading support. |
| 346 |
Notable contributors include: |
| 347 |
Sam Gross, Ken Jin, Donghee Na, Itamar Oren, Matt Page, Brett Simmers, |
| 348 |
Dino Viehland, Carl Meyer, Nathan Goldbaum, Ralf Gommers, |
| 349 |
Lysandros Nikolaou, and many others. |
| 350 |
Many of these contributors are employed by Meta, which has |
| 351 |
provided significant engineering resources to support this project. |
| 352 |
|
| 353 |
.. seealso:: |
| 354 |
|
| 355 |
:pep:`703` "Making the Global Interpreter Lock Optional in CPython" |
| 356 |
contains rationale and information surrounding this work. |
| 357 |
|
| 358 |
`Porting Extension Modules to Support Free-Threading |
| 359 |
<https://py-free-threading.github.io/porting/>`_: A community-maintained |
| 360 |
porting guide for extension authors. |
| 361 |
|
| 362 |
|
| 363 |
.. _whatsnew313-jit-compiler: |
| 364 |
|
| 365 |
An experimental just-in-time (JIT) compiler |
| 366 |
------------------------------------------- |
| 367 |
|
| 368 |
When CPython is configured and built using |
| 369 |
the :option:`!--enable-experimental-jit` option, |
| 370 |
a just-in-time (JIT) compiler is added which may speed up some Python programs. |
| 371 |
On Windows, use ``PCbuild/build.bat --experimental-jit`` to enable the JIT |
| 372 |
or ``--experimental-jit-interpreter`` to enable the Tier 2 interpreter. |
| 373 |
Build requirements and further supporting information `are contained at`__ |
| 374 |
:file:`Tools/jit/README.md`. |
| 375 |
|
| 376 |
__ https://github.com/python/cpython/blob/main/Tools/jit/README.md |
| 377 |
|
| 378 |
The :option:`!--enable-experimental-jit` option takes these (optional) values, |
| 379 |
defaulting to ``yes`` if :option:`!--enable-experimental-jit` is present |
| 380 |
without the optional value. |
| 381 |
|
| 382 |
* ``no``: Disable the entire Tier 2 and JIT pipeline. |
| 383 |
* ``yes``: Enable the JIT. |
| 384 |
To disable the JIT at runtime, pass the environment variable ``PYTHON_JIT=0``. |
| 385 |
* ``yes-off``: Build the JIT but disable it by default. |
| 386 |
To enable the JIT at runtime, pass the environment variable ``PYTHON_JIT=1``. |
| 387 |
* ``interpreter``: Enable the Tier 2 interpreter but disable the JIT. |
| 388 |
The interpreter can be disabled by running with ``PYTHON_JIT=0``. |
| 389 |
|
| 390 |
The internal architecture is roughly as follows: |
| 391 |
|
| 392 |
* We start with specialized *Tier 1 bytecode*. |
| 393 |
See :ref:`What's new in 3.11 <whatsnew311-pep659>` for details. |
| 394 |
* When the Tier 1 bytecode gets hot enough, it gets translated |
| 395 |
to a new purely internal intermediate representation (IR), |
| 396 |
called the *Tier 2 IR*, and sometimes referred to as micro-ops ("uops"). |
| 397 |
* The Tier 2 IR uses the same stack-based virtual machine as Tier 1, |
| 398 |
but the instruction format is better suited to translation to machine code. |
| 399 |
* We have several optimization passes for Tier 2 IR, which are applied |
| 400 |
before it is interpreted or translated to machine code. |
| 401 |
* There is a Tier 2 interpreter, but it is mostly intended for debugging |
| 402 |
the earlier stages of the optimization pipeline. |
| 403 |
The Tier 2 interpreter can be enabled by configuring Python |
| 404 |
with ``--enable-experimental-jit=interpreter``. |
| 405 |
* When the JIT is enabled, the optimized |
| 406 |
Tier 2 IR is translated to machine code, which is then executed. |
| 407 |
* The machine code translation process uses a technique called |
| 408 |
*copy-and-patch*. It has no runtime dependencies, but there is a new |
| 409 |
build-time dependency on LLVM. |
| 410 |
|
| 411 |
.. seealso:: :pep:`744` |
| 412 |
|
| 413 |
(JIT by Brandt Bucher, inspired by a paper by Haoran Xu and Fredrik Kjolstad. |
| 414 |
Tier 2 IR by Mark Shannon and Guido van Rossum. |
| 415 |
Tier 2 optimizer by Ken Jin.) |
| 416 |
|
| 417 |
|
| 418 |
.. _whatsnew313-locals-semantics: |
| 419 |
|
| 420 |
Defined mutation semantics for :py:func:`locals` |
| 421 |
------------------------------------------------ |
| 422 |
|
| 423 |
Historically, the expected result of mutating the return value of |
| 424 |
:func:`locals` has been left to individual Python implementations to define. |
| 425 |
Starting from Python 3.13, :pep:`667` standardises |
| 426 |
the historical behavior of CPython for most code execution scopes, |
| 427 |
but changes :term:`optimized scopes <optimized scope>` |
| 428 |
(functions, generators, coroutines, comprehensions, and generator expressions) |
| 429 |
to explicitly return independent snapshots of the currently assigned local |
| 430 |
variables, including locally referenced nonlocal variables captured in closures. |
| 431 |
|
| 432 |
This change to the semantics of :func:`locals` in optimized scopes also |
| 433 |
affects the default behavior of code execution functions that implicitly |
| 434 |
target :func:`!locals` if no explicit namespace is provided |
| 435 |
(such as :func:`exec` and :func:`eval`). |
| 436 |
In previous versions, whether or not changes could be accessed by calling |
| 437 |
:func:`!locals` after calling the code execution function was |
| 438 |
implementation-dependent. In CPython specifically, such code would typically |
| 439 |
appear to work as desired, but could sometimes fail in optimized scopes based |
| 440 |
on other code (including debuggers and code execution tracing tools) |
| 441 |
potentially resetting the shared snapshot in that scope. |
| 442 |
Now, the code will always run against an independent snapshot of |
| 443 |
the local variables in optimized scopes, and hence the changes will never |
| 444 |
be visible in subsequent calls to :func:`!locals`. |
| 445 |
To access the changes made in these cases, an explicit namespace reference |
| 446 |
must now be passed to the relevant function. |
| 447 |
Alternatively, it may make sense to update affected code to use a higher level |
| 448 |
code execution API that returns the resulting code execution namespace |
| 449 |
(e.g. :func:`runpy.run_path` when executing Python files from disk). |
| 450 |
|
| 451 |
To ensure debuggers and similar tools can reliably update local variables in |
| 452 |
scopes affected by this change, :attr:`FrameType.f_locals <frame.f_locals>` now |
| 453 |
returns a write-through proxy to the frame's local and locally referenced |
| 454 |
nonlocal variables in these scopes, rather than returning an inconsistently |
| 455 |
updated shared ``dict`` instance with undefined runtime semantics. |
| 456 |
|
| 457 |
See :pep:`667` for more details, including related C API changes |
| 458 |
and deprecations. Porting notes are also provided below for the affected |
| 459 |
:ref:`Python APIs <pep667-porting-notes-py>` and :ref:`C APIs |
| 460 |
<pep667-porting-notes-c>`. |
| 461 |
|
| 462 |
(PEP and implementation contributed by Mark Shannon and Tian Gao in |
| 463 |
:gh:`74929`. Documentation updates provided by Guido van Rossum and |
| 464 |
Alyssa Coghlan.) |
| 465 |
|
| 466 |
|
| 467 |
.. _whatsnew313-platform-support: |
| 468 |
|
| 469 |
Support for mobile platforms |
| 470 |
---------------------------- |
| 471 |
|
| 472 |
:pep:`730`: iOS is now a :pep:`11` supported platform, with the |
| 473 |
``arm64-apple-ios`` and ``arm64-apple-ios-simulator`` targets at tier 3 |
| 474 |
(iPhone and iPad devices released after 2013 and the Xcode iOS simulator |
| 475 |
running on Apple silicon hardware, respectively). |
| 476 |
``x86_64-apple-ios-simulator`` |
| 477 |
(the Xcode iOS simulator running on older ``x86_64`` hardware) |
| 478 |
is not a tier 3 supported platform, but will have best-effort support. |
| 479 |
(PEP written and implementation contributed by Russell Keith-Magee in |
| 480 |
:gh:`114099`.) |
| 481 |
|
| 482 |
:pep:`738`: Android is now a :pep:`11` supported platform, with the |
| 483 |
``aarch64-linux-android`` and ``x86_64-linux-android`` targets at tier 3. |
| 484 |
The 32-bit targets ``arm-linux-androideabi`` and ``i686-linux-android`` |
| 485 |
are not tier 3 supported platforms, but will have best-effort support. |
| 486 |
(PEP written and implementation contributed by Malcolm Smith in |
| 487 |
:gh:`116622`.) |
| 488 |
|
| 489 |
.. seealso:: :pep:`730`, :pep:`738` |
| 490 |
|
| 491 |
|
| 492 |
Other Language Changes |
| 493 |
====================== |
| 494 |
|
| 495 |
* The compiler now strips common leading whitespace |
| 496 |
from every line in a docstring. |
| 497 |
This reduces the size of the :term:`bytecode cache <bytecode>` |
| 498 |
(such as ``.pyc`` files), with reductions in file size of around 5%, |
| 499 |
for example in :mod:`!sqlalchemy.orm.session` from SQLAlchemy 2.0. |
| 500 |
This change affects tools that use docstrings, such as :mod:`doctest`. |
| 501 |
|
| 502 |
.. doctest:: |
| 503 |
|
| 504 |
>>> def spam(): |
| 505 |
... """ |
| 506 |
... This is a docstring with |
| 507 |
... leading whitespace. |
| 508 |
... |
| 509 |
... It even has multiple paragraphs! |
| 510 |
... """ |
| 511 |
... |
| 512 |
>>> spam.__doc__ |
| 513 |
'\nThis is a docstring with\n leading whitespace.\n\nIt even has multiple paragraphs!\n' |
| 514 |
|
| 515 |
(Contributed by Inada Naoki in :gh:`81283`.) |
| 516 |
|
| 517 |
* :ref:`Annotation scopes <annotation-scopes>` within class scopes |
| 518 |
can now contain lambdas and comprehensions. |
| 519 |
Comprehensions that are located within class scopes |
| 520 |
are not inlined into their parent scope. |
| 521 |
|
| 522 |
.. code-block:: python |
| 523 |
|
| 524 |
class C[T]: |
| 525 |
type Alias = lambda: T |
| 526 |
|
| 527 |
(Contributed by Jelle Zijlstra in :gh:`109118` and :gh:`118160`.) |
| 528 |
|
| 529 |
* :ref:`Future statements <future>` are no longer triggered by |
| 530 |
relative imports of the :mod:`__future__` module, |
| 531 |
meaning that statements of the form ``from .__future__ import ...`` |
| 532 |
are now simply standard relative imports, with no special features activated. |
| 533 |
(Contributed by Jeremiah Gabriel Pascual in :gh:`118216`.) |
| 534 |
|
| 535 |
* :keyword:`global` declarations are now permitted in :keyword:`except` blocks |
| 536 |
when that global is used in the :keyword:`else` block. |
| 537 |
Previously this raised an erroneous :exc:`SyntaxError`. |
| 538 |
(Contributed by Irit Katriel in :gh:`111123`.) |
| 539 |
|
| 540 |
* Add :envvar:`PYTHON_FROZEN_MODULES`, a new environment variable that |
| 541 |
determines whether frozen modules are ignored by the import machinery, |
| 542 |
equivalent to the :option:`-X frozen_modules <-X>` command-line option. |
| 543 |
(Contributed by Yilei Yang in :gh:`111374`.) |
| 544 |
|
| 545 |
* Add :ref:`support for the perf profiler <perf_profiling>` working |
| 546 |
without `frame pointers <https://en.wikipedia.org/wiki/Call_stack>`_ through |
| 547 |
the new environment variable :envvar:`PYTHON_PERF_JIT_SUPPORT` |
| 548 |
and command-line option :option:`-X perf_jit <-X>`. |
| 549 |
(Contributed by Pablo Galindo in :gh:`118518`.) |
| 550 |
|
| 551 |
* The location of a :file:`.python_history` file can be changed via the |
| 552 |
new :envvar:`PYTHON_HISTORY` environment variable. |
| 553 |
(Contributed by Levi Sabah, Zackery Spytz and Hugo van Kemenade |
| 554 |
in :gh:`73965`.) |
| 555 |
|
| 556 |
* Classes have a new :attr:`~type.__static_attributes__` attribute. |
| 557 |
This is populated by the compiler with a tuple of the class's attribute names |
| 558 |
which are assigned through ``self.<name>`` from any function in its body. |
| 559 |
(Contributed by Irit Katriel in :gh:`115775`.) |
| 560 |
|
| 561 |
* The compiler now creates a :attr:`!__firstlineno__` attribute on classes |
| 562 |
with the line number of the first line of the class definition. |
| 563 |
(Contributed by Serhiy Storchaka in :gh:`118465`.) |
| 564 |
|
| 565 |
* The :func:`exec` and :func:`eval` builtins now accept |
| 566 |
the *globals* and *locals* arguments as keywords. |
| 567 |
(Contributed by Raphael Gaschignard in :gh:`105879`) |
| 568 |
|
| 569 |
* The :func:`compile` builtin now accepts a new flag, |
| 570 |
``ast.PyCF_OPTIMIZED_AST``, which is similar to ``ast.PyCF_ONLY_AST`` |
| 571 |
except that the returned AST is optimized according to |
| 572 |
the value of the *optimize* argument. |
| 573 |
(Contributed by Irit Katriel in :gh:`108113`). |
| 574 |
|
| 575 |
* Add a :attr:`~property.__name__` attribute on :class:`property` objects. |
| 576 |
(Contributed by Eugene Toder in :gh:`101860`.) |
| 577 |
|
| 578 |
* Add :exc:`PythonFinalizationError`, a new exception derived from |
| 579 |
:exc:`RuntimeError` and used to signal when operations are blocked |
| 580 |
during :term:`finalization <interpreter shutdown>`. |
| 581 |
The following callables now raise :exc:`!PythonFinalizationError`, |
| 582 |
instead of :exc:`RuntimeError`: |
| 583 |
|
| 584 |
* :func:`_thread.start_new_thread` |
| 585 |
* :func:`os.fork` |
| 586 |
* :func:`os.forkpty` |
| 587 |
* :class:`subprocess.Popen` |
| 588 |
|
| 589 |
(Contributed by Victor Stinner in :gh:`114570`.) |
| 590 |
|
| 591 |
* Allow the *count* argument of :meth:`str.replace` to be a keyword. |
| 592 |
(Contributed by Hugo van Kemenade in :gh:`106487`.) |
| 593 |
|
| 594 |
* Many functions now emit a warning if a boolean value is passed as |
| 595 |
a file descriptor argument. |
| 596 |
This can help catch some errors earlier. |
| 597 |
(Contributed by Serhiy Storchaka in :gh:`82626`.) |
| 598 |
|
| 599 |
* Added :attr:`!name` and :attr:`!mode` attributes |
| 600 |
for compressed and archived file-like objects in |
| 601 |
the :mod:`bz2`, :mod:`lzma`, :mod:`tarfile`, and :mod:`zipfile` modules. |
| 602 |
(Contributed by Serhiy Storchaka in :gh:`115961`.) |
| 603 |
|
| 604 |
|
| 605 |
New Modules |
| 606 |
=========== |
| 607 |
|
| 608 |
* :mod:`dbm.sqlite3`: An SQLite backend for :mod:`dbm`. |
| 609 |
(Contributed by Raymond Hettinger and Erlend E. Aasland in :gh:`100414`.) |
| 610 |
|
| 611 |
|
| 612 |
Improved Modules |
| 613 |
================ |
| 614 |
|
| 615 |
|
| 616 |
argparse |
| 617 |
-------- |
| 618 |
|
| 619 |
* Add the *deprecated* parameter to the |
| 620 |
:meth:`~argparse.ArgumentParser.add_argument` |
| 621 |
and :meth:`!add_parser` methods, to enable deprecating |
| 622 |
command-line options, positional arguments, and subcommands. |
| 623 |
(Contributed by Serhiy Storchaka in :gh:`83648`.) |
| 624 |
|
| 625 |
|
| 626 |
array |
| 627 |
----- |
| 628 |
|
| 629 |
* Add the ``'w'`` type code (``Py_UCS4``) for Unicode characters. |
| 630 |
It should be used instead of the deprecated ``'u'`` type code. |
| 631 |
(Contributed by Inada Naoki in :gh:`80480`.) |
| 632 |
|
| 633 |
* Register :class:`array.array` as a :class:`~collections.abc.MutableSequence` |
| 634 |
by implementing the :meth:`~array.array.clear` method. |
| 635 |
(Contributed by Mike Zimin in :gh:`114894`.) |
| 636 |
|
| 637 |
|
| 638 |
ast |
| 639 |
--- |
| 640 |
|
| 641 |
* The constructors of node types in the :mod:`ast` module are now |
| 642 |
stricter in the arguments they accept, |
| 643 |
with more intuitive behavior when arguments are omitted. |
| 644 |
|
| 645 |
If an optional field on an AST node is not included as an argument when |
| 646 |
constructing an instance, the field will now be set to ``None``. Similarly, |
| 647 |
if a list field is omitted, that field will now be set to an empty list, |
| 648 |
and if an :class:`!expr_context` field is omitted, it defaults to |
| 649 |
:class:`Load() <ast.Load>`. |
| 650 |
(Previously, in all cases, the attribute would be missing on the newly |
| 651 |
constructed AST node instance.) |
| 652 |
|
| 653 |
In all other cases, where a required argument is omitted, |
| 654 |
the node constructor will emit a :exc:`DeprecationWarning`. |
| 655 |
This will raise an exception in Python 3.15. |
| 656 |
Similarly, passing a keyword argument to the constructor |
| 657 |
that does not map to a field on the AST node is now deprecated, |
| 658 |
and will raise an exception in Python 3.15. |
| 659 |
|
| 660 |
These changes do not apply to user-defined subclasses of :class:`ast.AST` |
| 661 |
unless the class opts in to the new behavior |
| 662 |
by defining the :attr:`.AST._field_types` mapping. |
| 663 |
|
| 664 |
(Contributed by Jelle Zijlstra in :gh:`105858`, :gh:`117486`, and :gh:`118851`.) |
| 665 |
|
| 666 |
* :func:`ast.parse` now accepts an optional argument *optimize* |
| 667 |
which is passed on to :func:`compile`. |
| 668 |
This makes it possible to obtain an optimized AST. |
| 669 |
(Contributed by Irit Katriel in :gh:`108113`.) |
| 670 |
|
| 671 |
|
| 672 |
asyncio |
| 673 |
------- |
| 674 |
|
| 675 |
* :func:`asyncio.as_completed` now returns an object that is both an |
| 676 |
:term:`asynchronous iterator` and a plain :term:`iterator` |
| 677 |
of :term:`awaitables <awaitable>`. |
| 678 |
The awaitables yielded by asynchronous iteration include original task |
| 679 |
or future objects that were passed in, |
| 680 |
making it easier to associate results with the tasks being completed. |
| 681 |
(Contributed by Justin Arthur in :gh:`77714`.) |
| 682 |
|
| 683 |
* :meth:`asyncio.loop.create_unix_server` will now automatically remove |
| 684 |
the Unix socket when the server is closed. |
| 685 |
(Contributed by Pierre Ossman in :gh:`111246`.) |
| 686 |
|
| 687 |
* :meth:`.DatagramTransport.sendto` will now send zero-length |
| 688 |
datagrams if called with an empty bytes object. |
| 689 |
The transport flow control also now accounts for the datagram header |
| 690 |
when calculating the buffer size. |
| 691 |
(Contributed by Jamie Phan in :gh:`115199`.) |
| 692 |
|
| 693 |
* Add :meth:`Queue.shutdown <asyncio.Queue.shutdown>` |
| 694 |
and :exc:`~asyncio.QueueShutDown` to manage queue termination. |
| 695 |
(Contributed by Laurie Opperman and Yves Duprat in :gh:`104228`.) |
| 696 |
|
| 697 |
* Add the :meth:`.Server.close_clients` and :meth:`.Server.abort_clients` |
| 698 |
methods, which more forcefully close an asyncio server. |
| 699 |
(Contributed by Pierre Ossman in :gh:`113538`.) |
| 700 |
|
| 701 |
* Accept a tuple of separators in :meth:`.StreamReader.readuntil`, |
| 702 |
stopping when any one of them is encountered. |
| 703 |
(Contributed by Bruce Merry in :gh:`81322`.) |
| 704 |
|
| 705 |
* Improve the behavior of :class:`~asyncio.TaskGroup` when |
| 706 |
an external cancellation collides with an internal cancellation. |
| 707 |
For example, when two task groups are nested |
| 708 |
and both experience an exception in a child task simultaneously, |
| 709 |
it was possible that the outer task group would hang, |
| 710 |
because its internal cancellation was swallowed by the inner task group. |
| 711 |
|
| 712 |
In the case where a task group is cancelled externally |
| 713 |
and also must raise an :exc:`ExceptionGroup`, |
| 714 |
it will now call the parent task's :meth:`~asyncio.Task.cancel` method. |
| 715 |
This ensures that a :exc:`~asyncio.CancelledError` will be raised |
| 716 |
at the next :keyword:`await`, so the cancellation is not lost. |
| 717 |
|
| 718 |
An added benefit of these changes is that task groups now preserve |
| 719 |
the cancellation count (:meth:`~asyncio.Task.cancelling`). |
| 720 |
|
| 721 |
In order to handle some corner cases, :meth:`~asyncio.Task.uncancel` may now |
| 722 |
reset the undocumented ``_must_cancel`` flag |
| 723 |
when the cancellation count reaches zero. |
| 724 |
|
| 725 |
(Inspired by an issue reported by Arthur Tacca in :gh:`116720`.) |
| 726 |
|
| 727 |
* When :meth:`.TaskGroup.create_task` is called on an inactive |
| 728 |
:class:`~asyncio.TaskGroup`, the given coroutine will be closed (which |
| 729 |
prevents a :exc:`RuntimeWarning` about the given coroutine being |
| 730 |
never awaited). |
| 731 |
(Contributed by Arthur Tacca and Jason Zhang in :gh:`115957`.) |
| 732 |
|
| 733 |
* The function and methods named ``create_task`` have received a new |
| 734 |
``**kwargs`` argument that is passed through to the task constructor. |
| 735 |
This change was accidentally added in 3.13.3, |
| 736 |
and broke the API contract for custom task factories. |
| 737 |
Several third-party task factories implemented workarounds for this. |
| 738 |
In 3.13.4 and later releases the old factory contract is honored |
| 739 |
once again (until 3.14). |
| 740 |
To keep the workarounds working, the extra ``**kwargs`` argument still |
| 741 |
allows passing additional keyword arguments to :class:`~asyncio.Task` |
| 742 |
and to custom task factories. |
| 743 |
|
| 744 |
This affects the following function and methods: |
| 745 |
:meth:`asyncio.create_task`, |
| 746 |
:meth:`asyncio.loop.create_task`, |
| 747 |
:meth:`asyncio.TaskGroup.create_task`. |
| 748 |
(Contributed by Thomas Grainger in :gh:`128307`.) |
| 749 |
|
| 750 |
base64 |
| 751 |
------ |
| 752 |
|
| 753 |
* Add :func:`~base64.z85encode` and :func:`~base64.z85decode` functions |
| 754 |
for encoding :class:`bytes` as `Z85 data`_ |
| 755 |
and decoding Z85-encoded data to :class:`!bytes`. |
| 756 |
(Contributed by Matan Perelman in :gh:`75299`.) |
| 757 |
|
| 758 |
.. _Z85 data: https://rfc.zeromq.org/spec/32/ |
| 759 |
|
| 760 |
|
| 761 |
compileall |
| 762 |
---------- |
| 763 |
|
| 764 |
* The default number of worker threads and processes is now selected using |
| 765 |
:func:`os.process_cpu_count` instead of :func:`os.cpu_count`. |
| 766 |
(Contributed by Victor Stinner in :gh:`109649`.) |
| 767 |
|
| 768 |
|
| 769 |
concurrent.futures |
| 770 |
------------------ |
| 771 |
|
| 772 |
* The default number of worker threads and processes is now selected using |
| 773 |
:func:`os.process_cpu_count` instead of :func:`os.cpu_count`. |
| 774 |
(Contributed by Victor Stinner in :gh:`109649`.) |
| 775 |
|
| 776 |
|
| 777 |
configparser |
| 778 |
------------ |
| 779 |
|
| 780 |
* :class:`~configparser.ConfigParser` now has support for unnamed sections, |
| 781 |
which allows for top-level key-value pairs. |
| 782 |
This can be enabled with the new *allow_unnamed_section* parameter. |
| 783 |
(Contributed by Pedro Sousa Lacerda in :gh:`66449`.) |
| 784 |
|
| 785 |
|
| 786 |
copy |
| 787 |
---- |
| 788 |
|
| 789 |
* The new :func:`~copy.replace` function and the :meth:`replace protocol |
| 790 |
<object.__replace__>` make creating modified copies of objects much simpler. |
| 791 |
This is especially useful when working with immutable objects. |
| 792 |
The following types support the :func:`~copy.replace` function |
| 793 |
and implement the replace protocol: |
| 794 |
|
| 795 |
* :func:`collections.namedtuple` |
| 796 |
* :class:`dataclasses.dataclass` |
| 797 |
* :class:`datetime.datetime`, :class:`datetime.date`, :class:`datetime.time` |
| 798 |
* :class:`inspect.Signature`, :class:`inspect.Parameter` |
| 799 |
* :class:`types.SimpleNamespace` |
| 800 |
* :ref:`code objects <code-objects>` |
| 801 |
|
| 802 |
Any user-defined class can also support :func:`copy.replace` by defining |
| 803 |
the :meth:`~object.__replace__` method. |
| 804 |
(Contributed by Serhiy Storchaka in :gh:`108751`.) |
| 805 |
|
| 806 |
|
| 807 |
ctypes |
| 808 |
------ |
| 809 |
|
| 810 |
* As a consequence of necessary internal refactoring, initialization of |
| 811 |
internal metaclasses now happens in ``__init__`` rather |
| 812 |
than in ``__new__``. This affects projects that subclass these internal |
| 813 |
metaclasses to provide custom initialization. |
| 814 |
Generally: |
| 815 |
|
| 816 |
- Custom logic that was done in ``__new__`` after calling ``super().__new__`` |
| 817 |
should be moved to ``__init__``. |
| 818 |
- To create a class, call the metaclass, not only the metaclass's |
| 819 |
``__new__`` method. |
| 820 |
|
| 821 |
See :gh:`124520` for discussion and links to changes in some affected |
| 822 |
projects. |
| 823 |
|
| 824 |
* :class:`ctypes.Structure` objects have a new :attr:`~ctypes.Structure._align_` |
| 825 |
attribute which allows the alignment of the structure being packed to/from |
| 826 |
memory to be specified explicitly. |
| 827 |
(Contributed by Matt Sanderson in :gh:`112433`) |
| 828 |
|
| 829 |
dbm |
| 830 |
--- |
| 831 |
|
| 832 |
* Add :mod:`dbm.sqlite3`, a new module which implements an SQLite backend, |
| 833 |
and make it the default :mod:`!dbm` backend. |
| 834 |
(Contributed by Raymond Hettinger and Erlend E. Aasland in :gh:`100414`.) |
| 835 |
|
| 836 |
* Allow removing all items from the database through |
| 837 |
the new :meth:`!clear` methods of the GDBM and NDBM database objects. |
| 838 |
(Contributed by Donghee Na in :gh:`107122`.) |
| 839 |
|
| 840 |
|
| 841 |
dis |
| 842 |
--- |
| 843 |
|
| 844 |
* Change the output of :mod:`dis` module functions to show logical |
| 845 |
labels for jump targets and exception handlers, rather than offsets. |
| 846 |
The offsets can be added with the new |
| 847 |
:option:`-O <dis --show-offsets>` command-line option |
| 848 |
or the *show_offsets* argument. |
| 849 |
(Contributed by Irit Katriel in :gh:`112137`.) |
| 850 |
|
| 851 |
* :meth:`~dis.get_instructions` no longer represents cache entries |
| 852 |
as separate instructions. |
| 853 |
Instead, it returns them as part of the :class:`~dis.Instruction`, |
| 854 |
in the new *cache_info* field. |
| 855 |
The *show_caches* argument to :meth:`~dis.get_instructions` is deprecated |
| 856 |
and no longer has any effect. |
| 857 |
(Contributed by Irit Katriel in :gh:`112962`.) |
| 858 |
|
| 859 |
|
| 860 |
.. _whatsnew313-doctest: |
| 861 |
|
| 862 |
doctest |
| 863 |
------- |
| 864 |
|
| 865 |
* :mod:`doctest` output is now colored by default. |
| 866 |
This can be controlled via the new :envvar:`PYTHON_COLORS` environment |
| 867 |
variable as well as the canonical |NO_COLOR|_ |
| 868 |
and |FORCE_COLOR|_ environment variables. |
| 869 |
See also :ref:`using-on-controlling-color`. |
| 870 |
(Contributed by Hugo van Kemenade in :gh:`117225`.) |
| 871 |
|
| 872 |
* The :meth:`.DocTestRunner.run` method now counts the number of skipped tests. |
| 873 |
Add the :attr:`.DocTestRunner.skips` and :attr:`.TestResults.skipped` attributes. |
| 874 |
(Contributed by Victor Stinner in :gh:`108794`.) |
| 875 |
|
| 876 |
|
| 877 |
email |
| 878 |
----- |
| 879 |
|
| 880 |
* Headers with embedded newlines are now quoted on output. |
| 881 |
The :mod:`~email.generator` will now refuse to serialize (write) headers |
| 882 |
that are improperly folded or delimited, such that they would be parsed as |
| 883 |
multiple headers or joined with adjacent data. |
| 884 |
If you need to turn this safety feature off, |
| 885 |
set :attr:`~email.policy.Policy.verify_generated_headers`. |
| 886 |
(Contributed by Bas Bloemsaat and Petr Viktorin in :gh:`121650`.) |
| 887 |
|
| 888 |
* :func:`~email.utils.getaddresses` and :func:`~email.utils.parseaddr` now |
| 889 |
return ``('', '')`` pairs in more situations where invalid email addresses |
| 890 |
are encountered instead of potentially inaccurate values. |
| 891 |
The two functions have a new optional *strict* parameter (default ``True``). |
| 892 |
To get the old behavior (accepting malformed input), use ``strict=False``. |
| 893 |
``getattr(email.utils, 'supports_strict_parsing', False)`` can be used |
| 894 |
to check if the *strict* parameter is available. |
| 895 |
(Contributed by Thomas Dwyer and Victor Stinner for :gh:`102988` to improve |
| 896 |
the :cve:`2023-27043` fix.) |
| 897 |
|
| 898 |
|
| 899 |
enum |
| 900 |
---- |
| 901 |
|
| 902 |
* :class:`~enum.EnumDict` has been made public to better support subclassing |
| 903 |
:class:`~enum.EnumType`. |
| 904 |
|
| 905 |
|
| 906 |
fractions |
| 907 |
--------- |
| 908 |
|
| 909 |
* :class:`~fractions.Fraction` objects now support the standard |
| 910 |
:ref:`format specification mini-language <formatspec>` rules |
| 911 |
for fill, alignment, sign handling, minimum width, and grouping. |
| 912 |
(Contributed by Mark Dickinson in :gh:`111320`.) |
| 913 |
|
| 914 |
|
| 915 |
glob |
| 916 |
---- |
| 917 |
|
| 918 |
* Add :func:`~glob.translate`, a function to convert a path specification |
| 919 |
with shell-style wildcards to a regular expression. |
| 920 |
(Contributed by Barney Gale in :gh:`72904`.) |
| 921 |
|
| 922 |
|
| 923 |
importlib |
| 924 |
--------- |
| 925 |
|
| 926 |
* The following functions in :mod:`importlib.resources` now allow accessing |
| 927 |
a directory (or tree) of resources, using multiple positional arguments |
| 928 |
(the *encoding* and *errors* arguments in the text-reading functions |
| 929 |
are now keyword-only): |
| 930 |
|
| 931 |
* :func:`~importlib.resources.is_resource` |
| 932 |
* :func:`~importlib.resources.open_binary` |
| 933 |
* :func:`~importlib.resources.open_text` |
| 934 |
* :func:`~importlib.resources.path` |
| 935 |
* :func:`~importlib.resources.read_binary` |
| 936 |
* :func:`~importlib.resources.read_text` |
| 937 |
|
| 938 |
These functions are no longer deprecated and are not scheduled for removal. |
| 939 |
(Contributed by Petr Viktorin in :gh:`116608`.) |
| 940 |
|
| 941 |
* :func:`~importlib.resources.contents` remains deprecated in favor of |
| 942 |
the fully-featured :class:`~importlib.resources.abc.Traversable` API. |
| 943 |
However, there is now no plan to remove it. |
| 944 |
(Contributed by Petr Viktorin in :gh:`116608`.) |
| 945 |
|
| 946 |
|
| 947 |
io |
| 948 |
-- |
| 949 |
|
| 950 |
* The :class:`~io.IOBase` finalizer now logs any errors raised by |
| 951 |
the :meth:`~io.IOBase.close` method with :data:`sys.unraisablehook`. |
| 952 |
Previously, errors were ignored silently by default, |
| 953 |
and only logged in :ref:`Python Development Mode <devmode>` |
| 954 |
or when using a :ref:`Python debug build <debug-build>`. |
| 955 |
(Contributed by Victor Stinner in :gh:`62948`.) |
| 956 |
|
| 957 |
|
| 958 |
ipaddress |
| 959 |
--------- |
| 960 |
|
| 961 |
* Add the :attr:`.IPv4Address.ipv6_mapped` property, |
| 962 |
which returns the IPv4-mapped IPv6 address. |
| 963 |
(Contributed by Charles Machalow in :gh:`109466`.) |
| 964 |
|
| 965 |
* Fix ``is_global`` and ``is_private`` behavior in |
| 966 |
:class:`~ipaddress.IPv4Address`, :class:`~ipaddress.IPv6Address`, |
| 967 |
:class:`~ipaddress.IPv4Network`, and :class:`~ipaddress.IPv6Network`. |
| 968 |
(Contributed by Jakub Stasiak in :gh:`113171`.) |
| 969 |
|
| 970 |
|
| 971 |
itertools |
| 972 |
--------- |
| 973 |
|
| 974 |
* :func:`~itertools.batched` has a new *strict* parameter, |
| 975 |
which raises a :exc:`ValueError` if the final batch is shorter |
| 976 |
than the specified batch size. |
| 977 |
(Contributed by Raymond Hettinger in :gh:`113202`.) |
| 978 |
|
| 979 |
|
| 980 |
marshal |
| 981 |
------- |
| 982 |
|
| 983 |
* Add the *allow_code* parameter in module functions. |
| 984 |
Passing ``allow_code=False`` prevents serialization and de-serialization |
| 985 |
of code objects which are incompatible between Python versions. |
| 986 |
(Contributed by Serhiy Storchaka in :gh:`113626`.) |
| 987 |
|
| 988 |
|
| 989 |
math |
| 990 |
---- |
| 991 |
|
| 992 |
* The new function :func:`~math.fma` performs fused multiply-add operations. |
| 993 |
This computes ``x * y + z`` with only a single round, |
| 994 |
and so avoids any intermediate loss of precision. |
| 995 |
It wraps the ``fma()`` function provided by C99, |
| 996 |
and follows the specification of the IEEE 754 "fusedMultiplyAdd" operation |
| 997 |
for special cases. |
| 998 |
(Contributed by Mark Dickinson and Victor Stinner in :gh:`73468`.) |
| 999 |
|
| 1000 |
|
| 1001 |
mimetypes |
| 1002 |
--------- |
| 1003 |
|
| 1004 |
* Add the :func:`~mimetypes.guess_file_type` function to guess a MIME type |
| 1005 |
from a filesystem path. |
| 1006 |
Using paths with :func:`~mimetypes.guess_type` is now :term:`soft deprecated`. |
| 1007 |
(Contributed by Serhiy Storchaka in :gh:`66543`.) |
| 1008 |
|
| 1009 |
|
| 1010 |
mmap |
| 1011 |
---- |
| 1012 |
|
| 1013 |
* :class:`~mmap.mmap` is now protected from crashing on Windows when the |
| 1014 |
mapped memory is inaccessible due to file system errors or access violations. |
| 1015 |
(Contributed by Jannis Weigend in :gh:`118209`.) |
| 1016 |
|
| 1017 |
* :class:`~mmap.mmap` has a new :meth:`~mmap.mmap.seekable` method |
| 1018 |
that can be used when a seekable file-like object is required. |
| 1019 |
The :meth:`~mmap.mmap.seek` method now returns the new absolute position. |
| 1020 |
(Contributed by Donghee Na and Sylvie Liberman in :gh:`111835`.) |
| 1021 |
|
| 1022 |
* The new UNIX-only *trackfd* parameter for :class:`~mmap.mmap` controls |
| 1023 |
file descriptor duplication; |
| 1024 |
if false, the file descriptor specified by *fileno* will not be duplicated. |
| 1025 |
(Contributed by Zackery Spytz and Petr Viktorin in :gh:`78502`.) |
| 1026 |
|
| 1027 |
|
| 1028 |
multiprocessing |
| 1029 |
--------------- |
| 1030 |
|
| 1031 |
* The default number of worker threads and processes is now selected using |
| 1032 |
:func:`os.process_cpu_count` instead of :func:`os.cpu_count`. |
| 1033 |
(Contributed by Victor Stinner in :gh:`109649`.) |
| 1034 |
|
| 1035 |
|
| 1036 |
os |
| 1037 |
-- |
| 1038 |
|
| 1039 |
* Add :func:`~os.process_cpu_count` function to get the number |
| 1040 |
of logical CPU cores usable by the calling thread of the current process. |
| 1041 |
(Contributed by Victor Stinner in :gh:`109649`.) |
| 1042 |
|
| 1043 |
* :func:`~os.cpu_count` and :func:`~os.process_cpu_count` can be overridden |
| 1044 |
through the new environment variable :envvar:`PYTHON_CPU_COUNT` |
| 1045 |
or the new command-line option :option:`-X cpu_count <-X>`. |
| 1046 |
This option is useful for users who need to limit CPU resources |
| 1047 |
of a container system without having to modify application code |
| 1048 |
or the container itself. |
| 1049 |
(Contributed by Donghee Na in :gh:`109595`.) |
| 1050 |
|
| 1051 |
* Add a :ref:`low level interface <os-timerfd>` to Linux's |
| 1052 |
:manpage:`timer file descriptors <timerfd_create(2)>` |
| 1053 |
via :func:`~os.timerfd_create`, |
| 1054 |
:func:`~os.timerfd_settime`, :func:`~os.timerfd_settime_ns`, |
| 1055 |
:func:`~os.timerfd_gettime`, :func:`~os.timerfd_gettime_ns`, |
| 1056 |
:const:`~os.TFD_NONBLOCK`, :const:`~os.TFD_CLOEXEC`, |
| 1057 |
:const:`~os.TFD_TIMER_ABSTIME`, and :const:`~os.TFD_TIMER_CANCEL_ON_SET` |
| 1058 |
(Contributed by Masaru Tsuchiyama in :gh:`108277`.) |
| 1059 |
|
| 1060 |
* :func:`~os.lchmod` and the *follow_symlinks* argument of :func:`~os.chmod` |
| 1061 |
are both now available on Windows. |
| 1062 |
Note that the default value of *follow_symlinks* |
| 1063 |
in :func:`!lchmod` is ``False`` on Windows. |
| 1064 |
(Contributed by Serhiy Storchaka in :gh:`59616`.) |
| 1065 |
|
| 1066 |
* :func:`~os.fchmod` and support for file descriptors in :func:`~os.chmod` |
| 1067 |
are both now available on Windows. |
| 1068 |
(Contributed by Serhiy Storchaka in :gh:`113191`.) |
| 1069 |
|
| 1070 |
* On Windows, :func:`~os.mkdir` and :func:`~os.makedirs` now support passing |
| 1071 |
a *mode* value of ``0o700`` to apply access control to the new directory. |
| 1072 |
This implicitly affects :func:`tempfile.mkdtemp` |
| 1073 |
and is a mitigation for :cve:`2024-4030`. |
| 1074 |
Other values for *mode* continue to be ignored. |
| 1075 |
(Contributed by Steve Dower in :gh:`118486`.) |
| 1076 |
|
| 1077 |
* :func:`~os.posix_spawn` now accepts ``None`` for the *env* argument, |
| 1078 |
which makes the newly spawned process use the current process environment. |
| 1079 |
(Contributed by Jakub Kulik in :gh:`113119`.) |
| 1080 |
|
| 1081 |
* :func:`~os.posix_spawn` can now use the :const:`~os.POSIX_SPAWN_CLOSEFROM` |
| 1082 |
attribute in the *file_actions* parameter on platforms that support |
| 1083 |
:c:func:`!posix_spawn_file_actions_addclosefrom_np`. |
| 1084 |
(Contributed by Jakub Kulik in :gh:`113117`.) |
| 1085 |
|
| 1086 |
|
| 1087 |
os.path |
| 1088 |
------- |
| 1089 |
|
| 1090 |
* Add :func:`~os.path.isreserved` to check if a path is reserved |
| 1091 |
on the current system. |
| 1092 |
This function is only available on Windows. |
| 1093 |
(Contributed by Barney Gale in :gh:`88569`.) |
| 1094 |
|
| 1095 |
* On Windows, :func:`~os.path.isabs` no longer considers paths |
| 1096 |
starting with exactly one slash (``\`` or ``/``) to be absolute. |
| 1097 |
(Contributed by Barney Gale and Jon Foster in :gh:`44626`.) |
| 1098 |
|
| 1099 |
* :func:`~os.path.realpath` now resolves MS-DOS style file names |
| 1100 |
even if the file is not accessible. |
| 1101 |
(Contributed by Moonsik Park in :gh:`82367`.) |
| 1102 |
|
| 1103 |
|
| 1104 |
pathlib |
| 1105 |
------- |
| 1106 |
|
| 1107 |
* Add :exc:`~pathlib.UnsupportedOperation`, which is raised instead of |
| 1108 |
:exc:`NotImplementedError` when a path operation isn't supported. |
| 1109 |
(Contributed by Barney Gale in :gh:`89812`.) |
| 1110 |
|
| 1111 |
* Add a new constructor for creating :class:`~pathlib.Path` objects |
| 1112 |
from 'file' URIs (``file:///``), :meth:`.Path.from_uri`. |
| 1113 |
(Contributed by Barney Gale in :gh:`107465`.) |
| 1114 |
|
| 1115 |
* Add :meth:`.PurePath.full_match` for matching paths with |
| 1116 |
shell-style wildcards, including the recursive wildcard "``**``". |
| 1117 |
(Contributed by Barney Gale in :gh:`73435`.) |
| 1118 |
|
| 1119 |
* Add the :attr:`.PurePath.parser` class attribute to store the |
| 1120 |
implementation of :mod:`os.path` used |
| 1121 |
for low-level path parsing and joining. |
| 1122 |
This will be either :mod:`!posixpath` or :mod:`!ntpath`. |
| 1123 |
|
| 1124 |
* Add *recurse_symlinks* keyword-only argument to |
| 1125 |
:meth:`.Path.glob` and :meth:`~pathlib.Path.rglob`. |
| 1126 |
(Contributed by Barney Gale in :gh:`77609`.) |
| 1127 |
|
| 1128 |
* :meth:`.Path.glob` and :meth:`~pathlib.Path.rglob` |
| 1129 |
now return files and directories when given a pattern that ends with "``**``". |
| 1130 |
Previously, only directories were returned. |
| 1131 |
(Contributed by Barney Gale in :gh:`70303`.) |
| 1132 |
|
| 1133 |
* Add the *follow_symlinks* keyword-only argument to |
| 1134 |
:meth:`Path.is_file <pathlib.Path.is_file>`, |
| 1135 |
:meth:`Path.is_dir <pathlib.Path.is_dir>`, |
| 1136 |
:meth:`.Path.owner`, and :meth:`.Path.group`. |
| 1137 |
(Contributed by Barney Gale in :gh:`105793` and Kamil Turek in :gh:`107962`.) |
| 1138 |
|
| 1139 |
|
| 1140 |
pdb |
| 1141 |
--- |
| 1142 |
|
| 1143 |
* :func:`breakpoint` and :func:`~pdb.set_trace` now enter the debugger immediately |
| 1144 |
rather than on the next line of code to be executed. This change prevents the |
| 1145 |
debugger from breaking outside of the context when :func:`!breakpoint` is positioned |
| 1146 |
at the end of the context. |
| 1147 |
(Contributed by Tian Gao in :gh:`118579`.) |
| 1148 |
|
| 1149 |
* ``sys.path[0]`` is no longer replaced by the directory of the script |
| 1150 |
being debugged when :attr:`sys.flags.safe_path` is set. |
| 1151 |
(Contributed by Tian Gao and Christian Walther in :gh:`111762`.) |
| 1152 |
|
| 1153 |
* :mod:`zipapp` is now supported as a debugging target. |
| 1154 |
(Contributed by Tian Gao in :gh:`118501`.) |
| 1155 |
|
| 1156 |
* Add ability to move between chained exceptions during |
| 1157 |
post-mortem debugging in :func:`~pdb.pm` using |
| 1158 |
the new :pdbcmd:`exceptions [exc_number] <exceptions>` command for Pdb. |
| 1159 |
(Contributed by Matthias Bussonnier in :gh:`106676`.) |
| 1160 |
|
| 1161 |
* Expressions and statements whose prefix is a pdb command are now correctly |
| 1162 |
identified and executed. |
| 1163 |
(Contributed by Tian Gao in :gh:`108464`.) |
| 1164 |
|
| 1165 |
|
| 1166 |
queue |
| 1167 |
----- |
| 1168 |
|
| 1169 |
* Add :meth:`Queue.shutdown <queue.Queue.shutdown>` and :exc:`~queue.ShutDown` |
| 1170 |
to manage queue termination. |
| 1171 |
(Contributed by Laurie Opperman and Yves Duprat in :gh:`104750`.) |
| 1172 |
|
| 1173 |
|
| 1174 |
random |
| 1175 |
------ |
| 1176 |
|
| 1177 |
* Add a :ref:`command-line interface <random-cli>`. |
| 1178 |
(Contributed by Hugo van Kemenade in :gh:`118131`.) |
| 1179 |
|
| 1180 |
|
| 1181 |
re |
| 1182 |
-- |
| 1183 |
|
| 1184 |
* Rename :exc:`!re.error` to :exc:`~re.PatternError` for improved clarity. |
| 1185 |
:exc:`!re.error` is kept for backward compatibility. |
| 1186 |
|
| 1187 |
|
| 1188 |
shutil |
| 1189 |
------ |
| 1190 |
|
| 1191 |
* Support the *dir_fd* and *follow_symlinks* keyword arguments |
| 1192 |
in :func:`~shutil.chown`. |
| 1193 |
(Contributed by Berker Peksag and Tahia K in :gh:`62308`) |
| 1194 |
|
| 1195 |
|
| 1196 |
site |
| 1197 |
---- |
| 1198 |
|
| 1199 |
* :file:`.pth` files are now decoded using UTF-8 first, |
| 1200 |
and then with the :term:`locale encoding` if UTF-8 decoding fails. |
| 1201 |
(Contributed by Inada Naoki in :gh:`117802`.) |
| 1202 |
|
| 1203 |
|
| 1204 |
sqlite3 |
| 1205 |
------- |
| 1206 |
|
| 1207 |
* A :exc:`ResourceWarning` is now emitted if a :class:`~sqlite3.Connection` |
| 1208 |
object is not :meth:`closed <sqlite3.Connection.close>` explicitly. |
| 1209 |
(Contributed by Erlend E. Aasland in :gh:`105539`.) |
| 1210 |
|
| 1211 |
* Add the *filter* keyword-only parameter to :meth:`.Connection.iterdump` |
| 1212 |
for filtering database objects to dump. |
| 1213 |
(Contributed by Mariusz Felisiak in :gh:`91602`.) |
| 1214 |
|
| 1215 |
|
| 1216 |
ssl |
| 1217 |
--- |
| 1218 |
|
| 1219 |
* The :func:`~ssl.create_default_context` API now includes |
| 1220 |
:data:`~ssl.VERIFY_X509_PARTIAL_CHAIN` and :data:`~ssl.VERIFY_X509_STRICT` |
| 1221 |
in its default flags. |
| 1222 |
|
| 1223 |
.. note:: |
| 1224 |
|
| 1225 |
:data:`~ssl.VERIFY_X509_STRICT` may reject pre-:rfc:`5280` |
| 1226 |
or malformed certificates that the underlying OpenSSL implementation |
| 1227 |
might otherwise accept. |
| 1228 |
Whilst disabling this is not recommended, you can do so using: |
| 1229 |
|
| 1230 |
.. code-block:: python |
| 1231 |
|
| 1232 |
import ssl |
| 1233 |
|
| 1234 |
ctx = ssl.create_default_context() |
| 1235 |
ctx.verify_flags &= ~ssl.VERIFY_X509_STRICT |
| 1236 |
|
| 1237 |
(Contributed by William Woodruff in :gh:`112389`.) |
| 1238 |
|
| 1239 |
|
| 1240 |
statistics |
| 1241 |
---------- |
| 1242 |
|
| 1243 |
* Add :func:`~statistics.kde` for kernel density estimation. |
| 1244 |
This makes it possible to estimate a continuous probability density function |
| 1245 |
from a fixed number of discrete samples. |
| 1246 |
(Contributed by Raymond Hettinger in :gh:`115863`.) |
| 1247 |
|
| 1248 |
* Add :func:`~statistics.kde_random` for sampling from an |
| 1249 |
estimated probability density function created by :func:`~statistics.kde`. |
| 1250 |
(Contributed by Raymond Hettinger in :gh:`115863`.) |
| 1251 |
|
| 1252 |
|
| 1253 |
.. _whatsnew313-subprocess: |
| 1254 |
|
| 1255 |
subprocess |
| 1256 |
---------- |
| 1257 |
|
| 1258 |
* The :mod:`subprocess` module now uses the :func:`~os.posix_spawn` function in |
| 1259 |
more situations. |
| 1260 |
|
| 1261 |
Notably, when *close_fds* is ``True`` (the default), |
| 1262 |
:func:`~os.posix_spawn` will be used when the C library provides |
| 1263 |
:c:func:`!posix_spawn_file_actions_addclosefrom_np`, |
| 1264 |
which includes recent versions of Linux, FreeBSD, and Solaris. |
| 1265 |
On Linux, this should perform similarly to the existing |
| 1266 |
Linux :c:func:`!vfork` based code. |
| 1267 |
|
| 1268 |
A private control knob :attr:`!subprocess._USE_POSIX_SPAWN` can |
| 1269 |
be set to ``False`` if you need to force :mod:`subprocess` |
| 1270 |
to never use :func:`~os.posix_spawn`. |
| 1271 |
Please report your reason and platform details in |
| 1272 |
the :ref:`issue tracker <using-the-tracker>` if you set this |
| 1273 |
so that we can improve our API selection logic for everyone. |
| 1274 |
(Contributed by Jakub Kulik in :gh:`113117`.) |
| 1275 |
|
| 1276 |
|
| 1277 |
sys |
| 1278 |
--- |
| 1279 |
|
| 1280 |
* Add the :func:`~sys._is_interned` function to test if a string was interned. |
| 1281 |
This function is not guaranteed to exist in all implementations of Python. |
| 1282 |
(Contributed by Serhiy Storchaka in :gh:`78573`.) |
| 1283 |
|
| 1284 |
|
| 1285 |
tempfile |
| 1286 |
-------- |
| 1287 |
|
| 1288 |
* On Windows, the default mode ``0o700`` used by :func:`tempfile.mkdtemp` now |
| 1289 |
limits access to the new directory due to changes to :func:`os.mkdir`. |
| 1290 |
This is a mitigation for :cve:`2024-4030`. |
| 1291 |
(Contributed by Steve Dower in :gh:`118486`.) |
| 1292 |
|
| 1293 |
|
| 1294 |
time |
| 1295 |
---- |
| 1296 |
|
| 1297 |
* On Windows, :func:`~time.monotonic` now uses the |
| 1298 |
``QueryPerformanceCounter()`` clock for a resolution of 1 microsecond, |
| 1299 |
instead of the ``GetTickCount64()`` clock which has |
| 1300 |
a resolution of 15.6 milliseconds. |
| 1301 |
(Contributed by Victor Stinner in :gh:`88494`.) |
| 1302 |
|
| 1303 |
* On Windows, :func:`~time.time` now uses the |
| 1304 |
``GetSystemTimePreciseAsFileTime()`` clock for a resolution of 1 microsecond, |
| 1305 |
instead of the ``GetSystemTimeAsFileTime()`` clock which has |
| 1306 |
a resolution of 15.6 milliseconds. |
| 1307 |
(Contributed by Victor Stinner in :gh:`63207`.) |
| 1308 |
|
| 1309 |
|
| 1310 |
tkinter |
| 1311 |
------- |
| 1312 |
|
| 1313 |
* Add :mod:`tkinter` widget methods: |
| 1314 |
:meth:`!tk_busy_hold`, :meth:`!tk_busy_configure`, |
| 1315 |
:meth:`!tk_busy_cget`, :meth:`!tk_busy_forget`, |
| 1316 |
:meth:`!tk_busy_current`, and :meth:`!tk_busy_status`. |
| 1317 |
(Contributed by Miguel, klappnase and Serhiy Storchaka in :gh:`72684`.) |
| 1318 |
|
| 1319 |
* The :mod:`tkinter` widget method :meth:`!wm_attributes` now accepts |
| 1320 |
the attribute name without the minus prefix to get window attributes, |
| 1321 |
for example ``w.wm_attributes('alpha')`` |
| 1322 |
and allows specifying attributes and values to set as keyword arguments, |
| 1323 |
for example ``w.wm_attributes(alpha=0.5)``. |
| 1324 |
(Contributed by Serhiy Storchaka in :gh:`43457`.) |
| 1325 |
|
| 1326 |
* :meth:`!wm_attributes` can now return attributes as a :class:`dict`, |
| 1327 |
by using the new optional keyword-only parameter *return_python_dict*. |
| 1328 |
(Contributed by Serhiy Storchaka in :gh:`43457`.) |
| 1329 |
|
| 1330 |
* :meth:`!Text.count` can now return a simple :class:`int` |
| 1331 |
when the new optional keyword-only parameter *return_ints* is used. |
| 1332 |
Otherwise, the single count is returned as a 1-tuple or ``None``. |
| 1333 |
(Contributed by Serhiy Storchaka in :gh:`97928`.) |
| 1334 |
|
| 1335 |
* Support the "vsapi" element type in |
| 1336 |
the :meth:`~tkinter.ttk.Style.element_create` method of |
| 1337 |
:class:`tkinter.ttk.Style`. |
| 1338 |
(Contributed by Serhiy Storchaka in :gh:`68166`.) |
| 1339 |
|
| 1340 |
* Add the :meth:`!after_info` method for Tkinter widgets. |
| 1341 |
(Contributed by Cheryl Sabella in :gh:`77020`.) |
| 1342 |
|
| 1343 |
* Add a new :meth:`!copy_replace` method to :class:`!PhotoImage` |
| 1344 |
to copy a region from one image to another, |
| 1345 |
possibly with pixel zooming, subsampling, or both. |
| 1346 |
(Contributed by Serhiy Storchaka in :gh:`118225`.) |
| 1347 |
|
| 1348 |
* Add *from_coords* parameter to the :class:`!PhotoImage` methods |
| 1349 |
:meth:`!copy`, :meth:`!zoom` and :meth:`!subsample`. |
| 1350 |
Add *zoom* and *subsample* parameters to the :class:`!PhotoImage` method |
| 1351 |
:meth:`!copy`. |
| 1352 |
(Contributed by Serhiy Storchaka in :gh:`118225`.) |
| 1353 |
|
| 1354 |
* Add the :class:`!PhotoImage` methods |
| 1355 |
:meth:`!read` to read an image from a file |
| 1356 |
and :meth:`!data` to get the image data. |
| 1357 |
Add *background* and *grayscale* parameters to the :meth:`!write` method. |
| 1358 |
(Contributed by Serhiy Storchaka in :gh:`118271`.) |
| 1359 |
|
| 1360 |
|
| 1361 |
traceback |
| 1362 |
--------- |
| 1363 |
|
| 1364 |
* Add the :attr:`~traceback.TracebackException.exc_type_str` attribute |
| 1365 |
to :class:`~traceback.TracebackException`, |
| 1366 |
which holds a string display of the *exc_type*. |
| 1367 |
Deprecate the :attr:`~traceback.TracebackException.exc_type` attribute, |
| 1368 |
which holds the type object itself. |
| 1369 |
Add parameter *save_exc_type* (default ``True``) |
| 1370 |
to indicate whether ``exc_type`` should be saved. |
| 1371 |
(Contributed by Irit Katriel in :gh:`112332`.) |
| 1372 |
|
| 1373 |
* Add a new *show_group* keyword-only parameter to |
| 1374 |
:meth:`.TracebackException.format_exception_only` to (recursively) format |
| 1375 |
the nested exceptions of a :exc:`BaseExceptionGroup` instance. |
| 1376 |
(Contributed by Irit Katriel in :gh:`105292`.) |
| 1377 |
|
| 1378 |
|
| 1379 |
types |
| 1380 |
----- |
| 1381 |
|
| 1382 |
* :class:`~types.SimpleNamespace` can now take a single positional argument |
| 1383 |
to initialise the namespace's arguments. |
| 1384 |
This argument must either be a mapping or an iterable of key-value pairs. |
| 1385 |
(Contributed by Serhiy Storchaka in :gh:`108191`.) |
| 1386 |
|
| 1387 |
|
| 1388 |
typing |
| 1389 |
------ |
| 1390 |
|
| 1391 |
* :pep:`705`: Add :data:`~typing.ReadOnly`, a special typing construct |
| 1392 |
to mark a :class:`~typing.TypedDict` item as read-only for type checkers. |
| 1393 |
|
| 1394 |
* :pep:`742`: Add :data:`~typing.TypeIs`, a typing construct |
| 1395 |
that can be used to instruct a type checker how to narrow a type. |
| 1396 |
|
| 1397 |
* Add :data:`~typing.NoDefault`, a sentinel object used to represent |
| 1398 |
the defaults of some parameters in the :mod:`typing` module. |
| 1399 |
(Contributed by Jelle Zijlstra in :gh:`116126`.) |
| 1400 |
|
| 1401 |
* Add :func:`~typing.get_protocol_members` to return the set of members |
| 1402 |
defining a :class:`typing.Protocol`. |
| 1403 |
(Contributed by Jelle Zijlstra in :gh:`104873`.) |
| 1404 |
|
| 1405 |
* Add :func:`~typing.is_protocol` to check whether a class |
| 1406 |
is a :class:`~typing.Protocol`. |
| 1407 |
(Contributed by Jelle Zijlstra in :gh:`104873`.) |
| 1408 |
|
| 1409 |
* :data:`~typing.ClassVar` can now be nested in :data:`~typing.Final`, |
| 1410 |
and vice versa. |
| 1411 |
(Contributed by Mehdi Drissi in :gh:`89547`.) |
| 1412 |
|
| 1413 |
|
| 1414 |
unicodedata |
| 1415 |
----------- |
| 1416 |
|
| 1417 |
* Update the Unicode database to `version 15.1.0`__. |
| 1418 |
(Contributed by James Gerity in :gh:`109559`.) |
| 1419 |
|
| 1420 |
__ https://www.unicode.org/versions/Unicode15.1.0/ |
| 1421 |
|
| 1422 |
|
| 1423 |
venv |
| 1424 |
---- |
| 1425 |
|
| 1426 |
* Add support for creating source control management (SCM) ignore files |
| 1427 |
in a virtual environment's directory. |
| 1428 |
By default, Git is supported. |
| 1429 |
This is implemented as opt-in via the API, |
| 1430 |
which can be extended to support other SCMs |
| 1431 |
(:class:`~venv.EnvBuilder` and :func:`~venv.create`), |
| 1432 |
and opt-out via the CLI, using :option:`!--without-scm-ignore-files`. |
| 1433 |
(Contributed by Brett Cannon in :gh:`108125`.) |
| 1434 |
|
| 1435 |
|
| 1436 |
warnings |
| 1437 |
-------- |
| 1438 |
|
| 1439 |
* :pep:`702`: The new :func:`warnings.deprecated` decorator provides a way to |
| 1440 |
communicate deprecations to a :term:`static type checker` |
| 1441 |
and to warn on usage of deprecated classes and functions. |
| 1442 |
A :exc:`DeprecationWarning` may also be emitted when |
| 1443 |
a decorated function or class is used at runtime. |
| 1444 |
(Contributed by Jelle Zijlstra in :gh:`104003`.) |
| 1445 |
|
| 1446 |
|
| 1447 |
xml |
| 1448 |
--- |
| 1449 |
|
| 1450 |
* Allow controlling Expat >=2.6.0 reparse deferral (:cve:`2023-52425`) |
| 1451 |
by adding five new methods: |
| 1452 |
|
| 1453 |
* :meth:`xml.etree.ElementTree.XMLParser.flush` |
| 1454 |
* :meth:`xml.etree.ElementTree.XMLPullParser.flush` |
| 1455 |
* :meth:`xml.parsers.expat.xmlparser.GetReparseDeferralEnabled` |
| 1456 |
* :meth:`xml.parsers.expat.xmlparser.SetReparseDeferralEnabled` |
| 1457 |
* :meth:`!xml.sax.expatreader.ExpatParser.flush` |
| 1458 |
|
| 1459 |
(Contributed by Sebastian Pipping in :gh:`115623`.) |
| 1460 |
|
| 1461 |
* Add the :meth:`!close` method for the iterator returned by |
| 1462 |
:func:`~xml.etree.ElementTree.iterparse` for explicit cleanup. |
| 1463 |
(Contributed by Serhiy Storchaka in :gh:`69893`.) |
| 1464 |
|
| 1465 |
|
| 1466 |
zipimport |
| 1467 |
--------- |
| 1468 |
|
| 1469 |
* Add support for ZIP64_ format files. |
| 1470 |
Everybody loves huge data, right? |
| 1471 |
(Contributed by Tim Hatch in :gh:`94146`.) |
| 1472 |
|
| 1473 |
.. _ZIP64: https://en.wikipedia.org/wiki/Zip_(file_format)#ZIP64 |
| 1474 |
|
| 1475 |
|
| 1476 |
Optimizations |
| 1477 |
============= |
| 1478 |
|
| 1479 |
* Several standard library modules have had |
| 1480 |
their import times significantly improved. |
| 1481 |
For example, the import time of the :mod:`typing` module |
| 1482 |
has been reduced by around a third by removing dependencies |
| 1483 |
on :mod:`re` and :mod:`contextlib`. |
| 1484 |
Other modules to enjoy import-time speedups include |
| 1485 |
:mod:`email.utils`, :mod:`enum`, :mod:`functools`, |
| 1486 |
:mod:`importlib.metadata`, and :mod:`threading`. |
| 1487 |
(Contributed by Alex Waygood, Shantanu Jain, Adam Turner, Daniel Hollas, |
| 1488 |
and others in :gh:`109653`.) |
| 1489 |
|
| 1490 |
* :func:`textwrap.indent` is now around 30% faster than before for large input. |
| 1491 |
(Contributed by Inada Naoki in :gh:`107369`.) |
| 1492 |
|
| 1493 |
* The :mod:`subprocess` module now uses the :func:`~os.posix_spawn` function in |
| 1494 |
more situations, including when *close_fds* is ``True`` (the default) |
| 1495 |
on many modern platforms. |
| 1496 |
This should provide a notable performance increase |
| 1497 |
when launching processes on FreeBSD and Solaris. |
| 1498 |
See the :ref:`subprocess <whatsnew313-subprocess>` section above for details. |
| 1499 |
(Contributed by Jakub Kulik in :gh:`113117`.) |
| 1500 |
|
| 1501 |
|
| 1502 |
Removed Modules And APIs |
| 1503 |
======================== |
| 1504 |
|
| 1505 |
|
| 1506 |
.. _whatsnew313-pep594: |
| 1507 |
|
| 1508 |
PEP 594: Remove "dead batteries" from the standard library |
| 1509 |
---------------------------------------------------------- |
| 1510 |
|
| 1511 |
:pep:`594` proposed removing 19 modules from the standard library, |
| 1512 |
colloquially referred to as 'dead batteries' due to their |
| 1513 |
historic, obsolete, or insecure status. |
| 1514 |
All of the following modules were deprecated in Python 3.11, |
| 1515 |
and are now removed: |
| 1516 |
|
| 1517 |
* :mod:`!aifc` |
| 1518 |
|
| 1519 |
* :pypi:`standard-aifc`: |
| 1520 |
Use the redistribution of ``aifc`` library from PyPI. |
| 1521 |
|
| 1522 |
* :mod:`!audioop` |
| 1523 |
|
| 1524 |
* :pypi:`audioop-lts`: |
| 1525 |
Use ``audioop-lts`` library from PyPI. |
| 1526 |
|
| 1527 |
* :mod:`!chunk` |
| 1528 |
|
| 1529 |
* :pypi:`standard-chunk`: |
| 1530 |
Use the redistribution of ``chunk`` library from PyPI. |
| 1531 |
|
| 1532 |
* :mod:`!cgi` and :mod:`!cgitb` |
| 1533 |
|
| 1534 |
* :class:`!cgi.FieldStorage` can typically be replaced with |
| 1535 |
:func:`urllib.parse.parse_qsl` for ``GET`` and ``HEAD`` requests, |
| 1536 |
and the :mod:`email.message` module or the :pypi:`multipart` library |
| 1537 |
for ``POST`` and ``PUT`` requests. |
| 1538 |
|
| 1539 |
* :func:`!cgi.parse` can be replaced by calling |
| 1540 |
:func:`urllib.parse.parse_qs` directly on the desired query string, |
| 1541 |
unless the input is ``multipart/form-data``, |
| 1542 |
which should be replaced as described below for :func:`!cgi.parse_multipart`. |
| 1543 |
|
| 1544 |
* :func:`!cgi.parse_header` can be replaced with the functionality |
| 1545 |
in the :mod:`email` package, which implements the same MIME RFCs. |
| 1546 |
For example, with :class:`email.message.EmailMessage`: |
| 1547 |
|
| 1548 |
.. code-block:: python |
| 1549 |
|
| 1550 |
from email.message import EmailMessage |
| 1551 |
|
| 1552 |
msg = EmailMessage() |
| 1553 |
msg['content-type'] = 'application/json; charset="utf8"' |
| 1554 |
main, params = msg.get_content_type(), msg['content-type'].params |
| 1555 |
|
| 1556 |
* :func:`!cgi.parse_multipart` can be replaced with the functionality |
| 1557 |
in the :mod:`email` package, which implements the same MIME RFCs, |
| 1558 |
or with the :pypi:`multipart` library. |
| 1559 |
For example, the :class:`email.message.EmailMessage` |
| 1560 |
and :class:`email.message.Message` classes. |
| 1561 |
|
| 1562 |
* :pypi:`standard-cgi`: and :pypi:`standard-cgitb`: |
| 1563 |
Use the redistribution of ``cgi`` and ``cgitb`` library from PyPI. |
| 1564 |
|
| 1565 |
* :mod:`!crypt` and the private :mod:`!_crypt` extension. |
| 1566 |
The :mod:`hashlib` module may be an appropriate replacement |
| 1567 |
when simply hashing a value is required. |
| 1568 |
Otherwise, various third-party libraries on PyPI are available: |
| 1569 |
|
| 1570 |
* :pypi:`bcrypt`: |
| 1571 |
Modern password hashing for your software and your servers. |
| 1572 |
* :pypi:`argon2-cffi`: |
| 1573 |
The secure Argon2 password hashing algorithm. |
| 1574 |
* :pypi:`legacycrypt`: |
| 1575 |
:mod:`ctypes` wrapper to the POSIX crypt library call |
| 1576 |
and associated functionality. |
| 1577 |
* :pypi:`crypt_r`: |
| 1578 |
Fork of the :mod:`!crypt` module, |
| 1579 |
wrapper to the :manpage:`crypt_r(3)` library call |
| 1580 |
and associated functionality. |
| 1581 |
* :pypi:`standard-crypt` and :pypi:`deprecated-crypt-alternative`: |
| 1582 |
Use the redistribution of ``crypt`` and reimplementation of ``_crypt`` libraries from PyPI. |
| 1583 |
|
| 1584 |
* :mod:`!imghdr`: |
| 1585 |
The :pypi:`filetype`, :pypi:`puremagic`, or :pypi:`python-magic` libraries |
| 1586 |
should be used as replacements. |
| 1587 |
For example, the :func:`!puremagic.what` function can be used |
| 1588 |
to replace the :func:`!imghdr.what` function for all file formats |
| 1589 |
that were supported by :mod:`!imghdr`. |
| 1590 |
|
| 1591 |
* :pypi:`standard-imghdr`: |
| 1592 |
Use the redistribution of ``imghdr`` library from PyPI. |
| 1593 |
|
| 1594 |
* :mod:`!mailcap`: |
| 1595 |
Use the :mod:`mimetypes` module instead. |
| 1596 |
|
| 1597 |
* :pypi:`standard-mailcap`: |
| 1598 |
Use the redistribution of ``mailcap`` library from PyPI. |
| 1599 |
|
| 1600 |
* :mod:`!msilib` |
| 1601 |
* :mod:`!nis` |
| 1602 |
* :mod:`!nntplib`: |
| 1603 |
Use the :pypi:`pynntp` library from PyPI instead. |
| 1604 |
|
| 1605 |
* :pypi:`standard-nntplib`: |
| 1606 |
Use the redistribution of ``nntplib`` library from PyPI. |
| 1607 |
|
| 1608 |
* :mod:`!ossaudiodev`: |
| 1609 |
For audio playback, use the :pypi:`pygame` library from PyPI instead. |
| 1610 |
* :mod:`!pipes`: |
| 1611 |
Use the :mod:`subprocess` module instead. |
| 1612 |
Use :func:`shlex.quote` to replace the undocumented ``pipes.quote`` |
| 1613 |
function. |
| 1614 |
|
| 1615 |
* :pypi:`standard-pipes`: |
| 1616 |
Use the redistribution of ``pipes`` library from PyPI. |
| 1617 |
|
| 1618 |
* :mod:`!sndhdr`: |
| 1619 |
The :pypi:`filetype`, :pypi:`puremagic`, or :pypi:`python-magic` libraries |
| 1620 |
should be used as replacements. |
| 1621 |
|
| 1622 |
* :pypi:`standard-sndhdr`: |
| 1623 |
Use the redistribution of ``sndhdr`` library from PyPI. |
| 1624 |
|
| 1625 |
* :mod:`!spwd`: |
| 1626 |
Use the :pypi:`python-pam` library from PyPI instead. |
| 1627 |
* :mod:`!sunau` |
| 1628 |
|
| 1629 |
* :pypi:`standard-sunau`: |
| 1630 |
Use the redistribution of ``sunau`` library from PyPI. |
| 1631 |
|
| 1632 |
* :mod:`!telnetlib`, |
| 1633 |
Use the :pypi:`telnetlib3` or :pypi:`Exscript` libraries from PyPI instead. |
| 1634 |
|
| 1635 |
* :pypi:`standard-telnetlib`: |
| 1636 |
Use the redistribution of ``telnetlib`` library from PyPI. |
| 1637 |
|
| 1638 |
* :mod:`!uu`: |
| 1639 |
Use the :mod:`base64` module instead, as a modern alternative. |
| 1640 |
|
| 1641 |
* :pypi:`standard-uu`: |
| 1642 |
Use the redistribution of ``uu`` library from PyPI. |
| 1643 |
|
| 1644 |
* :mod:`!xdrlib` |
| 1645 |
|
| 1646 |
* :pypi:`standard-xdrlib`: |
| 1647 |
Use the redistribution of ``xdrlib`` library from PyPI. |
| 1648 |
|
| 1649 |
(Contributed by Victor Stinner and Zachary Ware in :gh:`104773` and :gh:`104780`.) |
| 1650 |
|
| 1651 |
|
| 1652 |
2to3 |
| 1653 |
---- |
| 1654 |
|
| 1655 |
* Remove the :program:`2to3` program and the :mod:`!lib2to3` module, |
| 1656 |
previously deprecated in Python 3.11. |
| 1657 |
(Contributed by Victor Stinner in :gh:`104780`.) |
| 1658 |
|
| 1659 |
|
| 1660 |
builtins |
| 1661 |
-------- |
| 1662 |
|
| 1663 |
* Remove support for chained :class:`classmethod` descriptors |
| 1664 |
(introduced in :gh:`63272`). |
| 1665 |
These can no longer be used to wrap other descriptors, |
| 1666 |
such as :class:`property`. |
| 1667 |
The core design of this feature was flawed and led to several problems. |
| 1668 |
To "pass-through" a :class:`classmethod`, consider using |
| 1669 |
the :attr:`!__wrapped__` attribute that was added in Python 3.10. |
| 1670 |
(Contributed by Raymond Hettinger in :gh:`89519`.) |
| 1671 |
|
| 1672 |
* Raise a :exc:`RuntimeError` when calling :meth:`frame.clear` |
| 1673 |
on a suspended frame (as has always been the case for an executing frame). |
| 1674 |
(Contributed by Irit Katriel in :gh:`79932`.) |
| 1675 |
|
| 1676 |
|
| 1677 |
configparser |
| 1678 |
------------ |
| 1679 |
|
| 1680 |
* Remove the undocumented :class:`!LegacyInterpolation` class, |
| 1681 |
deprecated in the docstring since Python 3.2, |
| 1682 |
and at runtime since Python 3.11. |
| 1683 |
(Contributed by Hugo van Kemenade in :gh:`104886`.) |
| 1684 |
|
| 1685 |
|
| 1686 |
importlib.metadata |
| 1687 |
------------------ |
| 1688 |
|
| 1689 |
* Remove deprecated subscript (:meth:`~object.__getitem__`) access for |
| 1690 |
:ref:`EntryPoint <entry-points>` objects. |
| 1691 |
(Contributed by Jason R. Coombs in :gh:`113175`.) |
| 1692 |
|
| 1693 |
|
| 1694 |
locale |
| 1695 |
------ |
| 1696 |
|
| 1697 |
* Remove the :func:`!locale.resetlocale` function, deprecated in Python 3.11. |
| 1698 |
Use ``locale.setlocale(locale.LC_ALL, "")`` instead. |
| 1699 |
(Contributed by Victor Stinner in :gh:`104783`.) |
| 1700 |
|
| 1701 |
|
| 1702 |
opcode |
| 1703 |
------ |
| 1704 |
|
| 1705 |
* Move :attr:`!opcode.ENABLE_SPECIALIZATION` to :attr:`!_opcode.ENABLE_SPECIALIZATION`. |
| 1706 |
This field was added in 3.12, it was never documented, |
| 1707 |
and is not intended for external use. |
| 1708 |
(Contributed by Irit Katriel in :gh:`105481`.) |
| 1709 |
|
| 1710 |
* Remove :func:`!opcode.is_pseudo`, :attr:`!opcode.MIN_PSEUDO_OPCODE`, |
| 1711 |
and :attr:`!opcode.MAX_PSEUDO_OPCODE`, which were added in Python 3.12, |
| 1712 |
but were neither documented nor exposed through :mod:`dis`, |
| 1713 |
and were not intended to be used externally. |
| 1714 |
(Contributed by Irit Katriel in :gh:`105481`.) |
| 1715 |
|
| 1716 |
|
| 1717 |
optparse |
| 1718 |
-------- |
| 1719 |
|
| 1720 |
* This module is no longer considered :term:`soft deprecated`. |
| 1721 |
While :mod:`argparse` remains preferred for new projects that |
| 1722 |
aren't using a third party command line argument processing |
| 1723 |
library, there are aspects of the way ``argparse`` works that |
| 1724 |
mean the lower level ``optparse`` module may provide a better |
| 1725 |
foundation for *writing* argument processing libraries, and |
| 1726 |
for implementing command line applications which adhere more |
| 1727 |
strictly than ``argparse`` does to various Unix command line |
| 1728 |
processing conventions that originate in the behaviour of the |
| 1729 |
C :c:func:`!getopt` function . |
| 1730 |
(Contributed by Alyssa Coghlan and Serhiy Storchaka in :gh:`126180`.) |
| 1731 |
|
| 1732 |
|
| 1733 |
pathlib |
| 1734 |
------- |
| 1735 |
|
| 1736 |
* Remove the ability to use :class:`~pathlib.Path` objects as context managers. |
| 1737 |
This functionality was deprecated and has had no effect since Python 3.9. |
| 1738 |
(Contributed by Barney Gale in :gh:`83863`.) |
| 1739 |
|
| 1740 |
|
| 1741 |
re |
| 1742 |
-- |
| 1743 |
|
| 1744 |
* Remove the undocumented, deprecated, and broken |
| 1745 |
:func:`!re.template` function and :attr:`!re.TEMPLATE` / :attr:`!re.T` flag. |
| 1746 |
(Contributed by Serhiy Storchaka and Nikita Sobolev in :gh:`105687`.) |
| 1747 |
|
| 1748 |
|
| 1749 |
tkinter.tix |
| 1750 |
----------- |
| 1751 |
|
| 1752 |
* Remove the :mod:`!tkinter.tix` module, deprecated in Python 3.6. |
| 1753 |
The third-party Tix library which the module wrapped is unmaintained. |
| 1754 |
(Contributed by Zachary Ware in :gh:`75552`.) |
| 1755 |
|
| 1756 |
|
| 1757 |
turtle |
| 1758 |
------ |
| 1759 |
|
| 1760 |
* Remove the :meth:`!RawTurtle.settiltangle` method, |
| 1761 |
deprecated in the documentation since Python 3.1 |
| 1762 |
and at runtime since Python 3.11. |
| 1763 |
(Contributed by Hugo van Kemenade in :gh:`104876`.) |
| 1764 |
|
| 1765 |
|
| 1766 |
typing |
| 1767 |
------ |
| 1768 |
|
| 1769 |
* Remove the :mod:`!typing.io` and :mod:`!typing.re` namespaces, |
| 1770 |
deprecated since Python 3.8. |
| 1771 |
The items in those namespaces can be imported directly |
| 1772 |
from the :mod:`typing` module. |
| 1773 |
(Contributed by Sebastian Rittau in :gh:`92871`.) |
| 1774 |
|
| 1775 |
* Remove the keyword-argument method of creating |
| 1776 |
:class:`~typing.TypedDict` types, deprecated in Python 3.11. |
| 1777 |
(Contributed by Tomas Roun in :gh:`104786`.) |
| 1778 |
|
| 1779 |
|
| 1780 |
unittest |
| 1781 |
-------- |
| 1782 |
|
| 1783 |
* Remove the following :mod:`unittest` functions, deprecated in Python 3.11: |
| 1784 |
|
| 1785 |
* :func:`!unittest.findTestCases` |
| 1786 |
* :func:`!unittest.makeSuite` |
| 1787 |
* :func:`!unittest.getTestCaseNames` |
| 1788 |
|
| 1789 |
Use :class:`~unittest.TestLoader` methods instead: |
| 1790 |
|
| 1791 |
* :meth:`~unittest.TestLoader.loadTestsFromModule` |
| 1792 |
* :meth:`~unittest.TestLoader.loadTestsFromTestCase` |
| 1793 |
* :meth:`~unittest.TestLoader.getTestCaseNames` |
| 1794 |
|
| 1795 |
(Contributed by Hugo van Kemenade in :gh:`104835`.) |
| 1796 |
|
| 1797 |
* Remove the untested and undocumented :meth:`!TestProgram.usageExit` |
| 1798 |
method, deprecated in Python 3.11. |
| 1799 |
(Contributed by Hugo van Kemenade in :gh:`104992`.) |
| 1800 |
|
| 1801 |
|
| 1802 |
urllib |
| 1803 |
------ |
| 1804 |
|
| 1805 |
* Remove the *cafile*, *capath*, and *cadefault* parameters of the |
| 1806 |
:func:`urllib.request.urlopen` function, deprecated in Python 3.6. |
| 1807 |
Use the *context* parameter instead with an :class:`~ssl.SSLContext` instance. |
| 1808 |
The :meth:`ssl.SSLContext.load_cert_chain` function |
| 1809 |
can be used to load specific certificates, |
| 1810 |
or let :func:`ssl.create_default_context` select |
| 1811 |
the operating system's trusted certificate authority (CA) certificates. |
| 1812 |
(Contributed by Victor Stinner in :gh:`105382`.) |
| 1813 |
|
| 1814 |
|
| 1815 |
webbrowser |
| 1816 |
---------- |
| 1817 |
|
| 1818 |
* Remove the untested and undocumented :class:`!MacOSX` class, |
| 1819 |
deprecated in Python 3.11. |
| 1820 |
Use the :class:`!MacOSXOSAScript` class (introduced in Python 3.2) instead. |
| 1821 |
(Contributed by Hugo van Kemenade in :gh:`104804`.) |
| 1822 |
|
| 1823 |
* Remove the deprecated :attr:`!MacOSXOSAScript._name` attribute. |
| 1824 |
Use the :attr:`MacOSXOSAScript.name <webbrowser.controller.name>` |
| 1825 |
attribute instead. |
| 1826 |
(Contributed by Nikita Sobolev in :gh:`105546`.) |
| 1827 |
|
| 1828 |
|
| 1829 |
New Deprecations |
| 1830 |
================ |
| 1831 |
|
| 1832 |
* :ref:`User-defined functions <user-defined-funcs>`: |
| 1833 |
|
| 1834 |
* Deprecate assignment to a function's :attr:`~function.__code__` attribute, |
| 1835 |
where the new code object's type does not match the function's type. |
| 1836 |
The different types are: |
| 1837 |
plain function, generator, async generator, and coroutine. |
| 1838 |
(Contributed by Irit Katriel in :gh:`81137`.) |
| 1839 |
|
| 1840 |
* :mod:`array`: |
| 1841 |
|
| 1842 |
* Deprecate the ``'u'`` format code (:c:type:`wchar_t`) at runtime. |
| 1843 |
This format code has been deprecated in documentation since Python 3.3, |
| 1844 |
and will be removed in Python 3.16. |
| 1845 |
Use the ``'w'`` format code (:c:type:`Py_UCS4`) |
| 1846 |
for Unicode characters instead. |
| 1847 |
(Contributed by Hugo van Kemenade in :gh:`80480`.) |
| 1848 |
|
| 1849 |
* :mod:`ctypes`: |
| 1850 |
|
| 1851 |
* Deprecate the undocumented :func:`!SetPointerType` function, |
| 1852 |
to be removed in Python 3.15. |
| 1853 |
(Contributed by Victor Stinner in :gh:`105733`.) |
| 1854 |
|
| 1855 |
* :term:`Soft-deprecate <soft deprecated>` the :func:`~ctypes.ARRAY` |
| 1856 |
function in favour of ``type * length`` multiplication. |
| 1857 |
(Contributed by Victor Stinner in :gh:`105733`.) |
| 1858 |
|
| 1859 |
* :mod:`decimal`: |
| 1860 |
|
| 1861 |
* Deprecate the non-standard and undocumented :class:`~decimal.Decimal` |
| 1862 |
format specifier ``'N'``, |
| 1863 |
which is only supported in the :mod:`!decimal` module's C implementation. |
| 1864 |
Scheduled to be removed in Python 3.18. |
| 1865 |
(Contributed by Serhiy Storchaka in :gh:`89902`.) |
| 1866 |
|
| 1867 |
* :mod:`dis`: |
| 1868 |
|
| 1869 |
* Deprecate the :attr:`!HAVE_ARGUMENT` separator. |
| 1870 |
Check membership in :data:`~dis.hasarg` instead. |
| 1871 |
(Contributed by Irit Katriel in :gh:`109319`.) |
| 1872 |
|
| 1873 |
* :mod:`gettext`: |
| 1874 |
|
| 1875 |
* Deprecate non-integer numbers as arguments to functions and methods |
| 1876 |
that consider plural forms in the :mod:`!gettext` module, |
| 1877 |
even if no translation was found. |
| 1878 |
(Contributed by Serhiy Storchaka in :gh:`88434`.) |
| 1879 |
|
| 1880 |
* :mod:`glob`: |
| 1881 |
|
| 1882 |
* Deprecate the undocumented :func:`!glob0` and :func:`!glob1` functions. |
| 1883 |
Use :func:`~glob.glob` and pass a :term:`path-like object` specifying |
| 1884 |
the root directory to the *root_dir* parameter instead. |
| 1885 |
(Contributed by Barney Gale in :gh:`117337`.) |
| 1886 |
|
| 1887 |
* :mod:`http.server`: |
| 1888 |
|
| 1889 |
* Deprecate :class:`~http.server.CGIHTTPRequestHandler`, |
| 1890 |
to be removed in Python 3.15. |
| 1891 |
Process-based CGI HTTP servers have been out of favor for a very long time. |
| 1892 |
This code was outdated, unmaintained, and rarely used. |
| 1893 |
It has a high potential for both security and functionality bugs. |
| 1894 |
(Contributed by Gregory P. Smith in :gh:`109096`.) |
| 1895 |
|
| 1896 |
* Deprecate the :option:`!--cgi` flag to |
| 1897 |
the :program:`python -m http.server` command-line interface, |
| 1898 |
to be removed in Python 3.15. |
| 1899 |
(Contributed by Gregory P. Smith in :gh:`109096`.) |
| 1900 |
|
| 1901 |
* :mod:`mimetypes`: |
| 1902 |
|
| 1903 |
* :term:`Soft-deprecate <soft deprecated>` file path arguments |
| 1904 |
to :func:`~mimetypes.guess_type`, |
| 1905 |
use :func:`~mimetypes.guess_file_type` instead. |
| 1906 |
(Contributed by Serhiy Storchaka in :gh:`66543`.) |
| 1907 |
|
| 1908 |
* :mod:`re`: |
| 1909 |
|
| 1910 |
* Deprecate passing the optional *maxsplit*, *count*, or *flags* arguments |
| 1911 |
as positional arguments to the module-level |
| 1912 |
:func:`~re.split`, :func:`~re.sub`, and :func:`~re.subn` functions. |
| 1913 |
These parameters will become :ref:`keyword-only <keyword-only_parameter>` |
| 1914 |
in a future version of Python. |
| 1915 |
(Contributed by Serhiy Storchaka in :gh:`56166`.) |
| 1916 |
|
| 1917 |
* :mod:`pathlib`: |
| 1918 |
|
| 1919 |
* Deprecate :meth:`.PurePath.is_reserved`, |
| 1920 |
to be removed in Python 3.15. |
| 1921 |
Use :func:`os.path.isreserved` to detect reserved paths on Windows. |
| 1922 |
(Contributed by Barney Gale in :gh:`88569`.) |
| 1923 |
|
| 1924 |
* :mod:`platform`: |
| 1925 |
|
| 1926 |
* Deprecate :func:`~platform.java_ver`, |
| 1927 |
to be removed in Python 3.15. |
| 1928 |
This function is only useful for Jython support, has a confusing API, |
| 1929 |
and is largely untested. |
| 1930 |
(Contributed by Nikita Sobolev in :gh:`116349`.) |
| 1931 |
|
| 1932 |
* :mod:`pydoc`: |
| 1933 |
|
| 1934 |
* Deprecate the undocumented :func:`!ispackage` function. |
| 1935 |
(Contributed by Zackery Spytz in :gh:`64020`.) |
| 1936 |
|
| 1937 |
* :mod:`sqlite3`: |
| 1938 |
|
| 1939 |
* Deprecate passing more than one positional argument to |
| 1940 |
the :func:`~sqlite3.connect` function |
| 1941 |
and the :class:`~sqlite3.Connection` constructor. |
| 1942 |
The remaining parameters will become keyword-only in Python 3.15. |
| 1943 |
(Contributed by Erlend E. Aasland in :gh:`107948`.) |
| 1944 |
|
| 1945 |
* Deprecate passing name, number of arguments, and the callable as keyword |
| 1946 |
arguments for :meth:`.Connection.create_function` |
| 1947 |
and :meth:`.Connection.create_aggregate` |
| 1948 |
These parameters will become positional-only in Python 3.15. |
| 1949 |
(Contributed by Erlend E. Aasland in :gh:`108278`.) |
| 1950 |
|
| 1951 |
* Deprecate passing the callback callable by keyword for the |
| 1952 |
:meth:`~sqlite3.Connection.set_authorizer`, |
| 1953 |
:meth:`~sqlite3.Connection.set_progress_handler`, and |
| 1954 |
:meth:`~sqlite3.Connection.set_trace_callback` |
| 1955 |
:class:`~sqlite3.Connection` methods. |
| 1956 |
The callback callables will become positional-only in Python 3.15. |
| 1957 |
(Contributed by Erlend E. Aasland in :gh:`108278`.) |
| 1958 |
|
| 1959 |
* :mod:`sys`: |
| 1960 |
|
| 1961 |
* Deprecate the :func:`~sys._enablelegacywindowsfsencoding` function, |
| 1962 |
to be removed in Python 3.16. |
| 1963 |
Use the :envvar:`PYTHONLEGACYWINDOWSFSENCODING` environment variable instead. |
| 1964 |
(Contributed by Inada Naoki in :gh:`73427`.) |
| 1965 |
|
| 1966 |
* :mod:`tarfile`: |
| 1967 |
|
| 1968 |
* Deprecate the undocumented and unused :attr:`!TarFile.tarfile` attribute, |
| 1969 |
to be removed in Python 3.16. |
| 1970 |
(Contributed in :gh:`115256`.) |
| 1971 |
|
| 1972 |
* :mod:`traceback`: |
| 1973 |
|
| 1974 |
* Deprecate the :attr:`.TracebackException.exc_type` attribute. |
| 1975 |
Use :attr:`.TracebackException.exc_type_str` instead. |
| 1976 |
(Contributed by Irit Katriel in :gh:`112332`.) |
| 1977 |
|
| 1978 |
* :mod:`typing`: |
| 1979 |
|
| 1980 |
* Deprecate the undocumented keyword argument syntax for creating |
| 1981 |
:class:`~typing.NamedTuple` classes |
| 1982 |
(e.g. ``Point = NamedTuple("Point", x=int, y=int)``), |
| 1983 |
to be removed in Python 3.15. |
| 1984 |
Use the class-based syntax or the functional syntax instead. |
| 1985 |
(Contributed by Alex Waygood in :gh:`105566`.) |
| 1986 |
|
| 1987 |
* Deprecate omitting the *fields* parameter when creating |
| 1988 |
a :class:`~typing.NamedTuple` or :class:`typing.TypedDict` class, |
| 1989 |
and deprecate passing ``None`` to the *fields* parameter of both types. |
| 1990 |
Python 3.15 will require a valid sequence for the *fields* parameter. |
| 1991 |
To create a NamedTuple class with zero fields, |
| 1992 |
use ``class NT(NamedTuple): pass`` or ``NT = NamedTuple("NT", ())``. |
| 1993 |
To create a TypedDict class with zero fields, |
| 1994 |
use ``class TD(TypedDict): pass`` or ``TD = TypedDict("TD", {})``. |
| 1995 |
(Contributed by Alex Waygood in :gh:`105566` and :gh:`105570`.) |
| 1996 |
|
| 1997 |
* Deprecate the :func:`typing.no_type_check_decorator` decorator function, |
| 1998 |
to be removed in Python 3.15. |
| 1999 |
After eight years in the :mod:`typing` module, |
| 2000 |
it has yet to be supported by any major type checker. |
| 2001 |
(Contributed by Alex Waygood in :gh:`106309`.) |
| 2002 |
|
| 2003 |
* Deprecate :data:`typing.AnyStr`. |
| 2004 |
In Python 3.16, it will be removed from ``typing.__all__``, |
| 2005 |
and a :exc:`DeprecationWarning` will be emitted at runtime |
| 2006 |
when it is imported or accessed. |
| 2007 |
It will be removed entirely in Python 3.18. |
| 2008 |
Use the new :ref:`type parameter syntax <type-params>` instead. |
| 2009 |
(Contributed by Michael The in :gh:`107116`.) |
| 2010 |
|
| 2011 |
* :mod:`wave`: |
| 2012 |
|
| 2013 |
* Deprecate the :meth:`~wave.Wave_read.getmark`, :meth:`!setmark`, |
| 2014 |
and :meth:`~wave.Wave_read.getmarkers` methods of |
| 2015 |
the :class:`~wave.Wave_read` and :class:`~wave.Wave_write` classes, |
| 2016 |
to be removed in Python 3.15. |
| 2017 |
(Contributed by Victor Stinner in :gh:`105096`.) |
| 2018 |
|
| 2019 |
.. Add deprecations above alphabetically, not here at the end. |
| 2020 |
|
| 2021 |
.. include:: ../deprecations/pending-removal-in-3.14.rst |
| 2022 |
|
| 2023 |
.. include:: ../deprecations/pending-removal-in-3.15.rst |
| 2024 |
|
| 2025 |
.. include:: ../deprecations/pending-removal-in-3.16.rst |
| 2026 |
|
| 2027 |
.. include:: ../deprecations/pending-removal-in-3.17.rst |
| 2028 |
|
| 2029 |
.. include:: ../deprecations/pending-removal-in-3.18.rst |
| 2030 |
|
| 2031 |
.. include:: ../deprecations/pending-removal-in-3.19.rst |
| 2032 |
|
| 2033 |
.. include:: ../deprecations/pending-removal-in-future.rst |
| 2034 |
|
| 2035 |
CPython Bytecode Changes |
| 2036 |
======================== |
| 2037 |
|
| 2038 |
* The oparg of :opcode:`YIELD_VALUE` is now |
| 2039 |
``1`` if the yield is part of a yield-from or await, and ``0`` otherwise. |
| 2040 |
The oparg of :opcode:`RESUME` was changed to add a bit indicating |
| 2041 |
if the except-depth is 1, which is needed to optimize closing of generators. |
| 2042 |
(Contributed by Irit Katriel in :gh:`111354`.) |
| 2043 |
|
| 2044 |
|
| 2045 |
C API Changes |
| 2046 |
============= |
| 2047 |
|
| 2048 |
New Features |
| 2049 |
------------ |
| 2050 |
|
| 2051 |
* Add the :ref:`PyMonitoring C API <c-api-monitoring>` |
| 2052 |
for generating :pep:`669` monitoring events: |
| 2053 |
|
| 2054 |
* :c:type:`PyMonitoringState` |
| 2055 |
* :c:func:`PyMonitoring_FirePyStartEvent` |
| 2056 |
* :c:func:`PyMonitoring_FirePyResumeEvent` |
| 2057 |
* :c:func:`PyMonitoring_FirePyReturnEvent` |
| 2058 |
* :c:func:`PyMonitoring_FirePyYieldEvent` |
| 2059 |
* :c:func:`PyMonitoring_FireCallEvent` |
| 2060 |
* :c:func:`PyMonitoring_FireLineEvent` |
| 2061 |
* :c:func:`PyMonitoring_FireJumpEvent` |
| 2062 |
* ``PyMonitoring_FireBranchEvent`` |
| 2063 |
* :c:func:`PyMonitoring_FireCReturnEvent` |
| 2064 |
* :c:func:`PyMonitoring_FirePyThrowEvent` |
| 2065 |
* :c:func:`PyMonitoring_FireRaiseEvent` |
| 2066 |
* :c:func:`PyMonitoring_FireCRaiseEvent` |
| 2067 |
* :c:func:`PyMonitoring_FireReraiseEvent` |
| 2068 |
* :c:func:`PyMonitoring_FireExceptionHandledEvent` |
| 2069 |
* :c:func:`PyMonitoring_FirePyUnwindEvent` |
| 2070 |
* :c:func:`PyMonitoring_FireStopIterationEvent` |
| 2071 |
* :c:func:`PyMonitoring_EnterScope` |
| 2072 |
* :c:func:`PyMonitoring_ExitScope` |
| 2073 |
|
| 2074 |
(Contributed by Irit Katriel in :gh:`111997`). |
| 2075 |
|
| 2076 |
* Add :c:type:`PyMutex`, a lightweight mutex that occupies a single byte, |
| 2077 |
and the new :c:func:`PyMutex_Lock` and :c:func:`PyMutex_Unlock` functions. |
| 2078 |
:c:func:`!PyMutex_Lock` will release the :term:`GIL` (if currently held) |
| 2079 |
if the operation needs to block. |
| 2080 |
(Contributed by Sam Gross in :gh:`108724`.) |
| 2081 |
|
| 2082 |
* Add the :ref:`PyTime C API <c-api-time>` to provide access to system clocks: |
| 2083 |
|
| 2084 |
* :c:type:`PyTime_t`. |
| 2085 |
* :c:var:`PyTime_MIN` and :c:var:`PyTime_MAX`. |
| 2086 |
* :c:func:`PyTime_AsSecondsDouble`. |
| 2087 |
* :c:func:`PyTime_Monotonic`. |
| 2088 |
* :c:func:`PyTime_MonotonicRaw`. |
| 2089 |
* :c:func:`PyTime_PerfCounter`. |
| 2090 |
* :c:func:`PyTime_PerfCounterRaw`. |
| 2091 |
* :c:func:`PyTime_Time`. |
| 2092 |
* :c:func:`PyTime_TimeRaw`. |
| 2093 |
|
| 2094 |
(Contributed by Victor Stinner and Petr Viktorin in :gh:`110850`.) |
| 2095 |
|
| 2096 |
* Add the :c:func:`PyDict_ContainsString` function |
| 2097 |
with the same behavior as :c:func:`PyDict_Contains`, |
| 2098 |
but *key* is specified as a :c:expr:`const char*` UTF-8 encoded bytes string, |
| 2099 |
rather than a :c:expr:`PyObject*`. |
| 2100 |
(Contributed by Victor Stinner in :gh:`108314`.) |
| 2101 |
|
| 2102 |
* Add the :c:func:`PyDict_GetItemRef` and :c:func:`PyDict_GetItemStringRef` |
| 2103 |
functions, |
| 2104 |
which behave similarly to :c:func:`PyDict_GetItemWithError`, |
| 2105 |
but return a :term:`strong reference` instead of a :term:`borrowed reference`. |
| 2106 |
Moreover, these functions return ``-1`` on error, |
| 2107 |
removing the need to check :c:func:`!PyErr_Occurred`. |
| 2108 |
(Contributed by Victor Stinner in :gh:`106004`.) |
| 2109 |
|
| 2110 |
* Add the :c:func:`PyDict_SetDefaultRef` function, |
| 2111 |
which behaves similarly to :c:func:`PyDict_SetDefault`, |
| 2112 |
but returns a :term:`strong reference` instead of a :term:`borrowed reference`. |
| 2113 |
This function returns ``-1`` on error, |
| 2114 |
``0`` on insertion, |
| 2115 |
and ``1`` if the key was already present in the dictionary. |
| 2116 |
(Contributed by Sam Gross in :gh:`112066`.) |
| 2117 |
|
| 2118 |
* Add the :c:func:`PyDict_Pop` and :c:func:`PyDict_PopString` functions |
| 2119 |
to remove a key from a dictionary and optionally return the removed value. |
| 2120 |
This is similar to :meth:`dict.pop`, |
| 2121 |
though there is no default value, |
| 2122 |
and :exc:`KeyError` is not raised for missing keys. |
| 2123 |
(Contributed by Stefan Behnel and Victor Stinner in :gh:`111262`.) |
| 2124 |
|
| 2125 |
* Add the :c:func:`PyMapping_GetOptionalItem` |
| 2126 |
and :c:func:`PyMapping_GetOptionalItemString` functions |
| 2127 |
as alternatives to :c:func:`PyObject_GetItem` |
| 2128 |
and :c:func:`PyMapping_GetItemString` respectively. |
| 2129 |
The new functions do not raise :exc:`KeyError` |
| 2130 |
if the requested key is missing from the mapping. |
| 2131 |
These variants are more convenient and faster |
| 2132 |
if a missing key should not be treated as a failure. |
| 2133 |
(Contributed by Serhiy Storchaka in :gh:`106307`.) |
| 2134 |
|
| 2135 |
* Add the :c:func:`PyObject_GetOptionalAttr` |
| 2136 |
and :c:func:`PyObject_GetOptionalAttrString` functions |
| 2137 |
as alternatives to :c:func:`PyObject_GetAttr` |
| 2138 |
and :c:func:`PyObject_GetAttrString` respectively. |
| 2139 |
The new functions do not raise :exc:`AttributeError` |
| 2140 |
if the requested attribute is not found on the object. |
| 2141 |
These variants are more convenient and faster |
| 2142 |
if the missing attribute should not be treated as a failure. |
| 2143 |
(Contributed by Serhiy Storchaka in :gh:`106521`.) |
| 2144 |
|
| 2145 |
* Add the :c:func:`PyErr_FormatUnraisable` function |
| 2146 |
as an extension to :c:func:`PyErr_WriteUnraisable` |
| 2147 |
that allows customizing the warning message. |
| 2148 |
(Contributed by Serhiy Storchaka in :gh:`108082`.) |
| 2149 |
|
| 2150 |
* Add new functions that return a :term:`strong reference` instead of |
| 2151 |
a :term:`borrowed reference` for frame locals, globals, and builtins, |
| 2152 |
as part of :ref:`PEP 667 <whatsnew313-locals-semantics>`: |
| 2153 |
|
| 2154 |
* :c:func:`PyEval_GetFrameBuiltins` replaces :c:func:`PyEval_GetBuiltins` |
| 2155 |
* :c:func:`PyEval_GetFrameGlobals` replaces :c:func:`PyEval_GetGlobals` |
| 2156 |
* :c:func:`PyEval_GetFrameLocals` replaces :c:func:`PyEval_GetLocals` |
| 2157 |
|
| 2158 |
(Contributed by Mark Shannon and Tian Gao in :gh:`74929`.) |
| 2159 |
|
| 2160 |
* Add the :c:func:`Py_GetConstant` and :c:func:`Py_GetConstantBorrowed` |
| 2161 |
functions to get :term:`strong <strong reference>` |
| 2162 |
or :term:`borrowed <borrowed reference>` references to constants. |
| 2163 |
For example, ``Py_GetConstant(Py_CONSTANT_ZERO)`` returns a strong reference |
| 2164 |
to the constant zero. |
| 2165 |
(Contributed by Victor Stinner in :gh:`115754`.) |
| 2166 |
|
| 2167 |
* Add the :c:func:`PyImport_AddModuleRef` function |
| 2168 |
as a replacement for :c:func:`PyImport_AddModule` |
| 2169 |
that returns a :term:`strong reference` instead of a :term:`borrowed reference`. |
| 2170 |
(Contributed by Victor Stinner in :gh:`105922`.) |
| 2171 |
|
| 2172 |
* Add the :c:func:`Py_IsFinalizing` function to check |
| 2173 |
whether the main Python interpreter is |
| 2174 |
:term:`shutting down <interpreter shutdown>`. |
| 2175 |
(Contributed by Victor Stinner in :gh:`108014`.) |
| 2176 |
|
| 2177 |
* Add the :c:func:`PyList_GetItemRef` function |
| 2178 |
as a replacement for :c:func:`PyList_GetItem` |
| 2179 |
that returns a :term:`strong reference` instead of a :term:`borrowed reference`. |
| 2180 |
(Contributed by Sam Gross in :gh:`114329`.) |
| 2181 |
|
| 2182 |
* Add the :c:func:`PyList_Extend` and :c:func:`PyList_Clear` functions, |
| 2183 |
mirroring the Python :meth:`list.extend` and :meth:`list.clear` methods. |
| 2184 |
(Contributed by Victor Stinner in :gh:`111138`.) |
| 2185 |
|
| 2186 |
* Add the :c:func:`PyLong_AsInt` function. |
| 2187 |
It behaves similarly to :c:func:`PyLong_AsLong`, |
| 2188 |
but stores the result in a C :c:expr:`int` instead of a C :c:expr:`long`. |
| 2189 |
(Contributed by Victor Stinner in :gh:`108014`.) |
| 2190 |
|
| 2191 |
* Add the :c:func:`PyLong_AsNativeBytes`, :c:func:`PyLong_FromNativeBytes`, |
| 2192 |
and :c:func:`PyLong_FromUnsignedNativeBytes` functions |
| 2193 |
to simplify converting between native integer types |
| 2194 |
and Python :class:`int` objects. |
| 2195 |
(Contributed by Steve Dower in :gh:`111140`.) |
| 2196 |
|
| 2197 |
* Add :c:func:`PyModule_Add` function, which is similar to |
| 2198 |
:c:func:`PyModule_AddObjectRef` and :c:func:`PyModule_AddObject`, |
| 2199 |
but always steals a reference to the value. |
| 2200 |
(Contributed by Serhiy Storchaka in :gh:`86493`.) |
| 2201 |
|
| 2202 |
* Add the :c:func:`PyObject_GenericHash` function |
| 2203 |
that implements the default hashing function of a Python object. |
| 2204 |
(Contributed by Serhiy Storchaka in :gh:`113024`.) |
| 2205 |
|
| 2206 |
* Add the :c:func:`Py_HashPointer` function to hash a raw pointer. |
| 2207 |
(Contributed by Victor Stinner in :gh:`111545`.) |
| 2208 |
|
| 2209 |
* Add the :c:func:`PyObject_VisitManagedDict` and |
| 2210 |
:c:func:`PyObject_ClearManagedDict` functions. |
| 2211 |
which must be called by the traverse and clear functions of a type using |
| 2212 |
the :c:macro:`Py_TPFLAGS_MANAGED_DICT` flag. |
| 2213 |
The `pythoncapi-compat project`_ can be used to |
| 2214 |
use these functions with Python 3.11 and 3.12. |
| 2215 |
(Contributed by Victor Stinner in :gh:`107073`.) |
| 2216 |
|
| 2217 |
* Add the :c:func:`PyRefTracer_SetTracer` |
| 2218 |
and :c:func:`PyRefTracer_GetTracer` functions, |
| 2219 |
which enable tracking object creation and destruction |
| 2220 |
in the same way that the :mod:`tracemalloc` module does. |
| 2221 |
(Contributed by Pablo Galindo in :gh:`93502`.) |
| 2222 |
|
| 2223 |
* Add the :c:func:`PySys_AuditTuple` function |
| 2224 |
as an alternative to :c:func:`PySys_Audit` |
| 2225 |
that takes event arguments as a Python :class:`tuple` object. |
| 2226 |
(Contributed by Victor Stinner in :gh:`85283`.) |
| 2227 |
|
| 2228 |
* Add the :c:func:`PyThreadState_GetUnchecked()` function |
| 2229 |
as an alternative to :c:func:`PyThreadState_Get()` |
| 2230 |
that doesn't kill the process with a fatal error if it is ``NULL``. |
| 2231 |
The caller is responsible for checking if the result is ``NULL``. |
| 2232 |
(Contributed by Victor Stinner in :gh:`108867`.) |
| 2233 |
|
| 2234 |
* Add the :c:func:`PyType_GetFullyQualifiedName` function |
| 2235 |
to get the type's fully qualified name. |
| 2236 |
The module name is prepended if :attr:`type.__module__` is |
| 2237 |
a string and is not equal to either ``'builtins'`` or ``'__main__'``. |
| 2238 |
(Contributed by Victor Stinner in :gh:`111696`.) |
| 2239 |
|
| 2240 |
* Add the :c:func:`PyType_GetModuleName` function |
| 2241 |
to get the type's module name. This is equivalent to getting the |
| 2242 |
:attr:`type.__module__` attribute. |
| 2243 |
(Contributed by Eric Snow and Victor Stinner in :gh:`111696`.) |
| 2244 |
|
| 2245 |
* Add the :c:func:`PyUnicode_EqualToUTF8AndSize` |
| 2246 |
and :c:func:`PyUnicode_EqualToUTF8` functions |
| 2247 |
to compare a Unicode object with a :c:expr:`const char*` UTF-8 encoded string |
| 2248 |
and ``1`` if they are equal or ``0`` otherwise. |
| 2249 |
These functions do not raise exceptions. |
| 2250 |
(Contributed by Serhiy Storchaka in :gh:`110289`.) |
| 2251 |
|
| 2252 |
* Add the :c:func:`PyWeakref_GetRef` function |
| 2253 |
as an alternative to :c:func:`PyWeakref_GetObject` |
| 2254 |
that returns a :term:`strong reference` |
| 2255 |
or ``NULL`` if the referent is no longer live. |
| 2256 |
(Contributed by Victor Stinner in :gh:`105927`.) |
| 2257 |
|
| 2258 |
* Add fixed variants of functions which silently ignore errors: |
| 2259 |
|
| 2260 |
* :c:func:`PyObject_HasAttrWithError` replaces :c:func:`PyObject_HasAttr`. |
| 2261 |
* :c:func:`PyObject_HasAttrStringWithError` |
| 2262 |
replaces :c:func:`PyObject_HasAttrString`. |
| 2263 |
* :c:func:`PyMapping_HasKeyWithError` replaces :c:func:`PyMapping_HasKey`. |
| 2264 |
* :c:func:`PyMapping_HasKeyStringWithError` |
| 2265 |
replaces :c:func:`PyMapping_HasKeyString`. |
| 2266 |
|
| 2267 |
The new functions return ``-1`` for errors |
| 2268 |
and the standard ``1`` for true and ``0`` for false. |
| 2269 |
|
| 2270 |
(Contributed by Serhiy Storchaka in :gh:`108511`.) |
| 2271 |
|
| 2272 |
|
| 2273 |
Changed C APIs |
| 2274 |
-------------- |
| 2275 |
|
| 2276 |
* The *keywords* parameter of :c:func:`PyArg_ParseTupleAndKeywords` |
| 2277 |
and :c:func:`PyArg_VaParseTupleAndKeywords` |
| 2278 |
now has type :c:expr:`char * const *` in C |
| 2279 |
and :c:expr:`const char * const *` in C++, |
| 2280 |
instead of :c:expr:`char **`. |
| 2281 |
In C++, this makes these functions compatible with arguments |
| 2282 |
of type :c:expr:`const char * const *`, :c:expr:`const char **`, |
| 2283 |
or :c:expr:`char * const *` without an explicit type cast. |
| 2284 |
In C, the functions only support arguments of type :c:expr:`char * const *`. |
| 2285 |
This can be overridden with the :c:macro:`PY_CXX_CONST` macro. |
| 2286 |
(Contributed by Serhiy Storchaka in :gh:`65210`.) |
| 2287 |
|
| 2288 |
* :c:func:`PyArg_ParseTupleAndKeywords` now supports |
| 2289 |
non-ASCII keyword parameter names. |
| 2290 |
(Contributed by Serhiy Storchaka in :gh:`110815`.) |
| 2291 |
|
| 2292 |
* The :c:func:`!PyCode_GetFirstFree` function is now unstable API |
| 2293 |
and is now named :c:func:`PyUnstable_Code_GetFirstFree`. |
| 2294 |
(Contributed by Bogdan Romanyuk in :gh:`115781`.) |
| 2295 |
|
| 2296 |
* The :c:func:`PyDict_GetItem`, :c:func:`PyDict_GetItemString`, |
| 2297 |
:c:func:`PyMapping_HasKey`, :c:func:`PyMapping_HasKeyString`, |
| 2298 |
:c:func:`PyObject_HasAttr`, :c:func:`PyObject_HasAttrString`, |
| 2299 |
and :c:func:`PySys_GetObject` functions, |
| 2300 |
each of which clears all errors which occurred when calling them |
| 2301 |
now reports these errors using :func:`sys.unraisablehook`. |
| 2302 |
You may replace them with other functions as recommended in the documentation. |
| 2303 |
(Contributed by Serhiy Storchaka in :gh:`106672`.) |
| 2304 |
|
| 2305 |
* Add support for the ``%T``, ``%#T``, ``%N`` and ``%#N`` formats |
| 2306 |
to :c:func:`PyUnicode_FromFormat`: |
| 2307 |
|
| 2308 |
* ``%T``: Get the fully qualified name of an object type |
| 2309 |
* ``%#T``: As above, but use a colon as the separator |
| 2310 |
* ``%N``: Get the fully qualified name of a type |
| 2311 |
* ``%#N``: As above, but use a colon as the separator |
| 2312 |
|
| 2313 |
See :pep:`737` for more information. |
| 2314 |
(Contributed by Victor Stinner in :gh:`111696`.) |
| 2315 |
|
| 2316 |
* You no longer have to define the ``PY_SSIZE_T_CLEAN`` macro before |
| 2317 |
including :file:`Python.h` when using ``#`` formats in |
| 2318 |
:ref:`format codes <arg-parsing-string-and-buffers>`. |
| 2319 |
APIs accepting the format codes always use ``Py_ssize_t`` for ``#`` formats. |
| 2320 |
(Contributed by Inada Naoki in :gh:`104922`.) |
| 2321 |
|
| 2322 |
* If Python is built in :ref:`debug mode <debug-build>` |
| 2323 |
or :option:`with assertions <--with-assertions>`, |
| 2324 |
:c:func:`PyTuple_SET_ITEM` and :c:func:`PyList_SET_ITEM` |
| 2325 |
now check the index argument with an assertion. |
| 2326 |
(Contributed by Victor Stinner in :gh:`106168`.) |
| 2327 |
|
| 2328 |
|
| 2329 |
Limited C API Changes |
| 2330 |
--------------------- |
| 2331 |
|
| 2332 |
* The following functions are now included in the Limited C API: |
| 2333 |
|
| 2334 |
* :c:func:`PyMem_RawMalloc` |
| 2335 |
* :c:func:`PyMem_RawCalloc` |
| 2336 |
* :c:func:`PyMem_RawRealloc` |
| 2337 |
* :c:func:`PyMem_RawFree` |
| 2338 |
* :c:func:`PySys_Audit` |
| 2339 |
* :c:func:`PySys_AuditTuple` |
| 2340 |
* :c:func:`PyType_GetModuleByDef` |
| 2341 |
|
| 2342 |
(Contributed by Victor Stinner in :gh:`85283` and :gh:`116936`.) |
| 2343 |
|
| 2344 |
* Python built with :option:`--with-trace-refs` (tracing references) |
| 2345 |
now supports the :ref:`Limited API <limited-c-api>`. |
| 2346 |
(Contributed by Victor Stinner in :gh:`108634`.) |
| 2347 |
|
| 2348 |
|
| 2349 |
Removed C APIs |
| 2350 |
-------------- |
| 2351 |
|
| 2352 |
* Remove several functions, macros, variables, etc |
| 2353 |
with names prefixed by ``_Py`` or ``_PY`` (which are considered private). |
| 2354 |
If your project is affected by one of these removals |
| 2355 |
and you believe that the removed API should remain available, |
| 2356 |
please :ref:`open a new issue <using-the-tracker>` to request a public C API |
| 2357 |
and add ``cc: @vstinner`` to the issue to notify Victor Stinner. |
| 2358 |
(Contributed by Victor Stinner in :gh:`106320`.) |
| 2359 |
|
| 2360 |
* Remove old buffer protocols deprecated in Python 3.0. |
| 2361 |
Use :ref:`bufferobjects` instead. |
| 2362 |
|
| 2363 |
* :c:func:`!PyObject_CheckReadBuffer`: |
| 2364 |
Use :c:func:`PyObject_CheckBuffer` to test |
| 2365 |
whether the object supports the buffer protocol. |
| 2366 |
Note that :c:func:`PyObject_CheckBuffer` doesn't guarantee |
| 2367 |
that :c:func:`PyObject_GetBuffer` will succeed. |
| 2368 |
To test if the object is actually readable, |
| 2369 |
see the next example of :c:func:`PyObject_GetBuffer`. |
| 2370 |
|
| 2371 |
* :c:func:`!PyObject_AsCharBuffer`, :c:func:`!PyObject_AsReadBuffer`: |
| 2372 |
Use :c:func:`PyObject_GetBuffer` and :c:func:`PyBuffer_Release` instead: |
| 2373 |
|
| 2374 |
.. code-block:: c |
| 2375 |
|
| 2376 |
Py_buffer view; |
| 2377 |
if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) < 0) { |
| 2378 |
return NULL; |
| 2379 |
} |
| 2380 |
// Use `view.buf` and `view.len` to read from the buffer. |
| 2381 |
// You may need to cast buf as `(const char*)view.buf`. |
| 2382 |
PyBuffer_Release(&view); |
| 2383 |
|
| 2384 |
* :c:func:`!PyObject_AsWriteBuffer`: |
| 2385 |
Use :c:func:`PyObject_GetBuffer` and :c:func:`PyBuffer_Release` instead: |
| 2386 |
|
| 2387 |
.. code-block:: c |
| 2388 |
|
| 2389 |
Py_buffer view; |
| 2390 |
if (PyObject_GetBuffer(obj, &view, PyBUF_WRITABLE) < 0) { |
| 2391 |
return NULL; |
| 2392 |
} |
| 2393 |
// Use `view.buf` and `view.len` to write to the buffer. |
| 2394 |
PyBuffer_Release(&view); |
| 2395 |
|
| 2396 |
(Contributed by Inada Naoki in :gh:`85275`.) |
| 2397 |
|
| 2398 |
* Remove various functions deprecated in Python 3.9: |
| 2399 |
|
| 2400 |
* :c:func:`!PyEval_CallObject`, :c:func:`!PyEval_CallObjectWithKeywords`: |
| 2401 |
Use :c:func:`PyObject_CallNoArgs` or :c:func:`PyObject_Call` instead. |
| 2402 |
|
| 2403 |
.. warning:: |
| 2404 |
|
| 2405 |
In :c:func:`PyObject_Call`, positional arguments must be a :class:`tuple` |
| 2406 |
and must not be ``NULL``, |
| 2407 |
and keyword arguments must be a :class:`dict` or ``NULL``, |
| 2408 |
whereas the removed functions checked argument types |
| 2409 |
and accepted ``NULL`` positional and keyword arguments. |
| 2410 |
To replace ``PyEval_CallObjectWithKeywords(func, NULL, kwargs)`` with |
| 2411 |
:c:func:`PyObject_Call`, |
| 2412 |
pass an empty tuple as positional arguments using |
| 2413 |
:c:func:`PyTuple_New(0) <PyTuple_New>`. |
| 2414 |
|
| 2415 |
* :c:func:`!PyEval_CallFunction`: |
| 2416 |
Use :c:func:`PyObject_CallFunction` instead. |
| 2417 |
* :c:func:`!PyEval_CallMethod`: |
| 2418 |
Use :c:func:`PyObject_CallMethod` instead. |
| 2419 |
* :c:func:`!PyCFunction_Call`: |
| 2420 |
Use :c:func:`PyObject_Call` instead. |
| 2421 |
|
| 2422 |
(Contributed by Victor Stinner in :gh:`105107`.) |
| 2423 |
|
| 2424 |
* Remove the following old functions to configure the Python initialization, |
| 2425 |
deprecated in Python 3.11: |
| 2426 |
|
| 2427 |
* :c:func:`!PySys_AddWarnOptionUnicode`: |
| 2428 |
Use :c:member:`PyConfig.warnoptions` instead. |
| 2429 |
* :c:func:`!PySys_AddWarnOption`: |
| 2430 |
Use :c:member:`PyConfig.warnoptions` instead. |
| 2431 |
* :c:func:`!PySys_AddXOption`: |
| 2432 |
Use :c:member:`PyConfig.xoptions` instead. |
| 2433 |
* :c:func:`!PySys_HasWarnOptions`: |
| 2434 |
Use :c:member:`PyConfig.xoptions` instead. |
| 2435 |
* :c:func:`!PySys_SetPath`: |
| 2436 |
Set :c:member:`PyConfig.module_search_paths` instead. |
| 2437 |
* :c:func:`!Py_SetPath`: |
| 2438 |
Set :c:member:`PyConfig.module_search_paths` instead. |
| 2439 |
* :c:func:`!Py_SetStandardStreamEncoding`: |
| 2440 |
Set :c:member:`PyConfig.stdio_encoding` instead, |
| 2441 |
and set also maybe :c:member:`PyConfig.legacy_windows_stdio` (on Windows). |
| 2442 |
* :c:func:`!_Py_SetProgramFullPath`: |
| 2443 |
Set :c:member:`PyConfig.executable` instead. |
| 2444 |
|
| 2445 |
Use the new :c:type:`PyConfig` API of the :ref:`Python Initialization |
| 2446 |
Configuration <init-config>` instead (:pep:`587`), added to Python 3.8. |
| 2447 |
(Contributed by Victor Stinner in :gh:`105145`.) |
| 2448 |
|
| 2449 |
* Remove :c:func:`!PyEval_AcquireLock` and :c:func:`!PyEval_ReleaseLock` functions, |
| 2450 |
deprecated in Python 3.2. |
| 2451 |
They didn't update the current thread state. |
| 2452 |
They can be replaced with: |
| 2453 |
|
| 2454 |
* :c:func:`PyEval_SaveThread` and :c:func:`PyEval_RestoreThread`; |
| 2455 |
* low-level :c:func:`PyEval_AcquireThread` and :c:func:`PyEval_RestoreThread`; |
| 2456 |
* or :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release`. |
| 2457 |
|
| 2458 |
(Contributed by Victor Stinner in :gh:`105182`.) |
| 2459 |
|
| 2460 |
* Remove the :c:func:`!PyEval_ThreadsInitialized` function, |
| 2461 |
deprecated in Python 3.9. |
| 2462 |
Since Python 3.7, :c:func:`!Py_Initialize` always creates the GIL: |
| 2463 |
calling :c:func:`!PyEval_InitThreads` does nothing and |
| 2464 |
:c:func:`!PyEval_ThreadsInitialized` always returns non-zero. |
| 2465 |
(Contributed by Victor Stinner in :gh:`105182`.) |
| 2466 |
|
| 2467 |
* Remove the :c:func:`!_PyInterpreterState_Get` alias to |
| 2468 |
:c:func:`PyInterpreterState_Get()` |
| 2469 |
which was kept for backward compatibility with Python 3.8. |
| 2470 |
The `pythoncapi-compat project`_ can be used to get |
| 2471 |
:c:func:`PyInterpreterState_Get()` on Python 3.8 and older. |
| 2472 |
(Contributed by Victor Stinner in :gh:`106320`.) |
| 2473 |
|
| 2474 |
* Remove the private :c:func:`!_PyObject_FastCall` function: |
| 2475 |
use :c:func:`!PyObject_Vectorcall` which is available since Python 3.8 |
| 2476 |
(:pep:`590`). |
| 2477 |
(Contributed by Victor Stinner in :gh:`106023`.) |
| 2478 |
|
| 2479 |
* Remove the ``cpython/pytime.h`` header file, |
| 2480 |
which only contained private functions. |
| 2481 |
(Contributed by Victor Stinner in :gh:`106316`.) |
| 2482 |
|
| 2483 |
* Remove the undocumented ``PY_TIMEOUT_MAX`` constant from the limited C API. |
| 2484 |
(Contributed by Victor Stinner in :gh:`110014`.) |
| 2485 |
|
| 2486 |
* Remove the old trashcan macros ``Py_TRASHCAN_SAFE_BEGIN`` |
| 2487 |
and ``Py_TRASHCAN_SAFE_END``. |
| 2488 |
Replace both with the new macros ``Py_TRASHCAN_BEGIN`` |
| 2489 |
and ``Py_TRASHCAN_END``. |
| 2490 |
(Contributed by Irit Katriel in :gh:`105111`.) |
| 2491 |
|
| 2492 |
Deprecated C APIs |
| 2493 |
----------------- |
| 2494 |
|
| 2495 |
* Deprecate old Python initialization functions: |
| 2496 |
|
| 2497 |
* :c:func:`PySys_ResetWarnOptions`: |
| 2498 |
Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead. |
| 2499 |
* :c:func:`Py_GetExecPrefix`: |
| 2500 |
Get :data:`sys.exec_prefix` instead. |
| 2501 |
* :c:func:`Py_GetPath`: |
| 2502 |
Get :data:`sys.path` instead. |
| 2503 |
* :c:func:`Py_GetPrefix`: |
| 2504 |
Get :data:`sys.prefix` instead. |
| 2505 |
* :c:func:`Py_GetProgramFullPath`: |
| 2506 |
Get :data:`sys.executable` instead. |
| 2507 |
* :c:func:`Py_GetProgramName`: |
| 2508 |
Get :data:`sys.executable` instead. |
| 2509 |
* :c:func:`Py_GetPythonHome`: |
| 2510 |
Get :c:member:`PyConfig.home` |
| 2511 |
or the :envvar:`PYTHONHOME` environment variable instead. |
| 2512 |
|
| 2513 |
(Contributed by Victor Stinner in :gh:`105145`.) |
| 2514 |
|
| 2515 |
* :term:`Soft deprecate <soft deprecated>` the |
| 2516 |
:c:func:`PyEval_GetBuiltins`, :c:func:`PyEval_GetGlobals`, |
| 2517 |
and :c:func:`PyEval_GetLocals` functions, |
| 2518 |
which return a :term:`borrowed reference`. |
| 2519 |
(Soft deprecated as part of :pep:`667`.) |
| 2520 |
|
| 2521 |
* Deprecate the :c:func:`PyImport_ImportModuleNoBlock` function, |
| 2522 |
which is just an alias to :c:func:`PyImport_ImportModule` since Python 3.3. |
| 2523 |
(Contributed by Victor Stinner in :gh:`105396`.) |
| 2524 |
|
| 2525 |
* :term:`Soft deprecate <soft deprecated>` the |
| 2526 |
:c:func:`PyModule_AddObject` function. |
| 2527 |
It should be replaced with :c:func:`PyModule_Add` |
| 2528 |
or :c:func:`PyModule_AddObjectRef`. |
| 2529 |
(Contributed by Serhiy Storchaka in :gh:`86493`.) |
| 2530 |
|
| 2531 |
* Deprecate the old ``Py_UNICODE`` and ``PY_UNICODE_TYPE`` types |
| 2532 |
and the :c:macro:`!Py_UNICODE_WIDE` define. |
| 2533 |
Use the :c:type:`wchar_t` type directly instead. |
| 2534 |
Since Python 3.3, ``Py_UNICODE`` and ``PY_UNICODE_TYPE`` |
| 2535 |
are just aliases to :c:type:`!wchar_t`. |
| 2536 |
(Contributed by Victor Stinner in :gh:`105156`.) |
| 2537 |
|
| 2538 |
* Deprecate the :c:func:`PyWeakref_GetObject` and |
| 2539 |
:c:func:`PyWeakref_GET_OBJECT` functions, |
| 2540 |
which return a :term:`borrowed reference`. |
| 2541 |
Replace them with the new :c:func:`PyWeakref_GetRef` function, |
| 2542 |
which returns a :term:`strong reference`. |
| 2543 |
The `pythoncapi-compat project`_ can be used to get |
| 2544 |
:c:func:`PyWeakref_GetRef` on Python 3.12 and older. |
| 2545 |
(Contributed by Victor Stinner in :gh:`105927`.) |
| 2546 |
|
| 2547 |
.. Add deprecations above alphabetically, not here at the end. |
| 2548 |
|
| 2549 |
.. include:: ../deprecations/c-api-pending-removal-in-3.14.rst |
| 2550 |
|
| 2551 |
.. include:: ../deprecations/c-api-pending-removal-in-3.15.rst |
| 2552 |
|
| 2553 |
.. include:: ../deprecations/c-api-pending-removal-in-3.16.rst |
| 2554 |
|
| 2555 |
.. include:: ../deprecations/c-api-pending-removal-in-3.18.rst |
| 2556 |
|
| 2557 |
.. include:: ../deprecations/c-api-pending-removal-in-future.rst |
| 2558 |
|
| 2559 |
.. _pythoncapi-compat project: https://github.com/python/pythoncapi-compat/ |
| 2560 |
|
| 2561 |
Build Changes |
| 2562 |
============= |
| 2563 |
|
| 2564 |
* ``arm64-apple-ios`` and ``arm64-apple-ios-simulator`` are both |
| 2565 |
now :pep:`11` tier 3 platforms. |
| 2566 |
(:ref:`PEP 730 <whatsnew313-platform-support>` written |
| 2567 |
and implementation contributed by Russell Keith-Magee in :gh:`114099`.) |
| 2568 |
|
| 2569 |
* ``aarch64-linux-android`` and ``x86_64-linux-android`` are both |
| 2570 |
now :pep:`11` tier 3 platforms. |
| 2571 |
(:ref:`PEP 738 <whatsnew313-platform-support>` written |
| 2572 |
and implementation contributed by Malcolm Smith in :gh:`116622`.) |
| 2573 |
|
| 2574 |
* ``wasm32-wasi`` is now a :pep:`11` tier 2 platform. |
| 2575 |
(Contributed by Brett Cannon in :gh:`115192`.) |
| 2576 |
|
| 2577 |
* ``wasm32-emscripten`` is no longer a :pep:`11` supported platform. |
| 2578 |
(Contributed by Brett Cannon in :gh:`115192`.) |
| 2579 |
|
| 2580 |
* Building CPython now requires a compiler with support for the C11 atomic |
| 2581 |
library, GCC built-in atomic functions, or MSVC interlocked intrinsics. |
| 2582 |
|
| 2583 |
* Autoconf 2.71 and aclocal 1.16.5 are now required to regenerate |
| 2584 |
the :file:`configure` script. |
| 2585 |
(Contributed by Christian Heimes in :gh:`89886` and by Victor Stinner in :gh:`112090`.) |
| 2586 |
|
| 2587 |
* SQLite 3.15.2 or newer is required to build |
| 2588 |
the :mod:`sqlite3` extension module. |
| 2589 |
(Contributed by Erlend Aasland in :gh:`105875`.) |
| 2590 |
|
| 2591 |
* CPython now bundles the `mimalloc library`_ by default. |
| 2592 |
It is licensed under the MIT license; |
| 2593 |
see :ref:`mimalloc license <mimalloc-license>`. |
| 2594 |
The bundled mimalloc has custom changes, see :gh:`113141` for details. |
| 2595 |
(Contributed by Dino Viehland in :gh:`109914`.) |
| 2596 |
|
| 2597 |
.. _mimalloc library: https://github.com/microsoft/mimalloc/ |
| 2598 |
|
| 2599 |
* The :file:`configure` option :option:`--with-system-libmpdec` |
| 2600 |
now defaults to ``yes``. |
| 2601 |
The bundled copy of ``libmpdec`` will be removed in Python 3.16. |
| 2602 |
|
| 2603 |
* Python built with :file:`configure` :option:`--with-trace-refs` |
| 2604 |
(tracing references) is now ABI compatible with the Python release build |
| 2605 |
and :ref:`debug build <debug-build>`. |
| 2606 |
(Contributed by Victor Stinner in :gh:`108634`.) |
| 2607 |
|
| 2608 |
* On POSIX systems, the pkg-config (``.pc``) filenames now include the ABI |
| 2609 |
flags. For example, the free-threaded build generates ``python-3.13t.pc`` |
| 2610 |
and the debug build generates ``python-3.13d.pc``. |
| 2611 |
|
| 2612 |
* The ``errno``, ``fcntl``, ``grp``, ``md5``, ``pwd``, ``resource``, |
| 2613 |
``termios``, ``winsound``, |
| 2614 |
``_ctypes_test``, ``_multiprocessing.posixshmem``, ``_scproxy``, ``_stat``, |
| 2615 |
``_statistics``, ``_testconsole``, ``_testimportmultiple`` and ``_uuid`` |
| 2616 |
C extensions are now built with the :ref:`limited C API <limited-c-api>`. |
| 2617 |
(Contributed by Victor Stinner in :gh:`85283`.) |
| 2618 |
|
| 2619 |
|
| 2620 |
Porting to Python 3.13 |
| 2621 |
====================== |
| 2622 |
|
| 2623 |
This section lists previously described changes and other bugfixes |
| 2624 |
that may require changes to your code. |
| 2625 |
|
| 2626 |
Changes in the Python API |
| 2627 |
------------------------- |
| 2628 |
|
| 2629 |
.. _pep667-porting-notes-py: |
| 2630 |
|
| 2631 |
* :ref:`PEP 667 <whatsnew313-locals-semantics>` introduces several changes |
| 2632 |
to the semantics of :func:`locals` and :attr:`f_locals <frame.f_locals>`: |
| 2633 |
|
| 2634 |
* Calling :func:`locals` in an :term:`optimized scope` now produces an |
| 2635 |
independent snapshot on each call, and hence no longer implicitly updates |
| 2636 |
previously returned references. Obtaining the legacy CPython behavior now |
| 2637 |
requires explicit calls to update the initially returned dictionary with the |
| 2638 |
results of subsequent calls to :func:`!locals`. Code execution functions that |
| 2639 |
implicitly target :func:`!locals` (such as ``exec`` and ``eval``) must be |
| 2640 |
passed an explicit namespace to access their results in an optimized scope. |
| 2641 |
(Changed as part of :pep:`667`.) |
| 2642 |
|
| 2643 |
* Calling :func:`locals` from a comprehension at module or class scope |
| 2644 |
(including via ``exec`` or ``eval``) once more behaves as if the comprehension |
| 2645 |
were running as an independent nested function (i.e. the local variables from |
| 2646 |
the containing scope are not included). In Python 3.12, this had changed |
| 2647 |
to include the local variables from the containing scope when implementing |
| 2648 |
:pep:`709`. (Changed as part of :pep:`667`.) |
| 2649 |
|
| 2650 |
* Accessing :attr:`FrameType.f_locals <frame.f_locals>` in an |
| 2651 |
:term:`optimized scope` now returns a write-through proxy rather than a |
| 2652 |
snapshot that gets updated at ill-specified times. If a snapshot is desired, |
| 2653 |
it must be created explicitly with ``dict`` or the proxy's ``.copy()`` method. |
| 2654 |
(Changed as part of :pep:`667`.) |
| 2655 |
|
| 2656 |
* :class:`functools.partial` now emits a :exc:`FutureWarning` |
| 2657 |
when used as a method. |
| 2658 |
The behavior will change in future Python versions. |
| 2659 |
Wrap it in :func:`staticmethod` if you want to preserve the old behavior. |
| 2660 |
(Contributed by Serhiy Storchaka in :gh:`121027`.) |
| 2661 |
|
| 2662 |
* An :exc:`OSError` is now raised by :func:`getpass.getuser` |
| 2663 |
for any failure to retrieve a username, |
| 2664 |
instead of :exc:`ImportError` on non-Unix platforms |
| 2665 |
or :exc:`KeyError` on Unix platforms where the password database is empty. |
| 2666 |
|
| 2667 |
* The value of the :attr:`!mode` attribute of :class:`gzip.GzipFile` |
| 2668 |
is now a string (``'rb'`` or ``'wb'``) instead of an integer (``1`` or ``2``). |
| 2669 |
The value of the :attr:`!mode` attribute of the readable file-like object |
| 2670 |
returned by :meth:`zipfile.ZipFile.open` is now ``'rb'`` instead of ``'r'``. |
| 2671 |
(Contributed by Serhiy Storchaka in :gh:`115961`.) |
| 2672 |
|
| 2673 |
* :class:`mailbox.Maildir` now ignores files with a leading dot (``.``). |
| 2674 |
(Contributed by Zackery Spytz in :gh:`65559`.) |
| 2675 |
|
| 2676 |
* :meth:`pathlib.Path.glob` and :meth:`~pathlib.Path.rglob` now return both |
| 2677 |
files and directories if a pattern that ends with "``**``" is given, |
| 2678 |
rather than directories only. |
| 2679 |
Add a trailing slash to keep the previous behavior and only match directories. |
| 2680 |
|
| 2681 |
* The :mod:`threading` module now expects the :mod:`!_thread` module |
| 2682 |
to have an :func:`!_is_main_interpreter` function. |
| 2683 |
This function takes no arguments and returns ``True`` |
| 2684 |
if the current interpreter is the main interpreter. |
| 2685 |
|
| 2686 |
Any library or application that provides a custom :mod:`!_thread` module |
| 2687 |
must provide :func:`!_is_main_interpreter`, |
| 2688 |
just like the module's other "private" attributes. |
| 2689 |
(:gh:`112826`.) |
| 2690 |
|
| 2691 |
|
| 2692 |
Changes in the C API |
| 2693 |
-------------------- |
| 2694 |
|
| 2695 |
* ``Python.h`` no longer includes the ``<ieeefp.h>`` standard header. It was |
| 2696 |
included for the :c:func:`!finite` function which is now provided by the |
| 2697 |
``<math.h>`` header. It should now be included explicitly if needed. Remove |
| 2698 |
also the ``HAVE_IEEEFP_H`` macro. |
| 2699 |
(Contributed by Victor Stinner in :gh:`108765`.) |
| 2700 |
|
| 2701 |
* ``Python.h`` no longer includes these standard header files: ``<time.h>``, |
| 2702 |
``<sys/select.h>`` and ``<sys/time.h>``. If needed, they should now be |
| 2703 |
included explicitly. For example, ``<time.h>`` provides the :c:func:`!clock` and |
| 2704 |
:c:func:`!gmtime` functions, ``<sys/select.h>`` provides the :c:func:`!select` |
| 2705 |
function, and ``<sys/time.h>`` provides the :c:func:`!futimes`, :c:func:`!gettimeofday` |
| 2706 |
and :c:func:`!setitimer` functions. |
| 2707 |
(Contributed by Victor Stinner in :gh:`108765`.) |
| 2708 |
|
| 2709 |
* On Windows, ``Python.h`` no longer includes the ``<stddef.h>`` standard |
| 2710 |
header file. If needed, it should now be included explicitly. For example, it |
| 2711 |
provides :c:func:`!offsetof` function, and ``size_t`` and ``ptrdiff_t`` types. |
| 2712 |
Including ``<stddef.h>`` explicitly was already needed by all other |
| 2713 |
platforms, the ``HAVE_STDDEF_H`` macro is only defined on Windows. |
| 2714 |
(Contributed by Victor Stinner in :gh:`108765`.) |
| 2715 |
|
| 2716 |
* If the :c:macro:`Py_LIMITED_API` macro is defined, :c:macro:`!Py_BUILD_CORE`, |
| 2717 |
:c:macro:`!Py_BUILD_CORE_BUILTIN` and :c:macro:`!Py_BUILD_CORE_MODULE` macros |
| 2718 |
are now undefined by ``<Python.h>``. |
| 2719 |
(Contributed by Victor Stinner in :gh:`85283`.) |
| 2720 |
|
| 2721 |
* The old trashcan macros ``Py_TRASHCAN_SAFE_BEGIN`` and ``Py_TRASHCAN_SAFE_END`` |
| 2722 |
were removed. They should be replaced by the new macros ``Py_TRASHCAN_BEGIN`` |
| 2723 |
and ``Py_TRASHCAN_END``. |
| 2724 |
|
| 2725 |
A ``tp_dealloc`` function that has the old macros, such as:: |
| 2726 |
|
| 2727 |
static void |
| 2728 |
mytype_dealloc(mytype *p) |
| 2729 |
{ |
| 2730 |
PyObject_GC_UnTrack(p); |
| 2731 |
Py_TRASHCAN_SAFE_BEGIN(p); |
| 2732 |
... |
| 2733 |
Py_TRASHCAN_SAFE_END |
| 2734 |
} |
| 2735 |
|
| 2736 |
should migrate to the new macros as follows:: |
| 2737 |
|
| 2738 |
static void |
| 2739 |
mytype_dealloc(mytype *p) |
| 2740 |
{ |
| 2741 |
PyObject_GC_UnTrack(p); |
| 2742 |
Py_TRASHCAN_BEGIN(p, mytype_dealloc) |
| 2743 |
... |
| 2744 |
Py_TRASHCAN_END |
| 2745 |
} |
| 2746 |
|
| 2747 |
Note that ``Py_TRASHCAN_BEGIN`` has a second argument which |
| 2748 |
should be the deallocation function it is in. The new macros were |
| 2749 |
added in Python 3.8 and the old macros were deprecated in Python 3.11. |
| 2750 |
(Contributed by Irit Katriel in :gh:`105111`.) |
| 2751 |
|
| 2752 |
.. _pep667-porting-notes-c: |
| 2753 |
|
| 2754 |
* :ref:`PEP 667 <whatsnew313-locals-semantics>` introduces several changes |
| 2755 |
to frame-related functions: |
| 2756 |
|
| 2757 |
* The effects of mutating the dictionary returned from |
| 2758 |
:c:func:`PyEval_GetLocals` in an :term:`optimized scope` have changed. |
| 2759 |
New dict entries added this way will now *only* be visible to |
| 2760 |
subsequent :c:func:`PyEval_GetLocals` calls in that frame, |
| 2761 |
as :c:func:`PyFrame_GetLocals`, :func:`locals`, |
| 2762 |
and :attr:`FrameType.f_locals <frame.f_locals>` no longer access |
| 2763 |
the same underlying cached dictionary. |
| 2764 |
Changes made to entries for actual variable names and names added via |
| 2765 |
the write-through proxy interfaces will be overwritten on subsequent calls |
| 2766 |
to :c:func:`PyEval_GetLocals` in that frame. |
| 2767 |
The recommended code update depends on how the function was being used, |
| 2768 |
so refer to the deprecation notice on the function for details. |
| 2769 |
|
| 2770 |
* Calling :c:func:`PyFrame_GetLocals` in an :term:`optimized scope` |
| 2771 |
now returns a write-through proxy rather than a snapshot |
| 2772 |
that gets updated at ill-specified times. |
| 2773 |
If a snapshot is desired, it must be created explicitly |
| 2774 |
(e.g. with :c:func:`PyDict_Copy`), |
| 2775 |
or by calling the new :c:func:`PyEval_GetFrameLocals` API. |
| 2776 |
|
| 2777 |
* :c:func:`!PyFrame_FastToLocals` and :c:func:`!PyFrame_FastToLocalsWithError` |
| 2778 |
no longer have any effect. |
| 2779 |
Calling these functions has been redundant since Python 3.11, |
| 2780 |
when :c:func:`PyFrame_GetLocals` was first introduced. |
| 2781 |
|
| 2782 |
* :c:func:`!PyFrame_LocalsToFast` no longer has any effect. |
| 2783 |
Calling this function is redundant now that :c:func:`PyFrame_GetLocals` |
| 2784 |
returns a write-through proxy for :term:`optimized scopes <optimized scope>`. |
| 2785 |
|
| 2786 |
* Python 3.13 removed many private functions. Some of them can be replaced using these |
| 2787 |
alternatives: |
| 2788 |
|
| 2789 |
* ``_PyDict_Pop()``: :c:func:`PyDict_Pop` or :c:func:`PyDict_PopString`; |
| 2790 |
* ``_PyDict_GetItemWithError()``: :c:func:`PyDict_GetItemRef`; |
| 2791 |
* ``_PyErr_WriteUnraisableMsg()``: :c:func:`PyErr_FormatUnraisable`; |
| 2792 |
* ``_PyEval_SetTrace()``: :c:func:`PyEval_SetTrace` or :c:func:`PyEval_SetTraceAllThreads`; |
| 2793 |
* ``_PyList_Extend()``: :c:func:`PyList_Extend`; |
| 2794 |
* ``_PyLong_AsInt()``: :c:func:`PyLong_AsInt`; |
| 2795 |
* ``_PyMem_RawStrdup()``: ``strdup()``; |
| 2796 |
* ``_PyMem_Strdup()``: ``strdup()``; |
| 2797 |
* ``_PyObject_ClearManagedDict()``: :c:func:`PyObject_ClearManagedDict`; |
| 2798 |
* ``_PyObject_VisitManagedDict()``: :c:func:`PyObject_VisitManagedDict`; |
| 2799 |
* ``_PyThreadState_UncheckedGet()``: :c:func:`PyThreadState_GetUnchecked()`; |
| 2800 |
* ``_PyTime_AsSecondsDouble()``: :c:func:`PyTime_AsSecondsDouble`; |
| 2801 |
* ``_PyTime_GetMonotonicClock()``: :c:func:`PyTime_Monotonic` or :c:func:`PyTime_MonotonicRaw`; |
| 2802 |
* ``_PyTime_GetPerfCounter()``: :c:func:`PyTime_PerfCounter` or :c:func:`PyTime_PerfCounterRaw`; |
| 2803 |
* ``_PyTime_GetSystemClock()``: :c:func:`PyTime_Time` or :c:func:`PyTime_TimeRaw`; |
| 2804 |
* ``_PyTime_MAX``: :c:var:`PyTime_MAX`; |
| 2805 |
* ``_PyTime_MIN``: :c:var:`PyTime_MIN`; |
| 2806 |
* ``_PyTime_t``: :c:type:`PyTime_t`; |
| 2807 |
* ``_Py_HashPointer()``: :c:func:`Py_HashPointer`; |
| 2808 |
* ``_Py_IsFinalizing()``: :c:func:`Py_IsFinalizing`. |
| 2809 |
|
| 2810 |
The `pythoncapi-compat project`_ can be used to get most of these new |
| 2811 |
functions on Python 3.12 and older. |
| 2812 |
|
| 2813 |
Regression Test Changes |
| 2814 |
======================= |
| 2815 |
|
| 2816 |
* Python built with :file:`configure` :option:`--with-pydebug` now |
| 2817 |
supports a :option:`-X presite=package.module <-X>` command-line |
| 2818 |
option. If used, it specifies a module that should be imported early |
| 2819 |
in the lifecycle of the interpreter, before ``site.py`` is executed. |
| 2820 |
(Contributed by Łukasz Langa in :gh:`110769`.) |