What’s new in Python 3.15¶
- Editor:
TBD
This article explains the new features in Python 3.15, compared to 3.14.
For full details, see thechangelog.
Note
Prerelease users should be aware that this document is currently in draftform. 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¶
New features¶
High frequency statistical sampling profiler¶
A new statistical sampling profiler has been added to the newprofiling
module asprofiling.sampling
. This profiler enables low-overhead performance analysis ofrunning Python processes without requiring code modification or process restart.
Unlike deterministic profilers (cProfile
andprofile
) that instrumentevery function call, the sampling profiler periodically captures stack traces fromrunning processes. This approach provides virtually zero overhead while achievingsampling rates ofup to 1,000,000 Hz, making it the fastest sampling profileravailable for Python (at the time of its contribution) and ideal for debuggingperformance issues in production environments.
Key features include:
Zero-overhead profiling: Attach to any running Python process withoutaffecting its performance
No code modification required: Profile existing applications without restart
Real-time statistics: Monitor sampling quality during data collection
Multiple output formats: Generate both detailed statistics and flamegraph data
Thread-aware profiling: Option to profile all threads or just the main thread
Profile process 1234 for 10 seconds with default settings:
python-mprofiling.sampling1234
Profile with custom interval and duration, save to file:
python-mprofiling.sampling-i50-d30-oprofile.stats1234
Generate collapsed stacks for flamegraph:
python-mprofiling.sampling--collapsed1234
Profile all threads and sort by total time:
python-mprofiling.sampling-a--sort-tottime1234
The profiler generates statistical estimates of where time is spent:
Real-timesamplingstats:Mean:100261.5Hz(9.97µs)Min:86333.4Hz(11.58µs)Max:118807.2Hz(8.42µs)Samples:400001Captured498841samplesin5.00secondsSamplerate:99768.04samples/secErrorrate:0.72%ProfileStats:nsamplessample%tottime(s)cumul%cumtime(s)filename:lineno(function)43/4188580.00.00087.94.189case.py:667(TestCase.run)3293/4188120.70.03387.94.188case.py:613(TestCase._callTestMethod)158562/15856233.31.58633.31.586test_compile.py:725(TestSpecifics.test_compiler_recursion_limit.<locals>.check_limit)129553/12955327.21.29627.21.296ast.py:46(parse)0/1281290.00.00026.91.281test_ast.py:884(AST_Tests.test_ast_recursion_limit.<locals>.check_limit)7/674460.00.00014.20.674test_compile.py:729(TestSpecifics.test_compiler_recursion_limit)6/603800.00.00012.70.604test_ast.py:888(AST_Tests.test_ast_recursion_limit)3/500200.00.00010.50.500test_compile.py:727(TestSpecifics.test_compiler_recursion_limit)1/380110.00.0008.00.380test_ast.py:886(AST_Tests.test_ast_recursion_limit)1/250760.00.0005.30.251test_compile.py:728(TestSpecifics.test_compiler_recursion_limit)22361/223624.70.2244.70.224test_compile.py:1368(TestSpecifics.test_big_dict_literal)4/180080.00.0003.80.180test_ast.py:889(AST_Tests.test_ast_recursion_limit)11/176960.00.0003.70.177subprocess.py:1038(Popen.__init__)16968/169683.60.1703.60.170subprocess.py:1900(Popen._execute_child)2/169410.00.0003.60.169test_compile.py:730(TestSpecifics.test_compiler_recursion_limit)Legend:nsamples:Direct/Cumulativesamples(directexecuting/oncallstack)sample%:Percentageoftotalsamplesthisfunctionwasdirectlyexecutingtottime:Estimatedtotaltimespentdirectlyinthisfunctioncumul%:Percentageoftotalsampleswhenthisfunctionwasonthecallstackcumtime:Estimatedcumulativetime(includingtimeincalledfunctions)filename:lineno(function):FunctionlocationandnameSummaryofInterestingFunctions:FunctionswithHighestDirect/CumulativeRatio(HotSpots):1.000direct/cumulativeratio,33.3%directsamples:test_compile.py:(TestSpecifics.test_compiler_recursion_limit.<locals>.check_limit)1.000direct/cumulativeratio,27.2%directsamples:ast.py:(parse)1.000direct/cumulativeratio,3.6%directsamples:subprocess.py:(Popen._execute_child)FunctionswithHighestCallFrequency(IndirectCalls):418815indirectcalls,87.9%totalstackpresence:case.py:(TestCase.run)415519indirectcalls,87.9%totalstackpresence:case.py:(TestCase._callTestMethod)159470indirectcalls,33.5%totalstackpresence:test_compile.py:(TestSpecifics.test_compiler_recursion_limit)FunctionswithHighestCallMagnification(Cumulative/Direct):12267.9xcallmagnification,159470indirectcallsfrom13direct:test_compile.py:(TestSpecifics.test_compiler_recursion_limit)10581.7xcallmagnification,116388indirectcallsfrom11direct:test_ast.py:(AST_Tests.test_ast_recursion_limit)9740.9xcallmagnification,418815indirectcallsfrom43direct:case.py:(TestCase.run)
The profiler automatically identifies performance bottlenecks through statisticalanalysis, highlighting functions with high CPU usage and call frequency patterns.
This capability is particularly valuable for debugging performance issues inproduction systems where traditional profiling approaches would be too intrusive.
(Contributed by Pablo Galindo and László Kiss Kollár ingh-135953.)
Improved error messages¶
The interpreter now provides more helpful suggestions in
AttributeError
exceptions when accessing an attribute on an object that does not exist, buta similar attribute is available through one of its members.For example, if the object has an attribute that itself exposes the requestedname, the error message will suggest accessing it via that inner attribute:
@dataclassclassCircle:radius:float@propertydefarea(self)->float:returnpi*self.radius**2classContainer:def__init__(self,inner:Circle)->None:self.inner=innercircle=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'?
Other language changes¶
Python now usesUTF-8 as the default encoding, independent of the system’senvironment. This means that I/O operations without an explicit encoding,e.g.
open('flying-circus.txt')
, will use UTF-8.UTF-8 is a widely-supportedUnicode character encoding that has become ade facto standard for representing text, including nearly every webpageon the internet, many common file formats, programming languages, and more.This only applies when no
encoding
argument is given. For bestcompatibility between versions of Python, ensure that an explicitencoding
argument is always provided. Theopt-in encoding warningcan be used to identify code that may be affected by this change.The specialencoding='locale'
argument uses the current localeencoding, and has been supported since Python 3.10.To retain the previous behaviour, Python’s UTF-8 mode may be disabled withthe
PYTHONUTF8=0
environment variable or the-Xutf8=0
command line option.See also
PEP 686 for further details.
(Contributed by Adam Turner ingh-133711; PEP 686 written by Inada Naoki.)
Several error messages incorrectly using the term “argument” have been corrected.(Contributed by Stan Ulbrych ingh-133382.)
The interpreter now tries to provide a suggestion when
delattr()
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:>>>classA:...pass>>>a=A()>>>a.abcde=1>>>dela.abcdfTraceback (most recent call last):...AttributeError:'A' object has no attribute 'abcdf'. Did you mean: 'abcde'?
(Contributed by Nikita Sobolev and Pranjal Prajapati ingh-136588.)
Unraisable exceptions are now highlighted with color by default. This can becontrolled byenvironment variables.(Contributed by Peter Bierma ingh-134170.)
The
__repr__()
ofImportError
andModuleNotFoundError
now shows “name” and “path” asname=<name>
andpath=<path>
if they were givenas keyword arguments at construction time.(Contributed by Serhiy Storchaka, Oleg Iarygin, and Yoav Nir ingh-74185.)The
__dict__
and__weakref__
descriptors now use asingle descriptor instance per interpreter, shared across all types thatneed them.This speeds up class creation, and helps avoid reference cycles.(Contributed by Petr Viktorin ingh-135228.)The
-W
option and thePYTHONWARNINGS
environment variablecan now specify regular expressions instead of literal strings to matchthe warning message and the module name, if the corresponding field startsand ends with a forward slash (/
).(Contributed by Serhiy Storchaka ingh-134716.)Functions that take timestamp or timeout arguments now accept any realnumbers (such as
Decimal
andFraction
),not only integers or floats, although this does not improve precision.(Contributed by Serhiy Storchaka ingh-67795.)
New modules¶
None yet.
Improved modules¶
collections¶
collections.abc¶
collections.abc.ByteString
has been removed fromcollections.abc.__all__
.collections.abc.ByteString
has beendeprecated since Python 3.12, and is scheduled for removal in Python 3.17.The following statements now cause
DeprecationWarning
s to be emitted atruntime:fromcollections.abcimportByteString
importcollections.abc;collections.abc.ByteString
.
DeprecationWarning
s were already emitted ifcollections.abc.ByteString
was subclassed or used as the secondargument toisinstance()
orissubclass()
, but warnings were notpreviously emitted if it was merely imported or accessed from thecollections.abc
module.
dbm¶
Added new
reorganize()
methods todbm.dumb
anddbm.sqlite3
which allow to recover unused free space previously occupied by deleted entries.(Contributed by Andrea Oliveri ingh-134004.)
difflib¶
Introduced the optionalcolor parameter to
difflib.unified_diff()
,enabling color output similar togit diff.This can be controlled byenvironment variables.(Contributed by Douglas Thor ingh-133725.)Improved the styling of HTML diff pages generated by the
difflib.HtmlDiff
class, and migrated the output to the HTML5 standard.(Contributed by Jiahao Li ingh-134580.)
hashlib¶
Ensure that hash functions guaranteed to be alwaysavailable exist asattributes of
hashlib
even if they will not work at runtime due tomissing backend implementations. For instance,hashlib.md5
will nolonger raiseAttributeError
if OpenSSL is not available and Pythonhas been built without MD5 support.(Contributed by Bénédikt Tran ingh-136929.)
http.client¶
A newmax_response_headers keyword-only parameter has been added to
HTTPConnection
andHTTPSConnection
constructors. This parameter overrides the default maximum number of allowedresponse headers.(Contributed by Alexander Enrique Urieles Nieto ingh-131724.)
http.cookies¶
Allow ‘
"
’ double quotes in cookie values.(Contributed by Nick Burns and Senthil Kumaran ingh-92936.)
locale¶
setlocale()
now supports language codes with@
-modifiers.@
-modifier are no longer silently removed ingetlocale()
,but included in the language code.(Contributed by Serhiy Storchaka ingh-137729.)
math¶
Add
math.isnormal()
andmath.issubnormal()
functions.(Contributed by Sergey B Kirpichev ingh-132908.)Add
math.fmax()
,math.fmin()
andmath.signbit()
functions.(Contributed by Bénédikt Tran ingh-135853.)
mmap¶
os.path¶
Add support of the all-but-last mode in
realpath()
.(Contributed by Serhiy Storchaka ingh-71189.)Thestrict parameter to
os.path.realpath()
accepts a new value,os.path.ALLOW_MISSING
.If used, errors other thanFileNotFoundError
will be re-raised;the resulting path can be missing but it will be free of symlinks.(Contributed by Petr Viktorin forCVE 2025-4517.)
resource¶
Add new constants:
RLIMIT_NTHR
,RLIMIT_UMTXP
,RLIMIT_THREADS
,RLIM_SAVED_CUR
, andRLIM_SAVED_MAX
.(Contributed by Serhiy Storchaka ingh-137512.)
shelve¶
socket¶
Add constants for the ISO-TP CAN protocol.(Contributed by Patrick Menschel and Stefan Tatschner ingh-86819.)
sqlite3¶
Thecommand-line interface has several new features:
SQL keyword completion on <tab>.(Contributed by Long Tan ingh-133393.)
Prompts, error messages, and help text are now colored.This is enabled by default, seeControlling color fordetails.(Contributed by Stan Ulbrych and Łukasz Langa ingh-133461.)
ssl¶
Indicate through
ssl.HAS_PSK_TLS13
whether thessl
modulesupports “External PSKs” in TLSv1.3, as described in RFC 9258.(Contributed by Will Childs-Klein ingh-133624.)Added new methods for managing groups used for SSL key agreement
ssl.SSLContext.set_groups()
sets the groups allowed for doingkey agreement, extending the previousssl.SSLContext.set_ecdh_curve()
method.This new API provides the ability to list multiple groups andsupports fixed-field and post-quantum groups in addition to ECDHcurves. This method can also be used to control what key sharesare sent in the TLS handshake.ssl.SSLSocket.group()
returns the group selected for doing keyagreement on the current connection after the TLS handshake completes.This call requires OpenSSL 3.2 or later.ssl.SSLContext.get_groups()
returns a list of all available keyagreement groups compatible with the minimum and maximum TLS versionscurrently set in the context. This call requires OpenSSL 3.5 or later.
(Contributed by Ron Frederick ingh-136306.)
Added a new method
ssl.SSLContext.set_ciphersuites()
for setting TLS 1.3ciphers. For TLS 1.2 or earlier,ssl.SSLContext.set_ciphers()
shouldcontinue to be used. Both calls can be made on the same context and theselected cipher suite will depend on the TLS version negotiated when aconnection is made.(Contributed by Ron Frederick ingh-137197.)Added new methods for managing signature algorithms:
ssl.get_sigalgs()
returns a list of all available TLS signaturealgorithms. This call requires OpenSSL 3.4 or later.ssl.SSLContext.set_client_sigalgs()
sets the signature algorithmsallowed for certificate-based client authentication.ssl.SSLContext.set_server_sigalgs()
sets the signature algorithmsallowed for the server to complete the TLS handshake.ssl.SSLSocket.client_sigalg()
returns the signature algorithmselected for client authentication on the current connection. This callrequires OpenSSL 3.5 or later.ssl.SSLSocket.server_sigalg()
returns the signature algorithmselected for the server to complete the TLS handshake on the currentconnection. This call requires OpenSSL 3.5 or later.
(Contributed by Ron Frederick ingh-138252.)
sys¶
Add
sys.abi_info
namespace to improve access to ABI information.(Contributed by Klaus Zimmermann ingh-137476.)
tarfile¶
data_filter()
now normalizes symbolic link targets in order toavoid path traversal attacks.(Contributed by Petr Viktorin ingh-127987 andCVE 2025-4138.)extractall()
now skips fixing up directory attributeswhen a directory was removed or replaced by another kind of file.(Contributed by Petr Viktorin ingh-127987 andCVE 2024-12718.)extract()
andextractall()
now (re-)apply the extraction filter when substituting a link (hard orsymbolic) with a copy of another archive member, and when fixing updirectory attributes.The former raises a new exception,LinkFallbackError
.(Contributed by Petr Viktorin forCVE 2025-4330 andCVE 2024-12718.)extract()
andextractall()
no longer extract rejected members whenerrorlevel()
is zero.(Contributed by Matt Prodani and Petr Viktorin ingh-112887andCVE 2025-4435.)extract()
andextractall()
now replace slashes by backslashes in symlink targets on Windows to preventcreation of corrupted links.(Contributed by Christoph Walcher ingh-57911.)
timeit¶
The command-line interface now colorizes error tracebacksby default. This can be controlled withenvironment variables.(Contributed by Yi Hong ingh-139374.)
types¶
Expose the write-through
locals()
proxy typeastypes.FrameLocalsProxyType
.This represents the type of theframe.f_locals
attribute,as described inPEP 667.
unittest¶
unittest.TestCase.assertLogs()
will now accept a formatterto control how messages are formatted.(Contributed by Garry Cairns ingh-134567.)
xml.parsers.expat¶
Add
SetAllocTrackerActivationThreshold()
andSetAllocTrackerMaximumAmplification()
toxmlparser objects to tune protections againstdisproportional amounts of dynamic memory usage from within an Expat parser.(Contributed by Bénédikt Tran ingh-90949.)Add
SetBillionLaughsAttackProtectionActivationThreshold()
andSetBillionLaughsAttackProtectionMaximumAmplification()
toxmlparser objects to tune protections againstbillion laughs attacks.(Contributed by Bénédikt Tran ingh-90949.)
zlib¶
Allow combining two Adler-32 checksums via
adler32_combine()
.(Contributed by Callum Attryde and Bénédikt Tran ingh-134635.)Allow combining two CRC-32 checksums via
crc32_combine()
.(Contributed by Bénédikt Tran ingh-134635.)
Optimizations¶
module_name¶
TODO
Deprecated¶
CLI¶
Deprecate
-b
and-bb
command line optionsand schedule them to become no-op in Python 3.17.These were primarily helpers for the Python 2 -> 3 transition.Starting with Python 3.17, noBytesWarning
will be raisedfor these cases; use a type checker instead.(Contributed by Nikita Sobolev ingh-136355.)
hashlib¶
In hash function constructors such as
new()
or thedirect hash-named constructors such asmd5()
andsha256()
, their optional initial data parameter couldalso be passed a keyword argument nameddata=
orstring=
invarioushashlib
implementations.Support for the
string
keyword argument name is now deprecated andis slated for removal in Python 3.19. Prefer passing the initial data asa positional argument for maximum backwards compatibility.(Contributed by Bénédikt Tran ingh-134978.)
__version__¶
The
__version__
attribute has been deprecated in these standard librarymodules and will be removed in Python 3.20.Usesys.version_info
instead.ctypes.macholib
logging
(__date__
also deprecated)
(Contributed by Hugo van Kemenade ingh-76007.)
Pending removal in Python 3.16¶
The import system:
Setting
__loader__
on a module whilefailing to set__spec__.loader
is deprecated. In Python 3.16,__loader__
will cease to be set ortaken into consideration by the import system or the standard library.
The
'u'
format code (wchar_t
)has been deprecated in documentation since Python 3.3and at runtime since Python 3.13.Use the'w'
format code (Py_UCS4
)for Unicode characters instead.
asyncio.iscoroutinefunction()
is deprecatedand will be removed in Python 3.16;useinspect.iscoroutinefunction()
instead.(Contributed by Jiahao Li and Kumar Aditya ingh-122875.)asyncio
policy system is deprecated and will be removed in Python 3.16.In particular, the following classes and functions are deprecated:Users should use
asyncio.run()
orasyncio.Runner
withloop_factory to use the desired event loop implementation.For example, to use
asyncio.SelectorEventLoop
on Windows:importasyncioasyncdefmain():...asyncio.run(main(),loop_factory=asyncio.SelectorEventLoop)
(Contributed by Kumar Aditya ingh-127949.)
Bitwise inversion on boolean types,
~True
or~False
has been deprecated since Python 3.12,as it produces surprising and unintuitive results (-2
and-1
).Usenotx
instead for the logical negation of a Boolean.In the rare case that you need the bitwise inversion ofthe underlying integer, convert toint
explicitly (~int(x)
).
Calling the Python implementation of
functools.reduce()
withfunctionorsequence as keyword arguments has been deprecated since Python 3.14.
Support for custom logging handlers with thestrm argument is deprecatedand scheduled for removal in Python 3.16. Define handlers with thestreamargument instead. (Contributed by Mariusz Felisiak ingh-115032.)
Valid extensions start with a ‘.’ or are empty for
mimetypes.MimeTypes.add_type()
.Undotted extensions are deprecated and willraise aValueError
in Python 3.16.(Contributed by Hugo van Kemenade ingh-75223.)
The
ExecError
exceptionhas been deprecated since Python 3.14.It has not been used by any function inshutil
since Python 3.4,and is now an alias ofRuntimeError
.
The
Class.get_methods
methodhas been deprecated since Python 3.14.
sys
:The
_enablelegacywindowsfsencoding()
functionhas been deprecated since Python 3.13.Use thePYTHONLEGACYWINDOWSFSENCODING
environment variable instead.
The
sysconfig.expand_makefile_vars()
functionhas been deprecated since Python 3.14.Use thevars
argument ofsysconfig.get_paths()
instead.
The undocumented and unused
TarFile.tarfile
attributehas been deprecated since Python 3.13.
Pending removal in Python 3.17¶
collections.abc.ByteString
is scheduled for removal in Python 3.17.Use
isinstance(obj,collections.abc.Buffer)
to test ifobj
implements thebuffer protocol at runtime. For usein type annotations, either useBuffer
or a unionthat explicitly specifies the types your code supports (e.g.,bytes|bytearray|memoryview
).ByteString
was originally intended to be an abstract class thatwould serve as a supertype of bothbytes
andbytearray
.However, since the ABC never had any methods, knowing that an object was aninstance ofByteString
never actually told you anything usefulabout the object. Other common buffer types such asmemoryview
were also never understood as subtypes ofByteString
(either atruntime or by static type checkers).SeePEP 688 for more details.(Contributed by Shantanu Jain ingh-91896.)
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 Python3.17. Users should use documented introspection helpers liketyping.get_origin()
andtyping.get_args()
instead of relying on private implementation details.typing.ByteString
, deprecated since Python 3.9, is scheduled for removal inPython 3.17.Use
isinstance(obj,collections.abc.Buffer)
to test ifobj
implements thebuffer protocol at runtime. For usein type annotations, either useBuffer
or a unionthat explicitly specifies the types your code supports (e.g.,bytes|bytearray|memoryview
).ByteString
was originally intended to be an abstract class thatwould serve as a supertype of bothbytes
andbytearray
.However, since the ABC never had any methods, knowing that an object was aninstance ofByteString
never actually told you anything usefulabout the object. Other common buffer types such asmemoryview
were also never understood as subtypes ofByteString
(either atruntime or by static type checkers).SeePEP 688 for more details.(Contributed by Shantanu Jain ingh-91896.)
Pending removal in Python 3.19¶
In hash function constructors such as
new()
or thedirect hash-named constructors such asmd5()
andsha256()
, their optional initial data parameter couldalso be passed a keyword argument nameddata=
orstring=
invarioushashlib
implementations.Support for the
string
keyword argument name is now deprecatedand slated for removal in Python 3.19.Before Python 3.13, the
string
keyword parameter was not correctlysupported depending on the backend implementation of hash functions.Prefer passing the initial data as a positional argument for maximumbackwards compatibility.
Pending removal in Python 3.20¶
The
__version__
attribute has been deprecated in these standard librarymodules and will be removed in Python 3.20.Usesys.version_info
instead.ctypes.macholib
logging
(__date__
also deprecated)
(Contributed by Hugo van Kemenade ingh-76007.)
Pending removal in future versions¶
The following APIs will be removed in the future,although there is currently no date scheduled for their removal.
Nesting argument groups and nesting mutually exclusivegroups are deprecated.
Passing the undocumented keyword argumentprefix_chars to
add_argument_group()
is nowdeprecated.The
argparse.FileType
type converter is deprecated.
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
0inx
,1orx
,0if1else2
. It allows confusing andambiguous expressions like[0x1forxiny]
(which can be interpreted as[0x1forxiny]
or[0x1forxiny]
). A syntax warning is raisedif the numeric literal is immediately followed by one of keywordsand
,else
,for
,if
,in
,is
andor
. In a future release itwill be changed to a syntax error. (gh-87999)Support for
__index__()
and__int__()
method returning non-int type:these methods will be required to return an instance of a strict subclass ofint
.Support for
__float__()
method returning a strict subclass offloat
: these methods will be required to return an instance offloat
.Support for
__complex__()
method returning a strict subclass ofcomplex
: these methods will be required to return an instance ofcomplex
.Delegation of
int()
to__trunc__()
method.Passing a complex number as thereal orimag argument in the
complex()
constructor is now deprecated; it should only be passedas a single positional argument.(Contributed by Serhiy Storchaka ingh-109218.)
calendar
:calendar.January
andcalendar.February
constants aredeprecated and replaced bycalendar.JANUARY
andcalendar.FEBRUARY
.(Contributed by Prince Roshan ingh-103636.)codecs
: useopen()
instead ofcodecs.open()
. (gh-133038)codeobject.co_lnotab
: use thecodeobject.co_lines()
methodinstead.utcnow()
:usedatetime.datetime.now(tz=datetime.UTC)
.utcfromtimestamp()
:usedatetime.datetime.fromtimestamp(timestamp,tz=datetime.UTC)
.
gettext
: Plural value must be an integer.cache_from_source()
debug_override parameter isdeprecated: use theoptimization parameter instead.
EntryPoints
tuple interface.Implicit
None
on return values.
logging
: thewarn()
method has been deprecatedsince Python 3.3, usewarning()
instead.mailbox
: Use of StringIO input and text mode is deprecated, useBytesIO and binary mode instead.os
: Callingos.register_at_fork()
in multi-threaded process.pydoc.ErrorDuringImport
: A tuple value forexc_info parameter isdeprecated, use an exception instance.re
: More strict rules are now applied for numerical group referencesand group names in regular expressions. Only sequence of ASCII digits is nowaccepted as a numerical reference. The group name in bytes patterns andreplacement strings can now only contain ASCII letters and digits andunderscore.(Contributed by Serhiy Storchaka ingh-91760.)shutil
:rmtree()
’sonerror parameter is deprecated inPython 3.12; use theonexc parameter instead.ssl
options and protocols:ssl.SSLContext
without protocol argument is deprecated.ssl.SSLContext
:set_npn_protocols()
andselected_npn_protocol()
are deprecated: use ALPNinstead.ssl.OP_NO_SSL*
optionsssl.OP_NO_TLS*
optionsssl.PROTOCOL_SSLv3
ssl.PROTOCOL_TLS
ssl.PROTOCOL_TLSv1
ssl.PROTOCOL_TLSv1_1
ssl.PROTOCOL_TLSv1_2
ssl.TLSVersion.SSLv3
ssl.TLSVersion.TLSv1
ssl.TLSVersion.TLSv1_1
threading
methods:threading.Condition.notifyAll()
: usenotify_all()
.threading.Event.isSet()
: useis_set()
.threading.Thread.isDaemon()
,threading.Thread.setDaemon()
:usethreading.Thread.daemon
attribute.threading.Thread.getName()
,threading.Thread.setName()
:usethreading.Thread.name
attribute.threading.currentThread()
: usethreading.current_thread()
.threading.activeCount()
: usethreading.active_count()
.
The internal class
typing._UnionGenericAlias
is no longer used to implementtyping.Union
. To preserve compatibility with users using this privateclass, a compatibility shim will be provided until at least Python 3.17. (Contributed byJelle Zijlstra ingh-105499.)unittest.IsolatedAsyncioTestCase
: it is deprecated to return a valuethat is notNone
from a test case.urllib.parse
deprecated functions:urlparse()
insteadsplitattr()
splithost()
splitnport()
splitpasswd()
splitport()
splitquery()
splittag()
splittype()
splituser()
splitvalue()
to_bytes()
wsgiref
:SimpleHandler.stdout.write()
should not do partialwrites.xml.etree.ElementTree
: Testing the truth value of anElement
is deprecated. In a future release itwill always returnTrue
. Prefer explicitlen(elem)
orelemisnotNone
tests instead.sys._clear_type_cache()
is deprecated:usesys._clear_internal_caches()
instead.
Removed¶
ctypes¶
Removed the undocumented function
ctypes.SetPointerType()
,which has been deprecated since Python 3.13.(Contributed by Bénédikt Tran ingh-133866.)
glob¶
Removed the undocumented
glob.glob0()
andglob.glob1()
functions, which have been deprecated since Python 3.13. Useglob.glob()
and pass a directory to itsroot_dir argument instead.(Contributed by Barney Gale ingh-137466.)
http.server¶
Removed the
CGIHTTPRequestHandler
classand the--cgi
flag from thepython -m http.servercommand-line interface. They were deprecated in Python 3.13.(Contributed by Bénédikt Tran ingh-133810.)
importlib.resources¶
Removed deprecated
package
parameterfromimportlib.resources.files()
function.(Contributed by Semyon Moroz ingh-138044)
pathlib¶
Removed deprecated
pathlib.PurePath.is_reserved()
.Useos.path.isreserved()
to detect reserved paths on Windows.(Contributed by Nikita Sobolev ingh-133875.)
platform¶
Removed the
platform.java_ver()
function,which was deprecated since Python 3.13.(Contributed by Alexey Makridenko ingh-133604.)
sre_*¶
Removed
sre_compile
,sre_constants
andsre_parse
modules.(Contributed by Stan Ulbrych ingh-135994.)
sysconfig¶
Removed thecheck_home parameter of
sysconfig.is_python_build()
.(Contributed by Filipe Laíns ingh-92897.)
threading¶
typing¶
The undocumented keyword argument syntax for creating
NamedTuple
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 ingh-133817.)Using
TD=TypedDict("TD")
orTD=TypedDict("TD",None)
toconstruct aTypedDict
type with zero field is nolonger supported. UseclassTD(TypedDict):pass
orTD=TypedDict("TD",{})
instead.(Contributed by Bénédikt Tran ingh-133823.)Code like
classExtraTypeVars(P1[S],Protocol[T,T2]):...
now raisesaTypeError
, becauseS
is not listed inProtocol
parameters.(Contributed by Nikita Sobolev ingh-137191.)Code like
classB2(A[T2],Protocol[T1,T2]):...
now correctly handlestype parameters order: it is(T1,T2)
, not(T2,T1)
as it was incorrectly infered in runtime before.(Contributed by Nikita Sobolev ingh-137191.)typing.ByteString
has been removed fromtyping.__all__
.typing.ByteString
has been deprecated since Python 3.9, and isscheduled for removal in Python 3.17.The following statements now cause
DeprecationWarning
s to be emitted atruntime:fromtypingimportByteString
importtyping;typing.ByteString
.
DeprecationWarning
s were already emitted iftyping.ByteString
was subclassed or used as the second argument toisinstance()
orissubclass()
, but warnings were not previously emitted if it was merelyimported or accessed from thetyping
module.
unicodedata¶
The Unicode database has been updated to Unicode 17.0.0.
wave¶
Removed the
getmark()
,setmark()
andgetmarkers()
methodsof theWave_read
andWave_write
classes,which were deprecated since Python 3.13.(Contributed by Bénédikt Tran ingh-133873.)
zipimport¶
Remove deprecated
zipimport.zipimporter.load_module()
.Usezipimport.zipimporter.exec_module()
instead.(Contributed by Jiahao Li ingh-133656.)
Porting to Python 3.15¶
This section lists previously described changes and other bugfixesthat may require changes to your code.
Build changes¶
Removed implicit fallback to the bundled copy of the
libmpdec
library.Now this should be explicitly enabled with--with-system-libmpdec
set tono
or with--without-system-libmpdec
.(Contributed by Sergey B Kirpichev ingh-115119.)
C API changes¶
New features¶
Add
PySys_GetAttr()
,PySys_GetAttrString()
,PySys_GetOptionalAttr()
, andPySys_GetOptionalAttrString()
functions as replacements forPySys_GetObject()
.(Contributed by Serhiy Storchaka ingh-108512.)Add
PyUnstable_Unicode_GET_CACHED_HASH
to get the cached hash ofa string. See the documentation for caveats.(Contributed by Petr Viktorin ingh-131510.)Add API for checking an extension module’s ABI compatibility:
Py_mod_abi
,PyABIInfo_Check()
,PyABIInfo_VAR
andPy_mod_abi
.(Contributed by Petr Viktorin ingh-137210.)ImplementPEP 782, thePyBytesWriter API.Add functions:
(Contributed by Victor Stinner ingh-129813.)
Add
PyTuple_FromArray()
to create atuple
from an array.(Contributed by Victor Stinner ingh-111489.)
Porting to Python 3.15¶
sqlite3.Connection
APIs has been cleaned up.All parameters of
sqlite3.connect()
exceptdatabase are now keyword-only.The first three parameters of methods
create_function()
andcreate_aggregate()
are now positional-only.The first parameter of methods
set_authorizer()
,set_progress_handler()
andset_trace_callback()
is now positional-only.
(Contributed by Serhiy Storchaka ingh-133595.)
Private functions promoted to public C APIs:
Thepythoncapi-compat project can be used to get most of these newfunctions on Python 3.14 and older.
resource.RLIM_INFINITY
is now always positive.Passing a negative integer value that corresponded to its old value(such as-1
or-3
, depending on platform) toresource.setrlimit()
andresource.prlimit()
is now deprecated.(Contributed by Serhiy Storchaka ingh-137044.)resize()
has been removed on platforms that don’t support theunderlying syscall, instead of raising aSystemError
.
Deprecated C APIs¶
For unsigned integer formats in
PyArg_ParseTuple()
,accepting Python integers with value that is larger than the maximal valuefor the C type or less than the minimal value for the correspondingsigned integer type of the same size is now deprecated.(Contributed by Serhiy Storchaka ingh-132629.)PyBytes_FromStringAndSize(NULL,len)
and_PyBytes_Resize()
aresoft deprecated,use thePyBytesWriter
API instead.(Contributed by Victor Stinner ingh-129813.)Deprecate
cval
field of the thePyComplexObject
type.UsePyComplex_AsCComplex()
andPyComplex_FromCComplex()
to convert a Python complex number to/from the CPy_complex
representation.(Contributed by Sergey B Kirpichev ingh-128813.)Functions
_Py_c_sum()
,_Py_c_diff()
,_Py_c_neg()
,_Py_c_prod()
,_Py_c_quot()
,_Py_c_pow()
and_Py_c_abs()
aresoft deprecated.(Contributed by Sergey B Kirpichev ingh-128813.)bytes_warning
is deprecatedsince 3.15 and will be removed in 3.17.(Contributed by Nikita Sobolev ingh-136355.)
Removed C APIs¶
Remove deprecated
PyUnicode
functions:PyUnicode_AsDecodedObject()
:UsePyCodec_Decode()
instead.PyUnicode_AsDecodedUnicode()
:UsePyCodec_Decode()
instead; Note that some codecs (for example, “base64”)may return a type other thanstr
, such asbytes
.PyUnicode_AsEncodedObject()
:UsePyCodec_Encode()
instead.PyUnicode_AsEncodedUnicode()
:UsePyCodec_Encode()
instead; Note that some codecs (for example, “base64”)may return a type other thanbytes
, such asstr
.
(Contributed by Stan Ulbrych ingh-133612.)
PyImport_ImportModuleNoBlock()
: deprecated aliasofPyImport_ImportModule()
.(Contributed by Bénédikt Tran ingh-133644.)PyWeakref_GetObject()
andPyWeakref_GET_OBJECT
:usePyWeakref_GetRef()
instead. Thepythoncapi-compat projectcan be used to getPyWeakref_GetRef()
on Python 3.12 and older.(Contributed by Bénédikt Tran ingh-133644.)Remove deprecated
PySys_ResetWarnOptions()
.Clearsys.warnoptions
andwarnings.filters
instead.(Contributed by Nikita Sobolev ingh-138886.)
The following functions are removed in favor ofPyConfig_Get()
.Thepythoncapi-compat project can be used to getPyConfig_Get()
on Python 3.13 and older.
Python initialization functions:
Py_GetExecPrefix()
:usePyConfig_Get("base_exec_prefix")
(sys.base_exec_prefix
) instead.UsePyConfig_Get("exec_prefix")
(sys.exec_prefix
) ifvirtual environmentsneed to be handled.Py_GetPath()
:usePyConfig_Get("module_search_paths")
(sys.path
) instead.Py_GetPrefix()
:usePyConfig_Get("base_prefix")
(sys.base_prefix
) instead.UsePyConfig_Get("prefix")
(sys.prefix
) ifvirtual environmentsneed to be handled.Py_GetProgramFullPath()
:usePyConfig_Get("executable")
(sys.executable
) instead.Py_GetProgramName()
:usePyConfig_Get("executable")
(sys.executable
) instead.Py_GetPythonHome()
:usePyConfig_Get("home")
or thePYTHONHOME
environment variable instead.
(Contributed by Bénédikt Tran ingh-133644.)