| 1 |
|
| 2 |
**************************** |
| 3 |
What's new in Python 3.14 |
| 4 |
**************************** |
| 5 |
|
| 6 |
:Editors: Adam Turner and Hugo van Kemenade |
| 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.14, compared to 3.13. |
| 49 |
Python 3.14 was released on 7 October 2025. |
| 50 |
For full details, see the :ref:`changelog <changelog>`. |
| 51 |
|
| 52 |
.. seealso:: |
| 53 |
|
| 54 |
:pep:`745` -- Python 3.14 release schedule |
| 55 |
|
| 56 |
|
| 57 |
Summary -- Release highlights |
| 58 |
============================= |
| 59 |
|
| 60 |
.. This section singles out the most important changes in Python 3.14. |
| 61 |
Brevity is key. |
| 62 |
|
| 63 |
Python 3.14 is the latest 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 :ref:`template string literals |
| 67 |
<whatsnew314-template-string-literals>`, |
| 68 |
:ref:`deferred evaluation of annotations <whatsnew314-deferred-annotations>`, |
| 69 |
and support for :ref:`subinterpreters <whatsnew314-multiple-interpreters>` in |
| 70 |
the standard library. |
| 71 |
|
| 72 |
The library changes include significantly improved capabilities for |
| 73 |
:ref:`introspection in asyncio <whatsnew314-asyncio-introspection>`, |
| 74 |
:ref:`support for Zstandard <whatsnew314-zstandard>` via a new |
| 75 |
:mod:`compression.zstd` module, syntax highlighting in the REPL, |
| 76 |
as well as the usual deprecations and removals, |
| 77 |
and improvements in user-friendliness and correctness. |
| 78 |
|
| 79 |
This article doesn't attempt to provide a complete specification |
| 80 |
of all new features, but instead gives a convenient overview. |
| 81 |
For full details refer to the documentation, |
| 82 |
such as the :ref:`Library Reference <library-index>` |
| 83 |
and :ref:`Language Reference <reference-index>`. |
| 84 |
To understand the complete implementation and design rationale for a change, |
| 85 |
refer to the PEP for a particular new feature; |
| 86 |
but note that PEPs usually are not kept up-to-date |
| 87 |
once a feature has been fully implemented. |
| 88 |
See `Porting to Python 3.14`_ for guidance on upgrading from |
| 89 |
earlier versions of Python. |
| 90 |
|
| 91 |
-------------- |
| 92 |
|
| 93 |
.. PEP-sized items next. |
| 94 |
|
| 95 |
Interpreter improvements: |
| 96 |
|
| 97 |
* :pep:`649` and :pep:`749`: :ref:`Deferred evaluation of annotations |
| 98 |
<whatsnew314-deferred-annotations>` |
| 99 |
* :pep:`734`: :ref:`Multiple interpreters in the standard library |
| 100 |
<whatsnew314-multiple-interpreters>` |
| 101 |
* :pep:`750`: :ref:`Template strings <whatsnew314-template-string-literals>` |
| 102 |
* :pep:`758`: :ref:`Allow except and except* expressions without brackets |
| 103 |
<whatsnew314-bracketless-except>` |
| 104 |
* :pep:`765`: :ref:`Control flow in finally blocks |
| 105 |
<whatsnew314-finally-syntaxwarning>` |
| 106 |
* :pep:`768`: :ref:`Safe external debugger interface for CPython |
| 107 |
<whatsnew314-remote-debugging>` |
| 108 |
* :ref:`A new type of interpreter <whatsnew314-tail-call-interpreter>` |
| 109 |
* :ref:`Free-threaded mode improvements <whatsnew314-free-threaded-cpython>` |
| 110 |
* :ref:`Improved error messages <whatsnew314-improved-error-messages>` |
| 111 |
* :ref:`Incremental garbage collection <whatsnew314-incremental-gc>` |
| 112 |
|
| 113 |
Significant improvements in the standard library: |
| 114 |
|
| 115 |
* :pep:`784`: :ref:`Zstandard support in the standard library |
| 116 |
<whatsnew314-zstandard>` |
| 117 |
* :ref:`whatsnew314-asyncio-introspection` |
| 118 |
* :ref:`whatsnew314-concurrent-warnings-control` |
| 119 |
* :ref:`Syntax highlighting in the default interactive shell |
| 120 |
<whatsnew314-pyrepl-highlighting>`, and color output in several |
| 121 |
standard library CLIs |
| 122 |
|
| 123 |
C API improvements: |
| 124 |
|
| 125 |
* :pep:`741`: :ref:`Python configuration C API <whatsnew314-capi-config>` |
| 126 |
|
| 127 |
Platform support: |
| 128 |
|
| 129 |
* :pep:`776`: Emscripten is now an :ref:`officially supported platform |
| 130 |
<whatsnew314-build-changes>`, at :pep:`tier 3 <11#tier-3>`. |
| 131 |
|
| 132 |
Release changes: |
| 133 |
|
| 134 |
* :pep:`779`: :ref:`Free-threaded Python is officially supported |
| 135 |
<whatsnew314-free-threaded-now-supported>` |
| 136 |
* :pep:`761`: :ref:`PGP signatures have been discontinued for official releases |
| 137 |
<whatsnew314-no-more-pgp>` |
| 138 |
* :ref:`Windows and macOS binary releases now support the experimental |
| 139 |
just-in-time compiler <whatsnew314-jit-compiler>` |
| 140 |
* :ref:`Binary releases for Android are now provided <whatsnew314-build-changes>` |
| 141 |
|
| 142 |
|
| 143 |
New features |
| 144 |
============ |
| 145 |
|
| 146 |
.. _whatsnew314-deferred-annotations: |
| 147 |
|
| 148 |
:pep:`649` & :pep:`749`: Deferred evaluation of annotations |
| 149 |
------------------------------------------------------------ |
| 150 |
|
| 151 |
The :term:`annotations <annotation>` on functions, classes, and modules are no |
| 152 |
longer evaluated eagerly. Instead, annotations are stored in special-purpose |
| 153 |
:term:`annotate functions <annotate function>` and evaluated only when |
| 154 |
necessary (except if ``from __future__ import annotations`` is used). |
| 155 |
|
| 156 |
This change is designed to improve performance and usability of annotations |
| 157 |
in Python in most circumstances. The runtime cost for defining annotations is |
| 158 |
minimized, but it remains possible to introspect annotations at runtime. |
| 159 |
It is no longer necessary to enclose annotations in strings if they |
| 160 |
contain forward references. |
| 161 |
|
| 162 |
The new :mod:`annotationlib` module provides tools for inspecting deferred |
| 163 |
annotations. Annotations may be evaluated in the :attr:`~annotationlib.Format.VALUE` |
| 164 |
format (which evaluates annotations to runtime values, similar to the behavior in |
| 165 |
earlier Python versions), the :attr:`~annotationlib.Format.FORWARDREF` format |
| 166 |
(which replaces undefined names with special markers), and the |
| 167 |
:attr:`~annotationlib.Format.STRING` format (which returns annotations as strings). |
| 168 |
|
| 169 |
This example shows how these formats behave: |
| 170 |
|
| 171 |
.. doctest:: |
| 172 |
|
| 173 |
>>> from annotationlib import get_annotations, Format |
| 174 |
>>> def func(arg: Undefined): |
| 175 |
... pass |
| 176 |
>>> get_annotations(func, format=Format.VALUE) |
| 177 |
Traceback (most recent call last): |
| 178 |
... |
| 179 |
NameError: name 'Undefined' is not defined |
| 180 |
>>> get_annotations(func, format=Format.FORWARDREF) |
| 181 |
{'arg': ForwardRef('Undefined', owner=<function func at 0x...>)} |
| 182 |
>>> get_annotations(func, format=Format.STRING) |
| 183 |
{'arg': 'Undefined'} |
| 184 |
|
| 185 |
The :ref:`porting <whatsnew314-porting-annotations>` section contains guidance |
| 186 |
on changes that may be needed due to these changes, though in the majority of |
| 187 |
cases, code will continue working as-is. |
| 188 |
|
| 189 |
(Contributed by Jelle Zijlstra in :pep:`749` and :gh:`119180`; |
| 190 |
:pep:`649` was written by Larry Hastings.) |
| 191 |
|
| 192 |
.. seealso:: |
| 193 |
|
| 194 |
:pep:`649` |
| 195 |
Deferred Evaluation Of Annotations Using Descriptors |
| 196 |
:pep:`749` |
| 197 |
Implementing PEP 649 |
| 198 |
|
| 199 |
|
| 200 |
.. _whatsnew314-multiple-interpreters: |
| 201 |
|
| 202 |
:pep:`734`: Multiple interpreters in the standard library |
| 203 |
--------------------------------------------------------- |
| 204 |
|
| 205 |
The CPython runtime supports running multiple copies of Python in the |
| 206 |
same process simultaneously and has done so for over 20 years. |
| 207 |
Each of these separate copies is called an 'interpreter'. |
| 208 |
However, the feature had been available only through |
| 209 |
the :ref:`C-API <sub-interpreter-support>`. |
| 210 |
|
| 211 |
That limitation is removed in Python 3.14, |
| 212 |
with the new :mod:`concurrent.interpreters` module. |
| 213 |
|
| 214 |
There are at least two notable reasons why using multiple interpreters |
| 215 |
has significant benefits: |
| 216 |
|
| 217 |
* they support a new (to Python), human-friendly concurrency model |
| 218 |
* true multi-core parallelism |
| 219 |
|
| 220 |
For some use cases, concurrency in software improves efficiency and |
| 221 |
can simplify design, at a high level. |
| 222 |
At the same time, implementing and maintaining all but the simplest concurrency |
| 223 |
is often a struggle for the human brain. |
| 224 |
That especially applies to plain threads (for example, :mod:`threading`), |
| 225 |
where all memory is shared between all threads. |
| 226 |
|
| 227 |
With multiple isolated interpreters, you can take advantage of a class |
| 228 |
of concurrency models, like Communicating Sequential Processes (CSP) |
| 229 |
or the actor model, that have found |
| 230 |
success in other programming languages, like Smalltalk, Erlang, |
| 231 |
Haskell, and Go. Think of multiple interpreters as threads |
| 232 |
but with opt-in sharing. |
| 233 |
|
| 234 |
Regarding multi-core parallelism: as of Python 3.12, interpreters |
| 235 |
are now sufficiently isolated from one another to be used in parallel |
| 236 |
(see :pep:`684`). This unlocks a variety of CPU-intensive use cases |
| 237 |
for Python that were limited by the :term:`GIL`. |
| 238 |
|
| 239 |
Using multiple interpreters is similar in many ways to |
| 240 |
:mod:`multiprocessing`, in that they both provide isolated logical |
| 241 |
"processes" that can run in parallel, with no sharing by default. |
| 242 |
However, when using multiple interpreters, an application will use |
| 243 |
fewer system resources and will operate more efficiently (since it |
| 244 |
stays within the same process). Think of multiple interpreters as |
| 245 |
having the isolation of processes with the efficiency of threads. |
| 246 |
|
| 247 |
.. XXX Add an example or two. |
| 248 |
.. XXX Link to the not-yet-added HOWTO doc. |
| 249 |
|
| 250 |
While the feature has been around for decades, multiple interpreters |
| 251 |
have not been used widely, due to low awareness and the lack of a |
| 252 |
standard library module. Consequently, they currently have several |
| 253 |
notable limitations, which are expected to improve significantly now |
| 254 |
that the feature is going mainstream. |
| 255 |
|
| 256 |
Current limitations: |
| 257 |
|
| 258 |
* starting each interpreter has not been optimized yet |
| 259 |
* each interpreter uses more memory than necessary |
| 260 |
(work continues on extensive internal sharing between interpreters) |
| 261 |
* there aren't many options *yet* for truly sharing objects or other |
| 262 |
data between interpreters (other than :type:`memoryview`) |
| 263 |
* many third-party extension modules on PyPI are not yet compatible |
| 264 |
with multiple interpreters |
| 265 |
(all standard library extension modules *are* compatible) |
| 266 |
* the approach to writing applications that use multiple isolated |
| 267 |
interpreters is mostly unfamiliar to Python users, for now |
| 268 |
|
| 269 |
The impact of these limitations will depend on future CPython |
| 270 |
improvements, how interpreters are used, and what the community solves |
| 271 |
through PyPI packages. Depending on the use case, the limitations may |
| 272 |
not have much impact, so try it out! |
| 273 |
|
| 274 |
Furthermore, future CPython releases will reduce or eliminate overhead |
| 275 |
and provide utilities that are less appropriate on PyPI. In the |
| 276 |
meantime, most of the limitations can also be addressed through |
| 277 |
extension modules, meaning PyPI packages can fill any gap for 3.14, and |
| 278 |
even back to 3.12 where interpreters were finally properly isolated and |
| 279 |
stopped sharing the :term:`GIL`. Likewise, libraries on PyPI are expected |
| 280 |
to emerge for high-level abstractions on top of interpreters. |
| 281 |
|
| 282 |
Regarding extension modules, work is in progress to update some PyPI |
| 283 |
projects, as well as tools like Cython, pybind11, nanobind, and PyO3. |
| 284 |
The steps for isolating an extension module are found at |
| 285 |
:ref:`isolating-extensions-howto`. |
| 286 |
Isolating a module has a lot of overlap with what is required to support |
| 287 |
:ref:`free-threading <whatsnew314-free-threaded-cpython>`, so the ongoing |
| 288 |
work in the community in that area will help accelerate support |
| 289 |
for multiple interpreters. |
| 290 |
|
| 291 |
Also added in 3.14: :ref:`concurrent.futures.InterpreterPoolExecutor |
| 292 |
<whatsnew314-concurrent-futures-interp-pool>`. |
| 293 |
|
| 294 |
(Contributed by Eric Snow in :gh:`134939`.) |
| 295 |
|
| 296 |
.. seealso:: :pep:`734` |
| 297 |
|
| 298 |
|
| 299 |
.. _whatsnew314-template-string-literals: |
| 300 |
|
| 301 |
:pep:`750`: Template string literals |
| 302 |
------------------------------------ |
| 303 |
|
| 304 |
Template strings are a new mechanism for custom string processing. |
| 305 |
They share the familiar syntax of f-strings but, unlike f-strings, |
| 306 |
return an object representing the static and interpolated parts of |
| 307 |
the string, instead of a simple :class:`str`. |
| 308 |
|
| 309 |
To write a t-string, use a ``'t'`` prefix instead of an ``'f'``: |
| 310 |
|
| 311 |
.. doctest:: |
| 312 |
|
| 313 |
>>> variety = 'Stilton' |
| 314 |
>>> template = t'Try some {variety} cheese!' |
| 315 |
>>> type(template) |
| 316 |
<class 'string.templatelib.Template'> |
| 317 |
|
| 318 |
:class:`~string.templatelib.Template` objects provide access to the static |
| 319 |
and interpolated (in curly braces) parts of a string *before* they are combined. |
| 320 |
Iterate over :class:`!Template` instances to access their parts in order: |
| 321 |
|
| 322 |
.. testsetup:: |
| 323 |
|
| 324 |
variety = 'Stilton' |
| 325 |
template = t'Try some {variety} cheese!' |
| 326 |
|
| 327 |
.. doctest:: |
| 328 |
|
| 329 |
>>> list(template) |
| 330 |
['Try some ', Interpolation('Stilton', 'variety', None, ''), ' cheese!'] |
| 331 |
|
| 332 |
It's easy to write (or call) code to process :class:`!Template` instances. |
| 333 |
For example, here's a function that renders static parts lowercase and |
| 334 |
:class:`~string.templatelib.Interpolation` instances uppercase: |
| 335 |
|
| 336 |
.. code-block:: python |
| 337 |
|
| 338 |
from string.templatelib import Interpolation |
| 339 |
|
| 340 |
def lower_upper(template): |
| 341 |
"""Render static parts lowercase and interpolations uppercase.""" |
| 342 |
parts = [] |
| 343 |
for part in template: |
| 344 |
if isinstance(part, Interpolation): |
| 345 |
parts.append(str(part.value).upper()) |
| 346 |
else: |
| 347 |
parts.append(part.lower()) |
| 348 |
return ''.join(parts) |
| 349 |
|
| 350 |
name = 'Wenslydale' |
| 351 |
template = t'Mister {name}' |
| 352 |
assert lower_upper(template) == 'mister WENSLYDALE' |
| 353 |
|
| 354 |
Because :class:`!Template` instances distinguish between static strings and |
| 355 |
interpolations at runtime, they can be useful for sanitising user input. |
| 356 |
Writing a :func:`!html` function that escapes user input in HTML is an exercise |
| 357 |
left to the reader! |
| 358 |
Template processing code can provide improved flexibility. |
| 359 |
For instance, a more advanced :func:`!html` function could accept |
| 360 |
a :class:`!dict` of HTML attributes directly in the template: |
| 361 |
|
| 362 |
.. code-block:: python |
| 363 |
|
| 364 |
attributes = {'src': 'limburger.jpg', 'alt': 'lovely cheese'} |
| 365 |
template = t'<img {attributes}>' |
| 366 |
assert html(template) == '<img src="limburger.jpg" alt="lovely cheese" />' |
| 367 |
|
| 368 |
Of course, template processing code does not need to return a string-like result. |
| 369 |
An even *more* advanced :func:`!html` could return a custom type representing |
| 370 |
a DOM-like structure. |
| 371 |
|
| 372 |
With t-strings in place, developers can write systems that sanitise SQL, |
| 373 |
make safe shell operations, improve logging, tackle modern ideas in web |
| 374 |
development (HTML, CSS, and so on), and implement lightweight custom business DSLs. |
| 375 |
|
| 376 |
(Contributed by Jim Baker, Guido van Rossum, Paul Everitt, Koudai Aono, |
| 377 |
Lysandros Nikolaou, Dave Peck, Adam Turner, Jelle Zijlstra, Bénédikt Tran, |
| 378 |
and Pablo Galindo Salgado in :gh:`132661`.) |
| 379 |
|
| 380 |
.. seealso:: :pep:`750`. |
| 381 |
|
| 382 |
|
| 383 |
.. _whatsnew314-remote-debugging: |
| 384 |
|
| 385 |
:pep:`768`: Safe external debugger interface |
| 386 |
-------------------------------------------- |
| 387 |
|
| 388 |
Python 3.14 introduces a zero-overhead debugging interface that allows |
| 389 |
debuggers and profilers to safely attach to running Python processes |
| 390 |
without stopping or restarting them. |
| 391 |
This is a significant enhancement to Python's debugging capabilities, |
| 392 |
meaning that unsafe alternatives are no longer required. |
| 393 |
|
| 394 |
The new interface provides safe execution points for attaching debugger code |
| 395 |
without modifying the interpreter's normal execution path |
| 396 |
or adding any overhead at runtime. |
| 397 |
Due to this, tools can now inspect and interact with Python applications |
| 398 |
in real-time, which is a crucial capability for high-availability systems |
| 399 |
and production environments. |
| 400 |
|
| 401 |
For convenience, this interface is implemented in the :func:`sys.remote_exec` |
| 402 |
function. For example: |
| 403 |
|
| 404 |
.. code-block:: python |
| 405 |
|
| 406 |
import sys |
| 407 |
from tempfile import NamedTemporaryFile |
| 408 |
|
| 409 |
with NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f: |
| 410 |
script_path = f.name |
| 411 |
f.write(f'import my_debugger; my_debugger.connect({os.getpid()})') |
| 412 |
|
| 413 |
# Execute in process with PID 1234 |
| 414 |
print('Behold! An offering:') |
| 415 |
sys.remote_exec(1234, script_path) |
| 416 |
|
| 417 |
|
| 418 |
This function allows sending Python code to be executed in a target process |
| 419 |
at the next safe execution point. |
| 420 |
However, tool authors can also implement the protocol directly as described |
| 421 |
in the PEP, which details the underlying mechanisms used to safely attach to |
| 422 |
running processes. |
| 423 |
|
| 424 |
The debugging interface has been carefully designed with security in mind |
| 425 |
and includes several mechanisms to control access: |
| 426 |
|
| 427 |
* A :envvar:`PYTHON_DISABLE_REMOTE_DEBUG` environment variable. |
| 428 |
* A :option:`-X disable-remote-debug` command-line option. |
| 429 |
* A :option:`--without-remote-debug` configure flag to completely disable |
| 430 |
the feature at build time. |
| 431 |
|
| 432 |
(Contributed by Pablo Galindo Salgado, Matt Wozniski, and Ivona Stojanovic |
| 433 |
in :gh:`131591`.) |
| 434 |
|
| 435 |
.. seealso:: :pep:`768`. |
| 436 |
|
| 437 |
|
| 438 |
.. _whatsnew314-tail-call-interpreter: |
| 439 |
|
| 440 |
A new type of interpreter |
| 441 |
------------------------- |
| 442 |
|
| 443 |
A new type of interpreter has been added to CPython. |
| 444 |
It uses tail calls between small C functions that implement individual |
| 445 |
Python opcodes, rather than one large C ``case`` statement. |
| 446 |
For certain newer compilers, this interpreter provides |
| 447 |
significantly better performance. Preliminary benchmarks suggest a geometric |
| 448 |
mean of 3-5% faster on the standard ``pyperformance`` benchmark suite, |
| 449 |
depending on platform and architecture. |
| 450 |
The baseline is Python 3.14 built with Clang 19, without this new interpreter. |
| 451 |
|
| 452 |
This interpreter currently only works with Clang 19 and newer |
| 453 |
on x86-64 and AArch64 architectures. |
| 454 |
However, a future release of GCC is expected to support this as well. |
| 455 |
|
| 456 |
This feature is opt-in for now. Enabling profile-guided optimization is highly |
| 457 |
recommended when using the new interpreter as it is the only configuration |
| 458 |
that has been tested and validated for improved performance. |
| 459 |
For further information, see :option:`--with-tail-call-interp`. |
| 460 |
|
| 461 |
.. note:: |
| 462 |
|
| 463 |
This is not to be confused with `tail call optimization`__ of Python |
| 464 |
functions, which is currently not implemented in CPython. |
| 465 |
|
| 466 |
This new interpreter type is an internal implementation detail of the CPython |
| 467 |
interpreter. It doesn't change the visible behavior of Python programs at |
| 468 |
all. It can improve their performance, but doesn't change anything else. |
| 469 |
|
| 470 |
__ https://en.wikipedia.org/wiki/Tail_call |
| 471 |
|
| 472 |
(Contributed by Ken Jin in :gh:`128563`, with ideas on how to implement this |
| 473 |
in CPython by Mark Shannon, Garrett Gu, Haoran Xu, and Josh Haberman.) |
| 474 |
|
| 475 |
|
| 476 |
.. _whatsnew314-free-threaded-cpython: |
| 477 |
|
| 478 |
Free-threaded mode improvements |
| 479 |
------------------------------- |
| 480 |
|
| 481 |
CPython's free-threaded mode (:pep:`703`), initially added in 3.13, |
| 482 |
has been significantly improved in Python 3.14. |
| 483 |
The implementation described in PEP 703 has been finished, including C API |
| 484 |
changes, and temporary workarounds in the interpreter were replaced with |
| 485 |
more permanent solutions. |
| 486 |
The specializing adaptive interpreter (:pep:`659`) is now enabled |
| 487 |
in free-threaded mode, which along with many other optimizations |
| 488 |
greatly improves its performance. |
| 489 |
The performance penalty on single-threaded code in free-threaded mode |
| 490 |
is now roughly 5-10%, depending on the platform and C compiler used. |
| 491 |
|
| 492 |
From Python 3.14, when compiling extension modules for the free-threaded build of |
| 493 |
CPython on Windows, the preprocessor variable ``Py_GIL_DISABLED`` now needs to |
| 494 |
be specified by the build backend, as it will no longer be determined |
| 495 |
automatically by the C compiler. For a running interpreter, the setting that |
| 496 |
was used at compile time can be found using :func:`sysconfig.get_config_var`. |
| 497 |
|
| 498 |
The new :option:`-X context_aware_warnings <-X>` flag controls if |
| 499 |
:ref:`concurrent safe warnings control <whatsnew314-concurrent-warnings-control>` |
| 500 |
is enabled. The flag defaults to true for the free-threaded build |
| 501 |
and false for the GIL-enabled build. |
| 502 |
|
| 503 |
A new :data:`~sys.flags.thread_inherit_context` flag has been added, |
| 504 |
which if enabled means that threads created with :class:`threading.Thread` |
| 505 |
start with a copy of the :class:`~contextvars.Context()` of the caller of |
| 506 |
:meth:`~threading.Thread.start`. Most significantly, this makes the warning |
| 507 |
filtering context established by :class:`~warnings.catch_warnings` be |
| 508 |
"inherited" by threads (or asyncio tasks) started within that context. It also |
| 509 |
affects other modules that use context variables, such as the :mod:`decimal` |
| 510 |
context manager. |
| 511 |
This flag defaults to true for the free-threaded build and false for |
| 512 |
the GIL-enabled build. |
| 513 |
|
| 514 |
(Contributed by Sam Gross, Matt Page, Neil Schemenauer, Thomas Wouters, |
| 515 |
Donghee Na, Kirill Podoprigora, Ken Jin, Itamar Oren, Brett Simmers, |
| 516 |
Dino Viehland, Nathan Goldbaum, Ralf Gommers, Lysandros Nikolaou, Kumar Aditya, |
| 517 |
Edgar Margffoy, and many others. |
| 518 |
Some of these contributors are employed by Meta, which has continued to provide |
| 519 |
significant engineering resources to support this project.) |
| 520 |
|
| 521 |
|
| 522 |
.. _whatsnew314-improved-error-messages: |
| 523 |
|
| 524 |
Improved error messages |
| 525 |
----------------------- |
| 526 |
|
| 527 |
* The interpreter now provides helpful suggestions when it detects typos in Python |
| 528 |
keywords. When a word that closely resembles a Python keyword is encountered, |
| 529 |
the interpreter will suggest the correct keyword in the error message. This |
| 530 |
feature helps programmers quickly identify and fix common typing mistakes. For |
| 531 |
example: |
| 532 |
|
| 533 |
.. code-block:: pycon |
| 534 |
|
| 535 |
>>> whille True: |
| 536 |
... pass |
| 537 |
Traceback (most recent call last): |
| 538 |
File "<stdin>", line 1 |
| 539 |
whille True: |
| 540 |
^^^^^^ |
| 541 |
SyntaxError: invalid syntax. Did you mean 'while'? |
| 542 |
|
| 543 |
While the feature focuses on the most common cases, some variations of |
| 544 |
misspellings may still result in regular syntax errors. |
| 545 |
(Contributed by Pablo Galindo in :gh:`132449`.) |
| 546 |
|
| 547 |
* :keyword:`elif` statements that follow an :keyword:`else` block now have |
| 548 |
a specific error message. |
| 549 |
(Contributed by Steele Farnsworth in :gh:`129902`.) |
| 550 |
|
| 551 |
.. code-block:: pycon |
| 552 |
|
| 553 |
>>> if who == "me": |
| 554 |
... print("It's me!") |
| 555 |
... else: |
| 556 |
... print("It's not me!") |
| 557 |
... elif who is None: |
| 558 |
... print("Who is it?") |
| 559 |
File "<stdin>", line 5 |
| 560 |
elif who is None: |
| 561 |
^^^^ |
| 562 |
SyntaxError: 'elif' block follows an 'else' block |
| 563 |
|
| 564 |
* If a statement is passed to the :ref:`if_expr` after :keyword:`else`, |
| 565 |
or one of :keyword:`pass`, :keyword:`break`, or :keyword:`continue` |
| 566 |
is passed before :keyword:`if`, then the |
| 567 |
error message highlights where the :token:`~python-grammar:expression` is |
| 568 |
required. (Contributed by Sergey Miryanov in :gh:`129515`.) |
| 569 |
|
| 570 |
.. code-block:: pycon |
| 571 |
|
| 572 |
>>> x = 1 if True else pass |
| 573 |
Traceback (most recent call last): |
| 574 |
File "<string>", line 1 |
| 575 |
x = 1 if True else pass |
| 576 |
^^^^ |
| 577 |
SyntaxError: expected expression after 'else', but statement is given |
| 578 |
|
| 579 |
>>> x = continue if True else break |
| 580 |
Traceback (most recent call last): |
| 581 |
File "<string>", line 1 |
| 582 |
x = continue if True else break |
| 583 |
^^^^^^^^ |
| 584 |
SyntaxError: expected expression before 'if', but statement is given |
| 585 |
|
| 586 |
* When incorrectly closed strings are detected, the error message suggests |
| 587 |
that the string may be intended to be part of the string. |
| 588 |
(Contributed by Pablo Galindo in :gh:`88535`.) |
| 589 |
|
| 590 |
.. code-block:: pycon |
| 591 |
|
| 592 |
>>> "The interesting object "The important object" is very important" |
| 593 |
Traceback (most recent call last): |
| 594 |
SyntaxError: invalid syntax. Is this intended to be part of the string? |
| 595 |
|
| 596 |
* When strings have incompatible prefixes, the error now shows |
| 597 |
which prefixes are incompatible. |
| 598 |
(Contributed by Nikita Sobolev in :gh:`133197`.) |
| 599 |
|
| 600 |
.. code-block:: pycon |
| 601 |
|
| 602 |
>>> ub'abc' |
| 603 |
File "<python-input-0>", line 1 |
| 604 |
ub'abc' |
| 605 |
^^ |
| 606 |
SyntaxError: 'u' and 'b' prefixes are incompatible |
| 607 |
|
| 608 |
* Improved error messages when using ``as`` with incompatible targets in: |
| 609 |
|
| 610 |
- Imports: ``import ... as ...`` |
| 611 |
- From imports: ``from ... import ... as ...`` |
| 612 |
- Except handlers: ``except ... as ...`` |
| 613 |
- Pattern-match cases: ``case ... as ...`` |
| 614 |
|
| 615 |
(Contributed by Nikita Sobolev in :gh:`123539`, :gh:`123562`, and :gh:`123440`.) |
| 616 |
|
| 617 |
* Improved error message when trying to add an instance of an unhashable type to |
| 618 |
a :class:`dict` or :class:`set`. |
| 619 |
(Contributed by CF Bolz-Tereick and Victor Stinner in :gh:`132828`.) |
| 620 |
|
| 621 |
.. code-block:: pycon |
| 622 |
|
| 623 |
>>> s = set() |
| 624 |
>>> s.add({'pages': 12, 'grade': 'A'}) |
| 625 |
Traceback (most recent call last): |
| 626 |
File "<python-input-1>", line 1, in <module> |
| 627 |
s.add({'pages': 12, 'grade': 'A'}) |
| 628 |
~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 629 |
TypeError: cannot use 'dict' as a set element (unhashable type: 'dict') |
| 630 |
>>> d = {} |
| 631 |
>>> l = [1, 2, 3] |
| 632 |
>>> d[l] = 12 |
| 633 |
Traceback (most recent call last): |
| 634 |
File "<python-input-4>", line 1, in <module> |
| 635 |
d[l] = 12 |
| 636 |
~^^^ |
| 637 |
TypeError: cannot use 'list' as a dict key (unhashable type: 'list') |
| 638 |
|
| 639 |
* Improved error message when an object supporting the synchronous |
| 640 |
context manager protocol is entered using :keyword:`async with` |
| 641 |
instead of :keyword:`with`, |
| 642 |
and vice versa for the asynchronous context manager protocol. |
| 643 |
(Contributed by Bénédikt Tran in :gh:`128398`.) |
| 644 |
|
| 645 |
|
| 646 |
.. _whatsnew314-zstandard: |
| 647 |
|
| 648 |
:pep:`784`: Zstandard support in the standard library |
| 649 |
----------------------------------------------------- |
| 650 |
|
| 651 |
The new :mod:`!compression` package contains modules :mod:`!compression.lzma`, |
| 652 |
:mod:`!compression.bz2`, :mod:`!compression.gzip` and :mod:`!compression.zlib` |
| 653 |
which re-export the :mod:`lzma`, :mod:`bz2`, :mod:`gzip` and :mod:`zlib` |
| 654 |
modules respectively. The new import names under :mod:`!compression` are the |
| 655 |
preferred names for importing these compression modules from Python 3.14. However, |
| 656 |
the existing modules names have not been deprecated. Any deprecation or removal |
| 657 |
of the existing compression modules will occur no sooner than five years after |
| 658 |
the release of 3.14. |
| 659 |
|
| 660 |
The new :mod:`!compression.zstd` module provides compression and decompression |
| 661 |
APIs for the Zstandard format via bindings to `Meta's zstd library |
| 662 |
<https://facebook.github.io/zstd/>`__. Zstandard is a widely adopted, highly |
| 663 |
efficient, and fast compression format. In addition to the APIs introduced in |
| 664 |
:mod:`!compression.zstd`, support for reading and writing Zstandard compressed |
| 665 |
archives has been added to the :mod:`tarfile`, :mod:`zipfile`, and |
| 666 |
:mod:`shutil` modules. |
| 667 |
|
| 668 |
Here's an example of using the new module to compress some data: |
| 669 |
|
| 670 |
.. code-block:: python |
| 671 |
|
| 672 |
from compression import zstd |
| 673 |
import math |
| 674 |
|
| 675 |
data = str(math.pi).encode() * 20 |
| 676 |
compressed = zstd.compress(data) |
| 677 |
ratio = len(compressed) / len(data) |
| 678 |
print(f"Achieved compression ratio of {ratio}") |
| 679 |
|
| 680 |
As can be seen, the API is similar to the APIs of the :mod:`!lzma` and |
| 681 |
:mod:`!bz2` modules. |
| 682 |
|
| 683 |
(Contributed by Emma Harper Smith, Adam Turner, Gregory P. Smith, Tomas Roun, |
| 684 |
Victor Stinner, and Rogdham in :gh:`132983`.) |
| 685 |
|
| 686 |
.. seealso:: :pep:`784`. |
| 687 |
|
| 688 |
|
| 689 |
.. _whatsnew314-asyncio-introspection: |
| 690 |
|
| 691 |
Asyncio introspection capabilities |
| 692 |
---------------------------------- |
| 693 |
|
| 694 |
Added a new command-line interface to inspect running Python processes |
| 695 |
using asynchronous tasks, available via ``python -m asyncio ps PID`` |
| 696 |
or ``python -m asyncio pstree PID``. |
| 697 |
|
| 698 |
The ``ps`` subcommand inspects the given process ID (PID) and displays |
| 699 |
information about currently running asyncio tasks. |
| 700 |
It outputs a task table: a flat listing of all tasks, their names, |
| 701 |
their coroutine stacks, and which tasks are awaiting them. |
| 702 |
|
| 703 |
|
| 704 |
The ``pstree`` subcommand fetches the same information, but instead renders a |
| 705 |
visual async call tree, showing coroutine relationships in a hierarchical format. |
| 706 |
This command is particularly useful for debugging long-running or stuck |
| 707 |
asynchronous programs. |
| 708 |
It can help developers quickly identify where a program is blocked, |
| 709 |
what tasks are pending, and how coroutines are chained together. |
| 710 |
|
| 711 |
For example given this code: |
| 712 |
|
| 713 |
.. code-block:: python |
| 714 |
|
| 715 |
import asyncio |
| 716 |
|
| 717 |
async def play_track(track): |
| 718 |
await asyncio.sleep(5) |
| 719 |
print(f'🎵 Finished: {track}') |
| 720 |
|
| 721 |
async def play_album(name, tracks): |
| 722 |
async with asyncio.TaskGroup() as tg: |
| 723 |
for track in tracks: |
| 724 |
tg.create_task(play_track(track), name=track) |
| 725 |
|
| 726 |
async def main(): |
| 727 |
async with asyncio.TaskGroup() as tg: |
| 728 |
tg.create_task( |
| 729 |
play_album('Sundowning', ['TNDNBTG', 'Levitate']), |
| 730 |
name='Sundowning') |
| 731 |
tg.create_task( |
| 732 |
play_album('TMBTE', ['DYWTYLM', 'Aqua Regia']), |
| 733 |
name='TMBTE') |
| 734 |
|
| 735 |
if __name__ == '__main__': |
| 736 |
asyncio.run(main()) |
| 737 |
|
| 738 |
Executing the new tool on the running process will yield a table like this: |
| 739 |
|
| 740 |
.. code-block:: bash |
| 741 |
|
| 742 |
python -m asyncio ps 12345 |
| 743 |
|
| 744 |
tid task id task name coroutine stack awaiter chain awaiter name awaiter id |
| 745 |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 746 |
1935500 0x7fc930c18050 Task-1 TaskGroup._aexit -> TaskGroup.__aexit__ -> main 0x0 |
| 747 |
1935500 0x7fc930c18230 Sundowning TaskGroup._aexit -> TaskGroup.__aexit__ -> album TaskGroup._aexit -> TaskGroup.__aexit__ -> main Task-1 0x7fc930c18050 |
| 748 |
1935500 0x7fc93173fa50 TMBTE TaskGroup._aexit -> TaskGroup.__aexit__ -> album TaskGroup._aexit -> TaskGroup.__aexit__ -> main Task-1 0x7fc930c18050 |
| 749 |
1935500 0x7fc93173fdf0 TNDNBTG sleep -> play TaskGroup._aexit -> TaskGroup.__aexit__ -> album Sundowning 0x7fc930c18230 |
| 750 |
1935500 0x7fc930d32510 Levitate sleep -> play TaskGroup._aexit -> TaskGroup.__aexit__ -> album Sundowning 0x7fc930c18230 |
| 751 |
1935500 0x7fc930d32890 DYWTYLM sleep -> play TaskGroup._aexit -> TaskGroup.__aexit__ -> album TMBTE 0x7fc93173fa50 |
| 752 |
1935500 0x7fc93161ec30 Aqua Regia sleep -> play TaskGroup._aexit -> TaskGroup.__aexit__ -> album TMBTE 0x7fc93173fa50 |
| 753 |
|
| 754 |
or a tree like this: |
| 755 |
|
| 756 |
.. code-block:: bash |
| 757 |
|
| 758 |
python -m asyncio pstree 12345 |
| 759 |
|
| 760 |
└── (T) Task-1 |
| 761 |
└── main example.py:13 |
| 762 |
└── TaskGroup.__aexit__ Lib/asyncio/taskgroups.py:72 |
| 763 |
└── TaskGroup._aexit Lib/asyncio/taskgroups.py:121 |
| 764 |
├── (T) Sundowning |
| 765 |
│ └── album example.py:8 |
| 766 |
│ └── TaskGroup.__aexit__ Lib/asyncio/taskgroups.py:72 |
| 767 |
│ └── TaskGroup._aexit Lib/asyncio/taskgroups.py:121 |
| 768 |
│ ├── (T) TNDNBTG |
| 769 |
│ │ └── play example.py:4 |
| 770 |
│ │ └── sleep Lib/asyncio/tasks.py:702 |
| 771 |
│ └── (T) Levitate |
| 772 |
│ └── play example.py:4 |
| 773 |
│ └── sleep Lib/asyncio/tasks.py:702 |
| 774 |
└── (T) TMBTE |
| 775 |
└── album example.py:8 |
| 776 |
└── TaskGroup.__aexit__ Lib/asyncio/taskgroups.py:72 |
| 777 |
└── TaskGroup._aexit Lib/asyncio/taskgroups.py:121 |
| 778 |
├── (T) DYWTYLM |
| 779 |
│ └── play example.py:4 |
| 780 |
│ └── sleep Lib/asyncio/tasks.py:702 |
| 781 |
└── (T) Aqua Regia |
| 782 |
└── play example.py:4 |
| 783 |
└── sleep Lib/asyncio/tasks.py:702 |
| 784 |
|
| 785 |
If a cycle is detected in the async await graph (which could indicate a |
| 786 |
programming issue), the tool raises an error and lists the cycle paths that |
| 787 |
prevent tree construction: |
| 788 |
|
| 789 |
.. code-block:: bash |
| 790 |
|
| 791 |
python -m asyncio pstree 12345 |
| 792 |
|
| 793 |
ERROR: await-graph contains cycles - cannot print a tree! |
| 794 |
|
| 795 |
cycle: Task-2 → Task-3 → Task-2 |
| 796 |
|
| 797 |
(Contributed by Pablo Galindo, Łukasz Langa, Yury Selivanov, and Marta |
| 798 |
Gomez Macias in :gh:`91048`.) |
| 799 |
|
| 800 |
|
| 801 |
.. _whatsnew314-concurrent-warnings-control: |
| 802 |
|
| 803 |
Concurrent safe warnings control |
| 804 |
-------------------------------- |
| 805 |
|
| 806 |
The :class:`warnings.catch_warnings` context manager will now optionally |
| 807 |
use a context variable for warning filters. This is enabled by setting |
| 808 |
the :data:`~sys.flags.context_aware_warnings` flag, either with the ``-X`` |
| 809 |
command-line option or an environment variable. This gives predictable |
| 810 |
warnings control when using :class:`~warnings.catch_warnings` combined with |
| 811 |
multiple threads or asynchronous tasks. The flag defaults to true for the |
| 812 |
free-threaded build and false for the GIL-enabled build. |
| 813 |
|
| 814 |
(Contributed by Neil Schemenauer and Kumar Aditya in :gh:`130010`.) |
| 815 |
|
| 816 |
|
| 817 |
Other language changes |
| 818 |
====================== |
| 819 |
|
| 820 |
* All Windows code pages are now supported as 'cpXXX' codecs on Windows. |
| 821 |
(Contributed by Serhiy Storchaka in :gh:`123803`.) |
| 822 |
|
| 823 |
* Implement mixed-mode arithmetic rules combining real and complex numbers |
| 824 |
as specified by the C standard since C99. |
| 825 |
(Contributed by Sergey B Kirpichev in :gh:`69639`.) |
| 826 |
|
| 827 |
* More syntax errors are now detected regardless of optimisation and |
| 828 |
the :option:`-O` command-line option. |
| 829 |
This includes writes to ``__debug__``, incorrect use of :keyword:`await`, |
| 830 |
and asynchronous comprehensions outside asynchronous functions. |
| 831 |
For example, ``python -O -c 'assert (__debug__ := 1)'`` |
| 832 |
or ``python -O -c 'assert await 1'`` now produce :exc:`SyntaxError`\ s. |
| 833 |
(Contributed by Irit Katriel and Jelle Zijlstra in :gh:`122245` & :gh:`121637`.) |
| 834 |
|
| 835 |
* When subclassing a pure C type, the C slots for the new type |
| 836 |
are no longer replaced with a wrapped version on class creation |
| 837 |
if they are not explicitly overridden in the subclass. |
| 838 |
(Contributed by Tomasz Pytel in :gh:`132284`.) |
| 839 |
|
| 840 |
|
| 841 |
Built-ins |
| 842 |
--------- |
| 843 |
|
| 844 |
* The :meth:`bytes.fromhex` and :meth:`bytearray.fromhex` methods now accept |
| 845 |
ASCII :class:`bytes` and :term:`bytes-like objects <bytes-like object>`. |
| 846 |
(Contributed by Daniel Pope in :gh:`129349`.) |
| 847 |
|
| 848 |
* Add class methods :meth:`float.from_number` and :meth:`complex.from_number` |
| 849 |
to convert a number to :class:`float` or :class:`complex` type correspondingly. |
| 850 |
They raise a :exc:`TypeError` if the argument is not a real number. |
| 851 |
(Contributed by Serhiy Storchaka in :gh:`84978`.) |
| 852 |
|
| 853 |
* Support underscore and comma as thousands separators in the fractional part |
| 854 |
for floating-point presentation types of the new-style string formatting |
| 855 |
(with :func:`format` or :ref:`f-strings`). |
| 856 |
(Contributed by Sergey B Kirpichev in :gh:`87790`.) |
| 857 |
|
| 858 |
* The :func:`int` function no longer delegates to :meth:`~object.__trunc__`. |
| 859 |
Classes that want to support conversion to :func:`!int` must implement |
| 860 |
either :meth:`~object.__int__` or :meth:`~object.__index__`. |
| 861 |
(Contributed by Mark Dickinson in :gh:`119743`.) |
| 862 |
|
| 863 |
* The :func:`map` function now has an optional keyword-only *strict* flag |
| 864 |
like :func:`zip` to check that all the iterables are of equal length. |
| 865 |
(Contributed by Wannes Boeykens in :gh:`119793`.) |
| 866 |
|
| 867 |
* The :class:`memoryview` type now supports subscription, |
| 868 |
making it a :term:`generic type`. |
| 869 |
(Contributed by Brian Schubert in :gh:`126012`.) |
| 870 |
|
| 871 |
* Using :data:`NotImplemented` in a boolean context |
| 872 |
will now raise a :exc:`TypeError`. |
| 873 |
This has raised a :exc:`DeprecationWarning` since Python 3.9. |
| 874 |
(Contributed by Jelle Zijlstra in :gh:`118767`.) |
| 875 |
|
| 876 |
* Three-argument :func:`pow` now tries calling :meth:`~object.__rpow__` |
| 877 |
if necessary. |
| 878 |
Previously it was only called in two-argument :func:`!pow` |
| 879 |
and the binary power operator. |
| 880 |
(Contributed by Serhiy Storchaka in :gh:`130104`.) |
| 881 |
|
| 882 |
* :class:`super` objects are now :mod:`copyable <copy>` and :mod:`pickleable |
| 883 |
<pickle>`. |
| 884 |
(Contributed by Serhiy Storchaka in :gh:`125767`.) |
| 885 |
|
| 886 |
|
| 887 |
Command line and environment |
| 888 |
---------------------------- |
| 889 |
|
| 890 |
* The import time flag can now track modules that are already loaded ('cached'), |
| 891 |
via the new :option:`-X importtime=2 <-X>`. |
| 892 |
When such a module is imported, the ``self`` and ``cumulative`` times |
| 893 |
are replaced by the string ``cached``. |
| 894 |
|
| 895 |
Values above ``2`` for ``-X importtime`` are now reserved for future use. |
| 896 |
|
| 897 |
(Contributed by Noah Kim and Adam Turner in :gh:`118655`.) |
| 898 |
|
| 899 |
* The command-line option :option:`-c` now automatically dedents its code |
| 900 |
argument before execution. The auto-dedentation behavior mirrors |
| 901 |
:func:`textwrap.dedent`. |
| 902 |
(Contributed by Jon Crall and Steven Sun in :gh:`103998`.) |
| 903 |
|
| 904 |
* :option:`!-J` is no longer a reserved flag for Jython_, |
| 905 |
and now has no special meaning. |
| 906 |
(Contributed by Adam Turner in :gh:`133336`.) |
| 907 |
|
| 908 |
.. _Jython: https://www.jython.org/ |
| 909 |
|
| 910 |
|
| 911 |
.. _whatsnew314-bracketless-except: |
| 912 |
|
| 913 |
PEP 758: Allow ``except`` and ``except*`` expressions without brackets |
| 914 |
---------------------------------------------------------------------- |
| 915 |
|
| 916 |
The :keyword:`except` and :keyword:`except* <except_star>` expressions |
| 917 |
now allow brackets to be omitted when there are multiple exception types |
| 918 |
and the ``as`` clause is not used. |
| 919 |
For example: |
| 920 |
|
| 921 |
.. code-block:: python |
| 922 |
|
| 923 |
try: |
| 924 |
connect_to_server() |
| 925 |
except TimeoutError, ConnectionRefusedError: |
| 926 |
print('The network has ceased to be!') |
| 927 |
|
| 928 |
(Contributed by Pablo Galindo and Brett Cannon in :pep:`758` and :gh:`131831`.) |
| 929 |
|
| 930 |
|
| 931 |
.. _whatsnew314-finally-syntaxwarning: |
| 932 |
|
| 933 |
PEP 765: Control flow in :keyword:`finally` blocks |
| 934 |
-------------------------------------------------- |
| 935 |
|
| 936 |
The compiler now emits a :exc:`SyntaxWarning` when a :keyword:`return`, |
| 937 |
:keyword:`break`, or :keyword:`continue` statement have the effect of |
| 938 |
leaving a :keyword:`finally` block. |
| 939 |
This change is specified in :pep:`765`. |
| 940 |
|
| 941 |
In situations where this change is inconvenient (such as those where the |
| 942 |
warnings are redundant due to code linting), the :ref:`warning filter |
| 943 |
<warning-filter>` can be used to turn off all syntax warnings by adding |
| 944 |
``ignore::SyntaxWarning`` as a filter. This can be specified in combination |
| 945 |
with a filter that converts other warnings to errors (for example, passing |
| 946 |
``-Werror -Wignore::SyntaxWarning`` as CLI options, or setting |
| 947 |
``PYTHONWARNINGS=error,ignore::SyntaxWarning``). |
| 948 |
|
| 949 |
Note that applying such a filter at runtime using the :mod:`warnings` module |
| 950 |
will only suppress the warning in code that is compiled *after* the filter is |
| 951 |
adjusted. Code that is compiled prior to the filter adjustment (for example, |
| 952 |
when a module is imported) will still emit the syntax warning. |
| 953 |
|
| 954 |
(Contributed by Irit Katriel in :gh:`130080`.) |
| 955 |
|
| 956 |
|
| 957 |
.. _incremental-garbage-collection: |
| 958 |
.. _whatsnew314-incremental-gc: |
| 959 |
|
| 960 |
Garbage collection |
| 961 |
------------------ |
| 962 |
|
| 963 |
**From Python 3.14.5 onwards:** |
| 964 |
|
| 965 |
The garbage collector (GC) has changed in Python 3.14.5. |
| 966 |
|
| 967 |
Python 3.14.0-3.14.4 shipped with a new incremental GC. |
| 968 |
However, due to a number of `reports |
| 969 |
<https://github.com/python/cpython/issues/142516>`__ |
| 970 |
of significant memory pressure in production environments, |
| 971 |
it has been reverted back to the generational GC from 3.13. |
| 972 |
This is the GC now used in Python 3.14.5 and later. |
| 973 |
|
| 974 |
**Previously in Python 3.14.0-3.14.4:** |
| 975 |
|
| 976 |
The cycle garbage collector is now incremental. |
| 977 |
This means that maximum pause times are reduced |
| 978 |
by an order of magnitude or more for larger heaps. |
| 979 |
|
| 980 |
There are now only two generations: young and old. |
| 981 |
When :func:`gc.collect` is not called directly, the |
| 982 |
GC is invoked a little less frequently. When invoked, it |
| 983 |
collects the young generation and an increment of the |
| 984 |
old generation, instead of collecting one or more generations. |
| 985 |
|
| 986 |
The behavior of :func:`!gc.collect` changes slightly: |
| 987 |
|
| 988 |
* ``gc.collect(1)``: Performs an increment of garbage collection, |
| 989 |
rather than collecting generation 1. |
| 990 |
* Other calls to :func:`!gc.collect` are unchanged. |
| 991 |
|
| 992 |
(Contributed by Mark Shannon in :gh:`108362`.) |
| 993 |
|
| 994 |
|
| 995 |
Default interactive shell |
| 996 |
------------------------- |
| 997 |
|
| 998 |
.. _whatsnew314-pyrepl-highlighting: |
| 999 |
|
| 1000 |
* The default :term:`interactive` shell now highlights Python syntax. |
| 1001 |
The feature is enabled by default, save if :envvar:`PYTHON_BASIC_REPL` |
| 1002 |
or any other environment variable that disables colour is set. |
| 1003 |
See :ref:`using-on-controlling-color` for details. |
| 1004 |
|
| 1005 |
The default color theme for syntax highlighting strives for good contrast |
| 1006 |
and exclusively uses the 4-bit VGA standard ANSI color codes for maximum |
| 1007 |
compatibility. The theme can be customized using an experimental API |
| 1008 |
:func:`!_colorize.set_theme`. |
| 1009 |
This can be called interactively or in the :envvar:`PYTHONSTARTUP` script. |
| 1010 |
Note that this function has no stability guarantees, |
| 1011 |
and may change or be removed. |
| 1012 |
|
| 1013 |
(Contributed by Łukasz Langa in :gh:`131507`.) |
| 1014 |
|
| 1015 |
* The default :term:`interactive` shell now supports import auto-completion. |
| 1016 |
This means that typing ``import co`` and pressing :kbd:`<Tab>` will suggest |
| 1017 |
modules starting with ``co``. Similarly, typing ``from concurrent import i`` |
| 1018 |
will suggest submodules of ``concurrent`` starting with ``i``. |
| 1019 |
Note that autocompletion of module attributes is not currently supported. |
| 1020 |
(Contributed by Tomas Roun in :gh:`69605`.) |
| 1021 |
|
| 1022 |
|
| 1023 |
New modules |
| 1024 |
=========== |
| 1025 |
|
| 1026 |
* :mod:`annotationlib`: |
| 1027 |
For introspecting :term:`annotations <annotation>`. |
| 1028 |
See :ref:`PEP 749 <whatsnew314-deferred-annotations>` for more details. |
| 1029 |
(Contributed by Jelle Zijlstra in :gh:`119180`.) |
| 1030 |
|
| 1031 |
* :mod:`compression` (including :mod:`compression.zstd`): |
| 1032 |
A package for compression-related modules, |
| 1033 |
including a new module to support the Zstandard compression format. |
| 1034 |
See :ref:`PEP 784 <whatsnew314-zstandard>` for more details. |
| 1035 |
(Contributed by Emma Harper Smith, Adam Turner, Gregory P. Smith, Tomas Roun, |
| 1036 |
Victor Stinner, and Rogdham in :gh:`132983`.) |
| 1037 |
|
| 1038 |
* :mod:`concurrent.interpreters`: |
| 1039 |
Support for multiple interpreters in the standard library. |
| 1040 |
See :ref:`PEP 734 <whatsnew314-multiple-interpreters>` for more details. |
| 1041 |
(Contributed by Eric Snow in :gh:`134939`.) |
| 1042 |
|
| 1043 |
* :mod:`string.templatelib`: |
| 1044 |
Support for template string literals (t-strings). |
| 1045 |
See :ref:`PEP 750 <whatsnew314-template-string-literals>` for more details. |
| 1046 |
(Contributed by Jim Baker, Guido van Rossum, Paul Everitt, Koudai Aono, |
| 1047 |
Lysandros Nikolaou, Dave Peck, Adam Turner, Jelle Zijlstra, Bénédikt Tran, |
| 1048 |
and Pablo Galindo Salgado in :gh:`132661`.) |
| 1049 |
|
| 1050 |
|
| 1051 |
Improved modules |
| 1052 |
================ |
| 1053 |
|
| 1054 |
argparse |
| 1055 |
-------- |
| 1056 |
|
| 1057 |
* The default value of the :ref:`program name <prog>` for |
| 1058 |
:class:`argparse.ArgumentParser` now reflects the way the Python |
| 1059 |
interpreter was instructed to find the ``__main__`` module code. |
| 1060 |
(Contributed by Serhiy Storchaka and Alyssa Coghlan in :gh:`66436`.) |
| 1061 |
|
| 1062 |
* Introduced the optional *suggest_on_error* parameter to |
| 1063 |
:class:`argparse.ArgumentParser`, enabling suggestions for argument choices |
| 1064 |
and subparser names if mistyped by the user. |
| 1065 |
(Contributed by Savannah Ostrowski in :gh:`124456`.) |
| 1066 |
|
| 1067 |
* Enable color for help text, which can be disabled with the optional *color* |
| 1068 |
parameter to :class:`argparse.ArgumentParser`. |
| 1069 |
This can also be controlled by :ref:`environment variables |
| 1070 |
<using-on-controlling-color>`. |
| 1071 |
(Contributed by Hugo van Kemenade in :gh:`130645`.) |
| 1072 |
|
| 1073 |
|
| 1074 |
ast |
| 1075 |
--- |
| 1076 |
|
| 1077 |
* Add :func:`~ast.compare`, a function for comparing two ASTs. |
| 1078 |
(Contributed by Batuhan Taskaya and Jeremy Hylton in :gh:`60191`.) |
| 1079 |
|
| 1080 |
* Add support for :func:`copy.replace` for AST nodes. |
| 1081 |
(Contributed by Bénédikt Tran in :gh:`121141`.) |
| 1082 |
|
| 1083 |
* Docstrings are now removed from an optimized AST in optimization level 2. |
| 1084 |
(Contributed by Irit Katriel in :gh:`123958`.) |
| 1085 |
|
| 1086 |
* The :func:`repr` output for AST nodes now includes more information. |
| 1087 |
(Contributed by Tomas Roun in :gh:`116022`.) |
| 1088 |
|
| 1089 |
* When called with an AST as input, the :func:`~ast.parse` function |
| 1090 |
now always verifies that the root node type is appropriate. |
| 1091 |
(Contributed by Irit Katriel in :gh:`130139`.) |
| 1092 |
|
| 1093 |
* Add new options to the command-line interface: |
| 1094 |
:option:`--feature-version <ast --feature-version>`, |
| 1095 |
:option:`--optimize <ast --optimize>`, and |
| 1096 |
:option:`--show-empty <ast --show-empty>`. |
| 1097 |
(Contributed by Semyon Moroz in :gh:`133367`.) |
| 1098 |
|
| 1099 |
|
| 1100 |
asyncio |
| 1101 |
------- |
| 1102 |
|
| 1103 |
* The function and methods named :func:`!create_task` now take an arbitrary |
| 1104 |
list of keyword arguments. All keyword arguments are passed to the |
| 1105 |
:class:`~asyncio.Task` constructor or the custom task factory. |
| 1106 |
(See :meth:`~asyncio.loop.set_task_factory` for details.) |
| 1107 |
The ``name`` and ``context`` keyword arguments are no longer special; |
| 1108 |
the name should now be set using the ``name`` keyword argument of the factory, |
| 1109 |
and ``context`` may be ``None``. |
| 1110 |
|
| 1111 |
This affects the following function and methods: |
| 1112 |
:meth:`asyncio.create_task`, |
| 1113 |
:meth:`asyncio.loop.create_task`, |
| 1114 |
:meth:`asyncio.TaskGroup.create_task`. |
| 1115 |
|
| 1116 |
(Contributed by Thomas Grainger in :gh:`128307`.) |
| 1117 |
|
| 1118 |
* There are two new utility functions for |
| 1119 |
introspecting and printing a program's call graph: |
| 1120 |
:func:`~asyncio.capture_call_graph` and :func:`~asyncio.print_call_graph`. |
| 1121 |
See :ref:`Asyncio introspection capabilities |
| 1122 |
<whatsnew314-asyncio-introspection>` for more details. |
| 1123 |
(Contributed by Yury Selivanov, Pablo Galindo Salgado, and Łukasz Langa |
| 1124 |
in :gh:`91048`.) |
| 1125 |
|
| 1126 |
|
| 1127 |
calendar |
| 1128 |
-------- |
| 1129 |
|
| 1130 |
.. _whatsnew314-color-calendar: |
| 1131 |
|
| 1132 |
* By default, today's date is highlighted in color in :mod:`calendar`'s |
| 1133 |
:ref:`command-line <calendar-cli>` text output. |
| 1134 |
This can be controlled by :ref:`environment variables |
| 1135 |
<using-on-controlling-color>`. |
| 1136 |
(Contributed by Hugo van Kemenade in :gh:`128317`.) |
| 1137 |
|
| 1138 |
|
| 1139 |
concurrent.futures |
| 1140 |
------------------ |
| 1141 |
|
| 1142 |
.. _whatsnew314-concurrent-futures-interp-pool: |
| 1143 |
|
| 1144 |
* Add a new executor class, :class:`~concurrent.futures.InterpreterPoolExecutor`, |
| 1145 |
which exposes multiple Python interpreters in the same process |
| 1146 |
('subinterpreters') to Python code. |
| 1147 |
This uses a pool of independent Python interpreters to execute calls |
| 1148 |
asynchronously. |
| 1149 |
|
| 1150 |
This is separate from the new :mod:`~concurrent.interpreters` module |
| 1151 |
introduced by :ref:`PEP 734 <whatsnew314-multiple-interpreters>`. |
| 1152 |
(Contributed by Eric Snow in :gh:`124548`.) |
| 1153 |
|
| 1154 |
.. _whatsnew314-concurrent-futures-start-method: |
| 1155 |
|
| 1156 |
* On Unix platforms other than macOS, :ref:`'forkserver' |
| 1157 |
<multiprocessing-start-method-forkserver>` is now the default :ref:`start |
| 1158 |
method <multiprocessing-start-methods>` for |
| 1159 |
:class:`~concurrent.futures.ProcessPoolExecutor` |
| 1160 |
(replacing :ref:`'fork' <multiprocessing-start-method-fork>`). |
| 1161 |
This change does not affect Windows or macOS, where :ref:`'spawn' |
| 1162 |
<multiprocessing-start-method-spawn>` remains the default start method. |
| 1163 |
|
| 1164 |
If the threading incompatible *fork* method is required, you must explicitly |
| 1165 |
request it by supplying a multiprocessing context *mp_context* to |
| 1166 |
:class:`~concurrent.futures.ProcessPoolExecutor`. |
| 1167 |
|
| 1168 |
See :ref:`forkserver restrictions <multiprocessing-programming-forkserver>` |
| 1169 |
for information and differences with the *fork* method and how this change |
| 1170 |
may affect existing code with mutable global shared variables and/or shared |
| 1171 |
objects that can not be automatically :mod:`pickled <pickle>`. |
| 1172 |
|
| 1173 |
(Contributed by Gregory P. Smith in :gh:`84559`.) |
| 1174 |
|
| 1175 |
* Add two new methods to :class:`~concurrent.futures.ProcessPoolExecutor`, |
| 1176 |
:meth:`~concurrent.futures.ProcessPoolExecutor.terminate_workers` |
| 1177 |
and :meth:`~concurrent.futures.ProcessPoolExecutor.kill_workers`, |
| 1178 |
as ways to terminate or kill all living worker processes in the given pool. |
| 1179 |
(Contributed by Charles Machalow in :gh:`130849`.) |
| 1180 |
|
| 1181 |
* Add the optional *buffersize* parameter to :meth:`Executor.map |
| 1182 |
<concurrent.futures.Executor.map>` to limit the number of submitted |
| 1183 |
tasks whose results have not yet been yielded. If the buffer is full, |
| 1184 |
iteration over the *iterables* pauses until a result is yielded from the |
| 1185 |
buffer. |
| 1186 |
(Contributed by Enzo Bonnal and Josh Rosenberg in :gh:`74028`.) |
| 1187 |
|
| 1188 |
|
| 1189 |
configparser |
| 1190 |
------------ |
| 1191 |
|
| 1192 |
* :mod:`!configparser` will no longer write config files it cannot read, |
| 1193 |
to improve security. |
| 1194 |
Attempting to :meth:`~configparser.ConfigParser.write` keys containing |
| 1195 |
delimiters or beginning with the section header pattern will raise an |
| 1196 |
:class:`~configparser.InvalidWriteError`. |
| 1197 |
(Contributed by Jacob Lincoln in :gh:`129270`.) |
| 1198 |
|
| 1199 |
|
| 1200 |
contextvars |
| 1201 |
----------- |
| 1202 |
|
| 1203 |
* Support the :term:`context manager` protocol |
| 1204 |
for :class:`~contextvars.Token` objects. |
| 1205 |
(Contributed by Andrew Svetlov in :gh:`129889`.) |
| 1206 |
|
| 1207 |
|
| 1208 |
ctypes |
| 1209 |
------ |
| 1210 |
|
| 1211 |
* The layout of :ref:`bit fields <ctypes-bit-fields-in-structures-unions>` |
| 1212 |
in :class:`~ctypes.Structure` and :class:`~ctypes.Union` objects |
| 1213 |
is now a closer match to platform defaults (GCC/Clang or MSVC). |
| 1214 |
In particular, fields no longer overlap. |
| 1215 |
(Contributed by Matthias Görgens in :gh:`97702`.) |
| 1216 |
|
| 1217 |
* The :attr:`.Structure._layout_` class attribute can now be set |
| 1218 |
to help match a non-default ABI. |
| 1219 |
(Contributed by Petr Viktorin in :gh:`97702`.) |
| 1220 |
|
| 1221 |
* The class of :class:`~ctypes.Structure`/:class:`~ctypes.Union` |
| 1222 |
field descriptors is now available as :class:`~ctypes.CField`, |
| 1223 |
and has new attributes to aid debugging and introspection. |
| 1224 |
(Contributed by Petr Viktorin in :gh:`128715`.) |
| 1225 |
|
| 1226 |
* On Windows, the :exc:`~ctypes.COMError` exception is now public. |
| 1227 |
(Contributed by Jun Komoda in :gh:`126686`.) |
| 1228 |
|
| 1229 |
* On Windows, the :func:`~ctypes.CopyComPointer` function is now public. |
| 1230 |
(Contributed by Jun Komoda in :gh:`127275`.) |
| 1231 |
|
| 1232 |
* Add :func:`~ctypes.memoryview_at`, a function to create a |
| 1233 |
:class:`memoryview` object that refers to the supplied pointer and |
| 1234 |
length. This works like :func:`ctypes.string_at` except it avoids a |
| 1235 |
buffer copy, and is typically useful when implementing pure Python |
| 1236 |
callback functions that are passed dynamically-sized buffers. |
| 1237 |
(Contributed by Rian Hunter in :gh:`112018`.) |
| 1238 |
|
| 1239 |
* Complex types, :class:`~ctypes.c_float_complex`, |
| 1240 |
:class:`~ctypes.c_double_complex`, and :class:`~ctypes.c_longdouble_complex`, |
| 1241 |
are now available if both the compiler and the ``libffi`` library support |
| 1242 |
complex C types. |
| 1243 |
(Contributed by Sergey B Kirpichev in :gh:`61103`.) |
| 1244 |
|
| 1245 |
* Add :func:`ctypes.util.dllist` for listing the shared libraries |
| 1246 |
loaded by the current process. |
| 1247 |
(Contributed by Brian Ward in :gh:`119349`.) |
| 1248 |
|
| 1249 |
* Move :func:`ctypes.POINTER` types cache from a global internal cache |
| 1250 |
(``_pointer_type_cache``) to the :attr:`_CData.__pointer_type__ |
| 1251 |
<ctypes._CData.__pointer_type__>` attribute of the corresponding |
| 1252 |
:mod:`!ctypes` types. |
| 1253 |
This will stop the cache from growing without limits in some situations. |
| 1254 |
(Contributed by Sergey Miryanov in :gh:`100926`.) |
| 1255 |
|
| 1256 |
* The :class:`~ctypes.py_object` type now supports subscription, |
| 1257 |
making it a :term:`generic type`. |
| 1258 |
(Contributed by Brian Schubert in :gh:`132168`.) |
| 1259 |
|
| 1260 |
* :mod:`!ctypes` now supports :term:`free-threading builds <free threading>`. |
| 1261 |
(Contributed by Kumar Aditya and Peter Bierma in :gh:`127945`.) |
| 1262 |
|
| 1263 |
|
| 1264 |
curses |
| 1265 |
------ |
| 1266 |
|
| 1267 |
* Add the :func:`~curses.assume_default_colors` function, |
| 1268 |
a refinement of the :func:`~curses.use_default_colors` function which |
| 1269 |
allows changing the color pair ``0``. |
| 1270 |
(Contributed by Serhiy Storchaka in :gh:`133139`.) |
| 1271 |
|
| 1272 |
|
| 1273 |
datetime |
| 1274 |
-------- |
| 1275 |
|
| 1276 |
* Add the :meth:`~datetime.date.strptime` method to the |
| 1277 |
:class:`datetime.date` and :class:`datetime.time` classes. |
| 1278 |
(Contributed by Wannes Boeykens in :gh:`41431`.) |
| 1279 |
|
| 1280 |
|
| 1281 |
decimal |
| 1282 |
------- |
| 1283 |
|
| 1284 |
* Add :meth:`.Decimal.from_number` as an alternative constructor for |
| 1285 |
:class:`~decimal.Decimal`. |
| 1286 |
(Contributed by Serhiy Storchaka in :gh:`121798`.) |
| 1287 |
|
| 1288 |
* Expose :func:`~decimal.IEEEContext` to support creation of contexts |
| 1289 |
corresponding to the IEEE 754 (2008) decimal interchange formats. |
| 1290 |
(Contributed by Sergey B Kirpichev in :gh:`53032`.) |
| 1291 |
|
| 1292 |
|
| 1293 |
difflib |
| 1294 |
------- |
| 1295 |
|
| 1296 |
* Comparison pages with highlighted changes generated by the |
| 1297 |
:class:`~difflib.HtmlDiff` class now support 'dark mode'. |
| 1298 |
(Contributed by Jiahao Li in :gh:`129939`.) |
| 1299 |
|
| 1300 |
|
| 1301 |
dis |
| 1302 |
--- |
| 1303 |
|
| 1304 |
* Add support for rendering full source location information of |
| 1305 |
:class:`instructions <dis.Instruction>`, rather than only the line number. |
| 1306 |
This feature is added to the following interfaces via the *show_positions* |
| 1307 |
keyword argument: |
| 1308 |
|
| 1309 |
- :class:`dis.Bytecode` |
| 1310 |
- :func:`dis.dis` |
| 1311 |
- :func:`dis.distb` |
| 1312 |
- :func:`dis.disassemble` |
| 1313 |
|
| 1314 |
This feature is also exposed via :option:`dis --show-positions`. |
| 1315 |
(Contributed by Bénédikt Tran in :gh:`123165`.) |
| 1316 |
|
| 1317 |
* Add the :option:`dis --specialized` command-line option to |
| 1318 |
show specialized bytecode. |
| 1319 |
(Contributed by Bénédikt Tran in :gh:`127413`.) |
| 1320 |
|
| 1321 |
|
| 1322 |
errno |
| 1323 |
----- |
| 1324 |
|
| 1325 |
* Add the :data:`~errno.EHWPOISON` error code constant. |
| 1326 |
(Contributed by James Roy in :gh:`126585`.) |
| 1327 |
|
| 1328 |
|
| 1329 |
faulthandler |
| 1330 |
------------ |
| 1331 |
|
| 1332 |
* Add support for printing the C stack trace on systems that |
| 1333 |
:ref:`support it <c-stack-compatibility>` via the new |
| 1334 |
:func:`~faulthandler.dump_c_stack` function or via the *c_stack* argument |
| 1335 |
in :func:`faulthandler.enable`. |
| 1336 |
(Contributed by Peter Bierma in :gh:`127604`.) |
| 1337 |
|
| 1338 |
|
| 1339 |
fnmatch |
| 1340 |
------- |
| 1341 |
|
| 1342 |
* Add :func:`~fnmatch.filterfalse`, a function to reject names |
| 1343 |
matching a given pattern. |
| 1344 |
(Contributed by Bénédikt Tran in :gh:`74598`.) |
| 1345 |
|
| 1346 |
|
| 1347 |
fractions |
| 1348 |
--------- |
| 1349 |
|
| 1350 |
* A :class:`~fractions.Fraction` object may now be constructed from any |
| 1351 |
object with the :meth:`!as_integer_ratio` method. |
| 1352 |
(Contributed by Serhiy Storchaka in :gh:`82017`.) |
| 1353 |
|
| 1354 |
* Add :meth:`.Fraction.from_number` as an alternative constructor for |
| 1355 |
:class:`~fractions.Fraction`. |
| 1356 |
(Contributed by Serhiy Storchaka in :gh:`121797`.) |
| 1357 |
|
| 1358 |
|
| 1359 |
functools |
| 1360 |
--------- |
| 1361 |
|
| 1362 |
* Add the :data:`~functools.Placeholder` sentinel. |
| 1363 |
This may be used with the :func:`~functools.partial` |
| 1364 |
or :func:`~functools.partialmethod` functions to reserve a place |
| 1365 |
for positional arguments in the returned :ref:`partial object |
| 1366 |
<partial-objects>`. |
| 1367 |
(Contributed by Dominykas Grigonis in :gh:`119127`.) |
| 1368 |
|
| 1369 |
* Allow the *initial* parameter of :func:`~functools.reduce` to be passed |
| 1370 |
as a keyword argument. |
| 1371 |
(Contributed by Sayandip Dutta in :gh:`125916`.) |
| 1372 |
|
| 1373 |
|
| 1374 |
getopt |
| 1375 |
------ |
| 1376 |
|
| 1377 |
* Add support for options with optional arguments. |
| 1378 |
(Contributed by Serhiy Storchaka in :gh:`126374`.) |
| 1379 |
|
| 1380 |
* Add support for returning intermixed options and non-option arguments in order. |
| 1381 |
(Contributed by Serhiy Storchaka in :gh:`126390`.) |
| 1382 |
|
| 1383 |
|
| 1384 |
getpass |
| 1385 |
------- |
| 1386 |
|
| 1387 |
* Support keyboard feedback in the :func:`~getpass.getpass` function via |
| 1388 |
the keyword-only optional argument *echo_char*. |
| 1389 |
Placeholder characters are rendered whenever a character is entered, |
| 1390 |
and removed when a character is deleted. |
| 1391 |
(Contributed by Semyon Moroz in :gh:`77065`.) |
| 1392 |
|
| 1393 |
|
| 1394 |
graphlib |
| 1395 |
-------- |
| 1396 |
|
| 1397 |
* Allow :meth:`.TopologicalSorter.prepare` to be called more than once |
| 1398 |
as long as sorting has not started. |
| 1399 |
(Contributed by Daniel Pope in :gh:`130914`.) |
| 1400 |
|
| 1401 |
|
| 1402 |
heapq |
| 1403 |
----- |
| 1404 |
|
| 1405 |
* The :mod:`!heapq` module has improved support for working with max-heaps, |
| 1406 |
via the following new functions: |
| 1407 |
|
| 1408 |
* :func:`~heapq.heapify_max` |
| 1409 |
* :func:`~heapq.heappush_max` |
| 1410 |
* :func:`~heapq.heappop_max` |
| 1411 |
* :func:`~heapq.heapreplace_max` |
| 1412 |
* :func:`~heapq.heappushpop_max` |
| 1413 |
|
| 1414 |
|
| 1415 |
hmac |
| 1416 |
---- |
| 1417 |
|
| 1418 |
* Add a built-in implementation for HMAC (:rfc:`2104`) using formally verified |
| 1419 |
code from the `HACL* <https://github.com/hacl-star/hacl-star/>`__ project. |
| 1420 |
This implementation is used as a fallback when the OpenSSL implementation |
| 1421 |
of HMAC is not available. |
| 1422 |
(Contributed by Bénédikt Tran in :gh:`99108`.) |
| 1423 |
|
| 1424 |
|
| 1425 |
http |
| 1426 |
---- |
| 1427 |
|
| 1428 |
* Directory lists and error pages generated by the :mod:`http.server` |
| 1429 |
module allow the browser to apply its default dark mode. |
| 1430 |
(Contributed by Yorik Hansen in :gh:`123430`.) |
| 1431 |
|
| 1432 |
* The :mod:`http.server` module now supports serving over HTTPS using the |
| 1433 |
:class:`http.server.HTTPSServer` class. This functionality is exposed by |
| 1434 |
the command-line interface (``python -m http.server``) through the following |
| 1435 |
options: |
| 1436 |
|
| 1437 |
* :option:`--tls-cert \<path\> <http.server --tls-cert>`: |
| 1438 |
Path to the TLS certificate file. |
| 1439 |
* :option:`--tls-key \<path\> <http.server --tls-key>`: |
| 1440 |
Optional path to the private key file. |
| 1441 |
* :option:`--tls-password-file \<path\> <http.server --tls-password-file>`: |
| 1442 |
Optional path to the password file for the private key. |
| 1443 |
|
| 1444 |
(Contributed by Semyon Moroz in :gh:`85162`.) |
| 1445 |
|
| 1446 |
|
| 1447 |
imaplib |
| 1448 |
------- |
| 1449 |
|
| 1450 |
* Add :meth:`.IMAP4.idle`, implementing the IMAP4 |
| 1451 |
``IDLE`` command as defined in :rfc:`2177`. |
| 1452 |
(Contributed by Forest in :gh:`55454`.) |
| 1453 |
|
| 1454 |
|
| 1455 |
inspect |
| 1456 |
------- |
| 1457 |
|
| 1458 |
* :func:`~inspect.signature` takes a new argument *annotation_format* to control |
| 1459 |
the :class:`annotationlib.Format` used for representing annotations. |
| 1460 |
(Contributed by Jelle Zijlstra in :gh:`101552`.) |
| 1461 |
|
| 1462 |
* :meth:`.Signature.format` takes a new argument *unquote_annotations*. |
| 1463 |
If true, string :term:`annotations <annotation>` are displayed without |
| 1464 |
surrounding quotes. |
| 1465 |
(Contributed by Jelle Zijlstra in :gh:`101552`.) |
| 1466 |
|
| 1467 |
* Add function :func:`~inspect.ispackage` to determine whether an object is a |
| 1468 |
:term:`package` or not. |
| 1469 |
(Contributed by Zhikang Yan in :gh:`125634`.) |
| 1470 |
|
| 1471 |
|
| 1472 |
io |
| 1473 |
-- |
| 1474 |
|
| 1475 |
* Reading text from a non-blocking stream with ``read`` may now raise a |
| 1476 |
:exc:`BlockingIOError` if the operation cannot immediately return bytes. |
| 1477 |
(Contributed by Giovanni Siragusa in :gh:`109523`.) |
| 1478 |
|
| 1479 |
* Add the :class:`~io.Reader` and :class:`~io.Writer` protocols as simpler |
| 1480 |
alternatives to the pseudo-protocols :class:`typing.IO`, |
| 1481 |
:class:`typing.TextIO`, and :class:`typing.BinaryIO`. |
| 1482 |
(Contributed by Sebastian Rittau in :gh:`127648`.) |
| 1483 |
|
| 1484 |
|
| 1485 |
json |
| 1486 |
---- |
| 1487 |
|
| 1488 |
* Add exception notes for JSON serialization errors that allow |
| 1489 |
identifying the source of the error. |
| 1490 |
(Contributed by Serhiy Storchaka in :gh:`122163`.) |
| 1491 |
|
| 1492 |
* Allow using the :mod:`json` module as a script using the :option:`-m` switch: |
| 1493 |
:program:`python -m json`. |
| 1494 |
This is now preferred to :program:`python -m json.tool`, |
| 1495 |
which is :term:`soft deprecated`. |
| 1496 |
See the :ref:`JSON command-line interface <json-commandline>` documentation. |
| 1497 |
(Contributed by Trey Hunner in :gh:`122873`.) |
| 1498 |
|
| 1499 |
* By default, the output of the :ref:`JSON command-line interface |
| 1500 |
<json-commandline>` is highlighted in color. |
| 1501 |
This can be controlled by :ref:`environment variables |
| 1502 |
<using-on-controlling-color>`. |
| 1503 |
(Contributed by Tomas Roun in :gh:`131952`.) |
| 1504 |
|
| 1505 |
|
| 1506 |
linecache |
| 1507 |
--------- |
| 1508 |
|
| 1509 |
* :func:`~linecache.getline` can now retrieve source code for frozen modules. |
| 1510 |
(Contributed by Tian Gao in :gh:`131638`.) |
| 1511 |
|
| 1512 |
|
| 1513 |
logging.handlers |
| 1514 |
---------------- |
| 1515 |
|
| 1516 |
* :class:`~logging.handlers.QueueListener` objects now support the |
| 1517 |
:term:`context manager` protocol. |
| 1518 |
(Contributed by Charles Machalow in :gh:`132106`.) |
| 1519 |
|
| 1520 |
* :meth:`QueueListener.start <logging.handlers.QueueListener.start>` now |
| 1521 |
raises a :exc:`RuntimeError` if the listener is already started. |
| 1522 |
(Contributed by Charles Machalow in :gh:`132106`.) |
| 1523 |
|
| 1524 |
|
| 1525 |
math |
| 1526 |
---- |
| 1527 |
|
| 1528 |
* Added more detailed error messages for domain errors in the module. |
| 1529 |
(Contributed by Charlie Zhao and Sergey B Kirpichev in :gh:`101410`.) |
| 1530 |
|
| 1531 |
|
| 1532 |
mimetypes |
| 1533 |
--------- |
| 1534 |
|
| 1535 |
* Add a public :ref:`command-line <mimetypes-cli>` for the module, |
| 1536 |
invoked via :program:`python -m mimetypes`. |
| 1537 |
(Contributed by Oleg Iarygin and Hugo van Kemenade in :gh:`93096`.) |
| 1538 |
|
| 1539 |
* Add several new MIME types based on RFCs and common usage: |
| 1540 |
|
| 1541 |
.. rubric:: Microsoft and :rfc:`8081` MIME types for fonts |
| 1542 |
|
| 1543 |
* Embedded OpenType: ``application/vnd.ms-fontobject`` |
| 1544 |
* OpenType Layout (OTF) ``font/otf`` |
| 1545 |
* TrueType: ``font/ttf`` |
| 1546 |
* WOFF 1.0 ``font/woff`` |
| 1547 |
* WOFF 2.0 ``font/woff2`` |
| 1548 |
|
| 1549 |
.. rubric:: :rfc:`9559` MIME types for Matroska audiovisual |
| 1550 |
data container structures |
| 1551 |
|
| 1552 |
* audio with no video: ``audio/matroska`` (``.mka``) |
| 1553 |
* video: ``video/matroska`` (``.mkv``) |
| 1554 |
* stereoscopic video: ``video/matroska-3d`` (``.mk3d``) |
| 1555 |
|
| 1556 |
.. rubric:: Images with RFCs |
| 1557 |
|
| 1558 |
* :rfc:`1494`: CCITT Group 3 (``.g3``) |
| 1559 |
* :rfc:`3362`: Real-time Facsimile, T.38 (``.t38``) |
| 1560 |
* :rfc:`3745`: JPEG 2000 (``.jp2``), extension (``.jpx``) and compound (``.jpm``) |
| 1561 |
* :rfc:`3950`: Tag Image File Format Fax eXtended, TIFF-FX (``.tfx``) |
| 1562 |
* :rfc:`4047`: Flexible Image Transport System (``.fits``) |
| 1563 |
* :rfc:`7903`: Enhanced Metafile (``.emf``) and Windows Metafile (``.wmf``) |
| 1564 |
|
| 1565 |
.. rubric:: Other MIME type additions and changes |
| 1566 |
|
| 1567 |
* :rfc:`2361`: Change type for ``.avi`` to ``video/vnd.avi`` |
| 1568 |
and for ``.wav`` to ``audio/vnd.wave`` |
| 1569 |
* :rfc:`4337`: Add MPEG-4 ``audio/mp4`` (``.m4a``) |
| 1570 |
* :rfc:`5334`: Add Ogg media (``.oga``, ``.ogg`` and ``.ogx``) |
| 1571 |
* :rfc:`6713`: Add gzip ``application/gzip`` (``.gz``) |
| 1572 |
* :rfc:`9639`: Add FLAC ``audio/flac`` (``.flac``) |
| 1573 |
* :rfc:`9512` ``application/yaml`` MIME type for YAML files (``.yaml`` |
| 1574 |
and ``.yml``) |
| 1575 |
* Add 7z ``application/x-7z-compressed`` (``.7z``) |
| 1576 |
* Add Android Package ``application/vnd.android.package-archive`` (``.apk``) |
| 1577 |
when not strict |
| 1578 |
* Add deb ``application/x-debian-package`` (``.deb``) |
| 1579 |
* Add glTF binary ``model/gltf-binary`` (``.glb``) |
| 1580 |
* Add glTF JSON/ASCII ``model/gltf+json`` (``.gltf``) |
| 1581 |
* Add M4V ``video/x-m4v`` (``.m4v``) |
| 1582 |
* Add PHP ``application/x-httpd-php`` (``.php``) |
| 1583 |
* Add RAR ``application/vnd.rar`` (``.rar``) |
| 1584 |
* Add RPM ``application/x-rpm`` (``.rpm``) |
| 1585 |
* Add STL ``model/stl`` (``.stl``) |
| 1586 |
* Add Windows Media Video ``video/x-ms-wmv`` (``.wmv``) |
| 1587 |
* De facto: Add WebM ``audio/webm`` (``.weba``) |
| 1588 |
* `ECMA-376 |
| 1589 |
<https://ecma-international.org/publications-and-standards/standards/ecma-376/>`__: |
| 1590 |
Add ``.docx``, ``.pptx`` and ``.xlsx`` types |
| 1591 |
* `OASIS |
| 1592 |
<https://docs.oasis-open.org/office/v1.2/cs01/OpenDocument-v1.2-cs01-part1.html#Appendix_C>`__: |
| 1593 |
Add OpenDocument ``.odg``, ``.odp``, ``.ods`` and ``.odt`` types |
| 1594 |
* `W3C <https://www.w3.org/TR/epub-33/#app-media-type>`__: |
| 1595 |
Add EPUB ``application/epub+zip`` (``.epub``) |
| 1596 |
|
| 1597 |
(Contributed by Sahil Prajapati and Hugo van Kemenade in :gh:`84852`, |
| 1598 |
by Sasha "Nelie" Chernykh and Hugo van Kemenade in :gh:`132056`, |
| 1599 |
and by Hugo van Kemenade in :gh:`89416`, :gh:`85957`, and :gh:`129965`.) |
| 1600 |
|
| 1601 |
|
| 1602 |
multiprocessing |
| 1603 |
--------------- |
| 1604 |
|
| 1605 |
.. _whatsnew314-multiprocessing-start-method: |
| 1606 |
|
| 1607 |
* On Unix platforms other than macOS, :ref:`'forkserver' |
| 1608 |
<multiprocessing-start-method-forkserver>` is now the default :ref:`start |
| 1609 |
method <multiprocessing-start-methods>` |
| 1610 |
(replacing :ref:`'fork' <multiprocessing-start-method-fork>`). |
| 1611 |
This change does not affect Windows or macOS, where :ref:`'spawn' |
| 1612 |
<multiprocessing-start-method-spawn>` remains the default start method. |
| 1613 |
|
| 1614 |
If the threading incompatible *fork* method is required, you must explicitly |
| 1615 |
request it via a context from :func:`~multiprocessing.get_context` (preferred) |
| 1616 |
or change the default via :func:`~multiprocessing.set_start_method`. |
| 1617 |
|
| 1618 |
See :ref:`forkserver restrictions <multiprocessing-programming-forkserver>` |
| 1619 |
for information and differences with the *fork* method and how this change |
| 1620 |
may affect existing code with mutable global shared variables and/or shared |
| 1621 |
objects that can not be automatically :mod:`pickled <pickle>`. |
| 1622 |
|
| 1623 |
(Contributed by Gregory P. Smith in :gh:`84559`.) |
| 1624 |
|
| 1625 |
* :mod:`multiprocessing`'s ``'forkserver'`` start method now authenticates |
| 1626 |
its control socket to avoid solely relying on filesystem permissions |
| 1627 |
to restrict what other processes could cause the forkserver to spawn workers |
| 1628 |
and run code. |
| 1629 |
(Contributed by Gregory P. Smith for :gh:`97514`.) |
| 1630 |
|
| 1631 |
* The :ref:`multiprocessing proxy objects <multiprocessing-proxy_objects>` |
| 1632 |
for *list* and *dict* types gain previously overlooked missing methods: |
| 1633 |
|
| 1634 |
* :meth:`!clear` and :meth:`!copy` for proxies of :class:`list` |
| 1635 |
* :meth:`~dict.fromkeys`, ``reversed(d)``, ``d | {}``, ``{} | d``, |
| 1636 |
``d |= {'b': 2}`` for proxies of :class:`dict` |
| 1637 |
|
| 1638 |
(Contributed by Roy Hyunjin Han for :gh:`103134`.) |
| 1639 |
|
| 1640 |
* Add support for shared :class:`set` objects via |
| 1641 |
:meth:`.SyncManager.set`. |
| 1642 |
The :func:`set` in :func:`~multiprocessing.Manager` method is now available. |
| 1643 |
(Contributed by Mingyu Park in :gh:`129949`.) |
| 1644 |
|
| 1645 |
* Add the :meth:`~multiprocessing.Process.interrupt` |
| 1646 |
to :class:`multiprocessing.Process` objects, which terminates the child |
| 1647 |
process by sending :py:const:`~signal.SIGINT`. This enables |
| 1648 |
:keyword:`finally` clauses to print a stack trace for the terminated |
| 1649 |
process. (Contributed by Artem Pulkin in :gh:`131913`.) |
| 1650 |
|
| 1651 |
|
| 1652 |
operator |
| 1653 |
-------- |
| 1654 |
|
| 1655 |
* Add :func:`~operator.is_none` and :func:`~operator.is_not_none` as a pair |
| 1656 |
of functions, such that ``operator.is_none(obj)`` is equivalent |
| 1657 |
to ``obj is None`` and ``operator.is_not_none(obj)`` is equivalent |
| 1658 |
to ``obj is not None``. |
| 1659 |
(Contributed by Raymond Hettinger and Nico Mexis in :gh:`115808`.) |
| 1660 |
|
| 1661 |
|
| 1662 |
os |
| 1663 |
-- |
| 1664 |
|
| 1665 |
* Add the :func:`~os.reload_environ` function to update :data:`os.environ` and |
| 1666 |
:data:`os.environb` with changes to the environment made by |
| 1667 |
:func:`os.putenv`, by :func:`os.unsetenv`, or made outside Python in the |
| 1668 |
same process. |
| 1669 |
(Contributed by Victor Stinner in :gh:`120057`.) |
| 1670 |
|
| 1671 |
* Add the :data:`~os.SCHED_DEADLINE` and :data:`~os.SCHED_NORMAL` constants |
| 1672 |
to the :mod:`!os` module. |
| 1673 |
(Contributed by James Roy in :gh:`127688`.) |
| 1674 |
|
| 1675 |
* Add the :func:`~os.readinto` function to read into a |
| 1676 |
:ref:`buffer object <bufferobjects>` from a file descriptor. |
| 1677 |
(Contributed by Cody Maloney in :gh:`129205`.) |
| 1678 |
|
| 1679 |
|
| 1680 |
os.path |
| 1681 |
------- |
| 1682 |
|
| 1683 |
* The *strict* parameter to :func:`~os.path.realpath` accepts a new value, |
| 1684 |
:data:`~os.path.ALLOW_MISSING`. |
| 1685 |
If used, errors other than :exc:`FileNotFoundError` will be re-raised; |
| 1686 |
the resulting path can be missing but it will be free of symlinks. |
| 1687 |
(Contributed by Petr Viktorin for :cve:`2025-4517`.) |
| 1688 |
|
| 1689 |
|
| 1690 |
pathlib |
| 1691 |
------- |
| 1692 |
|
| 1693 |
* Add methods to :class:`pathlib.Path` to recursively copy or move files and |
| 1694 |
directories: |
| 1695 |
|
| 1696 |
* :meth:`~pathlib.Path.copy` copies a file or directory tree to a destination. |
| 1697 |
* :meth:`~pathlib.Path.copy_into` copies *into* a destination directory. |
| 1698 |
* :meth:`~pathlib.Path.move` moves a file or directory tree to a destination. |
| 1699 |
* :meth:`~pathlib.Path.move_into` moves *into* a destination directory. |
| 1700 |
|
| 1701 |
(Contributed by Barney Gale in :gh:`73991`.) |
| 1702 |
|
| 1703 |
* Add the :attr:`~pathlib.Path.info` attribute, which stores an object |
| 1704 |
implementing the new :class:`pathlib.types.PathInfo` protocol. The |
| 1705 |
object supports querying the file type and internally caching |
| 1706 |
:func:`~os.stat` results. Path objects generated by |
| 1707 |
:meth:`~pathlib.Path.iterdir` are initialized with file type information |
| 1708 |
gleaned from scanning the parent directory. |
| 1709 |
(Contributed by Barney Gale in :gh:`125413`.) |
| 1710 |
|
| 1711 |
|
| 1712 |
pdb |
| 1713 |
--- |
| 1714 |
|
| 1715 |
* The :mod:`pdb` module now supports remote attaching to a running Python process |
| 1716 |
using a new :option:`-p PID <pdb --pid>` command-line option: |
| 1717 |
|
| 1718 |
.. code-block:: sh |
| 1719 |
|
| 1720 |
python -m pdb -p 1234 |
| 1721 |
|
| 1722 |
This will connect to the Python process with the given PID and allow you to |
| 1723 |
debug it interactively. Notice that due to how the Python interpreter works |
| 1724 |
attaching to a remote process that is blocked in a system call or waiting for |
| 1725 |
I/O will only work once the next bytecode instruction is executed or when the |
| 1726 |
process receives a signal. |
| 1727 |
|
| 1728 |
This feature uses :ref:`PEP 768 <whatsnew314-remote-debugging>` |
| 1729 |
and the new :func:`sys.remote_exec` function to attach to the remote process |
| 1730 |
and send the PDB commands to it. |
| 1731 |
|
| 1732 |
(Contributed by Matt Wozniski and Pablo Galindo in :gh:`131591`.) |
| 1733 |
|
| 1734 |
* Hardcoded breakpoints (:func:`breakpoint` and :func:`~pdb.set_trace`) now |
| 1735 |
reuse the most recent :class:`~pdb.Pdb` instance that calls |
| 1736 |
:meth:`~pdb.Pdb.set_trace`, instead of creating a new one each time. |
| 1737 |
As a result, all the instance specific data like :pdbcmd:`display` and |
| 1738 |
:pdbcmd:`commands` are preserved across hardcoded breakpoints. |
| 1739 |
(Contributed by Tian Gao in :gh:`121450`.) |
| 1740 |
|
| 1741 |
* Add a new argument *mode* to :class:`pdb.Pdb`. Disable the ``restart`` |
| 1742 |
command when :mod:`pdb` is in ``inline`` mode. |
| 1743 |
(Contributed by Tian Gao in :gh:`123757`.) |
| 1744 |
|
| 1745 |
* A confirmation prompt will be shown when the user tries to quit :mod:`pdb` |
| 1746 |
in ``inline`` mode. ``y``, ``Y``, ``<Enter>`` or ``EOF`` will confirm |
| 1747 |
the quit and call :func:`sys.exit`, instead of raising :exc:`bdb.BdbQuit`. |
| 1748 |
(Contributed by Tian Gao in :gh:`124704`.) |
| 1749 |
|
| 1750 |
* Inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` will |
| 1751 |
always stop the program at calling frame, ignoring the ``skip`` pattern |
| 1752 |
(if any). |
| 1753 |
(Contributed by Tian Gao in :gh:`130493`.) |
| 1754 |
|
| 1755 |
* ``<tab>`` at the beginning of the line in :mod:`pdb` multi-line input will |
| 1756 |
fill in a 4-space indentation now, instead of inserting a ``\t`` character. |
| 1757 |
(Contributed by Tian Gao in :gh:`130471`.) |
| 1758 |
|
| 1759 |
* Auto-indent is introduced in :mod:`pdb` multi-line input. It will either |
| 1760 |
keep the indentation of the last line or insert a 4-space indentation when |
| 1761 |
it detects a new code block. |
| 1762 |
(Contributed by Tian Gao in :gh:`133350`.) |
| 1763 |
|
| 1764 |
* ``$_asynctask`` is added to access the current asyncio task if applicable. |
| 1765 |
(Contributed by Tian Gao in :gh:`124367`.) |
| 1766 |
|
| 1767 |
* :func:`pdb.set_trace_async` is added to support debugging asyncio |
| 1768 |
coroutines. :keyword:`await` statements are supported with this |
| 1769 |
function. |
| 1770 |
(Contributed by Tian Gao in :gh:`132576`.) |
| 1771 |
|
| 1772 |
* Source code displayed in :mod:`pdb` will be syntax-highlighted. This feature |
| 1773 |
can be controlled using the same methods as the default :term:`interactive` |
| 1774 |
shell, in addition to the newly added ``colorize`` argument of :class:`pdb.Pdb`. |
| 1775 |
(Contributed by Tian Gao and Łukasz Langa in :gh:`133355`.) |
| 1776 |
|
| 1777 |
|
| 1778 |
pickle |
| 1779 |
------ |
| 1780 |
|
| 1781 |
* Set the default protocol version on the :mod:`pickle` module to 5. |
| 1782 |
For more details, see :ref:`pickle protocols <pickle-protocols>`. |
| 1783 |
|
| 1784 |
* Add exception notes for pickle serialization errors that allow |
| 1785 |
identifying the source of the error. |
| 1786 |
(Contributed by Serhiy Storchaka in :gh:`122213`.) |
| 1787 |
|
| 1788 |
|
| 1789 |
platform |
| 1790 |
-------- |
| 1791 |
|
| 1792 |
* Add :func:`~platform.invalidate_caches`, a function to invalidate |
| 1793 |
cached results in the :mod:`!platform` module. |
| 1794 |
(Contributed by Bénédikt Tran in :gh:`122549`.) |
| 1795 |
|
| 1796 |
|
| 1797 |
pydoc |
| 1798 |
----- |
| 1799 |
|
| 1800 |
* :term:`Annotations <annotation>` in help output are now usually |
| 1801 |
displayed in a format closer to that in the original source. |
| 1802 |
(Contributed by Jelle Zijlstra in :gh:`101552`.) |
| 1803 |
|
| 1804 |
|
| 1805 |
re |
| 1806 |
-- |
| 1807 |
|
| 1808 |
* Support ``\z`` as a synonym for ``\Z`` in :mod:`regular expressions <re>`. |
| 1809 |
It is interpreted unambiguously in many other regular expression engines, |
| 1810 |
unlike ``\Z``, which has subtly different behavior. |
| 1811 |
(Contributed by Serhiy Storchaka in :gh:`133306`.) |
| 1812 |
|
| 1813 |
* ``\B`` in :mod:`regular expression <re>` now matches the empty input string, |
| 1814 |
meaning that it is now always the opposite of ``\b``. |
| 1815 |
(Contributed by Serhiy Storchaka in :gh:`124130`.) |
| 1816 |
|
| 1817 |
|
| 1818 |
socket |
| 1819 |
------ |
| 1820 |
|
| 1821 |
* Improve and fix support for Bluetooth sockets. |
| 1822 |
|
| 1823 |
* Fix support of Bluetooth sockets on NetBSD and DragonFly BSD. |
| 1824 |
(Contributed by Serhiy Storchaka in :gh:`132429`.) |
| 1825 |
* Fix support for :const:`~socket.BTPROTO_HCI` on FreeBSD. |
| 1826 |
(Contributed by Victor Stinner in :gh:`111178`.) |
| 1827 |
* Add support for :const:`~socket.BTPROTO_SCO` on FreeBSD. |
| 1828 |
(Contributed by Serhiy Storchaka in :gh:`85302`.) |
| 1829 |
* Add support for *cid* and *bdaddr_type* in the address for |
| 1830 |
:const:`~socket.BTPROTO_L2CAP` on FreeBSD. |
| 1831 |
(Contributed by Serhiy Storchaka in :gh:`132429`.) |
| 1832 |
* Add support for *channel* in the address for |
| 1833 |
:const:`~socket.BTPROTO_HCI` on Linux. |
| 1834 |
(Contributed by Serhiy Storchaka in :gh:`70145`.) |
| 1835 |
* Accept an integer as the address for |
| 1836 |
:const:`~socket.BTPROTO_HCI` on Linux. |
| 1837 |
(Contributed by Serhiy Storchaka in :gh:`132099`.) |
| 1838 |
* Return *cid* in :meth:`~socket.socket.getsockname` for |
| 1839 |
:const:`~socket.BTPROTO_L2CAP`. |
| 1840 |
(Contributed by Serhiy Storchaka in :gh:`132429`.) |
| 1841 |
* Add many new constants. |
| 1842 |
(Contributed by Serhiy Storchaka in :gh:`132734`.) |
| 1843 |
|
| 1844 |
|
| 1845 |
ssl |
| 1846 |
--- |
| 1847 |
|
| 1848 |
* Indicate through the :data:`~ssl.HAS_PHA` Boolean whether the :mod:`!ssl` |
| 1849 |
module supports TLSv1.3 post-handshake client authentication (PHA). |
| 1850 |
(Contributed by Will Childs-Klein in :gh:`128036`.) |
| 1851 |
|
| 1852 |
|
| 1853 |
struct |
| 1854 |
------ |
| 1855 |
|
| 1856 |
* Support the :c:expr:`float complex` and :c:expr:`double complex` C types in |
| 1857 |
the :mod:`struct` module (formatting characters ``'F'`` and ``'D'`` |
| 1858 |
respectively). |
| 1859 |
(Contributed by Sergey B Kirpichev in :gh:`121249`.) |
| 1860 |
|
| 1861 |
|
| 1862 |
symtable |
| 1863 |
-------- |
| 1864 |
|
| 1865 |
* Expose the following :class:`~symtable.Symbol` methods: |
| 1866 |
|
| 1867 |
* :meth:`~symtable.Symbol.is_comp_cell` |
| 1868 |
* :meth:`~symtable.Symbol.is_comp_iter` |
| 1869 |
* :meth:`~symtable.Symbol.is_free_class` |
| 1870 |
|
| 1871 |
(Contributed by Bénédikt Tran in :gh:`120029`.) |
| 1872 |
|
| 1873 |
|
| 1874 |
sys |
| 1875 |
--- |
| 1876 |
|
| 1877 |
* The previously undocumented special function :func:`sys.getobjects`, |
| 1878 |
which only exists in specialized builds of Python, may now return objects |
| 1879 |
from other interpreters than the one it's called in. |
| 1880 |
(Contributed by Eric Snow in :gh:`125286`.) |
| 1881 |
|
| 1882 |
* Add :func:`sys._is_immortal` for determining if an object is :term:`immortal`. |
| 1883 |
(Contributed by Peter Bierma in :gh:`128509`.) |
| 1884 |
|
| 1885 |
* On FreeBSD, :data:`sys.platform` no longer contains the major version number. |
| 1886 |
It is always ``'freebsd'``, instead of ``'freebsd13'`` or ``'freebsd14'``. |
| 1887 |
(Contributed by Michael Osipov in :gh:`129393`.) |
| 1888 |
|
| 1889 |
* Raise :exc:`DeprecationWarning` for :func:`sys._clear_type_cache`. This |
| 1890 |
function was deprecated in Python 3.13 but it didn't raise a runtime warning. |
| 1891 |
|
| 1892 |
* Add :func:`sys.remote_exec` to implement the new external debugger interface. |
| 1893 |
See :ref:`PEP 768 <whatsnew314-remote-debugging>` for details. |
| 1894 |
(Contributed by Pablo Galindo Salgado, Matt Wozniski, and Ivona Stojanovic |
| 1895 |
in :gh:`131591`.) |
| 1896 |
|
| 1897 |
* Add the :data:`sys._jit` namespace, containing utilities for introspecting |
| 1898 |
just-in-time compilation. |
| 1899 |
(Contributed by Brandt Bucher in :gh:`133231`.) |
| 1900 |
|
| 1901 |
|
| 1902 |
sys.monitoring |
| 1903 |
-------------- |
| 1904 |
|
| 1905 |
* Add two new monitoring events, :monitoring-event:`BRANCH_LEFT` and |
| 1906 |
:monitoring-event:`BRANCH_RIGHT`. |
| 1907 |
These replace and deprecate the :monitoring-event:`!BRANCH` event. |
| 1908 |
(Contributed by Mark Shannon in :gh:`122548`.) |
| 1909 |
|
| 1910 |
|
| 1911 |
sysconfig |
| 1912 |
--------- |
| 1913 |
|
| 1914 |
* Add ``ABIFLAGS`` key to :func:`~sysconfig.get_config_vars` on Windows. |
| 1915 |
(Contributed by Xuehai Pan in :gh:`131799`.) |
| 1916 |
|
| 1917 |
|
| 1918 |
tarfile |
| 1919 |
------- |
| 1920 |
|
| 1921 |
* :func:`~tarfile.data_filter` now normalizes symbolic link targets in order to |
| 1922 |
avoid path traversal attacks. |
| 1923 |
(Contributed by Petr Viktorin in :gh:`127987` and :cve:`2025-4138`.) |
| 1924 |
|
| 1925 |
* :func:`~tarfile.TarFile.extractall` now skips fixing up directory attributes |
| 1926 |
when a directory was removed or replaced by another kind of file. |
| 1927 |
(Contributed by Petr Viktorin in :gh:`127987` and :cve:`2024-12718`.) |
| 1928 |
|
| 1929 |
* :func:`~tarfile.TarFile.extract` and :func:`~tarfile.TarFile.extractall` |
| 1930 |
now (re-)apply the extraction filter when substituting a link (hard or |
| 1931 |
symbolic) with a copy of another archive member, and when fixing up |
| 1932 |
directory attributes. |
| 1933 |
The former raises a new exception, :exc:`~tarfile.LinkFallbackError`. |
| 1934 |
(Contributed by Petr Viktorin for :cve:`2025-4330` and :cve:`2024-12718`.) |
| 1935 |
|
| 1936 |
* :func:`~tarfile.TarFile.extract` and :func:`~tarfile.TarFile.extractall` |
| 1937 |
no longer extract rejected members when |
| 1938 |
:func:`~tarfile.TarFile.errorlevel` is zero. |
| 1939 |
(Contributed by Matt Prodani and Petr Viktorin in :gh:`112887` |
| 1940 |
and :cve:`2025-4435`.) |
| 1941 |
|
| 1942 |
|
| 1943 |
threading |
| 1944 |
--------- |
| 1945 |
|
| 1946 |
* :meth:`threading.Thread.start` now sets the operating system thread name |
| 1947 |
to :attr:`threading.Thread.name`. |
| 1948 |
(Contributed by Victor Stinner in :gh:`59705`.) |
| 1949 |
|
| 1950 |
|
| 1951 |
tkinter |
| 1952 |
------- |
| 1953 |
|
| 1954 |
* Make :mod:`tkinter` widget methods :meth:`!after` and :meth:`!after_idle` |
| 1955 |
accept keyword arguments. |
| 1956 |
(Contributed by Zhikang Yan in :gh:`126899`.) |
| 1957 |
|
| 1958 |
* Add ability to specify a name for :class:`!tkinter.OptionMenu` and |
| 1959 |
:class:`!tkinter.ttk.OptionMenu`. |
| 1960 |
(Contributed by Zhikang Yan in :gh:`130482`.) |
| 1961 |
|
| 1962 |
|
| 1963 |
turtle |
| 1964 |
------ |
| 1965 |
|
| 1966 |
* Add context managers for :func:`turtle.fill`, :func:`turtle.poly`, |
| 1967 |
and :func:`turtle.no_animation`. |
| 1968 |
(Contributed by Marie Roald and Yngve Mardal Moe in :gh:`126350`.) |
| 1969 |
|
| 1970 |
|
| 1971 |
types |
| 1972 |
----- |
| 1973 |
|
| 1974 |
* :class:`types.UnionType` is now an alias for :class:`typing.Union`. |
| 1975 |
See :ref:`below <whatsnew314-typing-union>` for more details. |
| 1976 |
(Contributed by Jelle Zijlstra in :gh:`105499`.) |
| 1977 |
|
| 1978 |
|
| 1979 |
typing |
| 1980 |
------ |
| 1981 |
|
| 1982 |
.. _whatsnew314-typing-union: |
| 1983 |
|
| 1984 |
* The :class:`types.UnionType` and :class:`typing.Union` types are now |
| 1985 |
aliases for each other, meaning that both old-style unions |
| 1986 |
(created with ``Union[int, str]``) and new-style unions (``int | str``) |
| 1987 |
now create instances of the same runtime type. This unifies the behavior |
| 1988 |
between the two syntaxes, but leads to some differences in behavior that |
| 1989 |
may affect users who introspect types at runtime: |
| 1990 |
|
| 1991 |
- Both syntaxes for creating a union now produce the same string |
| 1992 |
representation in :func:`repr`. |
| 1993 |
For example, ``repr(Union[int, str])`` is now ``"int | str"`` instead of |
| 1994 |
``"typing.Union[int, str]"``. |
| 1995 |
|
| 1996 |
- Unions created using the old syntax are no longer cached. |
| 1997 |
Previously, running ``Union[int, str]`` multiple times would return |
| 1998 |
the same object (``Union[int, str] is Union[int, str]`` would be ``True``), |
| 1999 |
but now it will return two different objects. |
| 2000 |
Use ``==`` to compare unions for equality, not ``is``. |
| 2001 |
New-style unions have never been cached this way. |
| 2002 |
This change could increase memory usage for some programs that use |
| 2003 |
a large number of unions created by subscripting ``typing.Union``. |
| 2004 |
However, several factors offset this cost: |
| 2005 |
unions used in annotations are no longer evaluated by default in Python |
| 2006 |
3.14 because of :pep:`649`; an instance of :class:`types.UnionType` is |
| 2007 |
itself much smaller than the object returned by ``Union[]`` was on prior |
| 2008 |
Python versions; and removing the cache also saves some space. |
| 2009 |
It is therefore unlikely that this change will cause a significant increase |
| 2010 |
in memory usage for most users. |
| 2011 |
|
| 2012 |
- Previously, old-style unions were implemented using the private class |
| 2013 |
``typing._UnionGenericAlias``. |
| 2014 |
This class is no longer needed for the implementation, |
| 2015 |
but it has been retained for backward compatibility, |
| 2016 |
with removal scheduled for Python 3.17. |
| 2017 |
Users should use documented introspection helpers like |
| 2018 |
:func:`~typing.get_origin` and :func:`typing.get_args` instead of |
| 2019 |
relying on private implementation details. |
| 2020 |
|
| 2021 |
- It is now possible to use :class:`typing.Union` itself in |
| 2022 |
:func:`isinstance` checks. |
| 2023 |
For example, ``isinstance(int | str, typing.Union)`` will return ``True``; |
| 2024 |
previously this raised :exc:`TypeError`. |
| 2025 |
|
| 2026 |
- The :attr:`!__args__` attribute of :class:`typing.Union` objects is |
| 2027 |
no longer writable. |
| 2028 |
|
| 2029 |
- It is no longer possible to set any attributes on :class:`~typing.Union` |
| 2030 |
objects. |
| 2031 |
This only ever worked for dunder attributes on previous versions, was never |
| 2032 |
documented to work, and was subtly broken in many cases. |
| 2033 |
|
| 2034 |
(Contributed by Jelle Zijlstra in :gh:`105499`.) |
| 2035 |
|
| 2036 |
* :class:`~typing.TypeAliasType` now supports star unpacking. |
| 2037 |
|
| 2038 |
|
| 2039 |
unicodedata |
| 2040 |
----------- |
| 2041 |
|
| 2042 |
* The Unicode database has been updated to Unicode 16.0.0. |
| 2043 |
|
| 2044 |
|
| 2045 |
unittest |
| 2046 |
-------- |
| 2047 |
|
| 2048 |
.. _whatsnew314-color-unittest: |
| 2049 |
|
| 2050 |
* :mod:`unittest` output is now colored by default. |
| 2051 |
This can be controlled by :ref:`environment variables |
| 2052 |
<using-on-controlling-color>`. |
| 2053 |
(Contributed by Hugo van Kemenade in :gh:`127221`.) |
| 2054 |
|
| 2055 |
* unittest discovery supports :term:`namespace package` as start |
| 2056 |
directory again. It was removed in Python 3.11. |
| 2057 |
(Contributed by Jacob Walls in :gh:`80958`.) |
| 2058 |
|
| 2059 |
* A number of new methods were added in the :class:`~unittest.TestCase` class |
| 2060 |
that provide more specialized tests. |
| 2061 |
|
| 2062 |
- :meth:`~unittest.TestCase.assertHasAttr` and |
| 2063 |
:meth:`~unittest.TestCase.assertNotHasAttr` check whether the object |
| 2064 |
has a particular attribute. |
| 2065 |
- :meth:`~unittest.TestCase.assertIsSubclass` and |
| 2066 |
:meth:`~unittest.TestCase.assertNotIsSubclass` check whether the object |
| 2067 |
is a subclass of a particular class, or of one of a tuple of classes. |
| 2068 |
- :meth:`~unittest.TestCase.assertStartsWith`, |
| 2069 |
:meth:`~unittest.TestCase.assertNotStartsWith`, |
| 2070 |
:meth:`~unittest.TestCase.assertEndsWith` and |
| 2071 |
:meth:`~unittest.TestCase.assertNotEndsWith` check whether the Unicode |
| 2072 |
or byte string starts or ends with particular strings. |
| 2073 |
|
| 2074 |
(Contributed by Serhiy Storchaka in :gh:`71339`.) |
| 2075 |
|
| 2076 |
|
| 2077 |
urllib |
| 2078 |
------ |
| 2079 |
|
| 2080 |
* Upgrade HTTP digest authentication algorithm for :mod:`urllib.request` by |
| 2081 |
supporting SHA-256 digest authentication as specified in :rfc:`7616`. |
| 2082 |
(Contributed by Calvin Bui in :gh:`128193`.) |
| 2083 |
|
| 2084 |
* Improve ergonomics and standards compliance when parsing and emitting |
| 2085 |
``file:`` URLs. |
| 2086 |
|
| 2087 |
In :func:`~urllib.request.url2pathname`: |
| 2088 |
|
| 2089 |
- Accept a complete URL when the new *require_scheme* argument is set to |
| 2090 |
true. |
| 2091 |
- Discard URL authority if it matches the local hostname. |
| 2092 |
- Discard URL authority if it resolves to a local IP address when the new |
| 2093 |
*resolve_host* argument is set to true. |
| 2094 |
- Discard URL query and fragment components. |
| 2095 |
- Raise :exc:`~urllib.error.URLError` if a URL authority isn't local, |
| 2096 |
except on Windows where we return a UNC path as before. |
| 2097 |
|
| 2098 |
In :func:`~urllib.request.pathname2url`: |
| 2099 |
|
| 2100 |
- Return a complete URL when the new *add_scheme* argument is set to true. |
| 2101 |
- Include an empty URL authority when a path begins with a slash. For |
| 2102 |
example, the path ``/etc/hosts`` is converted to the URL ``///etc/hosts``. |
| 2103 |
|
| 2104 |
On Windows, drive letters are no longer converted to uppercase, and ``:`` |
| 2105 |
characters not following a drive letter no longer cause an :exc:`OSError` |
| 2106 |
exception to be raised. |
| 2107 |
|
| 2108 |
(Contributed by Barney Gale in :gh:`125866`.) |
| 2109 |
|
| 2110 |
|
| 2111 |
uuid |
| 2112 |
---- |
| 2113 |
|
| 2114 |
* Add support for UUID versions 6, 7, and 8 via :func:`~uuid.uuid6`, |
| 2115 |
:func:`~uuid.uuid7`, and :func:`~uuid.uuid8` respectively, as specified |
| 2116 |
in :rfc:`9562`. |
| 2117 |
(Contributed by Bénédikt Tran in :gh:`89083`.) |
| 2118 |
|
| 2119 |
* :const:`~uuid.NIL` and :const:`~uuid.MAX` are now available to represent the |
| 2120 |
Nil and Max UUID formats as defined by :rfc:`9562`. |
| 2121 |
(Contributed by Nick Pope in :gh:`128427`.) |
| 2122 |
|
| 2123 |
* Allow generating multiple UUIDs simultaneously on the command-line via |
| 2124 |
:option:`python -m uuid --count <uuid --count>`. |
| 2125 |
(Contributed by Simon Legner in :gh:`131236`.) |
| 2126 |
|
| 2127 |
|
| 2128 |
webbrowser |
| 2129 |
---------- |
| 2130 |
|
| 2131 |
* Names in the :envvar:`BROWSER` environment variable can now refer to already |
| 2132 |
registered browsers for the :mod:`webbrowser` module, instead of always |
| 2133 |
generating a new browser command. |
| 2134 |
|
| 2135 |
This makes it possible to set :envvar:`BROWSER` to the value of one of the |
| 2136 |
supported browsers on macOS. |
| 2137 |
|
| 2138 |
|
| 2139 |
zipfile |
| 2140 |
------- |
| 2141 |
|
| 2142 |
* Added :meth:`ZipInfo._for_archive <zipfile.ZipInfo._for_archive>`, a method |
| 2143 |
to resolve suitable defaults for a :class:`~zipfile.ZipInfo` object |
| 2144 |
as used by :func:`ZipFile.writestr <zipfile.ZipFile.writestr>`. |
| 2145 |
(Contributed by Bénédikt Tran in :gh:`123424`.) |
| 2146 |
|
| 2147 |
* :meth:`.ZipFile.writestr` now respects the :envvar:`SOURCE_DATE_EPOCH` |
| 2148 |
environment variable in order to better support reproducible builds. |
| 2149 |
(Contributed by Jiahao Li in :gh:`91279`.) |
| 2150 |
|
| 2151 |
|
| 2152 |
.. Add improved modules above alphabetically, not here at the end. |
| 2153 |
|
| 2154 |
|
| 2155 |
Optimizations |
| 2156 |
============= |
| 2157 |
|
| 2158 |
* The import time for several standard library modules has been improved, |
| 2159 |
including :mod:`annotationlib`, :mod:`ast`, :mod:`asyncio`, :mod:`base64`, |
| 2160 |
:mod:`cmd`, :mod:`csv`, :mod:`gettext`, :mod:`importlib.util`, :mod:`locale`, |
| 2161 |
:mod:`mimetypes`, :mod:`optparse`, :mod:`pickle`, :mod:`pprint`, |
| 2162 |
:mod:`pstats`, :mod:`shlex`, :mod:`socket`, :mod:`string`, :mod:`subprocess`, |
| 2163 |
:mod:`threading`, :mod:`tomllib`, :mod:`types`, and :mod:`zipfile`. |
| 2164 |
|
| 2165 |
(Contributed by Adam Turner, Bénédikt Tran, Chris Markiewicz, Eli Schwartz, |
| 2166 |
Hugo van Kemenade, Jelle Zijlstra, and others in :gh:`118761`.) |
| 2167 |
|
| 2168 |
* The interpreter now avoids some reference count modifications internally |
| 2169 |
when it's safe to do so. |
| 2170 |
This can lead to different values being returned from :func:`sys.getrefcount` |
| 2171 |
and :c:func:`Py_REFCNT` compared to previous versions of Python. |
| 2172 |
See :ref:`below <whatsnew314-refcount>` for details. |
| 2173 |
|
| 2174 |
|
| 2175 |
asyncio |
| 2176 |
------- |
| 2177 |
|
| 2178 |
* Standard benchmark results have improved by 10-20% following the |
| 2179 |
implementation of a new per-thread doubly linked list |
| 2180 |
for :class:`native tasks <asyncio.Task>`, |
| 2181 |
also reducing memory usage. |
| 2182 |
This enables external introspection tools such as |
| 2183 |
:ref:`python -m asyncio pstree <whatsnew314-asyncio-introspection>` |
| 2184 |
to introspect the call graph of asyncio tasks running in all threads. |
| 2185 |
(Contributed by Kumar Aditya in :gh:`107803`.) |
| 2186 |
|
| 2187 |
* The module now has first class support for |
| 2188 |
:term:`free-threading builds <free threading>`. |
| 2189 |
This enables parallel execution of multiple event loops across |
| 2190 |
different threads, scaling linearly with the number of threads. |
| 2191 |
(Contributed by Kumar Aditya in :gh:`128002`.) |
| 2192 |
|
| 2193 |
|
| 2194 |
base64 |
| 2195 |
------ |
| 2196 |
|
| 2197 |
* :func:`~base64.b16decode` is now up to six times faster. |
| 2198 |
(Contributed by Bénédikt Tran, Chris Markiewicz, and Adam Turner |
| 2199 |
in :gh:`118761`.) |
| 2200 |
|
| 2201 |
|
| 2202 |
bdb |
| 2203 |
--- |
| 2204 |
|
| 2205 |
* The basic debugger now has a :mod:`sys.monitoring`-based backend, |
| 2206 |
which can be selected via the passing ``'monitoring'`` |
| 2207 |
to the :class:`~bdb.Bdb` class's new *backend* parameter. |
| 2208 |
(Contributed by Tian Gao in :gh:`124533`.) |
| 2209 |
|
| 2210 |
|
| 2211 |
difflib |
| 2212 |
------- |
| 2213 |
|
| 2214 |
* The :func:`~difflib.IS_LINE_JUNK` function is now up to twice as fast. |
| 2215 |
(Contributed by Adam Turner and Semyon Moroz in :gh:`130167`.) |
| 2216 |
|
| 2217 |
|
| 2218 |
gc |
| 2219 |
-- |
| 2220 |
|
| 2221 |
* **From Python 3.14.5 onwards:** |
| 2222 |
|
| 2223 |
Python 3.14.0-3.14.4 shipped with a new incremental garbage collector. |
| 2224 |
However, due to a number of `reports |
| 2225 |
<https://github.com/python/cpython/issues/142516>`__ |
| 2226 |
of significant memory pressure in production environments, |
| 2227 |
it has been reverted back to the generational GC from 3.13. |
| 2228 |
This is the GC now used in Python 3.14.5 and later. |
| 2229 |
|
| 2230 |
* **Previously in Python 3.14.0-3.14.4:** |
| 2231 |
|
| 2232 |
The new :ref:`incremental garbage collector <whatsnew314-incremental-gc>` |
| 2233 |
means that maximum pause times are reduced |
| 2234 |
by an order of magnitude or more for larger heaps. |
| 2235 |
|
| 2236 |
Because of this optimization, the meaning of the results of |
| 2237 |
:meth:`~gc.get_threshold` and :meth:`~gc.set_threshold` have changed, |
| 2238 |
along with :meth:`~gc.get_count` and :meth:`~gc.get_stats`. |
| 2239 |
|
| 2240 |
- For backwards compatibility, :meth:`~gc.get_threshold` continues to return |
| 2241 |
a three-item tuple. |
| 2242 |
The first value is the threshold for young collections, as before; |
| 2243 |
the second value determines the rate at which the old collection is scanned |
| 2244 |
(the default is 10, and higher values mean that the old collection |
| 2245 |
is scanned more slowly). |
| 2246 |
The third value is now meaningless and is always zero. |
| 2247 |
|
| 2248 |
- :meth:`~gc.set_threshold` now ignores any items after the second. |
| 2249 |
|
| 2250 |
- :meth:`~gc.get_count` and :meth:`~gc.get_stats` continue to return |
| 2251 |
the same format of results. |
| 2252 |
The only difference is that instead of the results referring to |
| 2253 |
the young, aging and old generations, |
| 2254 |
the results refer to the young generation |
| 2255 |
and the aging and collecting spaces of the old generation. |
| 2256 |
|
| 2257 |
In summary, code that attempted to manipulate the behavior of the cycle GC |
| 2258 |
may not work exactly as intended, but it is very unlikely to be harmful. |
| 2259 |
All other code will work just fine. |
| 2260 |
|
| 2261 |
(Contributed by Mark Shannon in :gh:`108362`.) |
| 2262 |
|
| 2263 |
|
| 2264 |
io |
| 2265 |
--- |
| 2266 |
|
| 2267 |
* Opening and reading files now executes fewer system calls. |
| 2268 |
Reading a small operating system cached file in full is up to 15% faster. |
| 2269 |
(Contributed by Cody Maloney and Victor Stinner |
| 2270 |
in :gh:`120754` and :gh:`90102`.) |
| 2271 |
|
| 2272 |
|
| 2273 |
pathlib |
| 2274 |
------- |
| 2275 |
|
| 2276 |
* :func:`Path.read_bytes <pathlib.Path.read_bytes>` now uses unbuffered mode |
| 2277 |
to open files, which is between 9% and 17% faster to read in full. |
| 2278 |
(Contributed by Cody Maloney in :gh:`120754`.) |
| 2279 |
|
| 2280 |
|
| 2281 |
pdb |
| 2282 |
--- |
| 2283 |
|
| 2284 |
* :mod:`pdb` now supports two backends, based on either |
| 2285 |
:func:`sys.settrace` or :mod:`sys.monitoring`. |
| 2286 |
Using the :ref:`pdb CLI <pdb-cli>` or :func:`breakpoint` |
| 2287 |
will always use the :mod:`sys.monitoring` backend. |
| 2288 |
Explicitly instantiating :class:`pdb.Pdb` and its derived classes |
| 2289 |
will use the :func:`sys.settrace` backend by default, which is configurable. |
| 2290 |
(Contributed by Tian Gao in :gh:`124533`.) |
| 2291 |
|
| 2292 |
|
| 2293 |
textwrap |
| 2294 |
-------- |
| 2295 |
|
| 2296 |
* Optimize the :func:`~textwrap.dedent` function, improving performance by |
| 2297 |
an average of 2.4x, with larger improvements for bigger inputs, |
| 2298 |
and fix a bug with incomplete normalization of blank lines with whitespace |
| 2299 |
characters other than space and tab. |
| 2300 |
|
| 2301 |
|
| 2302 |
uuid |
| 2303 |
---- |
| 2304 |
|
| 2305 |
* :func:`~uuid.uuid3` and :func:`~uuid.uuid5` are now both roughly 40% faster |
| 2306 |
for 16-byte names and 20% faster for 1024-byte names. |
| 2307 |
Performance for longer names remains unchanged. |
| 2308 |
(Contributed by Bénédikt Tran in :gh:`128150`.) |
| 2309 |
|
| 2310 |
* :func:`~uuid.uuid4` is now c. 30% faster. |
| 2311 |
(Contributed by Bénédikt Tran in :gh:`128150`.) |
| 2312 |
|
| 2313 |
|
| 2314 |
zlib |
| 2315 |
---- |
| 2316 |
|
| 2317 |
* On Windows, `zlib-ng <https://github.com/zlib-ng/zlib-ng>`__ |
| 2318 |
is now used as the implementation of the :mod:`zlib` module |
| 2319 |
in the default binaries. |
| 2320 |
There are no known incompatibilities between ``zlib-ng`` |
| 2321 |
and the previously-used ``zlib`` implementation. |
| 2322 |
This should result in better performance at all compression levels. |
| 2323 |
|
| 2324 |
It is worth noting that ``zlib.Z_BEST_SPEED`` (``1``) may result in |
| 2325 |
significantly less compression than the previous implementation, |
| 2326 |
whilst also significantly reducing the time taken to compress. |
| 2327 |
|
| 2328 |
(Contributed by Steve Dower in :gh:`91349`.) |
| 2329 |
|
| 2330 |
|
| 2331 |
Removed |
| 2332 |
======= |
| 2333 |
|
| 2334 |
argparse |
| 2335 |
-------- |
| 2336 |
|
| 2337 |
* Remove the *type*, *choices*, and *metavar* parameters |
| 2338 |
of :class:`!BooleanOptionalAction`. |
| 2339 |
These have been deprecated since Python 3.12. |
| 2340 |
(Contributed by Nikita Sobolev in :gh:`118805`.) |
| 2341 |
|
| 2342 |
* Calling :meth:`~argparse.ArgumentParser.add_argument_group` |
| 2343 |
on an argument group now raises a :exc:`ValueError`. |
| 2344 |
Similarly, :meth:`~argparse.ArgumentParser.add_argument_group` |
| 2345 |
or :meth:`~argparse.ArgumentParser.add_mutually_exclusive_group` |
| 2346 |
on a mutually exclusive group now both raise :exc:`ValueError`\ s. |
| 2347 |
This 'nesting' was never supported, often failed to work correctly, |
| 2348 |
and was unintentionally exposed through inheritance. |
| 2349 |
This functionality has been deprecated since Python 3.11. |
| 2350 |
(Contributed by Savannah Ostrowski in :gh:`127186`.) |
| 2351 |
|
| 2352 |
|
| 2353 |
ast |
| 2354 |
--- |
| 2355 |
|
| 2356 |
* Remove the following classes, which have been deprecated aliases of |
| 2357 |
:class:`~ast.Constant` since Python 3.8 and have emitted |
| 2358 |
deprecation warnings since Python 3.12: |
| 2359 |
|
| 2360 |
* :class:`!Bytes` |
| 2361 |
* :class:`!Ellipsis` |
| 2362 |
* :class:`!NameConstant` |
| 2363 |
* :class:`!Num` |
| 2364 |
* :class:`!Str` |
| 2365 |
|
| 2366 |
As a consequence of these removals, user-defined ``visit_Num``, ``visit_Str``, |
| 2367 |
``visit_Bytes``, ``visit_NameConstant`` and ``visit_Ellipsis`` methods |
| 2368 |
on custom :class:`~ast.NodeVisitor` subclasses will no longer be called |
| 2369 |
when the :class:`!NodeVisitor` subclass is visiting an AST. |
| 2370 |
Define a ``visit_Constant`` method instead. |
| 2371 |
|
| 2372 |
(Contributed by Alex Waygood in :gh:`119562`.) |
| 2373 |
|
| 2374 |
* Remove the following deprecated properties on :class:`ast.Constant`, |
| 2375 |
which were present for compatibility with the now-removed AST classes: |
| 2376 |
|
| 2377 |
* :attr:`!Constant.n` |
| 2378 |
* :attr:`!Constant.s` |
| 2379 |
|
| 2380 |
Use :attr:`!Constant.value` instead. |
| 2381 |
(Contributed by Alex Waygood in :gh:`119562`.) |
| 2382 |
|
| 2383 |
|
| 2384 |
asyncio |
| 2385 |
------- |
| 2386 |
|
| 2387 |
* Remove the following classes, methods, and functions, |
| 2388 |
which have been deprecated since Python 3.12: |
| 2389 |
|
| 2390 |
* :class:`!AbstractChildWatcher` |
| 2391 |
* :class:`!FastChildWatcher` |
| 2392 |
* :class:`!MultiLoopChildWatcher` |
| 2393 |
* :class:`!PidfdChildWatcher` |
| 2394 |
* :class:`!SafeChildWatcher` |
| 2395 |
* :class:`!ThreadedChildWatcher` |
| 2396 |
* :meth:`!AbstractEventLoopPolicy.get_child_watcher` |
| 2397 |
* :meth:`!AbstractEventLoopPolicy.set_child_watcher` |
| 2398 |
* :func:`!get_child_watcher` |
| 2399 |
* :func:`!set_child_watcher` |
| 2400 |
|
| 2401 |
(Contributed by Kumar Aditya in :gh:`120804`.) |
| 2402 |
|
| 2403 |
* :func:`asyncio.get_event_loop` now raises a :exc:`RuntimeError` |
| 2404 |
if there is no current event loop, |
| 2405 |
and no longer implicitly creates an event loop. |
| 2406 |
|
| 2407 |
(Contributed by Kumar Aditya in :gh:`126353`.) |
| 2408 |
|
| 2409 |
.. TODO: move these patterns to the asyncio docs? |
| 2410 |
quite long for What's New |
| 2411 |
|
| 2412 |
There's a few patterns that use :func:`asyncio.get_event_loop`, most |
| 2413 |
of them can be replaced with :func:`asyncio.run`. |
| 2414 |
|
| 2415 |
If you're running an async function, simply use :func:`asyncio.run`. |
| 2416 |
|
| 2417 |
Before: |
| 2418 |
|
| 2419 |
.. code:: python |
| 2420 |
|
| 2421 |
async def main(): |
| 2422 |
... |
| 2423 |
|
| 2424 |
|
| 2425 |
loop = asyncio.get_event_loop() |
| 2426 |
try: |
| 2427 |
loop.run_until_complete(main()) |
| 2428 |
finally: |
| 2429 |
loop.close() |
| 2430 |
|
| 2431 |
After: |
| 2432 |
|
| 2433 |
.. code:: python |
| 2434 |
|
| 2435 |
async def main(): |
| 2436 |
... |
| 2437 |
|
| 2438 |
asyncio.run(main()) |
| 2439 |
|
| 2440 |
If you need to start something, for example, a server listening on a socket |
| 2441 |
and then run forever, use :func:`asyncio.run` and an |
| 2442 |
:class:`asyncio.Event`. |
| 2443 |
|
| 2444 |
Before: |
| 2445 |
|
| 2446 |
.. code:: python |
| 2447 |
|
| 2448 |
def start_server(loop): ... |
| 2449 |
|
| 2450 |
loop = asyncio.get_event_loop() |
| 2451 |
try: |
| 2452 |
start_server(loop) |
| 2453 |
loop.run_forever() |
| 2454 |
finally: |
| 2455 |
loop.close() |
| 2456 |
|
| 2457 |
After: |
| 2458 |
|
| 2459 |
.. code:: python |
| 2460 |
|
| 2461 |
def start_server(loop): ... |
| 2462 |
|
| 2463 |
async def main(): |
| 2464 |
start_server(asyncio.get_running_loop()) |
| 2465 |
await asyncio.Event().wait() |
| 2466 |
|
| 2467 |
asyncio.run(main()) |
| 2468 |
|
| 2469 |
If you need to run something in an event loop, then run some blocking |
| 2470 |
code around it, use :class:`asyncio.Runner`. |
| 2471 |
|
| 2472 |
Before: |
| 2473 |
|
| 2474 |
.. code:: python |
| 2475 |
|
| 2476 |
async def operation_one(): ... |
| 2477 |
def blocking_code(): ... |
| 2478 |
async def operation_two(): ... |
| 2479 |
|
| 2480 |
loop = asyncio.get_event_loop() |
| 2481 |
try: |
| 2482 |
loop.run_until_complete(operation_one()) |
| 2483 |
blocking_code() |
| 2484 |
loop.run_until_complete(operation_two()) |
| 2485 |
finally: |
| 2486 |
loop.close() |
| 2487 |
|
| 2488 |
After: |
| 2489 |
|
| 2490 |
.. code:: python |
| 2491 |
|
| 2492 |
async def operation_one(): ... |
| 2493 |
def blocking_code(): ... |
| 2494 |
async def operation_two(): ... |
| 2495 |
|
| 2496 |
with asyncio.Runner() as runner: |
| 2497 |
runner.run(operation_one()) |
| 2498 |
blocking_code() |
| 2499 |
runner.run(operation_two()) |
| 2500 |
|
| 2501 |
|
| 2502 |
email |
| 2503 |
----- |
| 2504 |
|
| 2505 |
* Remove :func:`email.utils.localtime`'s *isdst* parameter, |
| 2506 |
which was deprecated in and has been ignored since Python 3.12. |
| 2507 |
(Contributed by Hugo van Kemenade in :gh:`118798`.) |
| 2508 |
|
| 2509 |
|
| 2510 |
importlib.abc |
| 2511 |
------------- |
| 2512 |
|
| 2513 |
* Remove deprecated :mod:`importlib.abc` classes: |
| 2514 |
|
| 2515 |
* :class:`!ResourceReader` |
| 2516 |
(use :class:`~importlib.resources.abc.TraversableResources`) |
| 2517 |
* :class:`!Traversable` |
| 2518 |
(use :class:`~importlib.resources.abc.Traversable`) |
| 2519 |
* :class:`!TraversableResources` |
| 2520 |
(use :class:`~importlib.resources.abc.TraversableResources`) |
| 2521 |
|
| 2522 |
(Contributed by Jason R. Coombs and Hugo van Kemenade in :gh:`93963`.) |
| 2523 |
|
| 2524 |
|
| 2525 |
itertools |
| 2526 |
--------- |
| 2527 |
|
| 2528 |
* Remove support for copy, deepcopy, and pickle operations |
| 2529 |
from :mod:`itertools` iterators. |
| 2530 |
These have emitted a :exc:`DeprecationWarning` since Python 3.12. |
| 2531 |
(Contributed by Raymond Hettinger in :gh:`101588`.) |
| 2532 |
|
| 2533 |
|
| 2534 |
pathlib |
| 2535 |
------- |
| 2536 |
|
| 2537 |
* Remove support for passing additional keyword arguments |
| 2538 |
to :class:`~pathlib.Path`. |
| 2539 |
In previous versions, any such arguments are ignored. |
| 2540 |
(Contributed by Barney Gale in :gh:`74033`.) |
| 2541 |
|
| 2542 |
* Remove support for passing additional positional arguments to |
| 2543 |
:meth:`.PurePath.relative_to` and :meth:`~pathlib.PurePath.is_relative_to`. |
| 2544 |
In previous versions, any such arguments are joined onto *other*. |
| 2545 |
(Contributed by Barney Gale in :gh:`78707`.) |
| 2546 |
|
| 2547 |
|
| 2548 |
pkgutil |
| 2549 |
------- |
| 2550 |
|
| 2551 |
* Remove the :func:`!get_loader` and :func:`!find_loader` functions, |
| 2552 |
which have been deprecated since Python 3.12. |
| 2553 |
(Contributed by Bénédikt Tran in :gh:`97850`.) |
| 2554 |
|
| 2555 |
|
| 2556 |
pty |
| 2557 |
--- |
| 2558 |
|
| 2559 |
* Remove the :func:`!master_open` and :func:`!slave_open` functions, |
| 2560 |
which have been deprecated since Python 3.12. |
| 2561 |
Use :func:`pty.openpty` instead. |
| 2562 |
(Contributed by Nikita Sobolev in :gh:`118824`.) |
| 2563 |
|
| 2564 |
|
| 2565 |
sqlite3 |
| 2566 |
------- |
| 2567 |
|
| 2568 |
* Remove :data:`!version` and :data:`!version_info` from |
| 2569 |
the :mod:`sqlite3` module; |
| 2570 |
use :data:`~sqlite3.sqlite_version` and :data:`~sqlite3.sqlite_version_info` |
| 2571 |
for the actual version number of the runtime SQLite library. |
| 2572 |
(Contributed by Hugo van Kemenade in :gh:`118924`.) |
| 2573 |
|
| 2574 |
* Using a sequence of parameters with named placeholders now |
| 2575 |
raises a :exc:`~sqlite3.ProgrammingError`, |
| 2576 |
having been deprecated since Python 3.12. |
| 2577 |
(Contributed by Erlend E. Aasland in :gh:`118928` and :gh:`101693`.) |
| 2578 |
|
| 2579 |
|
| 2580 |
urllib |
| 2581 |
------ |
| 2582 |
|
| 2583 |
* Remove the :class:`!Quoter` class from :mod:`urllib.parse`, |
| 2584 |
which has been deprecated since Python 3.11. |
| 2585 |
(Contributed by Nikita Sobolev in :gh:`118827`.) |
| 2586 |
|
| 2587 |
* Remove the :class:`!URLopener` and :class:`!FancyURLopener` classes |
| 2588 |
from :mod:`urllib.request`, |
| 2589 |
which have been deprecated since Python 3.3. |
| 2590 |
|
| 2591 |
``myopener.open()`` can be replaced with :func:`~urllib.request.urlopen`. |
| 2592 |
``myopener.retrieve()`` can be replaced with |
| 2593 |
:func:`~urllib.request.urlretrieve`. |
| 2594 |
Customisations to the opener classes can be replaced by passing |
| 2595 |
customized handlers to :func:`~urllib.request.build_opener`. |
| 2596 |
(Contributed by Barney Gale in :gh:`84850`.) |
| 2597 |
|
| 2598 |
|
| 2599 |
Deprecated |
| 2600 |
========== |
| 2601 |
|
| 2602 |
New deprecations |
| 2603 |
---------------- |
| 2604 |
|
| 2605 |
* Passing a complex number as the *real* or *imag* argument in the |
| 2606 |
:func:`complex` constructor is now deprecated; |
| 2607 |
complex numbers should only be passed as a single positional argument. |
| 2608 |
(Contributed by Serhiy Storchaka in :gh:`109218`.) |
| 2609 |
|
| 2610 |
* :mod:`argparse`: |
| 2611 |
|
| 2612 |
* Passing the undocumented keyword argument *prefix_chars* to the |
| 2613 |
:meth:`~argparse.ArgumentParser.add_argument_group` method is now deprecated. |
| 2614 |
(Contributed by Savannah Ostrowski in :gh:`125563`.) |
| 2615 |
|
| 2616 |
* Deprecated the :class:`argparse.FileType` type converter. |
| 2617 |
Anything relating to resource management should be handled |
| 2618 |
downstream, after the arguments have been parsed. |
| 2619 |
(Contributed by Serhiy Storchaka in :gh:`58032`.) |
| 2620 |
|
| 2621 |
* :mod:`asyncio`: |
| 2622 |
|
| 2623 |
* The :func:`!asyncio.iscoroutinefunction` is now deprecated |
| 2624 |
and will be removed in Python 3.16; |
| 2625 |
use :func:`inspect.iscoroutinefunction` instead. |
| 2626 |
(Contributed by Jiahao Li and Kumar Aditya in :gh:`122875`.) |
| 2627 |
|
| 2628 |
* The :mod:`asyncio` policy system is deprecated |
| 2629 |
and will be removed in Python 3.16. |
| 2630 |
In particular, the following classes and functions are deprecated: |
| 2631 |
|
| 2632 |
* :class:`asyncio.AbstractEventLoopPolicy` |
| 2633 |
* :class:`asyncio.DefaultEventLoopPolicy` |
| 2634 |
* :class:`asyncio.WindowsSelectorEventLoopPolicy` |
| 2635 |
* :class:`asyncio.WindowsProactorEventLoopPolicy` |
| 2636 |
* :func:`asyncio.get_event_loop_policy` |
| 2637 |
* :func:`asyncio.set_event_loop_policy` |
| 2638 |
|
| 2639 |
Users should use :func:`asyncio.run` or :class:`asyncio.Runner` with |
| 2640 |
the *loop_factory* argument to use the desired event loop implementation. |
| 2641 |
|
| 2642 |
For example, to use :class:`asyncio.SelectorEventLoop` on Windows: |
| 2643 |
|
| 2644 |
.. code-block:: python |
| 2645 |
|
| 2646 |
import asyncio |
| 2647 |
|
| 2648 |
async def main(): |
| 2649 |
... |
| 2650 |
|
| 2651 |
asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop) |
| 2652 |
|
| 2653 |
(Contributed by Kumar Aditya in :gh:`127949`.) |
| 2654 |
|
| 2655 |
* :mod:`codecs`: |
| 2656 |
The :func:`codecs.open` function is now deprecated, |
| 2657 |
and will be removed in a future version of Python. |
| 2658 |
Use :func:`open` instead. |
| 2659 |
(Contributed by Inada Naoki in :gh:`133036`.) |
| 2660 |
|
| 2661 |
* :mod:`ctypes`: |
| 2662 |
|
| 2663 |
* On non-Windows platforms, setting :attr:`.Structure._pack_` to use a |
| 2664 |
MSVC-compatible default memory layout is now deprecated in favor of setting |
| 2665 |
:attr:`.Structure._layout_` to ``'ms'``, and will be removed in Python 3.19. |
| 2666 |
(Contributed by Petr Viktorin in :gh:`131747`.) |
| 2667 |
|
| 2668 |
* Calling :func:`ctypes.POINTER` on a string is now deprecated. |
| 2669 |
Use :ref:`incomplete types <ctypes-incomplete-types>` |
| 2670 |
for self-referential structures. |
| 2671 |
Also, the internal ``ctypes._pointer_type_cache`` is deprecated. |
| 2672 |
See :func:`ctypes.POINTER` for updated implementation details. |
| 2673 |
(Contributed by Sergey Myrianov in :gh:`100926`.) |
| 2674 |
|
| 2675 |
* :mod:`functools`: |
| 2676 |
Calling the Python implementation of :func:`functools.reduce` with *function* |
| 2677 |
or *sequence* as keyword arguments is now deprecated; |
| 2678 |
the parameters will be made positional-only in Python 3.16. |
| 2679 |
(Contributed by Kirill Podoprigora in :gh:`121676`.) |
| 2680 |
|
| 2681 |
* :mod:`logging`: |
| 2682 |
Support for custom logging handlers with the *strm* argument |
| 2683 |
is now deprecated and scheduled for removal in Python 3.16. |
| 2684 |
Define handlers with the *stream* argument instead. |
| 2685 |
(Contributed by Mariusz Felisiak in :gh:`115032`.) |
| 2686 |
|
| 2687 |
* :mod:`mimetypes`: |
| 2688 |
Valid extensions are either empty or must start with '.' for |
| 2689 |
:meth:`mimetypes.MimeTypes.add_type`. |
| 2690 |
Undotted extensions are deprecated and will |
| 2691 |
raise a :exc:`ValueError` in Python 3.16. |
| 2692 |
(Contributed by Hugo van Kemenade in :gh:`75223`.) |
| 2693 |
|
| 2694 |
* :mod:`!nturl2path`: |
| 2695 |
This module is now deprecated. Call :func:`urllib.request.url2pathname` |
| 2696 |
and :func:`~urllib.request.pathname2url` instead. |
| 2697 |
(Contributed by Barney Gale in :gh:`125866`.) |
| 2698 |
|
| 2699 |
* :mod:`os`: |
| 2700 |
The :func:`os.popen` and :func:`os.spawn* <os.spawnl>` functions |
| 2701 |
are now :term:`soft deprecated`. |
| 2702 |
They should no longer be used to write new code. |
| 2703 |
The :mod:`subprocess` module is recommended instead. |
| 2704 |
(Contributed by Victor Stinner in :gh:`120743`.) |
| 2705 |
|
| 2706 |
* :mod:`pathlib`: |
| 2707 |
:meth:`!pathlib.PurePath.as_uri` is now deprecated |
| 2708 |
and scheduled for removal in Python 3.19. |
| 2709 |
Use :meth:`pathlib.Path.as_uri` instead. |
| 2710 |
(Contributed by Barney Gale in :gh:`123599`.) |
| 2711 |
|
| 2712 |
* :mod:`pdb`: |
| 2713 |
The undocumented ``pdb.Pdb.curframe_locals`` attribute is now a deprecated |
| 2714 |
read-only property, which will be removed in a future version of Python. |
| 2715 |
The low overhead dynamic frame locals access added in Python 3.13 by :pep:`667` |
| 2716 |
means the frame locals cache reference previously stored in this attribute |
| 2717 |
is no longer needed. Derived debuggers should access |
| 2718 |
``pdb.Pdb.curframe.f_locals`` directly in Python 3.13 and later versions. |
| 2719 |
(Contributed by Tian Gao in :gh:`124369` and :gh:`125951`.) |
| 2720 |
|
| 2721 |
* :mod:`symtable`: |
| 2722 |
Deprecate :meth:`symtable.Class.get_methods` due to the lack of interest, |
| 2723 |
scheduled for removal in Python 3.16. |
| 2724 |
(Contributed by Bénédikt Tran in :gh:`119698`.) |
| 2725 |
|
| 2726 |
* :mod:`tkinter`: |
| 2727 |
The :class:`!tkinter.Variable` methods :meth:`!trace_variable`, |
| 2728 |
:meth:`!trace_vdelete` and :meth:`!trace_vinfo` are now deprecated. |
| 2729 |
Use :meth:`!trace_add`, :meth:`!trace_remove` and :meth:`!trace_info` instead. |
| 2730 |
(Contributed by Serhiy Storchaka in :gh:`120220`.) |
| 2731 |
|
| 2732 |
* :mod:`urllib.parse`: |
| 2733 |
Accepting objects with false values (like ``0`` and ``[]``) except empty |
| 2734 |
strings, bytes-like objects and ``None`` in :func:`~urllib.parse.parse_qsl` |
| 2735 |
and :func:`~urllib.parse.parse_qs` is now deprecated. |
| 2736 |
(Contributed by Serhiy Storchaka in :gh:`116897`.) |
| 2737 |
|
| 2738 |
.. Add deprecations above alphabetically, not here at the end. |
| 2739 |
|
| 2740 |
.. include:: ../deprecations/pending-removal-in-3.15.rst |
| 2741 |
|
| 2742 |
.. include:: ../deprecations/pending-removal-in-3.16.rst |
| 2743 |
|
| 2744 |
.. include:: ../deprecations/pending-removal-in-3.17.rst |
| 2745 |
|
| 2746 |
.. include:: ../deprecations/pending-removal-in-3.18.rst |
| 2747 |
|
| 2748 |
.. include:: ../deprecations/pending-removal-in-3.19.rst |
| 2749 |
|
| 2750 |
.. include:: ../deprecations/pending-removal-in-future.rst |
| 2751 |
|
| 2752 |
|
| 2753 |
CPython bytecode changes |
| 2754 |
======================== |
| 2755 |
|
| 2756 |
* Replaced the opcode :opcode:`!BINARY_SUBSCR` by the :opcode:`BINARY_OP` |
| 2757 |
opcode with the ``NB_SUBSCR`` oparg. |
| 2758 |
(Contributed by Irit Katriel in :gh:`100239`.) |
| 2759 |
|
| 2760 |
* Add the :opcode:`BUILD_INTERPOLATION` and :opcode:`BUILD_TEMPLATE` |
| 2761 |
opcodes to construct new :class:`~string.templatelib.Interpolation` |
| 2762 |
and :class:`~string.templatelib.Template` instances, respectively. |
| 2763 |
(Contributed by Lysandros Nikolaou and others in :gh:`132661`; |
| 2764 |
see also :ref:`PEP 750: Template strings <whatsnew314-template-string-literals>`). |
| 2765 |
|
| 2766 |
* Remove the :opcode:`!BUILD_CONST_KEY_MAP` opcode. |
| 2767 |
Use :opcode:`BUILD_MAP` instead. |
| 2768 |
(Contributed by Mark Shannon in :gh:`122160`.) |
| 2769 |
|
| 2770 |
* Replace the :opcode:`!LOAD_ASSERTION_ERROR` opcode with |
| 2771 |
:opcode:`LOAD_COMMON_CONSTANT` and add support for loading |
| 2772 |
:exc:`NotImplementedError`. |
| 2773 |
|
| 2774 |
* Add the :opcode:`LOAD_FAST_BORROW` and :opcode:`LOAD_FAST_BORROW_LOAD_FAST_BORROW` |
| 2775 |
opcodes to reduce reference counting overhead when the interpreter can prove |
| 2776 |
that the reference in the frame outlives the reference loaded onto the stack. |
| 2777 |
(Contributed by Matt Page in :gh:`130704`.) |
| 2778 |
|
| 2779 |
* Add the :opcode:`LOAD_SMALL_INT` opcode, which pushes a small integer |
| 2780 |
equal to the ``oparg`` to the stack. |
| 2781 |
The :opcode:`!RETURN_CONST` opcode is removed as it is no longer used. |
| 2782 |
(Contributed by Mark Shannon in :gh:`125837`.) |
| 2783 |
|
| 2784 |
* Add the new :opcode:`LOAD_SPECIAL` instruction. |
| 2785 |
Generate code for :keyword:`with` and :keyword:`async with` statements |
| 2786 |
using the new instruction. |
| 2787 |
Removed the :opcode:`!BEFORE_WITH` and :opcode:`!BEFORE_ASYNC_WITH` instructions. |
| 2788 |
(Contributed by Mark Shannon in :gh:`120507`.) |
| 2789 |
|
| 2790 |
* Add the :opcode:`POP_ITER` opcode to support 'virtual' iterators. |
| 2791 |
(Contributed by Mark Shannon in :gh:`132554`.) |
| 2792 |
|
| 2793 |
|
| 2794 |
Pseudo-instructions |
| 2795 |
------------------- |
| 2796 |
|
| 2797 |
* Add the :opcode:`!ANNOTATIONS_PLACEHOLDER` pseudo instruction |
| 2798 |
to support partially executed module-level annotations with |
| 2799 |
:ref:`deferred evaluation of annotations <whatsnew314-deferred-annotations>`. |
| 2800 |
(Contributed by Jelle Zijlstra in :gh:`130907`.) |
| 2801 |
|
| 2802 |
* Add the :opcode:`!BINARY_OP_EXTEND` pseudo instruction, |
| 2803 |
which executes a pair of functions (guard and specialization functions) |
| 2804 |
accessed from the inline cache. |
| 2805 |
(Contributed by Irit Katriel in :gh:`100239`.) |
| 2806 |
|
| 2807 |
* Add three specializations for :opcode:`CALL_KW`; |
| 2808 |
:opcode:`!CALL_KW_PY` for calls to Python functions, |
| 2809 |
:opcode:`!CALL_KW_BOUND_METHOD` for calls to bound methods, and |
| 2810 |
:opcode:`!CALL_KW_NON_PY` for all other calls. |
| 2811 |
(Contributed by Mark Shannon in :gh:`118093`.) |
| 2812 |
|
| 2813 |
* Add the :opcode:`JUMP_IF_TRUE` and :opcode:`JUMP_IF_FALSE` pseudo instructions, |
| 2814 |
conditional jumps which do not impact the stack. |
| 2815 |
Replaced by the sequence ``COPY 1``, ``TO_BOOL``, ``POP_JUMP_IF_TRUE/FALSE``. |
| 2816 |
(Contributed by Irit Katriel in :gh:`124285`.) |
| 2817 |
|
| 2818 |
* Add the :opcode:`!LOAD_CONST_MORTAL` pseudo instruction. |
| 2819 |
(Contributed by Mark Shannon in :gh:`128685`.) |
| 2820 |
|
| 2821 |
* Add the :opcode:`LOAD_CONST_IMMORTAL` pseudo instruction, |
| 2822 |
which does the same as :opcode:`!LOAD_CONST`, but is more efficient |
| 2823 |
for immortal objects. |
| 2824 |
(Contributed by Mark Shannon in :gh:`125837`.) |
| 2825 |
|
| 2826 |
* Add the :opcode:`NOT_TAKEN` pseudo instruction, used by :mod:`sys.monitoring` |
| 2827 |
to record branch events (such as :monitoring-event:`BRANCH_LEFT`). |
| 2828 |
(Contributed by Mark Shannon in :gh:`122548`.) |
| 2829 |
|
| 2830 |
|
| 2831 |
C API changes |
| 2832 |
============= |
| 2833 |
|
| 2834 |
.. _whatsnew314-capi-config: |
| 2835 |
|
| 2836 |
Python configuration C API |
| 2837 |
-------------------------- |
| 2838 |
|
| 2839 |
Add a :ref:`PyInitConfig C API <pyinitconfig_api>` to configure the Python |
| 2840 |
initialization without relying on C structures and the ability to make |
| 2841 |
ABI-compatible changes in the future. |
| 2842 |
|
| 2843 |
Complete the :pep:`587` :ref:`PyConfig C API <pyconfig_api>` by adding |
| 2844 |
:c:func:`PyInitConfig_AddModule` which can be used to add a built-in extension |
| 2845 |
module; a feature previously referred to as the "inittab". |
| 2846 |
|
| 2847 |
Add :c:func:`PyConfig_Get` and :c:func:`PyConfig_Set` functions to get and set |
| 2848 |
the current runtime configuration. |
| 2849 |
|
| 2850 |
:pep:`587` 'Python Initialization Configuration' unified all the ways |
| 2851 |
to configure Python's initialization. This PEP also unifies the configuration |
| 2852 |
of Python's preinitialization and initialization in a single API. |
| 2853 |
Moreover, this PEP only provides a single choice to embed Python, |
| 2854 |
instead of having two 'Python' and 'Isolated' choices (PEP 587), |
| 2855 |
to further simplify the API. |
| 2856 |
|
| 2857 |
The lower level PEP 587 PyConfig API remains available for use cases |
| 2858 |
with an intentionally higher level of coupling to CPython implementation details |
| 2859 |
(such as emulating the full functionality of CPython's CLI, including its |
| 2860 |
configuration mechanisms). |
| 2861 |
|
| 2862 |
(Contributed by Victor Stinner in :gh:`107954`.) |
| 2863 |
|
| 2864 |
.. seealso:: :pep:`741` and :pep:`587` |
| 2865 |
|
| 2866 |
|
| 2867 |
New features in the C API |
| 2868 |
------------------------- |
| 2869 |
|
| 2870 |
* Add :c:func:`Py_PACK_VERSION` and :c:func:`Py_PACK_FULL_VERSION`, |
| 2871 |
two new macros for bit-packing Python version numbers. |
| 2872 |
This is useful for comparisons with :c:var:`Py_Version` |
| 2873 |
or :c:macro:`PY_VERSION_HEX`. |
| 2874 |
(Contributed by Petr Viktorin in :gh:`128629`.) |
| 2875 |
|
| 2876 |
* Add :c:func:`PyBytes_Join(sep, iterable) <PyBytes_Join>` function, |
| 2877 |
similar to ``sep.join(iterable)`` in Python. |
| 2878 |
(Contributed by Victor Stinner in :gh:`121645`.) |
| 2879 |
|
| 2880 |
* Add functions to manipulate the configuration of the current |
| 2881 |
runtime Python interpreter |
| 2882 |
(:ref:`PEP 741: Python configuration C API <whatsnew314-capi-config>`): |
| 2883 |
|
| 2884 |
* :c:func:`PyConfig_Get` |
| 2885 |
* :c:func:`PyConfig_GetInt` |
| 2886 |
* :c:func:`PyConfig_Set` |
| 2887 |
* :c:func:`PyConfig_Names` |
| 2888 |
|
| 2889 |
(Contributed by Victor Stinner in :gh:`107954`.) |
| 2890 |
|
| 2891 |
* Add functions to configure Python initialization |
| 2892 |
(:ref:`PEP 741: Python configuration C API <whatsnew314-capi-config>`): |
| 2893 |
|
| 2894 |
* :c:func:`Py_InitializeFromInitConfig` |
| 2895 |
* :c:func:`PyInitConfig_AddModule` |
| 2896 |
* :c:func:`PyInitConfig_Create` |
| 2897 |
* :c:func:`PyInitConfig_Free` |
| 2898 |
* :c:func:`PyInitConfig_FreeStrList` |
| 2899 |
* :c:func:`PyInitConfig_GetError` |
| 2900 |
* :c:func:`PyInitConfig_GetExitCode` |
| 2901 |
* :c:func:`PyInitConfig_GetInt` |
| 2902 |
* :c:func:`PyInitConfig_GetStr` |
| 2903 |
* :c:func:`PyInitConfig_GetStrList` |
| 2904 |
* :c:func:`PyInitConfig_HasOption` |
| 2905 |
* :c:func:`PyInitConfig_SetInt` |
| 2906 |
* :c:func:`PyInitConfig_SetStr` |
| 2907 |
* :c:func:`PyInitConfig_SetStrList` |
| 2908 |
|
| 2909 |
(Contributed by Victor Stinner in :gh:`107954`.) |
| 2910 |
|
| 2911 |
* Add :c:func:`Py_fopen` function to open a file. |
| 2912 |
This works similarly to the standard C :c:func:`!fopen` function, |
| 2913 |
instead accepting a Python object for the *path* parameter |
| 2914 |
and setting an exception on error. |
| 2915 |
The corresponding new :c:func:`Py_fclose` function should be used |
| 2916 |
to close a file. |
| 2917 |
(Contributed by Victor Stinner in :gh:`127350`.) |
| 2918 |
|
| 2919 |
* Add :c:func:`Py_HashBuffer` to compute and return the hash value of a buffer. |
| 2920 |
(Contributed by Antoine Pitrou and Victor Stinner in :gh:`122854`.) |
| 2921 |
|
| 2922 |
* Add :c:func:`PyImport_ImportModuleAttr` and |
| 2923 |
:c:func:`PyImport_ImportModuleAttrString` helper functions to import a module |
| 2924 |
and get an attribute of the module. |
| 2925 |
(Contributed by Victor Stinner in :gh:`128911`.) |
| 2926 |
|
| 2927 |
* Add :c:func:`PyIter_NextItem` to replace :c:func:`PyIter_Next`, |
| 2928 |
which has an ambiguous return value. |
| 2929 |
(Contributed by Irit Katriel and Erlend Aasland in :gh:`105201`.) |
| 2930 |
|
| 2931 |
* Add :c:func:`PyLong_GetSign` function to get the sign of :class:`int` objects. |
| 2932 |
(Contributed by Sergey B Kirpichev in :gh:`116560`.) |
| 2933 |
|
| 2934 |
* Add :c:func:`PyLong_IsPositive`, :c:func:`PyLong_IsNegative` |
| 2935 |
and :c:func:`PyLong_IsZero` for checking if :c:type:`PyLongObject` |
| 2936 |
is positive, negative, or zero, respectively. |
| 2937 |
(Contributed by James Roy and Sergey B Kirpichev in :gh:`126061`.) |
| 2938 |
|
| 2939 |
* Add new functions to convert C ``<stdint.h>`` numbers to/from |
| 2940 |
Python :class:`int` objects: |
| 2941 |
|
| 2942 |
* :c:func:`PyLong_AsInt32` |
| 2943 |
* :c:func:`PyLong_AsInt64` |
| 2944 |
* :c:func:`PyLong_AsUInt32` |
| 2945 |
* :c:func:`PyLong_AsUInt64` |
| 2946 |
* :c:func:`PyLong_FromInt32` |
| 2947 |
* :c:func:`PyLong_FromInt64` |
| 2948 |
* :c:func:`PyLong_FromUInt32` |
| 2949 |
* :c:func:`PyLong_FromUInt64` |
| 2950 |
|
| 2951 |
(Contributed by Victor Stinner in :gh:`120389`.) |
| 2952 |
|
| 2953 |
* Add a new import and export API for Python :class:`int` objects |
| 2954 |
(:pep:`757`): |
| 2955 |
|
| 2956 |
* :c:func:`PyLong_GetNativeLayout` |
| 2957 |
* :c:func:`PyLong_Export` |
| 2958 |
* :c:func:`PyLong_FreeExport` |
| 2959 |
* :c:func:`PyLongWriter_Create` |
| 2960 |
* :c:func:`PyLongWriter_Finish` |
| 2961 |
* :c:func:`PyLongWriter_Discard` |
| 2962 |
|
| 2963 |
(Contributed by Sergey B Kirpichev and Victor Stinner in :gh:`102471`.) |
| 2964 |
|
| 2965 |
* Add :c:func:`PyMonitoring_FireBranchLeftEvent` and |
| 2966 |
:c:func:`PyMonitoring_FireBranchRightEvent` for generating |
| 2967 |
:monitoring-event:`BRANCH_LEFT` and :monitoring-event:`BRANCH_RIGHT` |
| 2968 |
events, respectively. |
| 2969 |
(Contributed by Mark Shannon in :gh:`122548`.) |
| 2970 |
|
| 2971 |
* Add :c:func:`PyType_Freeze` function to make a type immutable. |
| 2972 |
(Contributed by Victor Stinner in :gh:`121654`.) |
| 2973 |
|
| 2974 |
* Add :c:func:`PyType_GetBaseByToken` and :c:data:`Py_tp_token` slot |
| 2975 |
for easier superclass identification, which attempts to resolve the |
| 2976 |
type checking issue mentioned in :pep:`PEP 630 <630#type-checking>`. |
| 2977 |
(Contributed in :gh:`124153`.) |
| 2978 |
|
| 2979 |
* Add a new :c:func:`PyUnicode_Equal` function to test if two |
| 2980 |
strings are equal. |
| 2981 |
The function is also added to the Limited C API. |
| 2982 |
(Contributed by Victor Stinner in :gh:`124502`.) |
| 2983 |
|
| 2984 |
* Add a new :c:type:`PyUnicodeWriter` API to create a Python :class:`str` |
| 2985 |
object, with the following functions: |
| 2986 |
|
| 2987 |
* :c:func:`PyUnicodeWriter_Create` |
| 2988 |
* :c:func:`PyUnicodeWriter_DecodeUTF8Stateful` |
| 2989 |
* :c:func:`PyUnicodeWriter_Discard` |
| 2990 |
* :c:func:`PyUnicodeWriter_Finish` |
| 2991 |
* :c:func:`PyUnicodeWriter_Format` |
| 2992 |
* :c:func:`PyUnicodeWriter_WriteASCII` |
| 2993 |
* :c:func:`PyUnicodeWriter_WriteChar` |
| 2994 |
* :c:func:`PyUnicodeWriter_WriteRepr` |
| 2995 |
* :c:func:`PyUnicodeWriter_WriteStr` |
| 2996 |
* :c:func:`PyUnicodeWriter_WriteSubstring` |
| 2997 |
* :c:func:`PyUnicodeWriter_WriteUCS4` |
| 2998 |
* :c:func:`PyUnicodeWriter_WriteUTF8` |
| 2999 |
* :c:func:`PyUnicodeWriter_WriteWideChar` |
| 3000 |
|
| 3001 |
(Contributed by Victor Stinner in :gh:`119182`.) |
| 3002 |
|
| 3003 |
* The ``k`` and ``K`` formats in :c:func:`PyArg_ParseTuple` and |
| 3004 |
similar functions now use :meth:`~object.__index__` if available, |
| 3005 |
like all other integer formats. |
| 3006 |
(Contributed by Serhiy Storchaka in :gh:`112068`.) |
| 3007 |
|
| 3008 |
* Add support for a new ``p`` format unit in :c:func:`Py_BuildValue` |
| 3009 |
that produces a Python :class:`bool` object from a C integer. |
| 3010 |
(Contributed by Pablo Galindo in :issue:`45325`.) |
| 3011 |
|
| 3012 |
* Add :c:func:`PyUnstable_IsImmortal` for determining if |
| 3013 |
an object is :term:`immortal`, for debugging purposes. |
| 3014 |
(Contributed by Peter Bierma in :gh:`128509`.) |
| 3015 |
|
| 3016 |
* Add :c:func:`PyUnstable_Object_EnableDeferredRefcount` for enabling |
| 3017 |
deferred reference counting, as outlined in :pep:`703`. |
| 3018 |
|
| 3019 |
* Add :c:func:`PyUnstable_Object_IsUniquelyReferenced` as |
| 3020 |
a replacement for ``Py_REFCNT(op) == 1`` on :term:`free threaded |
| 3021 |
<free threading>` builds. |
| 3022 |
(Contributed by Peter Bierma in :gh:`133140`.) |
| 3023 |
|
| 3024 |
* Add :c:func:`PyUnstable_Object_IsUniqueReferencedTemporary` to |
| 3025 |
determine if an object is a unique temporary object on the |
| 3026 |
interpreter's operand stack. |
| 3027 |
This can be used in some cases as a replacement for checking |
| 3028 |
if :c:func:`Py_REFCNT` is ``1`` for Python objects passed |
| 3029 |
as arguments to C API functions. |
| 3030 |
(Contributed by Sam Gross in :gh:`133164`.) |
| 3031 |
|
| 3032 |
|
| 3033 |
Limited C API changes |
| 3034 |
--------------------- |
| 3035 |
|
| 3036 |
* In the limited C API version 3.14 and newer, :c:func:`Py_TYPE` and |
| 3037 |
:c:func:`Py_REFCNT` are now implemented as an opaque function call |
| 3038 |
to hide implementation details. |
| 3039 |
(Contributed by Victor Stinner in :gh:`120600` and :gh:`124127`.) |
| 3040 |
|
| 3041 |
* Remove the :c:macro:`PySequence_Fast_GET_SIZE`, |
| 3042 |
:c:macro:`PySequence_Fast_GET_ITEM`, |
| 3043 |
and :c:macro:`PySequence_Fast_ITEMS` |
| 3044 |
macros from the limited C API, since they have always been broken |
| 3045 |
in the limited C API. |
| 3046 |
(Contributed by Victor Stinner in :gh:`91417`.) |
| 3047 |
|
| 3048 |
|
| 3049 |
.. _whatsnew314-c-api-removed: |
| 3050 |
|
| 3051 |
Removed C APIs |
| 3052 |
-------------- |
| 3053 |
|
| 3054 |
* Creating :c:data:`immutable types <Py_TPFLAGS_IMMUTABLETYPE>` with |
| 3055 |
mutable bases was deprecated in Python 3.12, |
| 3056 |
and now raises a :exc:`TypeError`. |
| 3057 |
(Contributed by Nikita Sobolev in :gh:`119775`.) |
| 3058 |
|
| 3059 |
* Remove ``PyDictObject.ma_version_tag`` member, which was deprecated |
| 3060 |
in Python 3.12. |
| 3061 |
Use the :c:func:`PyDict_AddWatcher` API instead. |
| 3062 |
(Contributed by Sam Gross in :gh:`124296`.) |
| 3063 |
|
| 3064 |
* Remove the private ``_Py_InitializeMain()`` function. |
| 3065 |
It was a :term:`provisional API` added to Python 3.8 by :pep:`587`. |
| 3066 |
(Contributed by Victor Stinner in :gh:`129033`.) |
| 3067 |
|
| 3068 |
* Remove the undocumented APIs :c:macro:`!Py_C_RECURSION_LIMIT` |
| 3069 |
and :c:member:`!PyThreadState.c_recursion_remaining`. |
| 3070 |
These were added in 3.13 and have been removed without deprecation. |
| 3071 |
Use :c:func:`Py_EnterRecursiveCall` to guard against runaway |
| 3072 |
recursion in C code. |
| 3073 |
(Removed by Petr Viktorin in :gh:`133079`, see also :gh:`130396`.) |
| 3074 |
|
| 3075 |
|
| 3076 |
.. _whatsnew314-c-api-deprecated: |
| 3077 |
|
| 3078 |
Deprecated C APIs |
| 3079 |
----------------- |
| 3080 |
|
| 3081 |
* The :c:macro:`!Py_HUGE_VAL` macro is now :term:`soft deprecated`. |
| 3082 |
Use :c:macro:`!Py_INFINITY` instead. |
| 3083 |
(Contributed by Sergey B Kirpichev in :gh:`120026`.) |
| 3084 |
|
| 3085 |
* The :c:macro:`!Py_IS_NAN`, :c:macro:`!Py_IS_INFINITY`, |
| 3086 |
and :c:macro:`!Py_IS_FINITE` macros are now :term:`soft deprecated`. |
| 3087 |
Use :c:macro:`!isnan`, :c:macro:`!isinf` and :c:macro:`!isfinite` |
| 3088 |
instead, available from :file:`math.h` since C99. |
| 3089 |
(Contributed by Sergey B Kirpichev in :gh:`119613`.) |
| 3090 |
|
| 3091 |
* Non-tuple sequences are now deprecated as argument for the ``(items)`` |
| 3092 |
format unit in :c:func:`PyArg_ParseTuple` and other :ref:`argument |
| 3093 |
parsing <arg-parsing>` functions if *items* contains format units |
| 3094 |
which store a :ref:`borrowed buffer <c-arg-borrowed-buffer>` or a |
| 3095 |
:term:`borrowed reference`. |
| 3096 |
(Contributed by Serhiy Storchaka in :gh:`50333`.) |
| 3097 |
|
| 3098 |
* The ``_PyMonitoring_FireBranchEvent`` function is now deprecated |
| 3099 |
and should be replaced with calls to |
| 3100 |
:c:func:`PyMonitoring_FireBranchLeftEvent` and |
| 3101 |
:c:func:`PyMonitoring_FireBranchRightEvent`. |
| 3102 |
|
| 3103 |
* The previously undocumented function :c:func:`PySequence_In` is |
| 3104 |
now :term:`soft deprecated`. |
| 3105 |
Use :c:func:`PySequence_Contains` instead. |
| 3106 |
(Contributed by Yuki Kobayashi in :gh:`127896`.) |
| 3107 |
|
| 3108 |
.. Add C API deprecations above alphabetically, not here at the end. |
| 3109 |
|
| 3110 |
.. include:: ../deprecations/c-api-pending-removal-in-3.15.rst |
| 3111 |
|
| 3112 |
.. include:: ../deprecations/c-api-pending-removal-in-3.16.rst |
| 3113 |
|
| 3114 |
.. include:: ../deprecations/c-api-pending-removal-in-3.18.rst |
| 3115 |
|
| 3116 |
.. include:: ../deprecations/c-api-pending-removal-in-future.rst |
| 3117 |
|
| 3118 |
|
| 3119 |
.. _whatsnew314-build-changes: |
| 3120 |
|
| 3121 |
Build changes |
| 3122 |
============= |
| 3123 |
|
| 3124 |
* :pep:`776`: Emscripten is now an officially supported platform at |
| 3125 |
:pep:`tier 3 <11#tier-3>`. As a part of this effort, more than 25 bugs in |
| 3126 |
`Emscripten libc`__ were fixed. Emscripten now includes support |
| 3127 |
for :mod:`ctypes`, :mod:`termios`, and :mod:`fcntl`, as well as |
| 3128 |
experimental support for the new :ref:`default interactive shell |
| 3129 |
<tut-interactive>`. |
| 3130 |
(Contributed by R. Hood Chatham in :gh:`127146`, :gh:`127683`, and :gh:`136931`.) |
| 3131 |
|
| 3132 |
__ https://emscripten.org/docs/porting/emscripten-runtime-environment.html |
| 3133 |
|
| 3134 |
* Official Android binary releases are now provided on python.org__. |
| 3135 |
|
| 3136 |
__ https://www.python.org/downloads/android/ |
| 3137 |
|
| 3138 |
* GNU Autoconf 2.72 is now required to generate :file:`configure`. |
| 3139 |
(Contributed by Erlend Aasland in :gh:`115765`.) |
| 3140 |
|
| 3141 |
* ``wasm32-unknown-emscripten`` is now a :pep:`11` tier 3 platform. |
| 3142 |
(Contributed by R. Hood Chatham in :gh:`127146`, :gh:`127683`, and :gh:`136931`.) |
| 3143 |
|
| 3144 |
* ``#pragma``-based linking with ``python3*.lib`` can now be switched off |
| 3145 |
with :c:expr:`Py_NO_LINK_LIB`. |
| 3146 |
(Contributed by Jean-Christophe Fillion-Robin in :gh:`82909`.) |
| 3147 |
|
| 3148 |
* CPython now enables a set of recommended compiler options by default |
| 3149 |
for improved security. |
| 3150 |
Use the :option:`--disable-safety` :file:`configure` option to disable them, |
| 3151 |
or the :option:`--enable-slower-safety` option for a larger set |
| 3152 |
of compiler options, albeit with a performance cost. |
| 3153 |
|
| 3154 |
* The ``WITH_FREELISTS`` macro and ``--without-freelists`` :file:`configure` |
| 3155 |
option have been removed. |
| 3156 |
|
| 3157 |
* The new :file:`configure` option :option:`--with-tail-call-interp` |
| 3158 |
may be used to enable the experimental tail call interpreter. |
| 3159 |
See :ref:`whatsnew314-tail-call-interpreter` for further details. |
| 3160 |
|
| 3161 |
* To disable the new remote debugging support, use the |
| 3162 |
:option:`--without-remote-debug` :file:`configure` option. |
| 3163 |
This may be useful for security reasons. |
| 3164 |
|
| 3165 |
* iOS and macOS apps can now be configured to redirect ``stdout`` and |
| 3166 |
``stderr`` content to the system log. |
| 3167 |
(Contributed by Russell Keith-Magee in :gh:`127592`.) |
| 3168 |
|
| 3169 |
* The iOS testbed is now able to stream test output while the test is running. |
| 3170 |
The testbed can also be used to run the test suite of projects other than |
| 3171 |
CPython itself. |
| 3172 |
(Contributed by Russell Keith-Magee in :gh:`127592`.) |
| 3173 |
|
| 3174 |
|
| 3175 |
.. _whatsnew314-build_details: |
| 3176 |
|
| 3177 |
:file:`build-details.json` |
| 3178 |
-------------------------- |
| 3179 |
|
| 3180 |
Installations of Python now contain a new file, :file:`build-details.json`. |
| 3181 |
This is a static JSON document containing build details for CPython, |
| 3182 |
to allow for introspection without needing to run code. |
| 3183 |
This is helpful for use-cases such as Python launchers, cross-compilation, |
| 3184 |
and so on. |
| 3185 |
|
| 3186 |
:file:`build-details.json` must be installed in the platform-independent |
| 3187 |
standard library directory. This corresponds to the :ref:`'stdlib' |
| 3188 |
<installation_paths>` :mod:`sysconfig` installation path, |
| 3189 |
which can be found by running ``sysconfig.get_path('stdlib')``. |
| 3190 |
|
| 3191 |
.. seealso:: |
| 3192 |
:pep:`739` -- ``build-details.json`` 1.0 -- a static description file |
| 3193 |
for Python build details |
| 3194 |
|
| 3195 |
|
| 3196 |
.. _whatsnew314-no-more-pgp: |
| 3197 |
|
| 3198 |
Discontinuation of PGP signatures |
| 3199 |
--------------------------------- |
| 3200 |
|
| 3201 |
PGP (Pretty Good Privacy) signatures will not be provided |
| 3202 |
for releases of Python 3.14 or future versions. |
| 3203 |
To verify CPython artifacts, users must use `Sigstore verification materials |
| 3204 |
<https://www.python.org/downloads/metadata/sigstore/>`__. |
| 3205 |
Releases have been signed using Sigstore_ since Python 3.11. |
| 3206 |
|
| 3207 |
This change in release process was specified in :pep:`761`. |
| 3208 |
|
| 3209 |
.. _Sigstore: https://www.sigstore.dev/ |
| 3210 |
|
| 3211 |
|
| 3212 |
.. _whatsnew314-free-threaded-now-supported: |
| 3213 |
|
| 3214 |
Free-threaded Python is officially supported |
| 3215 |
-------------------------------------------- |
| 3216 |
|
| 3217 |
The free-threaded build of Python is now supported and no longer experimental. |
| 3218 |
This is the start of `phase II <https://discuss.python.org/t/37075>`__ where |
| 3219 |
free-threaded Python is officially supported but still optional. |
| 3220 |
|
| 3221 |
The free-threading team are confident that the project is on the right path, |
| 3222 |
and appreciate the continued dedication from everyone working to make |
| 3223 |
free-threading ready for broader adoption across the Python community. |
| 3224 |
|
| 3225 |
With these recommendations and the acceptance of this PEP, the Python developer |
| 3226 |
community should broadly advertise that free-threading is a supported |
| 3227 |
Python build option now and into the future, and that it will not be removed |
| 3228 |
without a proper deprecation schedule. |
| 3229 |
|
| 3230 |
Any decision to transition to `phase III <https://discuss.python.org/t/37075>`__, |
| 3231 |
with free-threading as the default or sole build of Python is still undecided, |
| 3232 |
and dependent on many factors both within CPython itself and the community. |
| 3233 |
This decision is for the future. |
| 3234 |
|
| 3235 |
.. seealso:: |
| 3236 |
|
| 3237 |
:pep:`779` |
| 3238 |
|
| 3239 |
`PEP 779's acceptance <https://discuss.python.org/t/84319/123>`__ |
| 3240 |
|
| 3241 |
|
| 3242 |
.. _whatsnew314-jit-compiler: |
| 3243 |
|
| 3244 |
Binary releases for the experimental just-in-time compiler |
| 3245 |
---------------------------------------------------------- |
| 3246 |
|
| 3247 |
The official macOS and Windows release binaries now include an *experimental* |
| 3248 |
just-in-time (JIT) compiler. Although it is **not** recommended for production |
| 3249 |
use, it can be tested by setting :envvar:`PYTHON_JIT=1 <PYTHON_JIT>` as an |
| 3250 |
environment variable. Downstream source builds and redistributors can use the |
| 3251 |
:option:`--enable-experimental-jit=yes-off` configuration option for similar |
| 3252 |
behavior. |
| 3253 |
|
| 3254 |
The JIT is at an early stage and still in active development. As such, the |
| 3255 |
typical performance impact of enabling it can range from 10% slower to 20% |
| 3256 |
faster, depending on workload. To aid in testing and evaluation, a set of |
| 3257 |
introspection functions has been provided in the :data:`sys._jit` namespace. |
| 3258 |
:func:`sys._jit.is_available` can be used to determine if the current executable |
| 3259 |
supports JIT compilation, while :func:`sys._jit.is_enabled` can be used to tell |
| 3260 |
if JIT compilation has been enabled for the current process. |
| 3261 |
|
| 3262 |
Currently, the most significant missing functionality is that native debuggers |
| 3263 |
and profilers like ``gdb`` and ``perf`` are unable to unwind through JIT frames |
| 3264 |
(Python debuggers and profilers, like :mod:`pdb` or :mod:`profile`, continue to |
| 3265 |
work without modification). Free-threaded builds do not support JIT compilation. |
| 3266 |
|
| 3267 |
Please report any bugs or major performance regressions that you encounter! |
| 3268 |
|
| 3269 |
.. seealso:: :pep:`744` |
| 3270 |
|
| 3271 |
|
| 3272 |
Porting to Python 3.14 |
| 3273 |
====================== |
| 3274 |
|
| 3275 |
This section lists previously described changes and other bugfixes |
| 3276 |
that may require changes to your code. |
| 3277 |
|
| 3278 |
|
| 3279 |
Changes in the Python API |
| 3280 |
------------------------- |
| 3281 |
|
| 3282 |
* On Unix platforms other than macOS, *forkserver* is now the default |
| 3283 |
:ref:`start method <multiprocessing-start-methods>` for :mod:`multiprocessing` |
| 3284 |
and :class:`~concurrent.futures.ProcessPoolExecutor`, instead of *fork*. |
| 3285 |
|
| 3286 |
See :ref:`(1) <whatsnew314-concurrent-futures-start-method>` and |
| 3287 |
:ref:`(2) <whatsnew314-multiprocessing-start-method>` for details. |
| 3288 |
|
| 3289 |
If you encounter :exc:`NameError`\s or pickling errors coming out of |
| 3290 |
:mod:`multiprocessing` or :mod:`concurrent.futures`, see the |
| 3291 |
:ref:`forkserver restrictions <multiprocessing-programming-forkserver>`. |
| 3292 |
|
| 3293 |
This change does not affect Windows or macOS, where :ref:`'spawn' |
| 3294 |
<multiprocessing-start-method-spawn>` remains the default start method. |
| 3295 |
|
| 3296 |
* :class:`functools.partial` is now a method descriptor. |
| 3297 |
Wrap it in :func:`staticmethod` if you want to preserve the old behavior. |
| 3298 |
(Contributed by Serhiy Storchaka and Dominykas Grigonis in :gh:`121027`.) |
| 3299 |
|
| 3300 |
* The :ref:`garbage collector is now incremental <whatsnew314-incremental-gc>`, |
| 3301 |
which means that the behavior of :func:`gc.collect` changes slightly: |
| 3302 |
|
| 3303 |
* ``gc.collect(1)``: Performs an increment of garbage collection, |
| 3304 |
rather than collecting generation 1. |
| 3305 |
* Other calls to :func:`!gc.collect` are unchanged. |
| 3306 |
|
| 3307 |
* The :func:`locale.nl_langinfo` function now temporarily sets the ``LC_CTYPE`` |
| 3308 |
locale in some cases. |
| 3309 |
This temporary change affects other threads. |
| 3310 |
(Contributed by Serhiy Storchaka in :gh:`69998`.) |
| 3311 |
|
| 3312 |
* :class:`types.UnionType` is now an alias for :class:`typing.Union`, |
| 3313 |
causing changes in some behaviors. |
| 3314 |
See :ref:`above <whatsnew314-typing-union>` for more details. |
| 3315 |
(Contributed by Jelle Zijlstra in :gh:`105499`.) |
| 3316 |
|
| 3317 |
* The runtime behavior of annotations has changed in various ways; see |
| 3318 |
:ref:`above <whatsnew314-deferred-annotations>` for details. While most code that interacts |
| 3319 |
with annotations should continue to work, some undocumented details may behave |
| 3320 |
differently. |
| 3321 |
|
| 3322 |
* As part of making the :mod:`mimetypes` CLI public, |
| 3323 |
it now exits with ``1`` on failure instead of ``0`` |
| 3324 |
and ``2`` on incorrect command-line parameters instead of ``1``. |
| 3325 |
Error messages are now printed to stderr. |
| 3326 |
|
| 3327 |
* The ``\B`` pattern in regular expression now matches the empty string |
| 3328 |
when given as the entire pattern, which may cause behavioural changes. |
| 3329 |
|
| 3330 |
* On FreeBSD, :data:`sys.platform` no longer contains the major version number. |
| 3331 |
|
| 3332 |
|
| 3333 |
.. _whatsnew314-porting-annotations: |
| 3334 |
|
| 3335 |
Changes in annotations (:pep:`649` and :pep:`749`) |
| 3336 |
-------------------------------------------------- |
| 3337 |
|
| 3338 |
This section contains guidance on changes that may be needed to annotations |
| 3339 |
or Python code that interacts with or introspects annotations, |
| 3340 |
due to the changes related to :ref:`deferred evaluation of annotations |
| 3341 |
<whatsnew314-deferred-annotations>`. |
| 3342 |
|
| 3343 |
In the majority of cases, working code from older versions of Python |
| 3344 |
will not require any changes. |
| 3345 |
|
| 3346 |
|
| 3347 |
Implications for annotated code |
| 3348 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 3349 |
|
| 3350 |
If you define annotations in your code (for example, for use with a static type |
| 3351 |
checker), then this change probably does not affect you: you can keep |
| 3352 |
writing annotations the same way you did with previous versions of Python. |
| 3353 |
|
| 3354 |
You will likely be able to remove quoted strings in annotations, which are frequently |
| 3355 |
used for forward references. Similarly, if you use ``from __future__ import annotations`` |
| 3356 |
to avoid having to write strings in annotations, you may well be able to |
| 3357 |
remove that import once you support only Python 3.14 and newer. |
| 3358 |
However, if you rely on third-party libraries that read annotations, |
| 3359 |
those libraries may need changes to support unquoted annotations before they |
| 3360 |
work as expected. |
| 3361 |
|
| 3362 |
|
| 3363 |
Implications for readers of ``__annotations__`` |
| 3364 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 3365 |
|
| 3366 |
If your code reads the :attr:`~object.__annotations__` attribute on objects, |
| 3367 |
you may want to make changes in order to support code that relies on |
| 3368 |
deferred evaluation of annotations. |
| 3369 |
For example, you may want to use :func:`annotationlib.get_annotations` with |
| 3370 |
the :attr:`~annotationlib.Format.FORWARDREF` format, |
| 3371 |
as the :mod:`dataclasses` module now does. |
| 3372 |
|
| 3373 |
The external :pypi:`typing_extensions` package provides partial backports |
| 3374 |
of some of the functionality of the :mod:`annotationlib` module, |
| 3375 |
such as the :class:`~annotationlib.Format` enum and |
| 3376 |
the :func:`~annotationlib.get_annotations` function. |
| 3377 |
These can be used to write cross-version code that takes advantage of |
| 3378 |
the new behavior in Python 3.14. |
| 3379 |
|
| 3380 |
|
| 3381 |
Related changes |
| 3382 |
^^^^^^^^^^^^^^^ |
| 3383 |
|
| 3384 |
The changes in Python 3.14 are designed to rework how :attr:`!__annotations__` |
| 3385 |
works at runtime while minimizing breakage to code that contains |
| 3386 |
annotations in source code and to code that reads :attr:`!__annotations__`. |
| 3387 |
However, if you rely on undocumented details of the annotation behavior |
| 3388 |
or on private functions in the standard library, there are many ways in which |
| 3389 |
your code may not work in Python 3.14. |
| 3390 |
To safeguard your code against future changes, only use the documented |
| 3391 |
functionality of the :mod:`annotationlib` module. |
| 3392 |
|
| 3393 |
In particular, do not read annotations directly from the namespace dictionary |
| 3394 |
attribute of type objects. |
| 3395 |
Use :func:`annotationlib.get_annotate_from_class_namespace` during class |
| 3396 |
construction and :func:`annotationlib.get_annotations` afterwards. |
| 3397 |
|
| 3398 |
In previous releases, it was sometimes possible to access class annotations |
| 3399 |
from an instance of an annotated class. This behavior was undocumented |
| 3400 |
and accidental, and will no longer work in Python 3.14. |
| 3401 |
|
| 3402 |
|
| 3403 |
``from __future__ import annotations`` |
| 3404 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 3405 |
|
| 3406 |
In Python 3.7, :pep:`563` introduced the ``from __future__ import annotations`` |
| 3407 |
:ref:`future statement <future>`, which turns all annotations into strings. |
| 3408 |
|
| 3409 |
However, this statement is now deprecated and it is expected to be removed |
| 3410 |
in a future version of Python. |
| 3411 |
This removal will not happen until after Python 3.13 reaches its end of life |
| 3412 |
in 2029, being the last version of Python without support for deferred |
| 3413 |
evaluation of annotations. |
| 3414 |
|
| 3415 |
In Python 3.14, the behavior of code using ``from __future__ import annotations`` |
| 3416 |
is unchanged. |
| 3417 |
|
| 3418 |
|
| 3419 |
Changes in the C API |
| 3420 |
-------------------- |
| 3421 |
|
| 3422 |
* :c:func:`Py_Finalize` now deletes all interned strings. This |
| 3423 |
is backwards incompatible to any C extension that holds onto an interned |
| 3424 |
string after a call to :c:func:`Py_Finalize` and is then reused after a |
| 3425 |
call to :c:func:`Py_Initialize`. Any issues arising from this behavior will |
| 3426 |
normally result in crashes during the execution of the subsequent call to |
| 3427 |
:c:func:`Py_Initialize` from accessing uninitialized memory. To fix, use |
| 3428 |
an address sanitizer to identify any use-after-free coming from |
| 3429 |
an interned string and deallocate it during module shutdown. |
| 3430 |
(Contributed by Eddie Elizondo in :gh:`113601`.) |
| 3431 |
|
| 3432 |
* The :ref:`Unicode Exception Objects <unicodeexceptions>` C API |
| 3433 |
now raises a :exc:`TypeError` if its exception argument is not |
| 3434 |
a :exc:`UnicodeError` object. |
| 3435 |
(Contributed by Bénédikt Tran in :gh:`127691`.) |
| 3436 |
|
| 3437 |
.. _whatsnew314-refcount: |
| 3438 |
|
| 3439 |
* The interpreter internally avoids some reference count modifications when |
| 3440 |
loading objects onto the operands stack by :term:`borrowing <borrowed reference>` |
| 3441 |
references when possible. This can lead to smaller reference count values |
| 3442 |
compared to previous Python versions. C API extensions that checked |
| 3443 |
:c:func:`Py_REFCNT` of ``1`` to determine if an function argument is not |
| 3444 |
referenced by any other code should instead use |
| 3445 |
:c:func:`PyUnstable_Object_IsUniqueReferencedTemporary` as a safer replacement. |
| 3446 |
|
| 3447 |
|
| 3448 |
* Private functions promoted to public C APIs: |
| 3449 |
|
| 3450 |
* ``_PyBytes_Join()``: :c:func:`PyBytes_Join` |
| 3451 |
* ``_PyLong_IsNegative()``: :c:func:`PyLong_IsNegative` |
| 3452 |
* ``_PyLong_IsPositive()``: :c:func:`PyLong_IsPositive` |
| 3453 |
* ``_PyLong_IsZero()``: :c:func:`PyLong_IsZero` |
| 3454 |
* ``_PyLong_Sign()``: :c:func:`PyLong_GetSign` |
| 3455 |
* ``_PyUnicodeWriter_Dealloc()``: :c:func:`PyUnicodeWriter_Discard` |
| 3456 |
* ``_PyUnicodeWriter_Finish()``: :c:func:`PyUnicodeWriter_Finish` |
| 3457 |
* ``_PyUnicodeWriter_Init()``: use :c:func:`PyUnicodeWriter_Create` |
| 3458 |
* ``_PyUnicodeWriter_Prepare()``: (no replacement) |
| 3459 |
* ``_PyUnicodeWriter_PrepareKind()``: (no replacement) |
| 3460 |
* ``_PyUnicodeWriter_WriteChar()``: :c:func:`PyUnicodeWriter_WriteChar` |
| 3461 |
* ``_PyUnicodeWriter_WriteStr()``: :c:func:`PyUnicodeWriter_WriteStr` |
| 3462 |
* ``_PyUnicodeWriter_WriteSubstring()``: :c:func:`PyUnicodeWriter_WriteSubstring` |
| 3463 |
* ``_PyUnicode_EQ()``: :c:func:`PyUnicode_Equal` |
| 3464 |
* ``_PyUnicode_Equal()``: :c:func:`PyUnicode_Equal` |
| 3465 |
* ``_Py_GetConfig()``: :c:func:`PyConfig_Get` and :c:func:`PyConfig_GetInt` |
| 3466 |
* ``_Py_HashBytes()``: :c:func:`Py_HashBuffer` |
| 3467 |
* ``_Py_fopen_obj()``: :c:func:`Py_fopen` |
| 3468 |
* ``PyMutex_IsLocked()`` : :c:func:`PyMutex_IsLocked` |
| 3469 |
|
| 3470 |
The `pythoncapi-compat project`_ can be used to get most of these new |
| 3471 |
functions on Python 3.13 and older. |
| 3472 |
|
| 3473 |
.. _pythoncapi-compat project: https://github.com/python/pythoncapi-compat/ |
| 3474 |
|
| 3475 |
|
| 3476 |
Notable changes in 3.14.1 |
| 3477 |
========================= |
| 3478 |
|
| 3479 |
* Add :c:func:`PyUnstable_ThreadState_SetStackProtection` and |
| 3480 |
:c:func:`PyUnstable_ThreadState_ResetStackProtection` functions to set |
| 3481 |
the stack protection base address and stack protection size of a Python |
| 3482 |
thread state. |
| 3483 |
(Contributed by Victor Stinner in :gh:`139653`.) |
| 3484 |
|
| 3485 |
|
| 3486 |
Notable changes in 3.14.5 |
| 3487 |
========================= |
| 3488 |
|
| 3489 |
gc |
| 3490 |
-- |
| 3491 |
|
| 3492 |
* The incremental garbage collector shipped in Python 3.14.0-3.14.4 has been |
| 3493 |
reverted back to the generational garbage collector from 3.13, |
| 3494 |
due to a number of `reports |
| 3495 |
<https://github.com/python/cpython/issues/142516>`__ |
| 3496 |
of significant memory pressure in production environments. |
| 3497 |
See :ref:`whatsnew314-incremental-gc` for details. |