Spaces:
Running on Zero
A newer version of the Gradio SDK is available: 6.22.0
What's new in Python 3.15
Editor : Hugo van Kemenade
* Anyone can add text to this document. Do not spend very much time on the wording of your changes, because your text will probably get rewritten to some degree.
* The maintainer will go through Misc/NEWS periodically and add changes; it's therefore more important to add your changes to Misc/NEWS than to this file.
* This is not a complete list of every single change; completeness is the purpose of Misc/NEWS. Some changes I consider too small or esoteric to include. If such a change is added to the text, I'll just remove it. (This is another reason you shouldn't spend too much time on writing your addition.)
* If you want to draw your new text to the attention of the maintainer, add 'XXX' to the beginning of the paragraph or section.
* It's OK to just add a fragmentary note about a change. For example: "XXX Describe the transmogrify() function added to the socket module." The maintainer will research the change and write the necessary text.
* You can comment out your additions if you like, but it's not necessary (especially when a final release is some months away).
* Credit the author of a patch or bugfix. Just the name is sufficient; the e-mail address isn't necessary.
- It's helpful to add the issue number as a comment:
XXX Describe the transmogrify() function added to the socket module. (Contributed by P.Y. Developer in
12345{.interpreted-text role="gh"}.)This saves the maintainer the effort of going through the VCS log when researching a change.
This article explains the new features in Python 3.15, compared to 3.14.
For full details, see the changelog <changelog>{.interpreted-text role="ref"}.
:::: note ::: title Note :::
Prerelease users should be aware that this document is currently in draft form. It will be updated substantially as Python 3.15 moves towards release, so it's worth checking back even after reading earlier versions. ::::
Summary -- Release highlights
810{.interpreted-text role="pep"}:Explicit lazy imports for faster startup times <whatsnew315-pep810>{.interpreted-text role="ref"}814{.interpreted-text role="pep"}:Add frozendict built-in type <whatsnew315-frozendict>{.interpreted-text role="ref"}799{.interpreted-text role="pep"}:A dedicated profiling package for organizing Python profiling tools <whatsnew315-profiling-package>{.interpreted-text role="ref"}799{.interpreted-text role="pep"}:Tachyon: High frequency statistical sampling profiler <whatsnew315-sampling-profiler>{.interpreted-text role="ref"}798{.interpreted-text role="pep"}:Unpacking in Comprehensions <whatsnew315-unpacking-in-comprehensions>{.interpreted-text role="ref"}686{.interpreted-text role="pep"}:Python now uses UTF-8 as the default encoding <whatsnew315-utf8-default>{.interpreted-text role="ref"}782{.interpreted-text role="pep"}:A new PyBytesWriter C API to create a Python bytes object <whatsnew315-pep782>{.interpreted-text role="ref"}The JIT compiler has been significantly upgraded <whatsnew315-jit>{.interpreted-text role="ref"}Improved error messages <whatsnew315-improved-error-messages>{.interpreted-text role="ref"}
New features
810{.interpreted-text role="pep"}: Explicit lazy imports {#whatsnew315-pep810}
Large Python applications often suffer from slow startup times. A significant contributor to this problem is the import system: when a module is imported, Python must locate the file, read it from disk, compile it to bytecode, and execute all top-level code. For applications with deep dependency trees, this process can take seconds, even when most of the imported code is never actually used during a particular run.
Developers have worked around this by moving imports inside functions, using importlib{.interpreted-text role="mod"} to load modules on demand, or restructuring code to avoid unnecessary dependencies. These approaches work but make code harder to read and maintain, scatter import statements throughout the codebase, and require discipline to apply consistently.
Python now provides a cleaner solution through explicit lazy{.interpreted-text role="keyword"} imports using the new lazy soft keyword. When you mark an import as lazy, Python defers the actual module loading until the imported name is first used. This gives you the organizational benefits of declaring all imports at the top of the file while only paying the loading cost for modules you actually use.
The lazy keyword works with both import and from ... import statements. When you write lazy import heavy_module, Python does not immediately load the module. Instead, it creates a lightweight proxy object. The actual module loading happens transparently when you first access the name:
lazy import json
lazy from datetime import datetime
print("Starting up...") # json and datetime not loaded yet
data = json.loads('{"key": "value"}') # json gets loads here
now = datetime() # datetime loads here
This mechanism is particularly useful for applications that import many modules at the top level but may only use a subset of them in any given run. The deferred loading reduces startup latency without requiring code restructuring or conditional imports scattered throughout the codebase.
In the case where loading a lazily imported module fails (for example, if the module does not exist), Python raises the exception at the point of first use rather than at import time. The associated traceback includes both the location where the name was accessed and the original import statement, making it straightforward to diagnose & debug the failure.
For cases where you want to enable lazy loading globally without modifying source code, Python provides the -X lazy_imports <-X>{.interpreted-text role="option"} command-line option and the PYTHON_LAZY_IMPORTS{.interpreted-text role="envvar"} environment variable. Both accept three values: all makes all imports lazy by default, none disables lazy imports entirely (even explicit lazy statements become eager), and normal (the default) respects the lazy keyword in source code. The sys.set_lazy_imports{.interpreted-text role="func"} and sys.get_lazy_imports{.interpreted-text role="func"} functions allow changing and querying this mode at runtime.
For more selective control, sys.set_lazy_imports_filter{.interpreted-text role="func"} accepts a callable that determines whether a specific module should be loaded lazily. The filter receives three arguments: the importing module's name (or None), the imported module's name, and the fromlist (or None for regular imports). It should return True to allow the import to be lazy, or False to force eager loading. This allows patterns like making only your own application's modules lazy while keeping third-party dependencies eager:
import sys
def myapp_filter(importing, imported, fromlist):
return imported.startswith("myapp.")
sys.set_lazy_imports_filter(myapp_filter)
sys.set_lazy_imports("all")
import myapp.slow_module # lazy (matches filter)
import json # eager (does not match filter)
The proxy type itself is available as types.LazyImportType{.interpreted-text role="data"} for code that needs to detect lazy imports programmatically.
There are some restrictions on where the lazy keyword can be used. Lazy imports are only permitted at module scope; using lazy inside a function, class body, or try/except/finally block raises a SyntaxError{.interpreted-text role="exc"}. Neither star imports nor future imports can be lazy (lazy from module import * and lazy from __future__ import ... both raise SyntaxError{.interpreted-text role="exc"}).
::: seealso
810{.interpreted-text role="pep"} for the full specification and rationale.
:::
(Contributed by Pablo Galindo Salgado and Dino Viehland in 142349{.interpreted-text role="gh"}.)
814{.interpreted-text role="pep"}: Add frozendict built-in type {#whatsnew315-frozendict}
A new immutable{.interpreted-text role="term"} type, frozendict{.interpreted-text role="class"}, is added to the builtins{.interpreted-text role="mod"} module. It does not allow modification after creation. A frozendict is not a subclass of dict; it inherits directly from object. A frozendict is hashable{.interpreted-text role="term"} as long as all of its keys and values are hashable. A frozendict preserves insertion order, but comparison does not take order into account.
For example:
>>> a = frozendict(x=1, y=2)
>>> a
frozendict({'x': 1, 'y': 2})
>>> a['z'] = 3
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
a['z'] = 3
~^^^^^
TypeError: 'frozendict' object does not support item assignment
>>> b = frozendict(y=2, x=1)
>>> hash(a) == hash(b)
True
>>> a == b
True
::: seealso
814{.interpreted-text role="pep"} for the full specification and rationale.
:::
(Contributed by Victor Stinner and Donghee Na in 141510{.interpreted-text role="gh"}.)
799{.interpreted-text role="pep"}: A dedicated profiling package {#whatsnew315-profiling-package}
A new profiling{.interpreted-text role="mod"} module has been added to organize Python's built-in profiling tools under a single, coherent namespace. This module contains:
profiling.tracing{.interpreted-text role="mod"}: deterministic function-call tracing (relocated fromcProfile).profiling.sampling{.interpreted-text role="mod"}: a new statistical sampling profiler (named Tachyon).
The cProfile module remains as an alias for backwards compatibility. The profile{.interpreted-text role="mod"} module is deprecated and will be removed in Python 3.17.
::: seealso
799{.interpreted-text role="pep"} for further details.
:::
(Contributed by Pablo Galindo and László Kiss Kollár in 138122{.interpreted-text role="gh"}.)
Tachyon: High frequency statistical sampling profiler {#whatsnew315-sampling-profiler}
A new statistical sampling profiler (Tachyon) has been added as profiling.sampling{.interpreted-text role="mod"}. This profiler enables low-overhead performance analysis of running Python processes without requiring code modification or process restart.
Unlike deterministic profilers (such as profiling.tracing{.interpreted-text role="mod"}) that instrument every function call, the sampling profiler periodically captures stack traces from running processes. This approach provides virtually zero overhead while achieving sampling rates of up to 1,000,000 Hz, making it the fastest sampling profiler available for Python (at the time of its contribution) and ideal for debugging performance issues in production environments. This capability is particularly valuable for debugging performance issues in production systems where traditional profiling approaches would be too intrusive.
Key features include:
- Zero-overhead profiling: Attach to any running Python process without affecting its performance. Ideal for production debugging where you can't afford to restart or slow down your application.
- No code modification required: Profile existing applications without restart. Simply point the profiler at a running process by PID and start collecting data.
- Flexible target modes:
- Profile running processes by PID (
attach) - attach to already-running applications - Run and profile scripts directly (
run) - profile from the very start of execution - Execute and profile modules (
run -m) - profile packages run aspython -m module
- Profile running processes by PID (
- Multiple profiling modes: Choose what to measure based on your performance investigation:
- Wall-clock time (
--mode wall, default): Measures real elapsed time including I/O, network waits, and blocking operations. Use this to understand where your program spends calendar time, including when waiting for external resources. - CPU time (
--mode cpu): Measures only active CPU execution time, excluding I/O waits and blocking. Use this to identify CPU-bound bottlenecks and optimize computational work. - GIL-holding time (
--mode gil): Measures time spent holding Python's Global Interpreter Lock. Use this to identify which threads dominate GIL usage in multi-threaded applications. - Exception handling time (
--mode exception): Captures samples only from threads with an active exception. Use this to analyze exception handling overhead.
- Wall-clock time (
- Thread-aware profiling: Option to profile all threads (
-a) or just the main thread, essential for understanding multi-threaded application behavior. - Multiple output formats: Choose the visualization that best fits your workflow:
--pstats: Detailed tabular statistics compatible withpstats{.interpreted-text role="mod"}. Shows function-level timing with direct and cumulative samples. Best for detailed analysis and integration with existing Python profiling tools.--collapsed: Generates collapsed stack traces (one line per stack). This format is specifically designed for creating flame graphs with external tools like Brendan Gregg's FlameGraph scripts or speedscope.--flamegraph: Generates a self-contained interactive HTML flame graph using D3.js. Opens directly in your browser for immediate visual analysis. Flame graphs show the call hierarchy where width represents time spent, making it easy to spot bottlenecks at a glance.--gecko: Generates Gecko Profiler format compatible with Firefox Profiler. Upload the output to Firefox Profiler for advanced timeline-based analysis with features like stack charts, markers, and network activity.--heatmap: Generates an interactive HTML heatmap visualization with line-level sample counts. Creates a directory with per-file heatmaps showing exactly where time is spent at the source code level.
- Live interactive mode: Real-time TUI profiler with a top-like interface (
--live). Monitor performance as your application runs with interactive sorting and filtering. - Async-aware profiling: Profile async/await code with task-based stack reconstruction (
--async-aware). See which coroutines are consuming time, with options to show only running tasks or all tasks including those waiting. - Opcode-level profiling: Gather bytecode opcode information for instruction-level profiling (
--opcodes). Shows which bytecode instructions are executing, including specializations from the adaptive interpreter.
See profiling.sampling{.interpreted-text role="mod"} for the complete documentation, including all available output formats, profiling modes, and configuration options.
(Contributed by Pablo Galindo and László Kiss Kollár in 135953{.interpreted-text role="gh"} and 138122{.interpreted-text role="gh"}.)
798{.interpreted-text role="pep"}: Unpacking in Comprehensions {#whatsnew315-unpacking-in-comprehensions}
List, set, and dictionary comprehensions, as well as generator expressions, now support unpacking with * and **. This extends the unpacking syntax from 448{.interpreted-text role="pep"} to comprehensions, providing a new syntax for combining an arbitrary number of iterables or dictionaries into a single flat structure. This new syntax is a direct alternative to nested comprehensions, itertools.chain{.interpreted-text role="func"}, and itertools.chain.from_iterable{.interpreted-text role="meth"}. For example:
>>> lists = [[1, 2], [3, 4], [5]]
>>> [*L for L in lists] # equivalent to [x for L in lists for x in L]
[1, 2, 3, 4, 5]
>>> sets = [{1, 2}, {2, 3}, {3, 4}]
>>> {*s for s in sets} # equivalent to {x for s in sets for x in s}
{1, 2, 3, 4}
>>> dicts = [{'a': 1}, {'b': 2}, {'a': 3}]
>>> {**d for d in dicts} # equivalent to {k: v for d in dicts for k,v in d.items()}
{'a': 3, 'b': 2}
Generator expressions can similarly use unpacking to yield values from multiple iterables:
>>> gen = (*L for L in lists) # equivalent to (x for L in lists for x in L)
>>> list(gen)
[1, 2, 3, 4, 5]
This change also extends to asynchronous generator expressions, such that, for example, (*a async for a in agen()) is equivalent to (x async for a in agen() for x in a).
::: seealso
798{.interpreted-text role="pep"} for further details.
:::
(Contributed by Adam Hartz in 143055{.interpreted-text role="gh"}.)
Improved error messages {#whatsnew315-improved-error-messages}
The interpreter now provides more helpful suggestions in
AttributeError{.interpreted-text role="exc"} exceptions when accessing an attribute on an object that does not exist, but a similar attribute is available through one of its members.For example, if the object has an attribute that itself exposes the requested name, the error message will suggest accessing it via that inner attribute:
@dataclass class Circle: radius: float @property def area(self) -> float: return pi * self.radius**2 class Container: def __init__(self, inner: Circle) -> None: self.inner = inner circle = Circle(radius=4.0) container = Container(circle) print(container.area)Running this code now produces a clearer suggestion:
Traceback (most recent call last): File "/home/pablogsal/github/python/main/lel.py", line 42, in <module> print(container.area) ^^^^^^^^^^^^^^ AttributeError: 'Container' object has no attribute 'area'. Did you mean '.inner.area' instead of '.area'?
Other language changes
::: {#whatsnew315-utf8-default}
Python now uses UTF-8 as the default encoding, independent of the system's environment. This means that I/O operations without an explicit encoding, for example,
open('flying-circus.txt'), will use UTF-8. UTF-8 is a widely-supported Unicode character encoding that has become a de facto standard for representing text, including nearly every webpage on the internet, many common file formats, programming languages, and more.This only applies when no
encodingargument is given. For best compatibility between versions of Python, ensure that an explicitencodingargument is always provided. Theopt-in encoding warning <io-encoding-warning>{.interpreted-text role="ref"} can be used to identify code that may be affected by this change. The specialencoding='locale'argument uses the current locale encoding, and has been supported since Python 3.10.To retain the previous behaviour, Python's UTF-8 mode may be disabled with the
PYTHONUTF8=0 <PYTHONUTF8>{.interpreted-text role="envvar"} environment variable or the-X utf8=0 <-X>{.interpreted-text role="option"} command-line option.::: seealso
686{.interpreted-text role="pep"} for further details. :::(Contributed by Adam Turner in
133711{.interpreted-text role="gh"}; PEP 686 written by Inada Naoki.)Several error messages incorrectly using the term "argument" have been corrected. (Contributed by Stan Ulbrych in
133382{.interpreted-text role="gh"}.)The interpreter now tries to provide a suggestion when
delattr{.interpreted-text role="func"} fails due to a missing attribute. When an attribute name that closely resembles an existing attribute is used, the interpreter will suggest the correct attribute name in the error message. For example:::: doctest >>> class A: ... pass >>> a = A() >>> a.abcde = 1 >>> del a.abcdf # doctest: +ELLIPSIS Traceback (most recent call last): ... AttributeError: 'A' object has no attribute 'abcdf'. Did you mean: 'abcde'? :::
(Contributed by Nikita Sobolev and Pranjal Prajapati in
136588{.interpreted-text role="gh"}.)Unraisable exceptions are now highlighted with color by default. This can be controlled by
environment variables <using-on-controlling-color>{.interpreted-text role="ref"}. (Contributed by Peter Bierma in134170{.interpreted-text role="gh"}.)The
~object.__repr__{.interpreted-text role="meth"} ofImportError{.interpreted-text role="class"} andModuleNotFoundError{.interpreted-text role="class"} now shows "name" and "path" asname=<name>andpath=<path>if they were given as keyword arguments at construction time. (Contributed by Serhiy Storchaka, Oleg Iarygin, and Yoav Nir in74185{.interpreted-text role="gh"}.)The
~object.__dict__{.interpreted-text role="attr"} and!__weakref__{.interpreted-text role="attr"} descriptors now use a single descriptor instance per interpreter, shared across all types that need them. This speeds up class creation, and helps avoid reference cycles. (Contributed by Petr Viktorin in135228{.interpreted-text role="gh"}.)The
-W{.interpreted-text role="option"} option and thePYTHONWARNINGS{.interpreted-text role="envvar"} environment variable can now specify regular expressions instead of literal strings to match the warning message and the module name, if the corresponding field starts and ends with a forward slash (/). (Contributed by Serhiy Storchaka in134716{.interpreted-text role="gh"}.)Functions that take timestamp or timeout arguments now accept any real numbers (such as
~decimal.Decimal{.interpreted-text role="class"} and~fractions.Fraction{.interpreted-text role="class"}), not only integers or floats, although this does not improve precision. (Contributed by Serhiy Storchaka in67795{.interpreted-text role="gh"}.) :::
::: {#whatsnew315-bytearray-take-bytes}
Added
bytearray.take_bytes(n=None, /) <bytearray.take_bytes>{.interpreted-text role="meth"} to take bytes out of abytearray{.interpreted-text role="class"} without copying. This enables optimizing code which must returnbytes{.interpreted-text role="class"} after working with a mutable buffer of bytes such as data buffering, network protocol parsing, encoding, decoding, and compression. Common code patterns which can be optimized with~bytearray.take_bytes{.interpreted-text role="func"} are listed below.+---------------------------------------------------------------------------------------------------------------+------------------------------------+---------------------------------+ | Description | Old | New | +===============================================================================================================+====================================+=================================+ | Return
bytes{.interpreted-text role="class"} after working withbytearray{.interpreted-text role="class"} |python |python | | | def read() -> bytes: | def read() -> bytes: | | | buffer = bytearray(1024) | buffer = bytearray(1024) | | | ... | ... | | | return bytes(buffer) | return buffer.take_bytes() | | ||| +---------------------------------------------------------------------------------------------------------------+------------------------------------+---------------------------------+ | Empty a buffer getting the bytes |python |python | | | buffer = bytearray(1024) | buffer = bytearray(1024) | | | ... | ... | | | data = bytes(buffer) | data = buffer.take_bytes() | | | buffer.clear() || | || | +---------------------------------------------------------------------------------------------------------------+------------------------------------+---------------------------------+ | Split a buffer at a specific separator |python |python | | | buffer = bytearray(b'abc\ndef') | buffer = bytearray(b'abc\ndef') | | | n = buffer.find(b'\n') | n = buffer.find(b'\n') | | | data = bytes(buffer[:n + 1]) | data = buffer.take_bytes(n + 1) | | | del buffer[:n + 1] || | | assert data == b'abc' | | | | assert buffer == bytearray(b'def') | | | || | +---------------------------------------------------------------------------------------------------------------+------------------------------------+---------------------------------+ | Split a buffer at a specific separator; discard after the separator |python |python | | | buffer = bytearray(b'abc\ndef') | buffer = bytearray(b'abc\ndef') | | | n = buffer.find(b'\n') | n = buffer.find(b'\n') | | | data = bytes(buffer[:n]) | buffer.resize(n) | | | buffer.clear() | data = buffer.take_bytes() | | | assert data == b'abc' || | | assert len(buffer) == 0 | | | || | +---------------------------------------------------------------------------------------------------------------+------------------------------------+---------------------------------+: Suggested optimizing refactors
(Contributed by Cody Maloney in
139871{.interpreted-text role="gh"}.)Many functions related to compiling or parsing Python code, such as
compile{.interpreted-text role="func"},ast.parse{.interpreted-text role="func"},symtable.symtable{.interpreted-text role="func"}, andimportlib.abc.InspectLoader.source_to_code{.interpreted-text role="func"}, now allow the module name to be passed. It is needed to unambiguouslyfilter <warning-filter>{.interpreted-text role="ref"} syntax warnings by module name. (Contributed by Serhiy Storchaka in135801{.interpreted-text role="gh"}.)Allowed defining the __dict__ and __weakref__
__slots__ <slots>{.interpreted-text role="ref"} for any class. (Contributed by Serhiy Storchaka in41779{.interpreted-text role="gh"}.)Allowed defining any
__slots__ <slots>{.interpreted-text role="ref"} for a class derived fromtuple{.interpreted-text role="class"} (including classes created bycollections.namedtuple{.interpreted-text role="func"}). (Contributed by Serhiy Storchaka in41779{.interpreted-text role="gh"}.)The
slice{.interpreted-text role="class"} type now supports subscription, making it ageneric type{.interpreted-text role="term"}. (Contributed by James Hilton-Balfe in128335{.interpreted-text role="gh"}.) :::
New modules
math.integer
This module provides access to the mathematical functions for integer arguments (791{.interpreted-text role="pep"}). (Contributed by Serhiy Storchaka in 81313{.interpreted-text role="gh"}.)
Improved modules
argparse
- The
~argparse.BooleanOptionalAction{.interpreted-text role="class"} action supports now single-dash long options and alternate prefix characters. (Contributed by Serhiy Storchaka in138525{.interpreted-text role="gh"}.) - Changed the suggest_on_error parameter of
argparse.ArgumentParser{.interpreted-text role="class"} to default toTrue. This enables suggestions for mistyped arguments by default. (Contributed by Jakob Schluse in140450{.interpreted-text role="gh"}.) - Added backtick markup support in description and epilog text to highlight inline code when color output is enabled. (Contributed by Savannah Ostrowski in
142390{.interpreted-text role="gh"}.)
base64
- Added the pad parameter in
~base64.z85encode{.interpreted-text role="func"}. (Contributed by Hauke Dämpfling in143103{.interpreted-text role="gh"}.) - Added the wrapcol parameter in
~base64.b64encode{.interpreted-text role="func"}. (Contributed by Serhiy Storchaka in143214{.interpreted-text role="gh"}.) - Added the ignorechars parameter in
~base64.b64decode{.interpreted-text role="func"}. (Contributed by Serhiy Storchaka in144001{.interpreted-text role="gh"}.)
binascii
Added functions for Ascii85, Base85, and Z85 encoding:
~binascii.b2a_ascii85{.interpreted-text role="func"} and~binascii.a2b_ascii85{.interpreted-text role="func"}~binascii.b2a_base85{.interpreted-text role="func"} and~binascii.a2b_base85{.interpreted-text role="func"}~binascii.b2a_z85{.interpreted-text role="func"} and~binascii.a2b_z85{.interpreted-text role="func"}
(Contributed by James Seo and Serhiy Storchaka in
101178{.interpreted-text role="gh"}.)Added the wrapcol parameter in
~binascii.b2a_base64{.interpreted-text role="func"}. (Contributed by Serhiy Storchaka in143214{.interpreted-text role="gh"}.)Added the ignorechars parameter in
~binascii.a2b_base64{.interpreted-text role="func"}. (Contributed by Serhiy Storchaka in144001{.interpreted-text role="gh"}.)
calendar
- Calendar pages generated by the
calendar.HTMLCalendar{.interpreted-text role="class"} class now support dark mode and have been migrated to the HTML5 standard for improved accessibility. (Contributed by Jiahao Li and Hugo van Kemenade in137634{.interpreted-text role="gh"}.) - The
calendar{.interpreted-text role="mod"}'scommand-line <calendar-cli>{.interpreted-text role="ref"} HTML output now accepts the year-month option:python -m calendar -t html 2009 06. (Contributed by Pål Grønås Drange in140212{.interpreted-text role="gh"}.)
collections
- Added
!collections.Counter.__xor__{.interpreted-text role="meth"} and!collections.Counter.__ixor__{.interpreted-text role="meth"} to compute the symmetric difference between~collections.Counter{.interpreted-text role="class"} objects. (Contributed by Raymond Hettinger in138682{.interpreted-text role="gh"}.)
collections.abc
collections.abc.ByteString{.interpreted-text role="class"} has been removed fromcollections.abc.__all__.!collections.abc.ByteString{.interpreted-text role="class"} has been deprecated since Python 3.12, and is scheduled for removal in Python 3.17.The following statements now cause
DeprecationWarnings to be emitted at runtime:from collections.abc import ByteStringimport collections.abc; collections.abc.ByteString.
DeprecationWarnings were already emitted ifcollections.abc.ByteString{.interpreted-text role="class"} was subclassed or used as the second argument toisinstance{.interpreted-text role="func"} orissubclass{.interpreted-text role="func"}, but warnings were not previously emitted if it was merely imported or accessed from the!collections.abc{.interpreted-text role="mod"} module.
concurrent.futures
- Improved error reporting when a child process in a
concurrent.futures.ProcessPoolExecutor{.interpreted-text role="class"} terminates abruptly. The resulting traceback will now tell you the PID and exit code of the terminated process. (Contributed by Jonathan Berg in139486{.interpreted-text role="gh"}.)
contextlib
- Added support for arbitrary descriptors
!__enter__{.interpreted-text role="meth"},!__exit__{.interpreted-text role="meth"},!__aenter__{.interpreted-text role="meth"}, and!__aexit__{.interpreted-text role="meth"} in~contextlib.ExitStack{.interpreted-text role="class"} andcontextlib.AsyncExitStack{.interpreted-text role="class"}, for consistency with thewith{.interpreted-text role="keyword"} andasync with{.interpreted-text role="keyword"} statements. (Contributed by Serhiy Storchaka in144386{.interpreted-text role="gh"}.)
dataclasses
- Annotations for generated
__init__methods no longer include internal type names.
dbm
- Added new
!reorganize{.interpreted-text role="meth"} methods todbm.dumb{.interpreted-text role="mod"} anddbm.sqlite3{.interpreted-text role="mod"} which allow to recover unused free space previously occupied by deleted entries. (Contributed by Andrea Oliveri in134004{.interpreted-text role="gh"}.)
difflib
- Introduced the optional color parameter to
difflib.unified_diff{.interpreted-text role="func"}, enabling color output similar togit diff{.interpreted-text role="program"}. This can be controlled byenvironment variables <using-on-controlling-color>{.interpreted-text role="ref"}. (Contributed by Douglas Thor in133725{.interpreted-text role="gh"}.) - Improved the styling of HTML diff pages generated by the
difflib.HtmlDiff{.interpreted-text role="class"} class, and migrated the output to the HTML5 standard. (Contributed by Jiahao Li in134580{.interpreted-text role="gh"}.)
functools
~functools.singledispatchmethod{.interpreted-text role="func"} now supports non-descriptor{.interpreted-text role="term"} callables. (Contributed by Serhiy Storchaka in140873{.interpreted-text role="gh"}.)
hashlib
- Ensure that hash functions guaranteed to be always available exist as attributes of
hashlib{.interpreted-text role="mod"} even if they will not work at runtime due to missing backend implementations. For instance,hashlib.md5will no longer raiseAttributeError{.interpreted-text role="exc"} if OpenSSL is not available and Python has been built without MD5 support. (Contributed by Bénédikt Tran in136929{.interpreted-text role="gh"}.)
http.client
- A new max_response_headers keyword-only parameter has been added to
~http.client.HTTPConnection{.interpreted-text role="class"} and~http.client.HTTPSConnection{.interpreted-text role="class"} constructors. This parameter overrides the default maximum number of allowed response headers. (Contributed by Alexander Enrique Urieles Nieto in131724{.interpreted-text role="gh"}.)
http.cookies
- Allow '
"' double quotes in cookie values. (Contributed by Nick Burns and Senthil Kumaran in92936{.interpreted-text role="gh"}.)
inspect
- Add parameters inherit_class_doc and fallback_to_class_doc for
~inspect.getdoc{.interpreted-text role="func"}. (Contributed by Serhiy Storchaka in132686{.interpreted-text role="gh"}.)
locale
~locale.setlocale{.interpreted-text role="func"} now supports language codes with@-modifiers.@-modifiers are no longer silently removed in~locale.getlocale{.interpreted-text role="func"}, but included in the language code. (Contributed by Serhiy Storchaka in137729{.interpreted-text role="gh"}.)- Undeprecate the
locale.getdefaultlocale{.interpreted-text role="func"} function. (Contributed by Victor Stinner in130796{.interpreted-text role="gh"}.)
math
- Add
math.isnormal{.interpreted-text role="func"} andmath.issubnormal{.interpreted-text role="func"} functions. (Contributed by Sergey B Kirpichev in132908{.interpreted-text role="gh"}.) - Add
math.fmax{.interpreted-text role="func"},math.fmin{.interpreted-text role="func"} andmath.signbit{.interpreted-text role="func"} functions. (Contributed by Bénédikt Tran in135853{.interpreted-text role="gh"}.)
mimetypes
- Add
application/dicomMIME type for.dcmextension. (Contributed by Benedikt Johannes in144217{.interpreted-text role="gh"}.) - Add
application/nodeMIME type for.cjsextension. (Contributed by John Franey in140937{.interpreted-text role="gh"}.) - Add
application/toml. (Contributed by Gil Forcada in139959{.interpreted-text role="gh"}.) - Add
image/jxl. (Contributed by Foolbar in144213{.interpreted-text role="gh"}.) - Rename
application/x-texinfotoapplication/texinfo. (Contributed by Charlie Lin in140165{.interpreted-text role="gh"}.) - Changed the MIME type for
.aifiles toapplication/pdf. (Contributed by Stan Ulbrych in141239{.interpreted-text role="gh"}.)
mmap
mmap.mmap{.interpreted-text role="class"} now has a trackfd parameter on Windows; if it isFalse, the file handle corresponding to fileno will not be duplicated. (Contributed by Serhiy Storchaka in78502{.interpreted-text role="gh"}.)- Added the
mmap.mmap.set_name{.interpreted-text role="meth"} method to annotate an anonymous memory mapping if Linux kernel supportsPR_SET_VMA_ANON_NAME <PR_SET_VMA(2const)>{.interpreted-text role="manpage"} (Linux 5.17 or newer). (Contributed by Donghee Na in142419{.interpreted-text role="gh"}.)
os
- Add
os.statx{.interpreted-text role="func"} on Linux kernel versions 4.11 and later with glibc versions 2.28 and later. (Contributed by Jeffrey Bosboom and Victor Stinner in83714{.interpreted-text role="gh"}.)
os.path
- Add support of the all-but-last mode in
~os.path.realpath{.interpreted-text role="func"}. (Contributed by Serhiy Storchaka in71189{.interpreted-text role="gh"}.) - The strict parameter to
os.path.realpath{.interpreted-text role="func"} accepts a new value,os.path.ALLOW_MISSING{.interpreted-text role="data"}. If used, errors other thanFileNotFoundError{.interpreted-text role="exc"} will be re-raised; the resulting path can be missing but it will be free of symlinks. (Contributed by Petr Viktorin for2025-4517{.interpreted-text role="cve"}.)
pickle
- Add support for pickling private methods and nested classes. (Contributed by Zackery Spytz and Serhiy Storchaka in
77188{.interpreted-text role="gh"}.)
re
re.prefixmatch{.interpreted-text role="func"} and a corresponding~re.Pattern.prefixmatch{.interpreted-text role="meth"} have been added as alternate more explicit names for the existingre.match{.interpreted-text role="func"} and~re.Pattern.match{.interpreted-text role="meth"} APIs. These are intended to be used to alleviate confusion around what match means by following the Zen of Python's "Explicit is better than implicit" mantra. Most other language regular expression libraries use an API named match to mean what Python has always called search. (Contributed by Gregory P. Smith in86519{.interpreted-text role="gh"}.)
resource
- Add new constants:
~resource.RLIMIT_NTHR{.interpreted-text role="data"},~resource.RLIMIT_UMTXP{.interpreted-text role="data"},~resource.RLIMIT_THREADS{.interpreted-text role="data"},~resource.RLIM_SAVED_CUR{.interpreted-text role="data"}, and~resource.RLIM_SAVED_MAX{.interpreted-text role="data"}. (Contributed by Serhiy Storchaka in137512{.interpreted-text role="gh"}.)
shelve
- Added new
!reorganize{.interpreted-text role="meth"} method toshelve{.interpreted-text role="mod"} used to recover unused free space previously occupied by deleted entries. (Contributed by Andrea Oliveri in134004{.interpreted-text role="gh"}.)
socket
- Add constants for the ISO-TP CAN protocol. (Contributed by Patrick Menschel and Stefan Tatschner in
86819{.interpreted-text role="gh"}.)
sqlite3
- The
command-line interface <sqlite3-cli>{.interpreted-text role="ref"} has several new features:- SQL keyword completion on <tab>. (Contributed by Long Tan in
133393{.interpreted-text role="gh"}.) - Prompts, error messages, and help text are now colored. This is enabled by default, see
using-on-controlling-color{.interpreted-text role="ref"} for details. (Contributed by Stan Ulbrych and Łukasz Langa in133461{.interpreted-text role="gh"}.) - Table, index, trigger, view, column, function, and schema completion on <tab>. (Contributed by Long Tan in
136101{.interpreted-text role="gh"}.)
- SQL keyword completion on <tab>. (Contributed by Long Tan in
ssl
Indicate through
ssl.HAS_PSK_TLS13{.interpreted-text role="data"} whether thessl{.interpreted-text role="mod"} module supports "External PSKs" in TLSv1.3, as described in RFC 9258. (Contributed by Will Childs-Klein in133624{.interpreted-text role="gh"}.)Added new methods for managing groups used for SSL key agreement
ssl.SSLContext.set_groups{.interpreted-text role="meth"} sets the groups allowed for doing key agreement, extending the previousssl.SSLContext.set_ecdh_curve{.interpreted-text role="meth"} method. This new API provides the ability to list multiple groups and supports fixed-field and post-quantum groups in addition to ECDH curves. This method can also be used to control what key shares are sent in the TLS handshake.ssl.SSLSocket.group{.interpreted-text role="meth"} returns the group selected for doing key agreement on the current connection after the TLS handshake completes. This call requires OpenSSL 3.2 or later.ssl.SSLContext.get_groups{.interpreted-text role="meth"} returns a list of all available key agreement groups compatible with the minimum and maximum TLS versions currently set in the context. This call requires OpenSSL 3.5 or later.
(Contributed by Ron Frederick in
136306{.interpreted-text role="gh"}.)Added a new method
ssl.SSLContext.set_ciphersuites{.interpreted-text role="meth"} for setting TLS 1.3 ciphers. For TLS 1.2 or earlier,ssl.SSLContext.set_ciphers{.interpreted-text role="meth"} should continue to be used. Both calls can be made on the same context and the selected cipher suite will depend on the TLS version negotiated when a connection is made. (Contributed by Ron Frederick in137197{.interpreted-text role="gh"}.)Added new methods for managing signature algorithms:
ssl.get_sigalgs{.interpreted-text role="func"} returns a list of all available TLS signature algorithms. This call requires OpenSSL 3.4 or later.ssl.SSLContext.set_client_sigalgs{.interpreted-text role="meth"} sets the signature algorithms allowed for certificate-based client authentication.ssl.SSLContext.set_server_sigalgs{.interpreted-text role="meth"} sets the signature algorithms allowed for the server to complete the TLS handshake.ssl.SSLSocket.client_sigalg{.interpreted-text role="meth"} returns the signature algorithm selected for client authentication on the current connection. This call requires OpenSSL 3.5 or later.ssl.SSLSocket.server_sigalg{.interpreted-text role="meth"} returns the signature algorithm selected for the server to complete the TLS handshake on the current connection. This call requires OpenSSL 3.5 or later.
(Contributed by Ron Frederick in
138252{.interpreted-text role="gh"}.)
subprocess
subprocess.Popen.wait{.interpreted-text role="meth"}: whentimeoutis notNoneand the platform supports it, an efficient event-driven mechanism is used to wait for process termination:- Linux >= 5.3 uses
os.pidfd_open{.interpreted-text role="func"} +select.poll{.interpreted-text role="func"}. - macOS and other BSD variants use
select.kqueue{.interpreted-text role="func"} +KQ_FILTER_PROC+KQ_NOTE_EXIT. - Windows keeps using
WaitForSingleObject(unchanged).
If none of these mechanisms are available, the function falls back to the traditional busy loop (non-blocking call and short sleeps). (Contributed by Giampaolo Rodola in
83069{.interpreted-text role="gh"}).- Linux >= 5.3 uses
symtable
- Add
symtable.Function.get_cells{.interpreted-text role="meth"} andsymtable.Symbol.is_cell{.interpreted-text role="meth"} methods. (Contributed by Yashp002 in143504{.interpreted-text role="gh"}.)
symtable
- Add
symtable.Function.get_cells{.interpreted-text role="meth"} andsymtable.Symbol.is_cell{.interpreted-text role="meth"} methods. (Contributed by Yashp002 in143504{.interpreted-text role="gh"}.)
sys
- Add
sys.abi_info{.interpreted-text role="data"} namespace to improve access to ABI information. (Contributed by Klaus Zimmermann in137476{.interpreted-text role="gh"}.)
tarfile
~tarfile.data_filter{.interpreted-text role="func"} now normalizes symbolic link targets in order to avoid path traversal attacks. (Contributed by Petr Viktorin in127987{.interpreted-text role="gh"} and2025-4138{.interpreted-text role="cve"}.)~tarfile.TarFile.extractall{.interpreted-text role="func"} now skips fixing up directory attributes when a directory was removed or replaced by another kind of file. (Contributed by Petr Viktorin in127987{.interpreted-text role="gh"} and2024-12718{.interpreted-text role="cve"}.)~tarfile.TarFile.extract{.interpreted-text role="func"} and~tarfile.TarFile.extractall{.interpreted-text role="func"} now (re-)apply the extraction filter when substituting a link (hard or symbolic) with a copy of another archive member, and when fixing up directory attributes. The former raises a new exception,~tarfile.LinkFallbackError{.interpreted-text role="exc"}. (Contributed by Petr Viktorin for2025-4330{.interpreted-text role="cve"} and2024-12718{.interpreted-text role="cve"}.)~tarfile.TarFile.extract{.interpreted-text role="func"} and~tarfile.TarFile.extractall{.interpreted-text role="func"} no longer extract rejected members when~tarfile.TarFile.errorlevel{.interpreted-text role="func"} is zero. (Contributed by Matt Prodani and Petr Viktorin in112887{.interpreted-text role="gh"} and2025-4435{.interpreted-text role="cve"}.)~tarfile.TarFile.extract{.interpreted-text role="func"} and~tarfile.TarFile.extractall{.interpreted-text role="func"} now replace slashes by backslashes in symlink targets on Windows to prevent creation of corrupted links. (Contributed by Christoph Walcher in57911{.interpreted-text role="gh"}.)
timeit
- The command-line interface now colorizes error tracebacks by default. This can be controlled with
environment variables <using-on-controlling-color>{.interpreted-text role="ref"}. (Contributed by Yi Hong in139374{.interpreted-text role="gh"}.)
tkinter
- The
!tkinter.Text.search{.interpreted-text role="meth"} method now supports two additional arguments: nolinestop which allows the search to continue across line boundaries; and strictlimits which restricts the search to within the specified range. (Contributed by Rihaan Meher in130848{.interpreted-text role="gh"}.) - A new method
!tkinter.Text.search_all{.interpreted-text role="meth"} has been introduced. This method allows for searching for all matches of a pattern using Tcl's-alland-overlapoptions. (Contributed by Rihaan Meher in130848{.interpreted-text role="gh"}.) - Added new methods
!pack_content{.interpreted-text role="meth"},!place_content{.interpreted-text role="meth"} and!grid_content{.interpreted-text role="meth"} which use Tk commands with new names (introduced in Tk 8.6) instead of!*_slaves{.interpreted-text role="meth"} methods which use Tk commands with outdated names. (Contributed by Serhiy Storchaka in143754{.interpreted-text role="gh"}.)
tomllib {#whatsnew315-tomllib-1-1-0}
The
tomllib{.interpreted-text role="mod"} module now supports TOML 1.1.0. This is a backwards compatible update, meaning that all valid TOML 1.0.0 documents are parsed the same way.The changes, according to the official TOML changelog, are:
Allow newlines and trailing commas in inline tables.
Previously an inline table had to be on a single line and couldn't end with a trailing comma. This is now relaxed so that the following is valid:
tbl = { key = "a string", moar-tbl = { key = 1, }, }Add
\xHHnotation to basic strings for codepoints under 255, and the\eescape for the escape character:null = "null byte: \x00; letter a: \x61" csi = "\e["Seconds in datetime and time values are now optional. The following are now valid:
dt = 2010-02-03 14:15 t = 14:15
(Contributed by Taneli Hukkinen in
142956{.interpreted-text role="gh"}.)
types
- Expose the write-through
locals{.interpreted-text role="func"} proxy type astypes.FrameLocalsProxyType{.interpreted-text role="data"}. This represents the type of theframe.f_locals{.interpreted-text role="attr"} attribute, as described in667{.interpreted-text role="pep"}.
unicodedata
- The Unicode database has been updated to Unicode 17.0.0.
- Add
unicodedata.isxidstart{.interpreted-text role="func"} andunicodedata.isxidcontinue{.interpreted-text role="func"} functions to check whether a character can start or continue a Unicode Standard Annex #31 identifier. (Contributed by Stan Ulbrych in129117{.interpreted-text role="gh"}.) - Add the
~unicodedata.iter_graphemes{.interpreted-text role="func"} function to iterate over grapheme clusters according to rules defined in Unicode Standard Annex #29, "Unicode Text Segmentation". Add~unicodedata.grapheme_cluster_break{.interpreted-text role="func"},~unicodedata.indic_conjunct_break{.interpreted-text role="func"} and~unicodedata.extended_pictographic{.interpreted-text role="func"} functions to get the properties of the character which are related to the above algorithm. (Contributed by Serhiy Storchaka and Guillaume Sanchez in74902{.interpreted-text role="gh"}.) - Add
~unicodedata.block{.interpreted-text role="func"} function to return the Unicode block assigned to a character. (Contributed by Stan Ulbrych in66802{.interpreted-text role="gh"}.)
unittest
unittest.TestCase.assertLogs{.interpreted-text role="func"} will now accept a formatter to control how messages are formatted. (Contributed by Garry Cairns in134567{.interpreted-text role="gh"}.)
urllib.parse
- Add the missing_as_none parameter to
~urllib.parse.urlsplit{.interpreted-text role="func"},~urllib.parse.urlparse{.interpreted-text role="func"} and~urllib.parse.urldefrag{.interpreted-text role="func"} functions. Add the keep_empty parameter to~urllib.parse.urlunsplit{.interpreted-text role="func"} and~urllib.parse.urlunparse{.interpreted-text role="func"} functions. This allows to distinguish between empty and not defined URI components and preserve empty components. (Contributed by Serhiy Storchaka in67041{.interpreted-text role="gh"}.)
venv
- On POSIX platforms, platlib directories will be created if needed when creating virtual environments, instead of using
lib64 -> libsymlink. This means purelib and platlib of virtual environments no longer share the samelibdirectory on platforms wheresys.platlibdir{.interpreted-text role="data"} is not equal tolib. (Contributed by Rui Xi in133951{.interpreted-text role="gh"}.)
warnings
- Improve filtering by module in
warnings.warn_explicit{.interpreted-text role="func"} if no module argument is passed. It now tests the module regular expression in the warnings filter not only against the filename with.pystripped, but also against module names constructed starting from different parent directories of the filename (with/__init__.py,.pyand, on Windows,.pywstripped). (Contributed by Serhiy Storchaka in135801{.interpreted-text role="gh"}.)
xml.parsers.expat
- Add
~xml.parsers.expat.xmlparser.SetAllocTrackerActivationThreshold{.interpreted-text role="meth"} and~xml.parsers.expat.xmlparser.SetAllocTrackerMaximumAmplification{.interpreted-text role="meth"} toxmlparser <xmlparser-objects>{.interpreted-text role="ref"} objects to tune protections against disproportional amounts of dynamic memory usage from within an Expat parser. (Contributed by Bénédikt Tran in90949{.interpreted-text role="gh"}.) - Add
~xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionActivationThreshold{.interpreted-text role="meth"} and~xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionMaximumAmplification{.interpreted-text role="meth"} toxmlparser <xmlparser-objects>{.interpreted-text role="ref"} objects to tune protections against billion laughs attacks. (Contributed by Bénédikt Tran in90949{.interpreted-text role="gh"}.)
zlib
- Allow combining two Adler-32 checksums via
~zlib.adler32_combine{.interpreted-text role="func"}. (Contributed by Callum Attryde and Bénédikt Tran in134635{.interpreted-text role="gh"}.) - Allow combining two CRC-32 checksums via
~zlib.crc32_combine{.interpreted-text role="func"}. (Contributed by Bénédikt Tran in134635{.interpreted-text role="gh"}.)
Optimizations
- Builds using Visual Studio 2026 (MSVC 18) may now use the new
tail-calling interpreter <whatsnew314-tail-call-interpreter>{.interpreted-text role="ref"}. Results on Visual Studio 18.1.1 report between 15-20% speedup on the geometric mean of pyperformance on Windows x86-64 over the switch-case interpreter on an AMD Ryzen 7 5800X. We have observed speedups ranging from 14% for large pure-Python libraries to 40% for long-running small pure-Python scripts on Windows. This was made possible by a new feature introduced in MSVC 18. (Contributed by Chris Eibl, Ken Jin, and Brandt Bucher in143068{.interpreted-text role="gh"}. Special thanks to the MSVC team including Hulon Jenkins.) mimallocis now used as the default allocator for for raw memory allocations such as viaPyMem_RawMalloc{.interpreted-text role="c:func"} for better performance onfree-threaded builds <free-threaded build>{.interpreted-text role="term"}. (Contributed by Kumar Aditya in144914{.interpreted-text role="gh"}.)
base64 & binascii
- CPython's underlying base64 implementation now encodes 2x faster and decodes 3x faster thanks to simple CPU pipelining optimizations. (Contributed by Gregory P. Smith and Serhiy Storchaka in
143262{.interpreted-text role="gh"}.) - Implementation for Ascii85, Base85, and Z85 encoding has been rewritten in C. Encoding and decoding is now two orders of magnitude faster and consumes two orders of magnitude less memory. (Contributed by James Seo and Serhiy Storchaka in
101178{.interpreted-text role="gh"}.)
csv
csv.Sniffer.sniff{.interpreted-text role="meth"} delimiter detection is now up to 1.6x faster. (Contributed by Maurycy Pawłowski-Wieroński in137628{.interpreted-text role="gh"}.)
Upgraded JIT compiler {#whatsnew315-jit}
Results from the pyperformance benchmark suite report 4-5% geometric mean performance improvement for the JIT over the standard CPython interpreter built with all optimizations enabled on x86-64 Linux. On AArch64 macOS, the JIT has a 7-8% speedup over the tail calling interpreter <whatsnew314-tail-call-interpreter>{.interpreted-text role="ref"} with all optimizations enabled. The speedups for JIT builds versus no JIT builds range from roughly 15% slowdown to over 100% speedup (ignoring the unpack_sequence microbenchmark) on x86-64 Linux and AArch64 macOS systems.
:::: attention ::: title Attention :::
These results are not yet final. ::::
The major upgrades to the JIT are:
- LLVM 21 build-time dependency
- New tracing frontend
- Basic register allocation in the JIT
- More JIT optimizations
- Better machine code generation
LLVM 21 build-time dependency
The JIT compiler now uses LLVM 21 for build-time stencil generation. As always, LLVM is only needed when building CPython with the JIT enabled; end users running Python do not need LLVM installed. Instructions for installing LLVM can be found in the JIT compiler documentation for all supported platforms.
(Contributed by Savannah Ostrowski in 140973{.interpreted-text role="gh"}.)
A new tracing frontend
The JIT compiler now supports significantly more bytecode operations and control flow than in Python 3.14, enabling speedups on a wider variety of code. For example, simple Python object creation is now understood by the 3.15 JIT compiler. Overloaded operations and generators are also partially supported. This was made possible by an overhauled JIT tracing frontend that records actual execution paths through code, rather than estimating them as the previous implementation did.
(Contributed by Ken Jin in 139109{.interpreted-text role="gh"}. Support for Windows added by Mark Shannon in 141703{.interpreted-text role="gh"}.)
Basic register allocation in the JIT
A basic form of register allocation has been added to the JIT compiler's optimizer. This allows the JIT compiler to avoid certain stack operations altogether and instead operate on registers. This allows the JIT to produce more efficient traces by avoiding reads and writes to memory.
(Contributed by Mark Shannon in 135379{.interpreted-text role="gh"}.)
More JIT optimizations
More constant-propagation is now performed. This means when the JIT compiler detects that certain user code results in constants, the code can be simplified by the JIT.
(Contributed by Ken Jin and Savannah Ostrowski in 132732{.interpreted-text role="gh"}.)
The JIT avoids reference count{.interpreted-text role="term"}s where possible. This generally reduces the cost of most operations in Python.
(Contributed by Ken Jin, Donghee Na, Zheao Li, Hai Zhu, Savannah Ostrowski, Reiden Ong, Noam Cohen, Tomas Roun, PuQing, and Cajetan Rodrigues in 134584{.interpreted-text role="gh"}.)
Better machine code generation
The JIT compiler's machine code generator now produces better machine code for x86-64 and AArch64 macOS and Linux targets. In general, users should experience lower memory usage for generated machine code and more efficient machine code versus the old JIT.
(Contributed by Brandt Bucher in 136528{.interpreted-text role="gh"} and 136528{.interpreted-text role="gh"}. Implementation for AArch64 contributed by Mark Shannon in 139855{.interpreted-text role="gh"}. Additional optimizations for AArch64 contributed by Mark Shannon and Diego Russo in 140683{.interpreted-text role="gh"} and 142305{.interpreted-text role="gh"}.)
Removed
ctypes
- Removed the undocumented function
!ctypes.SetPointerType{.interpreted-text role="func"}, which has been deprecated since Python 3.13. (Contributed by Bénédikt Tran in133866{.interpreted-text role="gh"}.)
glob
- Removed the undocumented
!glob.glob0{.interpreted-text role="func"} and!glob.glob1{.interpreted-text role="func"} functions, which have been deprecated since Python 3.13. Useglob.glob{.interpreted-text role="func"} and pass a directory to its root_dir argument instead. (Contributed by Barney Gale in137466{.interpreted-text role="gh"}.)
http.server
- Removed the
!CGIHTTPRequestHandler{.interpreted-text role="class"} class and the--cgiflag from thepython -m http.server{.interpreted-text role="program"} command-line interface. They were deprecated in Python 3.13. (Contributed by Bénédikt Tran in133810{.interpreted-text role="gh"}.)
importlib.resources
- Removed deprecated
packageparameter fromimportlib.resources.files{.interpreted-text role="func"} function. (Contributed by Semyon Moroz in138044{.interpreted-text role="gh"}.)
pathlib
- Removed deprecated
!pathlib.PurePath.is_reserved{.interpreted-text role="meth"}. Useos.path.isreserved{.interpreted-text role="func"} to detect reserved paths on Windows. (Contributed by Nikita Sobolev in133875{.interpreted-text role="gh"}.)
platform
- Removed the
!platform.java_ver{.interpreted-text role="func"} function, which was deprecated since Python 3.13. (Contributed by Alexey Makridenko in133604{.interpreted-text role="gh"}.)
sre*
- Removed
!sre_compile{.interpreted-text role="mod"},!sre_constants{.interpreted-text role="mod"} and!sre_parse{.interpreted-text role="mod"} modules. (Contributed by Stan Ulbrych in135994{.interpreted-text role="gh"}.)
sysconfig
- Removed the check_home parameter of
sysconfig.is_python_build{.interpreted-text role="func"}. (Contributed by Filipe Laíns in92897{.interpreted-text role="gh"}.)
threading
- Remove support for arbitrary positional or keyword arguments in the C implementation of
~threading.RLock{.interpreted-text role="class"} objects. This was deprecated in Python 3.14. (Contributed by Bénédikt Tran in134087{.interpreted-text role="gh"}.)
typing
The undocumented keyword argument syntax for creating
~typing.NamedTuple{.interpreted-text role="class"} classes (for example,Point = NamedTuple("Point", x=int, y=int)) is no longer supported. Use the class-based syntax or the functional syntax instead. (Contributed by Bénédikt Tran in133817{.interpreted-text role="gh"}.)Using
TD = TypedDict("TD")orTD = TypedDict("TD", None)to construct a~typing.TypedDict{.interpreted-text role="class"} type with zero fields is no longer supported. Useclass TD(TypedDict): passorTD = TypedDict("TD", {})instead. (Contributed by Bénédikt Tran in133823{.interpreted-text role="gh"}.)Code like
class ExtraTypeVars(P1[S], Protocol[T, T2]): ...now raises aTypeError{.interpreted-text role="exc"}, becauseSis not listed inProtocolparameters. (Contributed by Nikita Sobolev in137191{.interpreted-text role="gh"}.)Code like
class B2(A[T2], Protocol[T1, T2]): ...now correctly handles type parameters order: it is(T1, T2), not(T2, T1)as it was incorrectly inferred in runtime before. (Contributed by Nikita Sobolev in137191{.interpreted-text role="gh"}.)typing.ByteString{.interpreted-text role="class"} has been removed fromtyping.__all__.!typing.ByteString{.interpreted-text role="class"} has been deprecated since Python 3.9, and is scheduled for removal in Python 3.17.The following statements now cause
DeprecationWarnings to be emitted at runtime:from typing import ByteStringimport typing; typing.ByteString.
DeprecationWarnings were already emitted iftyping.ByteString{.interpreted-text role="class"} was subclassed or used as the second argument toisinstance{.interpreted-text role="func"} orissubclass{.interpreted-text role="func"}, but warnings were not previously emitted if it was merely imported or accessed from the!typing{.interpreted-text role="mod"} module.Deprecated
!typing.no_type_check_decorator{.interpreted-text role="func"} has been removed. (Contributed by Nikita Sobolev in133601{.interpreted-text role="gh"}.)
wave
- Removed the
getmark(),setmark()andgetmarkers()methods of the~wave.Wave_read{.interpreted-text role="class"} and~wave.Wave_write{.interpreted-text role="class"} classes, which were deprecated since Python 3.13. (Contributed by Bénédikt Tran in133873{.interpreted-text role="gh"}.)
zipimport
- Remove deprecated
!zipimport.zipimporter.load_module{.interpreted-text role="meth"}. Usezipimport.zipimporter.exec_module{.interpreted-text role="meth"} instead. (Contributed by Jiahao Li in133656{.interpreted-text role="gh"}.)
Deprecated
New deprecations
base64{.interpreted-text role="mod"}:- Accepting the
+and/characters with an alternative alphabet in~base64.b64decode{.interpreted-text role="func"} and~base64.urlsafe_b64decode{.interpreted-text role="func"} is now deprecated. In future Python versions they will be errors in the strict mode and discarded in the non-strict mode. (Contributed by Serhiy Storchaka in125346{.interpreted-text role="gh"}.)
- Accepting the
- CLI:
Deprecate
-b{.interpreted-text role="option"} and!-bb{.interpreted-text role="option"} command-line options and schedule them to become no-ops in Python 3.17. These were primarily helpers for the Python 2 -> 3 transition. Starting with Python 3.17, noBytesWarning{.interpreted-text role="exc"} will be raised for these cases; use a type checker instead.(Contributed by Nikita Sobolev in
136355{.interpreted-text role="gh"}.)
hashlib{.interpreted-text role="mod"}:In hash function constructors such as
~hashlib.new{.interpreted-text role="func"} or the direct hash-named constructors such as~hashlib.md5{.interpreted-text role="func"} and~hashlib.sha256{.interpreted-text role="func"}, the optional initial data parameter could also be passed as a keyword argument nameddata=orstring=in varioushashlib{.interpreted-text role="mod"} implementations.Support for the
stringkeyword argument name is now deprecated and is slated for removal in Python 3.19. Prefer passing the initial data as a positional argument for maximum backwards compatibility.(Contributed by Bénédikt Tran in
134978{.interpreted-text role="gh"}.)
__version__The
__version__,versionandVERSIONattributes have been deprecated in these standard library modules and will be removed in Python 3.20. Usesys.version_info{.interpreted-text role="py:data"} instead.argparse{.interpreted-text role="mod"}csv{.interpreted-text role="mod"}ctypes{.interpreted-text role="mod"}!ctypes.macholib{.interpreted-text role="mod"}decimal{.interpreted-text role="mod"} (usedecimal.SPEC_VERSION{.interpreted-text role="data"} instead)http.server{.interpreted-text role="mod"}imaplib{.interpreted-text role="mod"}ipaddress{.interpreted-text role="mod"}json{.interpreted-text role="mod"}logging{.interpreted-text role="mod"} (__date__also deprecated)optparse{.interpreted-text role="mod"}pickle{.interpreted-text role="mod"}platform{.interpreted-text role="mod"}re{.interpreted-text role="mod"}socketserver{.interpreted-text role="mod"}tabnanny{.interpreted-text role="mod"}tkinter.font{.interpreted-text role="mod"}tkinter.ttk{.interpreted-text role="mod"}wsgiref.simple_server{.interpreted-text role="mod"}xml.etree.ElementTree{.interpreted-text role="mod"}!xml.sax.expatreader{.interpreted-text role="mod"}xml.sax.handler{.interpreted-text role="mod"}zlib{.interpreted-text role="mod"}
(Contributed by Hugo van Kemenade and Stan Ulbrych in
76007{.interpreted-text role="gh"}.)
Pending removal in Python 3.16
- The import system:
- Setting
~module.__loader__{.interpreted-text role="attr"} on a module while failing to set__spec__.loader <importlib.machinery.ModuleSpec.loader>{.interpreted-text role="attr"} is deprecated. In Python 3.16,!__loader__{.interpreted-text role="attr"} will cease to be set or taken into consideration by the import system or the standard library.
- Setting
array{.interpreted-text role="mod"}:- The
'u'format code (wchar_t{.interpreted-text role="c:type"}) has been deprecated in documentation since Python 3.3 and at runtime since Python 3.13. Use the'w'format code (Py_UCS4{.interpreted-text role="c:type"}) for Unicode characters instead.
- The
asyncio{.interpreted-text role="mod"}:!asyncio.iscoroutinefunction{.interpreted-text role="func"} is deprecated and will be removed in Python 3.16; useinspect.iscoroutinefunction{.interpreted-text role="func"} instead. (Contributed by Jiahao Li and Kumar Aditya in122875{.interpreted-text role="gh"}.)asyncio{.interpreted-text role="mod"} policy system is deprecated and will be removed in Python 3.16. In particular, the following classes and functions are deprecated:asyncio.AbstractEventLoopPolicy{.interpreted-text role="class"}asyncio.DefaultEventLoopPolicy{.interpreted-text role="class"}asyncio.WindowsSelectorEventLoopPolicy{.interpreted-text role="class"}asyncio.WindowsProactorEventLoopPolicy{.interpreted-text role="class"}asyncio.get_event_loop_policy{.interpreted-text role="func"}asyncio.set_event_loop_policy{.interpreted-text role="func"}
Users should use
asyncio.run{.interpreted-text role="func"} orasyncio.Runner{.interpreted-text role="class"} with loop_factory to use the desired event loop implementation.For example, to use
asyncio.SelectorEventLoop{.interpreted-text role="class"} on Windows:import asyncio async def main(): ... asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop)(Contributed by Kumar Aditya in
127949{.interpreted-text role="gh"}.)
builtins{.interpreted-text role="mod"}:- Bitwise inversion on boolean types,
~Trueor~Falsehas been deprecated since Python 3.12, as it produces surprising and unintuitive results (-2and-1). Usenot xinstead for the logical negation of a Boolean. In the rare case that you need the bitwise inversion of the underlying integer, convert tointexplicitly (~int(x)).
- Bitwise inversion on boolean types,
functools{.interpreted-text role="mod"}:- Calling the Python implementation of
functools.reduce{.interpreted-text role="func"} with function or sequence as keyword arguments has been deprecated since Python 3.14.
- Calling the Python implementation of
logging{.interpreted-text role="mod"}:- Support for custom logging handlers with the strm argument is deprecated and scheduled for removal in Python 3.16. Define handlers with the stream argument instead. (Contributed by Mariusz Felisiak in
115032{.interpreted-text role="gh"}.)
- Support for custom logging handlers with the strm argument is deprecated and scheduled for removal in Python 3.16. Define handlers with the stream argument instead. (Contributed by Mariusz Felisiak in
mimetypes{.interpreted-text role="mod"}:- Valid extensions start with a '.' or are empty for
mimetypes.MimeTypes.add_type{.interpreted-text role="meth"}. Undotted extensions are deprecated and will raise aValueError{.interpreted-text role="exc"} in Python 3.16. (Contributed by Hugo van Kemenade in75223{.interpreted-text role="gh"}.)
- Valid extensions start with a '.' or are empty for
shutil{.interpreted-text role="mod"}:- The
!ExecError{.interpreted-text role="class"} exception has been deprecated since Python 3.14. It has not been used by any function in!shutil{.interpreted-text role="mod"} since Python 3.4, and is now an alias ofRuntimeError{.interpreted-text role="exc"}.
- The
symtable{.interpreted-text role="mod"}:- The
Class.get_methods <symtable.Class.get_methods>{.interpreted-text role="meth"} method has been deprecated since Python 3.14.
- The
sys{.interpreted-text role="mod"}:- The
~sys._enablelegacywindowsfsencoding{.interpreted-text role="func"} function has been deprecated since Python 3.13. Use thePYTHONLEGACYWINDOWSFSENCODING{.interpreted-text role="envvar"} environment variable instead.
- The
sysconfig{.interpreted-text role="mod"}:- The
!sysconfig.expand_makefile_vars{.interpreted-text role="func"} function has been deprecated since Python 3.14. Use thevarsargument ofsysconfig.get_paths{.interpreted-text role="func"} instead.
- The
tarfile{.interpreted-text role="mod"}:- The undocumented and unused
!TarFile.tarfile{.interpreted-text role="attr"} attribute has been deprecated since Python 3.13.
- The undocumented and unused
Pending removal in Python 3.17
collections.abc{.interpreted-text role="mod"}:collections.abc.ByteString{.interpreted-text role="class"} is scheduled for removal in Python 3.17.Use
isinstance(obj, collections.abc.Buffer)to test ifobjimplements thebuffer protocol <bufferobjects>{.interpreted-text role="ref"} at runtime. For use in type annotations, either use~collections.abc.Buffer{.interpreted-text role="class"} or a union that explicitly specifies the types your code supports (e.g.,bytes | bytearray | memoryview).!ByteString{.interpreted-text role="class"} was originally intended to be an abstract class that would serve as a supertype of bothbytes{.interpreted-text role="class"} andbytearray{.interpreted-text role="class"}. However, since the ABC never had any methods, knowing that an object was an instance of!ByteString{.interpreted-text role="class"} never actually told you anything useful about the object. Other common buffer types such asmemoryview{.interpreted-text role="class"} were also never understood as subtypes of!ByteString{.interpreted-text role="class"} (either at runtime or by static type checkers).See
PEP 688 <688#current-options>{.interpreted-text role="pep"} for more details. (Contributed by Shantanu Jain in91896{.interpreted-text role="gh"}.)
encodings{.interpreted-text role="mod"}:- Passing non-ascii encoding names to
encodings.normalize_encoding{.interpreted-text role="func"} is deprecated and scheduled for removal in Python 3.17. (Contributed by Stan Ulbrych in136702{.interpreted-text role="gh"})
- Passing non-ascii encoding names to
typing{.interpreted-text role="mod"}:Before Python 3.14, old-style unions were implemented using the private class
typing._UnionGenericAlias. This class is no longer needed for the implementation, but it has been retained for backward compatibility, with removal scheduled for Python 3.17. Users should use documented introspection helpers liketyping.get_origin{.interpreted-text role="func"} andtyping.get_args{.interpreted-text role="func"} instead of relying on private implementation details.typing.ByteString{.interpreted-text role="class"}, deprecated since Python 3.9, is scheduled for removal in Python 3.17.Use
isinstance(obj, collections.abc.Buffer)to test ifobjimplements thebuffer protocol <bufferobjects>{.interpreted-text role="ref"} at runtime. For use in type annotations, either use~collections.abc.Buffer{.interpreted-text role="class"} or a union that explicitly specifies the types your code supports (e.g.,bytes | bytearray | memoryview).!ByteString{.interpreted-text role="class"} was originally intended to be an abstract class that would serve as a supertype of bothbytes{.interpreted-text role="class"} andbytearray{.interpreted-text role="class"}. However, since the ABC never had any methods, knowing that an object was an instance of!ByteString{.interpreted-text role="class"} never actually told you anything useful about the object. Other common buffer types such asmemoryview{.interpreted-text role="class"} were also never understood as subtypes of!ByteString{.interpreted-text role="class"} (either at runtime or by static type checkers).See
PEP 688 <688#current-options>{.interpreted-text role="pep"} for more details. (Contributed by Shantanu Jain in91896{.interpreted-text role="gh"}.)
Pending removal in Python 3.18
decimal{.interpreted-text role="mod"}:- The non-standard and undocumented
~decimal.Decimal{.interpreted-text role="class"} format specifier'N', which is only supported in the!decimal{.interpreted-text role="mod"} module's C implementation, has been deprecated since Python 3.13. (Contributed by Serhiy Storchaka in89902{.interpreted-text role="gh"}.)
- The non-standard and undocumented
Pending removal in Python 3.19
ctypes{.interpreted-text role="mod"}:- Implicitly switching to the MSVC-compatible struct layout by setting
~ctypes.Structure._pack_{.interpreted-text role="attr"} but not~ctypes.Structure._layout_{.interpreted-text role="attr"} on non-Windows platforms.
- Implicitly switching to the MSVC-compatible struct layout by setting
hashlib{.interpreted-text role="mod"}:In hash function constructors such as
~hashlib.new{.interpreted-text role="func"} or the direct hash-named constructors such as~hashlib.md5{.interpreted-text role="func"} and~hashlib.sha256{.interpreted-text role="func"}, their optional initial data parameter could also be passed a keyword argument nameddata=orstring=in various!hashlib{.interpreted-text role="mod"} implementations.Support for the
stringkeyword argument name is now deprecated and slated for removal in Python 3.19.Before Python 3.13, the
stringkeyword parameter was not correctly supported depending on the backend implementation of hash functions. Prefer passing the initial data as a positional argument for maximum backwards compatibility.
Pending removal in Python 3.20
The
__version__,versionandVERSIONattributes have been deprecated in these standard library modules and will be removed in Python 3.20. Usesys.version_info{.interpreted-text role="py:data"} instead.argparse{.interpreted-text role="mod"}csv{.interpreted-text role="mod"}ctypes{.interpreted-text role="mod"}!ctypes.macholib{.interpreted-text role="mod"}decimal{.interpreted-text role="mod"} (usedecimal.SPEC_VERSION{.interpreted-text role="data"} instead)http.server{.interpreted-text role="mod"}imaplib{.interpreted-text role="mod"}ipaddress{.interpreted-text role="mod"}json{.interpreted-text role="mod"}logging{.interpreted-text role="mod"} (__date__also deprecated)optparse{.interpreted-text role="mod"}pickle{.interpreted-text role="mod"}platform{.interpreted-text role="mod"}re{.interpreted-text role="mod"}socketserver{.interpreted-text role="mod"}tabnanny{.interpreted-text role="mod"}tkinter.font{.interpreted-text role="mod"}tkinter.ttk{.interpreted-text role="mod"}wsgiref.simple_server{.interpreted-text role="mod"}xml.etree.ElementTree{.interpreted-text role="mod"}!xml.sax.expatreader{.interpreted-text role="mod"}xml.sax.handler{.interpreted-text role="mod"}zlib{.interpreted-text role="mod"}
(Contributed by Hugo van Kemenade and Stan Ulbrych in
76007{.interpreted-text role="gh"}.)
Pending removal in future versions
The following APIs will be removed in the future, although there is currently no date scheduled for their removal.
argparse{.interpreted-text role="mod"}:- Nesting argument groups and nesting mutually exclusive groups are deprecated.
- Passing the undocumented keyword argument prefix_chars to
~argparse.ArgumentParser.add_argument_group{.interpreted-text role="meth"} is now deprecated. - The
argparse.FileType{.interpreted-text role="class"} type converter is deprecated.
builtins{.interpreted-text role="mod"}:- Generators:
throw(type, exc, tb)andathrow(type, exc, tb)signature is deprecated: usethrow(exc)andathrow(exc)instead, the single argument signature. - Currently Python accepts numeric literals immediately followed by keywords, for example
0in x,1or x,0if 1else 2. It allows confusing and ambiguous expressions like[0x1for x in y](which can be interpreted as[0x1 for x in y]or[0x1f or x in y]). A syntax warning is raised if the numeric literal is immediately followed by one of keywordsand{.interpreted-text role="keyword"},else{.interpreted-text role="keyword"},for{.interpreted-text role="keyword"},if{.interpreted-text role="keyword"},in{.interpreted-text role="keyword"},is{.interpreted-text role="keyword"} andor{.interpreted-text role="keyword"}. In a future release it will be changed to a syntax error. (87999{.interpreted-text role="gh"}) - Support for
__index__()and__int__()method returning non-int type: these methods will be required to return an instance of a strict subclass ofint{.interpreted-text role="class"}. - Support for
__float__()method returning a strict subclass offloat{.interpreted-text role="class"}: these methods will be required to return an instance offloat{.interpreted-text role="class"}. - Support for
__complex__()method returning a strict subclass ofcomplex{.interpreted-text role="class"}: these methods will be required to return an instance ofcomplex{.interpreted-text role="class"}. - Passing a complex number as the real or imag argument in the
complex{.interpreted-text role="func"} constructor is now deprecated; it should only be passed as a single positional argument. (Contributed by Serhiy Storchaka in109218{.interpreted-text role="gh"}.)
- Generators:
calendar{.interpreted-text role="mod"}:calendar.Januaryandcalendar.Februaryconstants are deprecated and replaced bycalendar.JANUARY{.interpreted-text role="data"} andcalendar.FEBRUARY{.interpreted-text role="data"}. (Contributed by Prince Roshan in103636{.interpreted-text role="gh"}.)codecs{.interpreted-text role="mod"}: useopen{.interpreted-text role="func"} instead ofcodecs.open{.interpreted-text role="func"}. (133038{.interpreted-text role="gh"})codeobject.co_lnotab{.interpreted-text role="attr"}: use thecodeobject.co_lines{.interpreted-text role="meth"} method instead.datetime{.interpreted-text role="mod"}:~datetime.datetime.utcnow{.interpreted-text role="meth"}: usedatetime.datetime.now(tz=datetime.UTC).~datetime.datetime.utcfromtimestamp{.interpreted-text role="meth"}: usedatetime.datetime.fromtimestamp(timestamp, tz=datetime.UTC).
gettext{.interpreted-text role="mod"}: Plural value must be an integer.importlib{.interpreted-text role="mod"}:~importlib.util.cache_from_source{.interpreted-text role="func"} debug_override parameter is deprecated: use the optimization parameter instead.
importlib.metadata{.interpreted-text role="mod"}:EntryPointstuple interface.- Implicit
Noneon return values.
logging{.interpreted-text role="mod"}: thewarn()method has been deprecated since Python 3.3, use~logging.warning{.interpreted-text role="meth"} instead.mailbox{.interpreted-text role="mod"}: Use of StringIO input and text mode is deprecated, use BytesIO and binary mode instead.os{.interpreted-text role="mod"}: Callingos.register_at_fork{.interpreted-text role="func"} in a multi-threaded process.os.path{.interpreted-text role="mod"}:os.path.commonprefix{.interpreted-text role="func"} is deprecated, useos.path.commonpath{.interpreted-text role="func"} for path prefixes. Theos.path.commonprefix{.interpreted-text role="func"} function is being deprecated due to having a misleading name and module. The function is not safe to use for path prefixes despite being included in a module about path manipulation, meaning it is easy to accidentally introduce path traversal vulnerabilities into Python programs by using this function.!pydoc.ErrorDuringImport{.interpreted-text role="class"}: A tuple value for exc_info parameter is deprecated, use an exception instance.re{.interpreted-text role="mod"}: More strict rules are now applied for numerical group references and group names in regular expressions. Only sequence of ASCII digits is now accepted as a numerical reference. The group name in bytes patterns and replacement strings can now only contain ASCII letters and digits and underscore. (Contributed by Serhiy Storchaka in91760{.interpreted-text role="gh"}.)shutil{.interpreted-text role="mod"}:~shutil.rmtree{.interpreted-text role="func"}'s onerror parameter is deprecated in Python 3.12; use the onexc parameter instead.ssl{.interpreted-text role="mod"} options and protocols:ssl.SSLContext{.interpreted-text role="class"} without protocol argument is deprecated.ssl.SSLContext{.interpreted-text role="class"}:~ssl.SSLContext.set_npn_protocols{.interpreted-text role="meth"} and!selected_npn_protocol{.interpreted-text role="meth"} are deprecated: use ALPN instead.ssl.OP_NO_SSL*optionsssl.OP_NO_TLS*optionsssl.PROTOCOL_SSLv3ssl.PROTOCOL_TLSssl.PROTOCOL_TLSv1ssl.PROTOCOL_TLSv1_1ssl.PROTOCOL_TLSv1_2ssl.TLSVersion.SSLv3ssl.TLSVersion.TLSv1ssl.TLSVersion.TLSv1_1
threading{.interpreted-text role="mod"} methods:!threading.Condition.notifyAll{.interpreted-text role="meth"}: use~threading.Condition.notify_all{.interpreted-text role="meth"}.!threading.Event.isSet{.interpreted-text role="meth"}: use~threading.Event.is_set{.interpreted-text role="meth"}.!threading.Thread.isDaemon{.interpreted-text role="meth"},threading.Thread.setDaemon{.interpreted-text role="meth"}: usethreading.Thread.daemon{.interpreted-text role="attr"} attribute.!threading.Thread.getName{.interpreted-text role="meth"},threading.Thread.setName{.interpreted-text role="meth"}: usethreading.Thread.name{.interpreted-text role="attr"} attribute.!threading.currentThread{.interpreted-text role="meth"}: usethreading.current_thread{.interpreted-text role="meth"}.!threading.activeCount{.interpreted-text role="meth"}: usethreading.active_count{.interpreted-text role="meth"}.
typing.Text{.interpreted-text role="class"} (92332{.interpreted-text role="gh"}).- The internal class
typing._UnionGenericAliasis no longer used to implementtyping.Union{.interpreted-text role="class"}. To preserve compatibility with users using this private class, a compatibility shim will be provided until at least Python 3.17. (Contributed by Jelle Zijlstra in105499{.interpreted-text role="gh"}.) unittest.IsolatedAsyncioTestCase{.interpreted-text role="class"}: it is deprecated to return a value that is notNonefrom a test case.urllib.parse{.interpreted-text role="mod"} deprecated functions:~urllib.parse.urlparse{.interpreted-text role="func"} insteadsplitattr()splithost()splitnport()splitpasswd()splitport()splitquery()splittag()splittype()splituser()splitvalue()to_bytes()
wsgiref{.interpreted-text role="mod"}:SimpleHandler.stdout.write()should not do partial writes.xml.etree.ElementTree{.interpreted-text role="mod"}: Testing the truth value of an~xml.etree.ElementTree.Element{.interpreted-text role="class"} is deprecated. In a future release it will always returnTrue. Prefer explicitlen(elem)orelem is not Nonetests instead.sys._clear_type_cache{.interpreted-text role="func"} is deprecated: usesys._clear_internal_caches{.interpreted-text role="func"} instead.
C API changes
New features
Add the following functions for the new
frozendict{.interpreted-text role="class"} type:PyAnyDict_Check{.interpreted-text role="c:func"}PyAnyDict_CheckExact{.interpreted-text role="c:func"}PyFrozenDict_Check{.interpreted-text role="c:func"}PyFrozenDict_CheckExact{.interpreted-text role="c:func"}PyFrozenDict_New{.interpreted-text role="c:func"}
(Contributed by Victor Stinner in
141510{.interpreted-text role="gh"}.)Add
PySys_GetAttr{.interpreted-text role="c:func"},PySys_GetAttrString{.interpreted-text role="c:func"},PySys_GetOptionalAttr{.interpreted-text role="c:func"}, andPySys_GetOptionalAttrString{.interpreted-text role="c:func"} functions as replacements forPySys_GetObject{.interpreted-text role="c:func"}. (Contributed by Serhiy Storchaka in108512{.interpreted-text role="gh"}.)Add
PyUnstable_Unicode_GET_CACHED_HASH{.interpreted-text role="c:type"} to get the cached hash of a string. See the documentation for caveats. (Contributed by Petr Viktorin in131510{.interpreted-text role="gh"}.)Add API for checking an extension module's ABI compatibility:
Py_mod_abi{.interpreted-text role="c:data"},PyABIInfo_Check{.interpreted-text role="c:func"},PyABIInfo_VAR{.interpreted-text role="c:macro"} andPy_mod_abi{.interpreted-text role="c:data"}. (Contributed by Petr Viktorin in137210{.interpreted-text role="gh"}.)
::: {#whatsnew315-pep782}
Implement
782{.interpreted-text role="pep"}, thePyBytesWriter API <pybyteswriter>{.interpreted-text role="ref"}. Add functions:PyBytesWriter_Create{.interpreted-text role="c:func"}PyBytesWriter_Discard{.interpreted-text role="c:func"}PyBytesWriter_FinishWithPointer{.interpreted-text role="c:func"}PyBytesWriter_FinishWithSize{.interpreted-text role="c:func"}PyBytesWriter_Finish{.interpreted-text role="c:func"}PyBytesWriter_Format{.interpreted-text role="c:func"}PyBytesWriter_GetData{.interpreted-text role="c:func"}PyBytesWriter_GetSize{.interpreted-text role="c:func"}PyBytesWriter_GrowAndUpdatePointer{.interpreted-text role="c:func"}PyBytesWriter_Grow{.interpreted-text role="c:func"}PyBytesWriter_Resize{.interpreted-text role="c:func"}PyBytesWriter_WriteBytes{.interpreted-text role="c:func"}
(Contributed by Victor Stinner in
129813{.interpreted-text role="gh"}.)Add a new
PyImport_CreateModuleFromInitfunc{.interpreted-text role="c:func"} C-API for creating a module from a spec and initfunc. (Contributed by Itamar Oren in116146{.interpreted-text role="gh"}.)Add
PyTuple_FromArray{.interpreted-text role="c:func"} to create atuple{.interpreted-text role="class"} from an array. (Contributed by Victor Stinner in111489{.interpreted-text role="gh"}.)Add
PyObject_Dump{.interpreted-text role="c:func"} to dump an object tostderr. It should only be used for debugging. (Contributed by Victor Stinner in141070{.interpreted-text role="gh"}.)Add
PyUnstable_ThreadState_SetStackProtection{.interpreted-text role="c:func"} andPyUnstable_ThreadState_ResetStackProtection{.interpreted-text role="c:func"} functions to set the stack protection base address and stack protection size of a Python thread state. (Contributed by Victor Stinner in139653{.interpreted-text role="gh"}.)Add
PyUnstable_SetImmortal{.interpreted-text role="c:func"} C-API function to mark objects asimmortal{.interpreted-text role="term"}. (Contributed by Kumar Aditya in143300{.interpreted-text role="gh"}.) :::
Changed C APIs
- If the
Py_TPFLAGS_MANAGED_DICT{.interpreted-text role="c:macro"} orPy_TPFLAGS_MANAGED_WEAKREF{.interpreted-text role="c:macro"} flag is set thenPy_TPFLAGS_HAVE_GC{.interpreted-text role="c:macro"} must be set too. (Contributed by Sergey Miryanov in134786{.interpreted-text role="gh"}.) PyDateTime_IMPORT{.interpreted-text role="c:macro"} is now thread safe. Code that directly checksPyDateTimeAPIforNULLshould be updated to callPyDateTime_IMPORT{.interpreted-text role="c:macro"} instead. (Contributed by Kumar Aditya in141563{.interpreted-text role="gh"}.)
Porting to Python 3.15
Private functions promoted to public C APIs:
The |pythoncapi_compat_project_link| can be used to get most of these new functions on Python 3.14 and older.
Removed C APIs
Remove deprecated
PyUnicodefunctions:!PyUnicode_AsDecodedObject{.interpreted-text role="c:func"}: UsePyCodec_Decode{.interpreted-text role="c:func"} instead.!PyUnicode_AsDecodedUnicode{.interpreted-text role="c:func"}: UsePyCodec_Decode{.interpreted-text role="c:func"} instead; Note that some codecs (for example, "base64") may return a type other thanstr{.interpreted-text role="class"}, such asbytes{.interpreted-text role="class"}.!PyUnicode_AsEncodedObject{.interpreted-text role="c:func"}: UsePyCodec_Encode{.interpreted-text role="c:func"} instead.!PyUnicode_AsEncodedUnicode{.interpreted-text role="c:func"}: UsePyCodec_Encode{.interpreted-text role="c:func"} instead; Note that some codecs (for example, "base64") may return a type other thanbytes{.interpreted-text role="class"}, such asstr{.interpreted-text role="class"}.
(Contributed by Stan Ulbrych in
133612{.interpreted-text role="gh"}.)!PyImport_ImportModuleNoBlock{.interpreted-text role="c:func"}: deprecated alias ofPyImport_ImportModule{.interpreted-text role="c:func"}. (Contributed by Bénédikt Tran in133644{.interpreted-text role="gh"}.)!PyWeakref_GetObject{.interpreted-text role="c:func"} and!PyWeakref_GET_OBJECT{.interpreted-text role="c:macro"}: usePyWeakref_GetRef{.interpreted-text role="c:func"} instead. The |pythoncapi_compat_project_link| can be used to get!PyWeakref_GetRef{.interpreted-text role="c:func"} on Python 3.12 and older. (Contributed by Bénédikt Tran in133644{.interpreted-text role="gh"}.)Remove deprecated
!PySys_ResetWarnOptions{.interpreted-text role="c:func"}. Clearsys.warnoptions{.interpreted-text role="data"} and!warnings.filters{.interpreted-text role="data"} instead.(Contributed by Nikita Sobolev in
138886{.interpreted-text role="gh"}.)
The following functions are removed in favor of PyConfig_Get{.interpreted-text role="c:func"}. The |pythoncapi_compat_project_link| can be used to get !PyConfig_Get{.interpreted-text role="c:func"} on Python 3.13 and older.
Python initialization functions:
!Py_GetExecPrefix{.interpreted-text role="c:func"}: usePyConfig_Get("base_exec_prefix") <PyConfig_Get>{.interpreted-text role="c:func"} (sys.base_exec_prefix{.interpreted-text role="data"}) instead. UsePyConfig_Get("exec_prefix") <PyConfig_Get>{.interpreted-text role="c:func"} (sys.exec_prefix{.interpreted-text role="data"}) ifvirtual environments <venv-def>{.interpreted-text role="ref"} need to be handled.!Py_GetPath{.interpreted-text role="c:func"}: usePyConfig_Get("module_search_paths") <PyConfig_Get>{.interpreted-text role="c:func"} (sys.path{.interpreted-text role="data"}) instead.!Py_GetPrefix{.interpreted-text role="c:func"}: usePyConfig_Get("base_prefix") <PyConfig_Get>{.interpreted-text role="c:func"} (sys.base_prefix{.interpreted-text role="data"}) instead. UsePyConfig_Get("prefix") <PyConfig_Get>{.interpreted-text role="c:func"} (sys.prefix{.interpreted-text role="data"}) ifvirtual environments <venv-def>{.interpreted-text role="ref"} need to be handled.!Py_GetProgramFullPath{.interpreted-text role="c:func"}: usePyConfig_Get("executable") <PyConfig_Get>{.interpreted-text role="c:func"} (sys.executable{.interpreted-text role="data"}) instead.!Py_GetProgramName{.interpreted-text role="c:func"}: usePyConfig_Get("executable") <PyConfig_Get>{.interpreted-text role="c:func"} (sys.executable{.interpreted-text role="data"}) instead.!Py_GetPythonHome{.interpreted-text role="c:func"}: usePyConfig_Get("home") <PyConfig_Get>{.interpreted-text role="c:func"} or thePYTHONHOME{.interpreted-text role="envvar"} environment variable instead.
(Contributed by Bénédikt Tran in
133644{.interpreted-text role="gh"}.)
Deprecated C APIs
Deprecate
456{.interpreted-text role="pep"} support for providing an external definition of the string hashing scheme. Removal is scheduled for Python 3.19.Previously, embedders could define
Py_HASH_ALGORITHM{.interpreted-text role="c:macro"} to bePy_HASH_EXTERNALto indicate that the hashing scheme was provided externally but this feature was undocumented, untested and most likely unused.(Contributed by Bénédikt Tran in
141226{.interpreted-text role="gh"}.)For unsigned integer formats in
PyArg_ParseTuple{.interpreted-text role="c:func"}, accepting Python integers with value that is larger than the maximal value for the C type or less than the minimal value for the corresponding signed integer type of the same size is now deprecated. (Contributed by Serhiy Storchaka in132629{.interpreted-text role="gh"}.)PyBytes_FromStringAndSize(NULL, len) <PyBytes_FromStringAndSize>{.interpreted-text role="c:func"} and_PyBytes_Resize{.interpreted-text role="c:func"} aresoft deprecated{.interpreted-text role="term"}, use thePyBytesWriter{.interpreted-text role="c:type"} API instead. (Contributed by Victor Stinner in129813{.interpreted-text role="gh"}.)!_PyObject_CallMethodId{.interpreted-text role="c:func"},!_PyObject_GetAttrId{.interpreted-text role="c:func"} and!_PyUnicode_FromId{.interpreted-text role="c:func"} are deprecated since 3.15 and will be removed in 3.20. Instead, usePyUnicode_InternFromString(){.interpreted-text role="c:func"} and cache the result in the module state, then callPyObject_CallMethod{.interpreted-text role="c:func"} orPyObject_GetAttr{.interpreted-text role="c:func"}. (Contributed by Victor Stinner in141049{.interpreted-text role="gh"}.)Deprecate
~PyComplexObject.cval{.interpreted-text role="c:member"} field of thePyComplexObject{.interpreted-text role="c:type"} type. UsePyComplex_AsCComplex{.interpreted-text role="c:func"} andPyComplex_FromCComplex{.interpreted-text role="c:func"} to convert a Python complex number to/from the CPy_complex{.interpreted-text role="c:type"} representation. (Contributed by Sergey B Kirpichev in128813{.interpreted-text role="gh"}.)Functions
_Py_c_sum{.interpreted-text role="c:func"},_Py_c_diff{.interpreted-text role="c:func"},_Py_c_neg{.interpreted-text role="c:func"},_Py_c_prod{.interpreted-text role="c:func"},_Py_c_quot{.interpreted-text role="c:func"},_Py_c_pow{.interpreted-text role="c:func"} and_Py_c_abs{.interpreted-text role="c:func"} aresoft deprecated{.interpreted-text role="term"}. (Contributed by Sergey B Kirpichev in128813{.interpreted-text role="gh"}.)~PyConfig.bytes_warning{.interpreted-text role="c:member"} is deprecated since 3.15 and will be removed in 3.17. (Contributed by Nikita Sobolev in136355{.interpreted-text role="gh"}.)!Py_INFINITY{.interpreted-text role="c:macro"} macro issoft deprecated{.interpreted-text role="term"}, use the C11 standard<math.h>!INFINITY{.interpreted-text role="c:macro"} instead. (Contributed by Sergey B Kirpichev in141004{.interpreted-text role="gh"}.)!Py_MATH_El{.interpreted-text role="c:macro"} and!Py_MATH_PIl{.interpreted-text role="c:macro"} are deprecated since 3.15 and will be removed in 3.20. (Contributed by Sergey B Kirpichev in141004{.interpreted-text role="gh"}.)
Build changes
- Removed implicit fallback to the bundled copy of the
libmpdeclibrary. Now this should be explicitly enabled with--with-system-libmpdec{.interpreted-text role="option"} set tonoor with!--without-system-libmpdec{.interpreted-text role="option"}. (Contributed by Sergey B Kirpichev in115119{.interpreted-text role="gh"}.) - The new configure option
--with-missing-stdlib-config=FILE{.interpreted-text role="option"} allows distributors to pass a JSON configuration file containing custom error messages forstandard library{.interpreted-text role="term"} modules that are missing or packaged separately. (Contributed by Stan Ulbrych and Petr Viktorin in139707{.interpreted-text role="gh"}.) - The new configure option
--with-pymalloc-hugepages{.interpreted-text role="option"} enables huge page support forpymalloc <pymalloc>{.interpreted-text role="ref"} arenas. When enabled, arena size increases to 2 MiB and allocation usesMAP_HUGETLB(Linux) orMEM_LARGE_PAGES(Windows) with automatic fallback to regular pages. On Windows, usebuild.bat --pymalloc-hugepages. At runtime, huge pages must be explicitly enabled by setting thePYTHON_PYMALLOC_HUGEPAGES{.interpreted-text role="envvar"} environment variable to1. - Annotating anonymous mmap usage is now supported if Linux kernel supports
PR_SET_VMA_ANON_NAME <PR_SET_VMA(2const)>{.interpreted-text role="manpage"} (Linux 5.17 or newer). Annotations are visible in/proc/<pid>/mapsif the kernel supports the feature and-X dev <-X>{.interpreted-text role="option"} is passed to the Python or Python is built indebug mode <debug-build>{.interpreted-text role="ref"}. (Contributed by Donghee Na in141770{.interpreted-text role="gh"}.)
Porting to Python 3.15
This section lists previously described changes and other bugfixes that may require changes to your code.
sqlite3.Connection{.interpreted-text role="class"} APIs have been cleaned up.- All parameters of
sqlite3.connect{.interpreted-text role="func"} except database are now keyword-only. - The first three parameters of methods
~sqlite3.Connection.create_function{.interpreted-text role="meth"} and~sqlite3.Connection.create_aggregate{.interpreted-text role="meth"} are now positional-only. - The first parameter of methods
~sqlite3.Connection.set_authorizer{.interpreted-text role="meth"},~sqlite3.Connection.set_progress_handler{.interpreted-text role="meth"} and~sqlite3.Connection.set_trace_callback{.interpreted-text role="meth"} is now positional-only.
(Contributed by Serhiy Storchaka in
133595{.interpreted-text role="gh"}.)- All parameters of
resource.RLIM_INFINITY{.interpreted-text role="data"} is now always positive. Passing a negative integer value that corresponded to its old value (such as-1or-3, depending on platform) toresource.setrlimit{.interpreted-text role="func"} andresource.prlimit{.interpreted-text role="func"} is now deprecated. (Contributed by Serhiy Storchaka in137044{.interpreted-text role="gh"}.)mmap.mmap.resize{.interpreted-text role="meth"} has been removed on platforms that don't support the underlying syscall, instead of raising aSystemError{.interpreted-text role="exc"}.A resource warning is now emitted for an unclosed
xml.etree.ElementTree.iterparse{.interpreted-text role="func"} iterator if it opened a file. Use its!close{.interpreted-text role="meth"} method or thecontextlib.closing{.interpreted-text role="func"} context manager to close it. (Contributed by Osama Abdelkader and Serhiy Storchaka in140601{.interpreted-text role="gh"}.)If a short option and a single-dash long option are passed to
argparse.ArgumentParser.add_argument{.interpreted-text role="meth"}, dest is now inferred from the single-dash long option. For example, inadd_argument('-f', '-foo'), dest is now'foo'instead of'f'. Pass an explicit dest argument to preserve the old behavior. (Contributed by Serhiy Storchaka in138697{.interpreted-text role="gh"}.)
