CINXE.COM
What’s New In Python 3.13 — Python 3.13.0 documentation
<!DOCTYPE html> <html lang="en" data-content_root="../"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" /> <meta property="og:title" content="What’s New In Python 3.13" /> <meta property="og:type" content="website" /> <meta property="og:url" content="https://docs.python.org/3/whatsnew/3.13.html" /> <meta property="og:site_name" content="Python documentation" /> <meta property="og:description" content="Editors, Adam Turner and Thomas Wouters,. This article explains the new features in Python 3.13, compared to 3.12. Python 3.13 was released on October 7, 2024. For full details, see the changelog. ..." /> <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" /> <meta property="og:image:alt" content="Python documentation" /> <meta name="description" content="Editors, Adam Turner and Thomas Wouters,. This article explains the new features in Python 3.13, compared to 3.12. Python 3.13 was released on October 7, 2024. For full details, see the changelog. ..." /> <meta property="og:image:width" content="200" /> <meta property="og:image:height" content="200" /> <meta name="theme-color" content="#3776ab" /> <title>What’s New In Python 3.13 — Python 3.13.0 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" /> <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=41b4f12d" /> <link rel="stylesheet" type="text/css" href="../_static/sidebar-wrap.css?v=65806c5a" /> <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" /> <script src="../_static/documentation_options.js?v=6aaf4047"></script> <script src="../_static/doctools.js?v=9bcbadda"></script> <script src="../_static/sphinx_highlight.js?v=dc90522c"></script> <script src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 3.13.0 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="What’s New In Python 3.12" href="3.12.html" /> <link rel="prev" title="What’s New in Python" href="index.html" /> <script defer data-domain="docs.python.org" src="https://plausible.io/js/script.js"></script> <link rel="canonical" href="https://docs.python.org/3/whatsnew/3.13.html" /> <style> @media only screen { table.full-width-table { width: 100%; } } </style> <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css"> <link rel="shortcut icon" type="image/png" href="../_static/py.svg" /> <script type="text/javascript" src="../_static/copybutton.js"></script> <script type="text/javascript" src="../_static/menu.js"></script> <script type="text/javascript" src="../_static/search-focus.js"></script> <script type="text/javascript" src="../_static/themetoggle.js"></script> <script type="text/javascript" src="../_static/rtd_switcher.js"></script> <meta name="readthedocs-addons-api-version" content="1"> </head> <body> <div class="mobile-nav"> <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation" aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" /> <nav class="nav-content" role="navigation"> <label for="menuToggler" class="toggler__label"> <span></span> </label> <span class="nav-items-wrapper"> <a href="https://www.python.org/" class="nav-logo"> <img src="../_static/py.svg" alt="Python logo"/> </a> <span class="version_switcher_placeholder"></span> <form role="search" class="search" action="../search.html" method="get"> <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon"> <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path> </svg> <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" /> <input type="submit" value="Go"/> </form> </span> </nav> <div class="menu-wrapper"> <nav class="menu" role="navigation" aria-label="main navigation"> <div class="language_switcher_placeholder"></div> <label class="theme-selector-label"> Theme <select class="theme-selector" oninput="activateTheme(this.value)"> <option value="auto" selected>Auto</option> <option value="light">Light</option> <option value="dark">Dark</option> </select> </label> <div> <h3><a href="../contents.html">Table of Contents</a></h3> <ul> <li><a class="reference internal" href="#">What’s New In Python 3.13</a><ul> <li><a class="reference internal" href="#summary-release-highlights">Summary – Release Highlights</a></li> <li><a class="reference internal" href="#new-features">New Features</a><ul> <li><a class="reference internal" href="#a-better-interactive-interpreter">A better interactive interpreter</a></li> <li><a class="reference internal" href="#improved-error-messages">Improved error messages</a></li> <li><a class="reference internal" href="#free-threaded-cpython">Free-threaded CPython</a></li> <li><a class="reference internal" href="#an-experimental-just-in-time-jit-compiler">An experimental just-in-time (JIT) compiler</a></li> <li><a class="reference internal" href="#defined-mutation-semantics-for-locals">Defined mutation semantics for <code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a></li> <li><a class="reference internal" href="#support-for-mobile-platforms">Support for mobile platforms</a></li> </ul> </li> <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li> <li><a class="reference internal" href="#new-modules">New Modules</a></li> <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul> <li><a class="reference internal" href="#argparse">argparse</a></li> <li><a class="reference internal" href="#array">array</a></li> <li><a class="reference internal" href="#ast">ast</a></li> <li><a class="reference internal" href="#asyncio">asyncio</a></li> <li><a class="reference internal" href="#base64">base64</a></li> <li><a class="reference internal" href="#compileall">compileall</a></li> <li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li> <li><a class="reference internal" href="#configparser">configparser</a></li> <li><a class="reference internal" href="#copy">copy</a></li> <li><a class="reference internal" href="#ctypes">ctypes</a></li> <li><a class="reference internal" href="#dbm">dbm</a></li> <li><a class="reference internal" href="#dis">dis</a></li> <li><a class="reference internal" href="#doctest">doctest</a></li> <li><a class="reference internal" href="#email">email</a></li> <li><a class="reference internal" href="#fractions">fractions</a></li> <li><a class="reference internal" href="#glob">glob</a></li> <li><a class="reference internal" href="#importlib">importlib</a></li> <li><a class="reference internal" href="#io">io</a></li> <li><a class="reference internal" href="#ipaddress">ipaddress</a></li> <li><a class="reference internal" href="#itertools">itertools</a></li> <li><a class="reference internal" href="#marshal">marshal</a></li> <li><a class="reference internal" href="#math">math</a></li> <li><a class="reference internal" href="#mimetypes">mimetypes</a></li> <li><a class="reference internal" href="#mmap">mmap</a></li> <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li> <li><a class="reference internal" href="#os">os</a></li> <li><a class="reference internal" href="#os-path">os.path</a></li> <li><a class="reference internal" href="#pathlib">pathlib</a></li> <li><a class="reference internal" href="#pdb">pdb</a></li> <li><a class="reference internal" href="#queue">queue</a></li> <li><a class="reference internal" href="#random">random</a></li> <li><a class="reference internal" href="#re">re</a></li> <li><a class="reference internal" href="#shutil">shutil</a></li> <li><a class="reference internal" href="#site">site</a></li> <li><a class="reference internal" href="#sqlite3">sqlite3</a></li> <li><a class="reference internal" href="#ssl">ssl</a></li> <li><a class="reference internal" href="#statistics">statistics</a></li> <li><a class="reference internal" href="#subprocess">subprocess</a></li> <li><a class="reference internal" href="#sys">sys</a></li> <li><a class="reference internal" href="#tempfile">tempfile</a></li> <li><a class="reference internal" href="#time">time</a></li> <li><a class="reference internal" href="#tkinter">tkinter</a></li> <li><a class="reference internal" href="#traceback">traceback</a></li> <li><a class="reference internal" href="#types">types</a></li> <li><a class="reference internal" href="#typing">typing</a></li> <li><a class="reference internal" href="#unicodedata">unicodedata</a></li> <li><a class="reference internal" href="#venv">venv</a></li> <li><a class="reference internal" href="#warnings">warnings</a></li> <li><a class="reference internal" href="#xml">xml</a></li> <li><a class="reference internal" href="#zipimport">zipimport</a></li> </ul> </li> <li><a class="reference internal" href="#optimizations">Optimizations</a></li> <li><a class="reference internal" href="#removed-modules-and-apis">Removed Modules And APIs</a><ul> <li><a class="reference internal" href="#pep-594-remove-dead-batteries-from-the-standard-library">PEP 594: Remove “dead batteries” from the standard library</a></li> <li><a class="reference internal" href="#to3">2to3</a></li> <li><a class="reference internal" href="#builtins">builtins</a></li> <li><a class="reference internal" href="#id3">configparser</a></li> <li><a class="reference internal" href="#importlib-metadata">importlib.metadata</a></li> <li><a class="reference internal" href="#locale">locale</a></li> <li><a class="reference internal" href="#opcode">opcode</a></li> <li><a class="reference internal" href="#id4">pathlib</a></li> <li><a class="reference internal" href="#id5">re</a></li> <li><a class="reference internal" href="#tkinter-tix">tkinter.tix</a></li> <li><a class="reference internal" href="#turtle">turtle</a></li> <li><a class="reference internal" href="#id6">typing</a></li> <li><a class="reference internal" href="#unittest">unittest</a></li> <li><a class="reference internal" href="#urllib">urllib</a></li> <li><a class="reference internal" href="#webbrowser">webbrowser</a></li> </ul> </li> <li><a class="reference internal" href="#new-deprecations">New Deprecations</a><ul> <li><a class="reference internal" href="#pending-removal-in-python-3-14">Pending Removal in Python 3.14</a></li> <li><a class="reference internal" href="#pending-removal-in-python-3-15">Pending Removal in Python 3.15</a></li> <li><a class="reference internal" href="#pending-removal-in-python-3-16">Pending removal in Python 3.16</a></li> <li><a class="reference internal" href="#pending-removal-in-future-versions">Pending Removal in Future Versions</a></li> </ul> </li> <li><a class="reference internal" href="#cpython-bytecode-changes">CPython Bytecode Changes</a></li> <li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul> <li><a class="reference internal" href="#id7">New Features</a></li> <li><a class="reference internal" href="#changed-c-apis">Changed C APIs</a></li> <li><a class="reference internal" href="#limited-c-api-changes">Limited C API Changes</a></li> <li><a class="reference internal" href="#removed-c-apis">Removed C APIs</a></li> <li><a class="reference internal" href="#deprecated-c-apis">Deprecated C APIs</a><ul> <li><a class="reference internal" href="#id8">Pending Removal in Python 3.14</a></li> <li><a class="reference internal" href="#id9">Pending Removal in Python 3.15</a></li> <li><a class="reference internal" href="#id10">Pending Removal in Future Versions</a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#build-changes">Build Changes</a></li> <li><a class="reference internal" href="#porting-to-python-3-13">Porting to Python 3.13</a><ul> <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li> <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li> </ul> </li> <li><a class="reference internal" href="#regression-test-changes">Regression Test Changes</a></li> <li><a class="reference internal" href="#notable-changes-in-3-13-1">Notable changes in 3.13.1</a><ul> <li><a class="reference internal" href="#id11">sys</a></li> </ul> </li> </ul> </li> </ul> </div> <div> <h4>Previous topic</h4> <p class="topless"><a href="index.html" title="previous chapter">What’s New in Python</a></p> </div> <div> <h4>Next topic</h4> <p class="topless"><a href="3.12.html" title="next chapter">What’s New In Python 3.12</a></p> </div> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li> <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.13.rst" rel="nofollow">Show Source </a> </li> </ul> </div> </nav> </div> </div> <div class="related" role="navigation" aria-label="Related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="3.12.html" title="What’s New In Python 3.12" accesskey="N">next</a> |</li> <li class="right" > <a href="index.html" title="What’s New in Python" accesskey="P">previous</a> |</li> <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li class="switchers"> <div class="language_switcher_placeholder"></div> <div class="version_switcher_placeholder"></div> </li> <li> </li> <li id="cpython-language-and-version"> <a href="../index.html">3.13.0 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> »</li> <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.13</a></li> <li class="right"> <div class="inline-search" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" /> <input type="submit" value="Go" /> </form> </div> | </li> <li class="right"> <label class="theme-selector-label"> Theme <select class="theme-selector" oninput="activateTheme(this.value)"> <option value="auto" selected>Auto</option> <option value="light">Light</option> <option value="dark">Dark</option> </select> </label> |</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <section id="what-s-new-in-python-3-13"> <h1>What’s New In Python 3.13<a class="headerlink" href="#what-s-new-in-python-3-13" title="Link to this heading">¶</a></h1> <dl class="field-list simple"> <dt class="field-odd">Editors<span class="colon">:</span></dt> <dd class="field-odd"><p>Adam Turner and Thomas Wouters</p> </dd> </dl> <p>This article explains the new features in Python 3.13, compared to 3.12. Python 3.13 was released on October 7, 2024. For full details, see the <a class="reference internal" href="changelog.html#changelog"><span class="std std-ref">changelog</span></a>.</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0719/"><strong>PEP 719</strong></a> – Python 3.13 Release Schedule</p> </div> <section id="summary-release-highlights"> <h2>Summary – Release Highlights<a class="headerlink" href="#summary-release-highlights" title="Link to this heading">¶</a></h2> <p>Python 3.13 is the latest stable release of the Python programming language, with a mix of changes to the language, the implementation and the standard library. The biggest changes include a new <a class="reference internal" href="#whatsnew313-better-interactive-interpreter">interactive interpreter</a>, experimental support for running in a <a class="reference internal" href="#whatsnew313-free-threaded-cpython">free-threaded mode</a> (<span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0703/"><strong>PEP 703</strong></a>), and a <a class="reference internal" href="#whatsnew313-jit-compiler">Just-In-Time compiler</a> (<span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0744/"><strong>PEP 744</strong></a>).</p> <p>Error messages continue to improve, with tracebacks now highlighted in color by default. The <a class="reference internal" href="../library/functions.html#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> builtin now has <a class="reference internal" href="#whatsnew313-locals-semantics"><span class="std std-ref">defined semantics</span></a> for changing the returned mapping, and type parameters now support default values.</p> <p>The library changes contain removal of deprecated APIs and modules, as well as the usual improvements in user-friendliness and correctness. Several legacy standard library modules have now <a class="reference internal" href="#whatsnew313-pep594">been removed</a> following their deprecation in Python 3.11 (<span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a>).</p> <p>This article doesn’t attempt to provide a complete specification of all new features, but instead gives a convenient overview. For full details refer to the documentation, such as the <a class="reference internal" href="../library/index.html#library-index"><span class="std std-ref">Library Reference</span></a> and <a class="reference internal" href="../reference/index.html#reference-index"><span class="std std-ref">Language Reference</span></a>. To understand the complete implementation and design rationale for a change, refer to the PEP for a particular new feature; but note that PEPs usually are not kept up-to-date once a feature has been fully implemented. See <a class="reference internal" href="#porting-to-python-3-13">Porting to Python 3.13</a> for guidance on upgrading from earlier versions of Python.</p> <hr class="docutils" /> <p>Interpreter improvements:</p> <ul class="simple"> <li><p>A greatly improved <a class="reference internal" href="#whatsnew313-better-interactive-interpreter"><span class="std std-ref">interactive interpreter</span></a> and <a class="reference internal" href="#whatsnew313-improved-error-messages"><span class="std std-ref">improved error messages</span></a>.</p></li> <li><p><span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0667/"><strong>PEP 667</strong></a>: The <a class="reference internal" href="../library/functions.html#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> builtin now has <a class="reference internal" href="#whatsnew313-locals-semantics"><span class="std std-ref">defined semantics</span></a> when mutating the returned mapping. Python debuggers and similar tools may now more reliably update local variables in optimized scopes even during concurrent code execution.</p></li> <li><p><span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0703/"><strong>PEP 703</strong></a>: CPython 3.13 has experimental support for running with the <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">global interpreter lock</span></a> disabled. See <a class="reference internal" href="#whatsnew313-free-threaded-cpython"><span class="std std-ref">Free-threaded CPython</span></a> for more details.</p></li> <li><p><span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0744/"><strong>PEP 744</strong></a>: A basic <a class="reference internal" href="#whatsnew313-jit-compiler"><span class="std std-ref">JIT compiler</span></a> was added. It is currently disabled by default (though we may turn it on later). Performance improvements are modest – we expect to improve this over the next few releases.</p></li> <li><p>Color support in the new <a class="reference internal" href="#whatsnew313-better-interactive-interpreter"><span class="std std-ref">interactive interpreter</span></a>, as well as in <a class="reference internal" href="#whatsnew313-improved-error-messages"><span class="std std-ref">tracebacks</span></a> and <a class="reference internal" href="#whatsnew313-doctest"><span class="std std-ref">doctest</span></a> output. This can be disabled through the <span class="target" id="index-7"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_COLORS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_COLORS</span></code></a> and <a class="reference external" href="https://no-color.org/"><code class="docutils literal notranslate"><span class="pre">NO_COLOR</span></code></a> environment variables.</p></li> </ul> <p>Python data model improvements:</p> <ul class="simple"> <li><p><a class="reference internal" href="../reference/datamodel.html#type.__static_attributes__" title="type.__static_attributes__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__static_attributes__</span></code></a> stores the names of attributes accessed through <code class="docutils literal notranslate"><span class="pre">self.X</span></code> in any function in a class body.</p></li> <li><p><a class="reference internal" href="../reference/datamodel.html#type.__firstlineno__" title="type.__firstlineno__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__firstlineno__</span></code></a> records the first line number of a class definition.</p></li> </ul> <p>Significant improvements in the standard library:</p> <ul class="simple"> <li><p>Add a new <a class="reference internal" href="../library/exceptions.html#PythonFinalizationError" title="PythonFinalizationError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PythonFinalizationError</span></code></a> exception, raised when an operation is blocked during <a class="reference internal" href="../glossary.html#term-interpreter-shutdown"><span class="xref std std-term">finalization</span></a>.</p></li> <li><p>The <a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a> module now supports deprecating command-line options, positional arguments, and subcommands.</p></li> <li><p>The new functions <a class="reference internal" href="../library/base64.html#base64.z85encode" title="base64.z85encode"><code class="xref py py-func docutils literal notranslate"><span class="pre">base64.z85encode()</span></code></a> and <a class="reference internal" href="../library/base64.html#base64.z85decode" title="base64.z85decode"><code class="xref py py-func docutils literal notranslate"><span class="pre">base64.z85decode()</span></code></a> support encoding and decoding <a class="reference external" href="https://rfc.zeromq.org/spec/32/">Z85 data</a>.</p></li> <li><p>The <a class="reference internal" href="../library/copy.html#module-copy" title="copy: Shallow and deep copy operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">copy</span></code></a> module now has a <a class="reference internal" href="../library/copy.html#copy.replace" title="copy.replace"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy.replace()</span></code></a> function, with support for many builtin types and any class defining the <a class="reference internal" href="../library/copy.html#object.__replace__" title="object.__replace__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__replace__()</span></code></a> method.</p></li> <li><p>The new <a class="reference internal" href="../library/dbm.html#module-dbm.sqlite3" title="dbm.sqlite3: SQLite backend for dbm (All)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.sqlite3</span></code></a> module is now the default <a class="reference internal" href="../library/dbm.html#module-dbm" title="dbm: Interfaces to various Unix "database" formats."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm</span></code></a> backend.</p></li> <li><p>The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module has a <a class="reference internal" href="../library/os.html#os-timerfd"><span class="std std-ref">suite of new functions</span></a> for working with Linux’s timer notification file descriptors.</p></li> <li><p>The <a class="reference internal" href="../library/random.html#module-random" title="random: Generate pseudo-random numbers with various common distributions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">random</span></code></a> module now has a <a class="reference internal" href="../library/random.html#random-cli"><span class="std std-ref">command-line interface</span></a>.</p></li> </ul> <p>Security improvements:</p> <ul class="simple"> <li><p><a class="reference internal" href="../library/ssl.html#ssl.create_default_context" title="ssl.create_default_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.create_default_context()</span></code></a> sets <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_X509_PARTIAL_CHAIN" title="ssl.VERIFY_X509_PARTIAL_CHAIN"><code class="xref py py-data docutils literal notranslate"><span class="pre">ssl.VERIFY_X509_PARTIAL_CHAIN</span></code></a> and <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_X509_STRICT" title="ssl.VERIFY_X509_STRICT"><code class="xref py py-data docutils literal notranslate"><span class="pre">ssl.VERIFY_X509_STRICT</span></code></a> as default flags.</p></li> </ul> <p>C API improvements:</p> <ul class="simple"> <li><p>The <a class="reference internal" href="../c-api/module.html#c.Py_mod_gil" title="Py_mod_gil"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_mod_gil</span></code></a> slot is now used to indicate that an extension module supports running with the <a class="reference internal" href="../glossary.html#term-GIL"><span class="xref std std-term">GIL</span></a> disabled.</p></li> <li><p>The <a class="reference internal" href="../c-api/time.html"><span class="doc">PyTime C API</span></a> has been added, providing access to system clocks.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.PyMutex" title="PyMutex"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyMutex</span></code></a> is a new lightweight mutex that occupies a single byte.</p></li> <li><p>There is a new <a class="reference internal" href="../c-api/monitoring.html#c-api-monitoring"><span class="std std-ref">suite of functions</span></a> for generating <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0669/"><strong>PEP 669</strong></a> monitoring events in the C API.</p></li> </ul> <p>New typing features:</p> <ul class="simple"> <li><p><span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0696/"><strong>PEP 696</strong></a>: Type parameters (<a class="reference internal" href="../library/typing.html#typing.TypeVar" title="typing.TypeVar"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.TypeVar</span></code></a>, <a class="reference internal" href="../library/typing.html#typing.ParamSpec" title="typing.ParamSpec"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.ParamSpec</span></code></a>, and <a class="reference internal" href="../library/typing.html#typing.TypeVarTuple" title="typing.TypeVarTuple"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.TypeVarTuple</span></code></a>) now support defaults.</p></li> <li><p><span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0702/"><strong>PEP 702</strong></a>: The new <a class="reference internal" href="../library/warnings.html#warnings.deprecated" title="warnings.deprecated"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.deprecated()</span></code></a> decorator adds support for marking deprecations in the type system and at runtime.</p></li> <li><p><span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0705/"><strong>PEP 705</strong></a>: <a class="reference internal" href="../library/typing.html#typing.ReadOnly" title="typing.ReadOnly"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.ReadOnly</span></code></a> can be used to mark an item of a <a class="reference internal" href="../library/typing.html#typing.TypedDict" title="typing.TypedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.TypedDict</span></code></a> as read-only for type checkers.</p></li> <li><p><span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0742/"><strong>PEP 742</strong></a>: <a class="reference internal" href="../library/typing.html#typing.TypeIs" title="typing.TypeIs"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.TypeIs</span></code></a> provides more intuitive type narrowing behavior, as an alternative to <a class="reference internal" href="../library/typing.html#typing.TypeGuard" title="typing.TypeGuard"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.TypeGuard</span></code></a>.</p></li> </ul> <p>Platform support:</p> <ul class="simple"> <li><p><span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0730/"><strong>PEP 730</strong></a>: Apple’s iOS is now an <a class="reference internal" href="#whatsnew313-platform-support"><span class="std std-ref">officially supported platform</span></a>, at <span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/#tier-3"><strong>tier 3</strong></a>.</p></li> <li><p><span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0738/"><strong>PEP 738</strong></a>: Android is now an <a class="reference internal" href="#whatsnew313-platform-support"><span class="std std-ref">officially supported platform</span></a>, at <span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/#tier-3"><strong>tier 3</strong></a>.</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">wasm32-wasi</span></code> is now supported as a <span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/#tier-2"><strong>tier 2</strong></a> platform.</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">wasm32-emscripten</span></code> is no longer an officially supported platform.</p></li> </ul> <p>Important removals:</p> <ul class="simple"> <li><p><a class="reference internal" href="#whatsnew313-pep594"><span class="std std-ref">PEP 594</span></a>: The remaining 19 “dead batteries” (legacy stdlib modules) have been removed from the standard library: <code class="xref py py-mod docutils literal notranslate"><span class="pre">aifc</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">cgi</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">cgitb</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">chunk</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">crypt</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">imghdr</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">mailcap</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">msilib</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">nis</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">nntplib</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">sndhdr</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">spwd</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">telnetlib</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">uu</span></code> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">xdrlib</span></code>.</p></li> <li><p>Remove the <strong class="program">2to3</strong> tool and <code class="xref py py-mod docutils literal notranslate"><span class="pre">lib2to3</span></code> module (deprecated in Python 3.11).</p></li> <li><p>Remove the <code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.tix</span></code> module (deprecated in Python 3.6).</p></li> <li><p>Remove the <code class="xref py py-func docutils literal notranslate"><span class="pre">locale.resetlocale()</span></code> function.</p></li> <li><p>Remove the <code class="xref py py-mod docutils literal notranslate"><span class="pre">typing.io</span></code> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">typing.re</span></code> namespaces.</p></li> <li><p>Remove chained <a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">classmethod</span></code></a> descriptors.</p></li> </ul> <p>Release schedule changes:</p> <p><span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0602/"><strong>PEP 602</strong></a> (“Annual Release Cycle for Python”) has been updated to extend the full support (‘bugfix’) period for new releases to two years. This updated policy means that:</p> <ul class="simple"> <li><p>Python 3.9–3.12 have one and a half years of full support, followed by three and a half years of security fixes.</p></li> <li><p>Python 3.13 and later have two years of full support, followed by three years of security fixes.</p></li> </ul> </section> <section id="new-features"> <h2>New Features<a class="headerlink" href="#new-features" title="Link to this heading">¶</a></h2> <section id="a-better-interactive-interpreter"> <span id="whatsnew313-better-interactive-interpreter"></span><h3>A better interactive interpreter<a class="headerlink" href="#a-better-interactive-interpreter" title="Link to this heading">¶</a></h3> <p>Python now uses a new <a class="reference internal" href="../glossary.html#term-interactive"><span class="xref std std-term">interactive</span></a> shell by default, based on code from the <a class="reference external" href="https://pypy.org/">PyPy project</a>. When the user starts the <a class="reference internal" href="../glossary.html#term-REPL"><span class="xref std std-term">REPL</span></a> from an interactive terminal, the following new features are now supported:</p> <ul class="simple"> <li><p>Multiline editing with history preservation.</p></li> <li><p>Direct support for REPL-specific commands like <kbd class="kbd docutils literal notranslate">help</kbd>, <kbd class="kbd docutils literal notranslate">exit</kbd>, and <kbd class="kbd docutils literal notranslate">quit</kbd>, without the need to call them as functions.</p></li> <li><p>Prompts and tracebacks with <a class="reference internal" href="../using/cmdline.html#using-on-controlling-color"><span class="std std-ref">color enabled by default</span></a>.</p></li> <li><p>Interactive help browsing using <kbd class="kbd docutils literal notranslate">F1</kbd> with a separate command history.</p></li> <li><p>History browsing using <kbd class="kbd docutils literal notranslate">F2</kbd> that skips output as well as the <a class="reference internal" href="../glossary.html#term-0"><span class="xref std std-term">>>></span></a> and <a class="reference internal" href="../glossary.html#term-..."><span class="xref std std-term">…</span></a> prompts.</p></li> <li><p>“Paste mode” with <kbd class="kbd docutils literal notranslate">F3</kbd> that makes pasting larger blocks of code easier (press <kbd class="kbd docutils literal notranslate">F3</kbd> again to return to the regular prompt).</p></li> </ul> <p>To disable the new interactive shell, set the <span class="target" id="index-19"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_BASIC_REPL"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_BASIC_REPL</span></code></a> environment variable. For more on interactive mode, see <a class="reference internal" href="../tutorial/appendix.html#tut-interac"><span class="std std-ref">Interactive Mode</span></a>.</p> <p>(Contributed by Pablo Galindo Salgado, Łukasz Langa, and Lysandros Nikolaou in <a class="reference external" href="https://github.com/python/cpython/issues/111201">gh-111201</a> based on code from the PyPy project. Windows support contributed by Dino Viehland and Anthony Shaw.)</p> </section> <section id="improved-error-messages"> <span id="whatsnew313-improved-error-messages"></span><h3>Improved error messages<a class="headerlink" href="#improved-error-messages" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>The interpreter now uses color by default when displaying tracebacks in the terminal. This feature <a class="reference internal" href="../using/cmdline.html#using-on-controlling-color"><span class="std std-ref">can be controlled</span></a> via the new <span class="target" id="index-20"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_COLORS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_COLORS</span></code></a> environment variable as well as the canonical <a class="reference external" href="https://no-color.org/"><code class="docutils literal notranslate"><span class="pre">NO_COLOR</span></code></a> and <a class="reference external" href="https://force-color.org/"><code class="docutils literal notranslate"><span class="pre">FORCE_COLOR</span></code></a> environment variables. (Contributed by Pablo Galindo Salgado in <a class="reference external" href="https://github.com/python/cpython/issues/112730">gh-112730</a>.)</p></li> </ul> <ul> <li><p>A common mistake is to write a script with the same name as a standard library module. When this results in errors, we now display a more helpful error message:</p> <div class="highlight-pytb notranslate"><div class="highlight"><pre><span></span><span class="x">$ python random.py</span> <span class="gt">Traceback (most recent call last):</span> File <span class="nb">"/home/me/random.py"</span>, line <span class="m">1</span>, in <span class="n"><module></span> <span class="w"> </span><span class="kn">import</span> <span class="nn">random</span> File <span class="nb">"/home/me/random.py"</span>, line <span class="m">3</span>, in <span class="n"><module></span> <span class="w"> </span><span class="nb">print</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">5</span><span class="p">))</span> <span class="w"> </span><span class="pm">^^^^^^^^^^^^^^</span> <span class="gr">AttributeError</span>: <span class="n">module 'random' has no attribute 'randint' (consider renaming '/home/me/random.py' since it has the same name as the standard library module named 'random' and prevents importing that standard library module)</span> </pre></div> </div> <p>Similarly, if a script has the same name as a third-party module that it attempts to import and this results in errors, we also display a more helpful error message:</p> <div class="highlight-pytb notranslate"><div class="highlight"><pre><span></span><span class="x">$ python numpy.py</span> <span class="gt">Traceback (most recent call last):</span> File <span class="nb">"/home/me/numpy.py"</span>, line <span class="m">1</span>, in <span class="n"><module></span> <span class="w"> </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> File <span class="nb">"/home/me/numpy.py"</span>, line <span class="m">3</span>, in <span class="n"><module></span> <span class="w"> </span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span> <span class="w"> </span><span class="pm">^^^^^^^^</span> <span class="gr">AttributeError</span>: <span class="n">module 'numpy' has no attribute 'array' (consider renaming '/home/me/numpy.py' if it has the same name as a library you intended to import)</span> </pre></div> </div> <p>(Contributed by Shantanu Jain in <a class="reference external" href="https://github.com/python/cpython/issues/95754">gh-95754</a>.)</p> </li> <li><p>The error message now tries to suggest the correct keyword argument when an incorrect keyword argument is passed to a function.</p> <div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="s2">"Better error messages!"</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">max_split</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> <span class="gt">Traceback (most recent call last):</span> File <span class="nb">"<python-input-0>"</span>, line <span class="m">1</span>, in <span class="n"><module></span> <span class="w"> </span><span class="s2">"Better error messages!"</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">max_split</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> <span class="w"> </span><span class="pm">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^</span> <span class="gr">TypeError</span>: <span class="n">split() got an unexpected keyword argument 'max_split'. Did you mean 'maxsplit'?</span> </pre></div> </div> <p>(Contributed by Pablo Galindo Salgado and Shantanu Jain in <a class="reference external" href="https://github.com/python/cpython/issues/107944">gh-107944</a>.)</p> </li> </ul> </section> <section id="free-threaded-cpython"> <span id="whatsnew313-free-threaded-cpython"></span><h3>Free-threaded CPython<a class="headerlink" href="#free-threaded-cpython" title="Link to this heading">¶</a></h3> <p>CPython now has experimental support for running in a free-threaded mode, with the <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">global interpreter lock</span></a> (GIL) disabled. This is an experimental feature and therefore is not enabled by default. The free-threaded mode requires a different executable, usually called <code class="docutils literal notranslate"><span class="pre">python3.13t</span></code> or <code class="docutils literal notranslate"><span class="pre">python3.13t.exe</span></code>. Pre-built binaries marked as <em>free-threaded</em> can be installed as part of the official <a class="reference internal" href="../using/windows.html#install-freethreaded-windows"><span class="std std-ref">Windows</span></a> and <a class="reference internal" href="../using/mac.html#install-freethreaded-macos"><span class="std std-ref">macOS</span></a> installers, or CPython can be built from source with the <a class="reference internal" href="../using/configure.html#cmdoption-disable-gil"><code class="xref std std-option docutils literal notranslate"><span class="pre">--disable-gil</span></code></a> option.</p> <p>Free-threaded execution allows for full utilization of the available processing power by running threads in parallel on available CPU cores. While not all software will benefit from this automatically, programs designed with threading in mind will run faster on multi-core hardware. <strong>The free-threaded mode is experimental</strong> and work is ongoing to improve it: expect some bugs and a substantial single-threaded performance hit. Free-threaded builds of CPython support optionally running with the GIL enabled at runtime using the environment variable <span class="target" id="index-21"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_GIL"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_GIL</span></code></a> or the command-line option <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">gil=1</span></code></a>.</p> <p>To check if the current interpreter supports free-threading, <a class="reference internal" href="../using/cmdline.html#cmdoption-V"><code class="xref std std-option docutils literal notranslate"><span class="pre">python</span> <span class="pre">-VV</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.version" title="sys.version"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.version</span></code></a> contain “experimental free-threading build”. The new <code class="xref py py-func docutils literal notranslate"><span class="pre">sys._is_gil_enabled()</span></code> function can be used to check whether the GIL is actually disabled in the running process.</p> <p>C-API extension modules need to be built specifically for the free-threaded build. Extensions that support running with the <a class="reference internal" href="../glossary.html#term-GIL"><span class="xref std std-term">GIL</span></a> disabled should use the <a class="reference internal" href="../c-api/module.html#c.Py_mod_gil" title="Py_mod_gil"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_mod_gil</span></code></a> slot. Extensions using single-phase init should use <a class="reference internal" href="../c-api/module.html#c.PyUnstable_Module_SetGIL" title="PyUnstable_Module_SetGIL"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnstable_Module_SetGIL()</span></code></a> to indicate whether they support running with the GIL disabled. Importing C extensions that don’t use these mechanisms will cause the GIL to be enabled, unless the GIL was explicitly disabled with the <span class="target" id="index-22"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_GIL"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_GIL</span></code></a> environment variable or the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">gil=0</span></code></a> option. pip 24.1 or newer is required to install packages with C extensions in the free-threaded build.</p> <p>This work was made possible thanks to many individuals and organizations, including the large community of contributors to Python and third-party projects to test and enable free-threading support. Notable contributors include: Sam Gross, Ken Jin, Donghee Na, Itamar Oren, Matt Page, Brett Simmers, Dino Viehland, Carl Meyer, Nathan Goldbaum, Ralf Gommers, Lysandros Nikolaou, and many others. Many of these contributors are employed by Meta, which has provided significant engineering resources to support this project.</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><span class="target" id="index-23"></span><a class="pep reference external" href="https://peps.python.org/pep-0703/"><strong>PEP 703</strong></a> “Making the Global Interpreter Lock Optional in CPython” contains rationale and information surrounding this work.</p> <p><a class="reference external" href="https://py-free-threading.github.io/porting/">Porting Extension Modules to Support Free-Threading</a>: A community-maintained porting guide for extension authors.</p> </div> </section> <section id="an-experimental-just-in-time-jit-compiler"> <span id="whatsnew313-jit-compiler"></span><h3>An experimental just-in-time (JIT) compiler<a class="headerlink" href="#an-experimental-just-in-time-jit-compiler" title="Link to this heading">¶</a></h3> <p>When CPython is configured and built using the <code class="xref std std-option docutils literal notranslate"><span class="pre">--enable-experimental-jit</span></code> option, a just-in-time (JIT) compiler is added which may speed up some Python programs. On Windows, use <code class="docutils literal notranslate"><span class="pre">PCbuild/build.bat</span> <span class="pre">--experimental-jit</span></code> to enable the JIT or <code class="docutils literal notranslate"><span class="pre">--experimental-jit-interpreter</span></code> to enable the Tier 2 interpreter. Build requirements and further supporting information <a class="reference external" href="https://github.com/python/cpython/blob/main/Tools/jit/README.md">are contained at</a> <code class="file docutils literal notranslate"><span class="pre">Tools/jit/README.md</span></code>.</p> <p>The <code class="xref std std-option docutils literal notranslate"><span class="pre">--enable-experimental-jit</span></code> option takes these (optional) values, defaulting to <code class="docutils literal notranslate"><span class="pre">yes</span></code> if <code class="xref std std-option docutils literal notranslate"><span class="pre">--enable-experimental-jit</span></code> is present without the optional value.</p> <ul class="simple"> <li><p><code class="docutils literal notranslate"><span class="pre">no</span></code>: Disable the entire Tier 2 and JIT pipeline.</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">yes</span></code>: Enable the JIT. To disable the JIT at runtime, pass the environment variable <code class="docutils literal notranslate"><span class="pre">PYTHON_JIT=0</span></code>.</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">yes-off</span></code>: Build the JIT but disable it by default. To enable the JIT at runtime, pass the environment variable <code class="docutils literal notranslate"><span class="pre">PYTHON_JIT=1</span></code>.</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">interpreter</span></code>: Enable the Tier 2 interpreter but disable the JIT. The interpreter can be disabled by running with <code class="docutils literal notranslate"><span class="pre">PYTHON_JIT=0</span></code>.</p></li> </ul> <p>The internal architecture is roughly as follows:</p> <ul class="simple"> <li><p>We start with specialized <em>Tier 1 bytecode</em>. See <a class="reference internal" href="3.11.html#whatsnew311-pep659"><span class="std std-ref">What’s new in 3.11</span></a> for details.</p></li> <li><p>When the Tier 1 bytecode gets hot enough, it gets translated to a new purely internal intermediate representation (IR), called the <em>Tier 2 IR</em>, and sometimes referred to as micro-ops (“uops”).</p></li> <li><p>The Tier 2 IR uses the same stack-based virtual machine as Tier 1, but the instruction format is better suited to translation to machine code.</p></li> <li><p>We have several optimization passes for Tier 2 IR, which are applied before it is interpreted or translated to machine code.</p></li> <li><p>There is a Tier 2 interpreter, but it is mostly intended for debugging the earlier stages of the optimization pipeline. The Tier 2 interpreter can be enabled by configuring Python with <code class="docutils literal notranslate"><span class="pre">--enable-experimental-jit=interpreter</span></code>.</p></li> <li><p>When the JIT is enabled, the optimized Tier 2 IR is translated to machine code, which is then executed.</p></li> <li><p>The machine code translation process uses a technique called <em>copy-and-patch</em>. It has no runtime dependencies, but there is a new build-time dependency on LLVM.</p></li> </ul> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0744/"><strong>PEP 744</strong></a></p> </div> <p>(JIT by Brandt Bucher, inspired by a paper by Haoran Xu and Fredrik Kjolstad. Tier 2 IR by Mark Shannon and Guido van Rossum. Tier 2 optimizer by Ken Jin.)</p> </section> <section id="defined-mutation-semantics-for-locals"> <span id="whatsnew313-locals-semantics"></span><h3>Defined mutation semantics for <a class="reference internal" href="../library/functions.html#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a><a class="headerlink" href="#defined-mutation-semantics-for-locals" title="Link to this heading">¶</a></h3> <p>Historically, the expected result of mutating the return value of <a class="reference internal" href="../library/functions.html#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> has been left to individual Python implementations to define. Starting from Python 3.13, <span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-0667/"><strong>PEP 667</strong></a> standardises the historical behavior of CPython for most code execution scopes, but changes <a class="reference internal" href="../glossary.html#term-optimized-scope"><span class="xref std std-term">optimized scopes</span></a> (functions, generators, coroutines, comprehensions, and generator expressions) to explicitly return independent snapshots of the currently assigned local variables, including locally referenced nonlocal variables captured in closures.</p> <p>This change to the semantics of <a class="reference internal" href="../library/functions.html#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> in optimized scopes also affects the default behavior of code execution functions that implicitly target <code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code> if no explicit namespace is provided (such as <a class="reference internal" href="../library/functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a> and <a class="reference internal" href="../library/functions.html#eval" title="eval"><code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code></a>). In previous versions, whether or not changes could be accessed by calling <code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code> after calling the code execution function was implementation-dependent. In CPython specifically, such code would typically appear to work as desired, but could sometimes fail in optimized scopes based on other code (including debuggers and code execution tracing tools) potentially resetting the shared snapshot in that scope. Now, the code will always run against an independent snapshot of the local variables in optimized scopes, and hence the changes will never be visible in subsequent calls to <code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code>. To access the changes made in these cases, an explicit namespace reference must now be passed to the relevant function. Alternatively, it may make sense to update affected code to use a higher level code execution API that returns the resulting code execution namespace (e.g. <a class="reference internal" href="../library/runpy.html#runpy.run_path" title="runpy.run_path"><code class="xref py py-func docutils literal notranslate"><span class="pre">runpy.run_path()</span></code></a> when executing Python files from disk).</p> <p>To ensure debuggers and similar tools can reliably update local variables in scopes affected by this change, <a class="reference internal" href="../reference/datamodel.html#frame.f_locals" title="frame.f_locals"><code class="xref py py-attr docutils literal notranslate"><span class="pre">FrameType.f_locals</span></code></a> now returns a write-through proxy to the frame’s local and locally referenced nonlocal variables in these scopes, rather than returning an inconsistently updated shared <code class="docutils literal notranslate"><span class="pre">dict</span></code> instance with undefined runtime semantics.</p> <p>See <span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-0667/"><strong>PEP 667</strong></a> for more details, including related C API changes and deprecations. Porting notes are also provided below for the affected <a class="reference internal" href="#pep667-porting-notes-py"><span class="std std-ref">Python APIs</span></a> and <a class="reference internal" href="#pep667-porting-notes-c"><span class="std std-ref">C APIs</span></a>.</p> <p>(PEP and implementation contributed by Mark Shannon and Tian Gao in <a class="reference external" href="https://github.com/python/cpython/issues/74929">gh-74929</a>. Documentation updates provided by Guido van Rossum and Alyssa Coghlan.)</p> </section> <section id="support-for-mobile-platforms"> <span id="whatsnew313-platform-support"></span><h3>Support for mobile platforms<a class="headerlink" href="#support-for-mobile-platforms" title="Link to this heading">¶</a></h3> <p><span class="target" id="index-27"></span><a class="pep reference external" href="https://peps.python.org/pep-0730/"><strong>PEP 730</strong></a>: iOS is now a <span class="target" id="index-28"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/"><strong>PEP 11</strong></a> supported platform, with the <code class="docutils literal notranslate"><span class="pre">arm64-apple-ios</span></code> and <code class="docutils literal notranslate"><span class="pre">arm64-apple-ios-simulator</span></code> targets at tier 3 (iPhone and iPad devices released after 2013 and the Xcode iOS simulator running on Apple silicon hardware, respectively). <code class="docutils literal notranslate"><span class="pre">x86_64-apple-ios-simulator</span></code> (the Xcode iOS simulator running on older <code class="docutils literal notranslate"><span class="pre">x86_64</span></code> hardware) is not a tier 3 supported platform, but will have best-effort support. (PEP written and implementation contributed by Russell Keith-Magee in <a class="reference external" href="https://github.com/python/cpython/issues/114099">gh-114099</a>.)</p> <p><span class="target" id="index-29"></span><a class="pep reference external" href="https://peps.python.org/pep-0738/"><strong>PEP 738</strong></a>: Android is now a <span class="target" id="index-30"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/"><strong>PEP 11</strong></a> supported platform, with the <code class="docutils literal notranslate"><span class="pre">aarch64-linux-android</span></code> and <code class="docutils literal notranslate"><span class="pre">x86_64-linux-android</span></code> targets at tier 3. The 32-bit targets <code class="docutils literal notranslate"><span class="pre">arm-linux-androideabi</span></code> and <code class="docutils literal notranslate"><span class="pre">i686-linux-android</span></code> are not tier 3 supported platforms, but will have best-effort support. (PEP written and implementation contributed by Malcolm Smith in <a class="reference external" href="https://github.com/python/cpython/issues/116622">gh-116622</a>.)</p> <div class="admonition seealso"> <p class="admonition-title">See also</p> <p><span class="target" id="index-31"></span><a class="pep reference external" href="https://peps.python.org/pep-0730/"><strong>PEP 730</strong></a>, <span class="target" id="index-32"></span><a class="pep reference external" href="https://peps.python.org/pep-0738/"><strong>PEP 738</strong></a></p> </div> </section> </section> <section id="other-language-changes"> <h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading">¶</a></h2> <ul> <li><p>The compiler now strips common leading whitespace from every line in a docstring. This reduces the size of the <a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode cache</span></a> (such as <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files), with reductions in file size of around 5%, for example in <code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlalchemy.orm.session</span></code> from SQLAlchemy 2.0. This change affects tools that use docstrings, such as <a class="reference internal" href="../library/doctest.html#module-doctest" title="doctest: Test pieces of code within docstrings."><code class="xref py py-mod docutils literal notranslate"><span class="pre">doctest</span></code></a>.</p> <div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">spam</span><span class="p">():</span> <span class="gp">... </span><span class="w"> </span><span class="sd">"""</span> <span class="gp">... </span><span class="sd"> This is a docstring with</span> <span class="gp">... </span><span class="sd"> leading whitespace.</span> <span class="gp">...</span> <span class="gp">... </span><span class="sd"> It even has multiple paragraphs!</span> <span class="gp">... </span><span class="sd"> """</span> <span class="gp">...</span> <span class="gp">>>> </span><span class="n">spam</span><span class="o">.</span><span class="vm">__doc__</span> <span class="go">'\nThis is a docstring with\n leading whitespace.\n\nIt even has multiple paragraphs!\n'</span> </pre></div> </div> <p>(Contributed by Inada Naoki in <a class="reference external" href="https://github.com/python/cpython/issues/81283">gh-81283</a>.)</p> </li> <li><p><a class="reference internal" href="../reference/executionmodel.html#annotation-scopes"><span class="std std-ref">Annotation scopes</span></a> within class scopes can now contain lambdas and comprehensions. Comprehensions that are located within class scopes are not inlined into their parent scope.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">C</span><span class="p">[</span><span class="n">T</span><span class="p">]:</span> <span class="nb">type</span> <span class="n">Alias</span> <span class="o">=</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">T</span> </pre></div> </div> <p>(Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/109118">gh-109118</a> and <a class="reference external" href="https://github.com/python/cpython/issues/118160">gh-118160</a>.)</p> </li> <li><p><a class="reference internal" href="../reference/simple_stmts.html#future"><span class="std std-ref">Future statements</span></a> are no longer triggered by relative imports of the <a class="reference internal" href="../library/__future__.html#module-__future__" title="__future__: Future statement definitions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">__future__</span></code></a> module, meaning that statements of the form <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">.__future__</span> <span class="pre">import</span> <span class="pre">...</span></code> are now simply standard relative imports, with no special features activated. (Contributed by Jeremiah Gabriel Pascual in <a class="reference external" href="https://github.com/python/cpython/issues/118216">gh-118216</a>.)</p></li> <li><p><a class="reference internal" href="../reference/simple_stmts.html#global"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">global</span></code></a> declarations are now permitted in <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> blocks when that global is used in the <a class="reference internal" href="../reference/compound_stmts.html#else"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">else</span></code></a> block. Previously this raised an erroneous <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/111123">gh-111123</a>.)</p></li> <li><p>Add <span class="target" id="index-33"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_FROZEN_MODULES"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_FROZEN_MODULES</span></code></a>, a new environment variable that determines whether frozen modules are ignored by the import machinery, equivalent to the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">frozen_modules</span></code></a> command-line option. (Contributed by Yilei Yang in <a class="reference external" href="https://github.com/python/cpython/issues/111374">gh-111374</a>.)</p></li> <li><p>Add <a class="reference internal" href="../howto/perf_profiling.html#perf-profiling"><span class="std std-ref">support for the perf profiler</span></a> working without <a class="reference external" href="https://en.wikipedia.org/wiki/Call_stack">frame pointers</a> through the new environment variable <span class="target" id="index-34"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_PERF_JIT_SUPPORT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_PERF_JIT_SUPPORT</span></code></a> and command-line option <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">perf_jit</span></code></a>. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/118518">gh-118518</a>.)</p></li> <li><p>The location of a <code class="file docutils literal notranslate"><span class="pre">.python_history</span></code> file can be changed via the new <span class="target" id="index-35"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_HISTORY"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_HISTORY</span></code></a> environment variable. (Contributed by Levi Sabah, Zackery Spytz and Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/73965">gh-73965</a>.)</p></li> <li><p>Classes have a new <a class="reference internal" href="../reference/datamodel.html#type.__static_attributes__" title="type.__static_attributes__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__static_attributes__</span></code></a> attribute. This is populated by the compiler with a tuple of the class’s attribute names which are assigned through <code class="docutils literal notranslate"><span class="pre">self.<name></span></code> from any function in its body. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/115775">gh-115775</a>.)</p></li> <li><p>The compiler now creates a <code class="xref py py-attr docutils literal notranslate"><span class="pre">__firstlineno__</span></code> attribute on classes with the line number of the first line of the class definition. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/118465">gh-118465</a>.)</p></li> <li><p>The <a class="reference internal" href="../library/functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a> and <a class="reference internal" href="../library/functions.html#eval" title="eval"><code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code></a> builtins now accept the <em>globals</em> and <em>locals</em> arguments as keywords. (Contributed by Raphael Gaschignard in <a class="reference external" href="https://github.com/python/cpython/issues/105879">gh-105879</a>)</p></li> <li><p>The <a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> builtin now accepts a new flag, <code class="docutils literal notranslate"><span class="pre">ast.PyCF_OPTIMIZED_AST</span></code>, which is similar to <code class="docutils literal notranslate"><span class="pre">ast.PyCF_ONLY_AST</span></code> except that the returned AST is optimized according to the value of the <em>optimize</em> argument. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/108113">gh-108113</a>).</p></li> <li><p>Add a <a class="reference internal" href="../library/functions.html#property.__name__" title="property.__name__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__name__</span></code></a> attribute on <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-class docutils literal notranslate"><span class="pre">property</span></code></a> objects. (Contributed by Eugene Toder in <a class="reference external" href="https://github.com/python/cpython/issues/101860">gh-101860</a>.)</p></li> <li><p>Add <a class="reference internal" href="../library/exceptions.html#PythonFinalizationError" title="PythonFinalizationError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PythonFinalizationError</span></code></a>, a new exception derived from <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> and used to signal when operations are blocked during <a class="reference internal" href="../glossary.html#term-interpreter-shutdown"><span class="xref std std-term">finalization</span></a>. The following callables now raise <code class="xref py py-exc docutils literal notranslate"><span class="pre">PythonFinalizationError</span></code>, instead of <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>:</p> <ul class="simple"> <li><p><a class="reference internal" href="../library/_thread.html#thread.start_new_thread" title="_thread.start_new_thread"><code class="xref py py-func docutils literal notranslate"><span class="pre">_thread.start_new_thread()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/os.html#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fork()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/os.html#os.forkpty" title="os.forkpty"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.forkpty()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a></p></li> </ul> <p>(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/114570">gh-114570</a>.)</p> </li> <li><p>Allow the <em>count</em> argument of <a class="reference internal" href="../library/stdtypes.html#str.replace" title="str.replace"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.replace()</span></code></a> to be a keyword. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/106487">gh-106487</a>.)</p></li> <li><p>Many functions now emit a warning if a boolean value is passed as a file descriptor argument. This can help catch some errors earlier. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/82626">gh-82626</a>.)</p></li> <li><p>Added <code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">mode</span></code> attributes for compressed and archived file-like objects in the <a class="reference internal" href="../library/bz2.html#module-bz2" title="bz2: Interfaces for bzip2 compression and decompression."><code class="xref py py-mod docutils literal notranslate"><span class="pre">bz2</span></code></a>, <a class="reference internal" href="../library/lzma.html#module-lzma" title="lzma: A Python wrapper for the liblzma compression library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">lzma</span></code></a>, <a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a>, and <a class="reference internal" href="../library/zipfile.html#module-zipfile" title="zipfile: Read and write ZIP-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipfile</span></code></a> modules. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/115961">gh-115961</a>.)</p></li> </ul> </section> <section id="new-modules"> <h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading">¶</a></h2> <ul class="simple"> <li><p><a class="reference internal" href="../library/dbm.html#module-dbm.sqlite3" title="dbm.sqlite3: SQLite backend for dbm (All)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.sqlite3</span></code></a>: An SQLite backend for <a class="reference internal" href="../library/dbm.html#module-dbm" title="dbm: Interfaces to various Unix "database" formats."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm</span></code></a>. (Contributed by Raymond Hettinger and Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/100414">gh-100414</a>.)</p></li> </ul> </section> <section id="improved-modules"> <h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading">¶</a></h2> <section id="argparse"> <h3>argparse<a class="headerlink" href="#argparse" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add the <em>deprecated</em> parameter to the <a class="reference internal" href="../library/argparse.html#argparse.ArgumentParser.add_argument" title="argparse.ArgumentParser.add_argument"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_argument()</span></code></a> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">add_parser()</span></code> methods, to enable deprecating command-line options, positional arguments, and subcommands. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/83648">gh-83648</a>.)</p></li> </ul> </section> <section id="array"> <h3>array<a class="headerlink" href="#array" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add the <code class="docutils literal notranslate"><span class="pre">'w'</span></code> type code (<code class="docutils literal notranslate"><span class="pre">Py_UCS4</span></code>) for Unicode characters. It should be used instead of the deprecated <code class="docutils literal notranslate"><span class="pre">'u'</span></code> type code. (Contributed by Inada Naoki in <a class="reference external" href="https://github.com/python/cpython/issues/80480">gh-80480</a>.)</p></li> <li><p>Register <a class="reference internal" href="../library/array.html#array.array" title="array.array"><code class="xref py py-class docutils literal notranslate"><span class="pre">array.array</span></code></a> as a <a class="reference internal" href="../library/collections.abc.html#collections.abc.MutableSequence" title="collections.abc.MutableSequence"><code class="xref py py-class docutils literal notranslate"><span class="pre">MutableSequence</span></code></a> by implementing the <a class="reference internal" href="../library/array.html#array.array.clear" title="array.array.clear"><code class="xref py py-meth docutils literal notranslate"><span class="pre">clear()</span></code></a> method. (Contributed by Mike Zimin in <a class="reference external" href="https://github.com/python/cpython/issues/114894">gh-114894</a>.)</p></li> </ul> </section> <section id="ast"> <h3>ast<a class="headerlink" href="#ast" title="Link to this heading">¶</a></h3> <ul> <li><p>The constructors of node types in the <a class="reference internal" href="../library/ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a> module are now stricter in the arguments they accept, with more intuitive behavior when arguments are omitted.</p> <p>If an optional field on an AST node is not included as an argument when constructing an instance, the field will now be set to <code class="docutils literal notranslate"><span class="pre">None</span></code>. Similarly, if a list field is omitted, that field will now be set to an empty list, and if an <code class="xref py py-class docutils literal notranslate"><span class="pre">expr_context</span></code> field is omitted, it defaults to <a class="reference internal" href="../library/ast.html#ast.Load" title="ast.Load"><code class="xref py py-class docutils literal notranslate"><span class="pre">Load()</span></code></a>. (Previously, in all cases, the attribute would be missing on the newly constructed AST node instance.)</p> <p>In all other cases, where a required argument is omitted, the node constructor will emit a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>. This will raise an exception in Python 3.15. Similarly, passing a keyword argument to the constructor that does not map to a field on the AST node is now deprecated, and will raise an exception in Python 3.15.</p> <p>These changes do not apply to user-defined subclasses of <a class="reference internal" href="../library/ast.html#ast.AST" title="ast.AST"><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.AST</span></code></a> unless the class opts in to the new behavior by defining the <a class="reference internal" href="../library/ast.html#ast.AST._field_types" title="ast.AST._field_types"><code class="xref py py-attr docutils literal notranslate"><span class="pre">AST._field_types</span></code></a> mapping.</p> <p>(Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/105858">gh-105858</a>, <a class="reference external" href="https://github.com/python/cpython/issues/117486">gh-117486</a>, and <a class="reference external" href="https://github.com/python/cpython/issues/118851">gh-118851</a>.)</p> </li> <li><p><a class="reference internal" href="../library/ast.html#ast.parse" title="ast.parse"><code class="xref py py-func docutils literal notranslate"><span class="pre">ast.parse()</span></code></a> now accepts an optional argument <em>optimize</em> which is passed on to <a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a>. This makes it possible to obtain an optimized AST. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/108113">gh-108113</a>.)</p></li> </ul> </section> <section id="asyncio"> <h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading">¶</a></h3> <ul> <li><p><a class="reference internal" href="../library/asyncio-task.html#asyncio.as_completed" title="asyncio.as_completed"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.as_completed()</span></code></a> now returns an object that is both an <a class="reference internal" href="../glossary.html#term-asynchronous-iterator"><span class="xref std std-term">asynchronous iterator</span></a> and a plain <a class="reference internal" href="../glossary.html#term-iterator"><span class="xref std std-term">iterator</span></a> of <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitables</span></a>. The awaitables yielded by asynchronous iteration include original task or future objects that were passed in, making it easier to associate results with the tasks being completed. (Contributed by Justin Arthur in <a class="reference external" href="https://github.com/python/cpython/issues/77714">gh-77714</a>.)</p></li> <li><p><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_unix_server" title="asyncio.loop.create_unix_server"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.create_unix_server()</span></code></a> will now automatically remove the Unix socket when the server is closed. (Contributed by Pierre Ossman in <a class="reference external" href="https://github.com/python/cpython/issues/111246">gh-111246</a>.)</p></li> <li><p><a class="reference internal" href="../library/asyncio-protocol.html#asyncio.DatagramTransport.sendto" title="asyncio.DatagramTransport.sendto"><code class="xref py py-meth docutils literal notranslate"><span class="pre">DatagramTransport.sendto()</span></code></a> will now send zero-length datagrams if called with an empty bytes object. The transport flow control also now accounts for the datagram header when calculating the buffer size. (Contributed by Jamie Phan in <a class="reference external" href="https://github.com/python/cpython/issues/115199">gh-115199</a>.)</p></li> <li><p>Add <a class="reference internal" href="../library/asyncio-queue.html#asyncio.Queue.shutdown" title="asyncio.Queue.shutdown"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Queue.shutdown</span></code></a> and <a class="reference internal" href="../library/asyncio-queue.html#asyncio.QueueShutDown" title="asyncio.QueueShutDown"><code class="xref py py-exc docutils literal notranslate"><span class="pre">QueueShutDown</span></code></a> to manage queue termination. (Contributed by Laurie Opperman and Yves Duprat in <a class="reference external" href="https://github.com/python/cpython/issues/104228">gh-104228</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.Server.close_clients" title="asyncio.Server.close_clients"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Server.close_clients()</span></code></a> and <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.Server.abort_clients" title="asyncio.Server.abort_clients"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Server.abort_clients()</span></code></a> methods, which more forcefully close an asyncio server. (Contributed by Pierre Ossman in <a class="reference external" href="https://github.com/python/cpython/issues/113538">gh-113538</a>.)</p></li> <li><p>Accept a tuple of separators in <a class="reference internal" href="../library/asyncio-stream.html#asyncio.StreamReader.readuntil" title="asyncio.StreamReader.readuntil"><code class="xref py py-meth docutils literal notranslate"><span class="pre">StreamReader.readuntil()</span></code></a>, stopping when any one of them is encountered. (Contributed by Bruce Merry in <a class="reference external" href="https://github.com/python/cpython/issues/81322">gh-81322</a>.)</p></li> <li><p>Improve the behavior of <a class="reference internal" href="../library/asyncio-task.html#asyncio.TaskGroup" title="asyncio.TaskGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">TaskGroup</span></code></a> when an external cancellation collides with an internal cancellation. For example, when two task groups are nested and both experience an exception in a child task simultaneously, it was possible that the outer task group would hang, because its internal cancellation was swallowed by the inner task group.</p> <p>In the case where a task group is cancelled externally and also must raise an <a class="reference internal" href="../library/exceptions.html#ExceptionGroup" title="ExceptionGroup"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExceptionGroup</span></code></a>, it will now call the parent task’s <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.cancel" title="asyncio.Task.cancel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">cancel()</span></code></a> method. This ensures that a <a class="reference internal" href="../library/asyncio-exceptions.html#asyncio.CancelledError" title="asyncio.CancelledError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">CancelledError</span></code></a> will be raised at the next <a class="reference internal" href="../reference/expressions.html#await"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">await</span></code></a>, so the cancellation is not lost.</p> <p>An added benefit of these changes is that task groups now preserve the cancellation count (<a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.cancelling" title="asyncio.Task.cancelling"><code class="xref py py-meth docutils literal notranslate"><span class="pre">cancelling()</span></code></a>).</p> <p>In order to handle some corner cases, <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.uncancel" title="asyncio.Task.uncancel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">uncancel()</span></code></a> may now reset the undocumented <code class="docutils literal notranslate"><span class="pre">_must_cancel</span></code> flag when the cancellation count reaches zero.</p> <p>(Inspired by an issue reported by Arthur Tacca in <a class="reference external" href="https://github.com/python/cpython/issues/116720">gh-116720</a>.)</p> </li> <li><p>When <a class="reference internal" href="../library/asyncio-task.html#asyncio.TaskGroup.create_task" title="asyncio.TaskGroup.create_task"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TaskGroup.create_task()</span></code></a> is called on an inactive <a class="reference internal" href="../library/asyncio-task.html#asyncio.TaskGroup" title="asyncio.TaskGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">TaskGroup</span></code></a>, the given coroutine will be closed (which prevents a <a class="reference internal" href="../library/exceptions.html#RuntimeWarning" title="RuntimeWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeWarning</span></code></a> about the given coroutine being never awaited). (Contributed by Arthur Tacca and Jason Zhang in <a class="reference external" href="https://github.com/python/cpython/issues/115957">gh-115957</a>.)</p></li> </ul> </section> <section id="base64"> <h3>base64<a class="headerlink" href="#base64" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add <a class="reference internal" href="../library/base64.html#base64.z85encode" title="base64.z85encode"><code class="xref py py-func docutils literal notranslate"><span class="pre">z85encode()</span></code></a> and <a class="reference internal" href="../library/base64.html#base64.z85decode" title="base64.z85decode"><code class="xref py py-func docutils literal notranslate"><span class="pre">z85decode()</span></code></a> functions for encoding <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> as <a class="reference external" href="https://rfc.zeromq.org/spec/32/">Z85 data</a> and decoding Z85-encoded data to <code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code>. (Contributed by Matan Perelman in <a class="reference external" href="https://github.com/python/cpython/issues/75299">gh-75299</a>.)</p> </li> </ul> </section> <section id="compileall"> <h3>compileall<a class="headerlink" href="#compileall" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>The default number of worker threads and processes is now selected using <a class="reference internal" href="../library/os.html#os.process_cpu_count" title="os.process_cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.process_cpu_count()</span></code></a> instead of <a class="reference internal" href="../library/os.html#os.cpu_count" title="os.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.cpu_count()</span></code></a>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/109649">gh-109649</a>.)</p></li> </ul> </section> <section id="concurrent-futures"> <h3>concurrent.futures<a class="headerlink" href="#concurrent-futures" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>The default number of worker threads and processes is now selected using <a class="reference internal" href="../library/os.html#os.process_cpu_count" title="os.process_cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.process_cpu_count()</span></code></a> instead of <a class="reference internal" href="../library/os.html#os.cpu_count" title="os.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.cpu_count()</span></code></a>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/109649">gh-109649</a>.)</p></li> </ul> </section> <section id="configparser"> <h3>configparser<a class="headerlink" href="#configparser" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p><a class="reference internal" href="../library/configparser.html#configparser.ConfigParser" title="configparser.ConfigParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">ConfigParser</span></code></a> now has support for unnamed sections, which allows for top-level key-value pairs. This can be enabled with the new <em>allow_unnamed_section</em> parameter. (Contributed by Pedro Sousa Lacerda in <a class="reference external" href="https://github.com/python/cpython/issues/66449">gh-66449</a>.)</p></li> </ul> </section> <section id="copy"> <h3>copy<a class="headerlink" href="#copy" title="Link to this heading">¶</a></h3> <ul> <li><p>The new <a class="reference internal" href="../library/copy.html#copy.replace" title="copy.replace"><code class="xref py py-func docutils literal notranslate"><span class="pre">replace()</span></code></a> function and the <a class="reference internal" href="../library/copy.html#object.__replace__" title="object.__replace__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">replace</span> <span class="pre">protocol</span></code></a> make creating modified copies of objects much simpler. This is especially useful when working with immutable objects. The following types support the <a class="reference internal" href="../library/copy.html#copy.replace" title="copy.replace"><code class="xref py py-func docutils literal notranslate"><span class="pre">replace()</span></code></a> function and implement the replace protocol:</p> <ul class="simple"> <li><p><a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">collections.namedtuple()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/dataclasses.html#dataclasses.dataclass" title="dataclasses.dataclass"><code class="xref py py-class docutils literal notranslate"><span class="pre">dataclasses.dataclass</span></code></a></p></li> <li><p><a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.datetime</span></code></a>, <a class="reference internal" href="../library/datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a>, <a class="reference internal" href="../library/datetime.html#datetime.time" title="datetime.time"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.time</span></code></a></p></li> <li><p><a class="reference internal" href="../library/inspect.html#inspect.Signature" title="inspect.Signature"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.Signature</span></code></a>, <a class="reference internal" href="../library/inspect.html#inspect.Parameter" title="inspect.Parameter"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.Parameter</span></code></a></p></li> <li><p><a class="reference internal" href="../library/types.html#types.SimpleNamespace" title="types.SimpleNamespace"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.SimpleNamespace</span></code></a></p></li> <li><p><a class="reference internal" href="../reference/datamodel.html#code-objects"><span class="std std-ref">code objects</span></a></p></li> </ul> <p>Any user-defined class can also support <a class="reference internal" href="../library/copy.html#copy.replace" title="copy.replace"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy.replace()</span></code></a> by defining the <a class="reference internal" href="../library/copy.html#object.__replace__" title="object.__replace__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__replace__()</span></code></a> method. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/108751">gh-108751</a>.)</p> </li> </ul> </section> <section id="ctypes"> <h3>ctypes<a class="headerlink" href="#ctypes" title="Link to this heading">¶</a></h3> <ul> <li><p>As a consequence of necessary internal refactoring, initialization of internal metaclasses now happens in <code class="docutils literal notranslate"><span class="pre">__init__</span></code> rather than in <code class="docutils literal notranslate"><span class="pre">__new__</span></code>. This affects projects that subclass these internal metaclasses to provide custom initialization. Generally:</p> <ul class="simple"> <li><p>Custom logic that was done in <code class="docutils literal notranslate"><span class="pre">__new__</span></code> after calling <code class="docutils literal notranslate"><span class="pre">super().__new__</span></code> should be moved to <code class="docutils literal notranslate"><span class="pre">__init__</span></code>.</p></li> <li><p>To create a class, call the metaclass, not only the metaclass’s <code class="docutils literal notranslate"><span class="pre">__new__</span></code> method.</p></li> </ul> <p>See <a class="reference external" href="https://github.com/python/cpython/issues/124520">gh-124520</a> for discussion and links to changes in some affected projects.</p> </li> <li><p><a class="reference internal" href="../library/ctypes.html#ctypes.Structure" title="ctypes.Structure"><code class="xref py py-class docutils literal notranslate"><span class="pre">ctypes.Structure</span></code></a> objects have a new <a class="reference internal" href="../library/ctypes.html#ctypes.Structure._align_" title="ctypes.Structure._align_"><code class="xref py py-attr docutils literal notranslate"><span class="pre">_align_</span></code></a> attribute which allows the alignment of the structure being packed to/from memory to be specified explicitly. (Contributed by Matt Sanderson in <a class="reference external" href="https://github.com/python/cpython/issues/112433">gh-112433</a>)</p></li> </ul> </section> <section id="dbm"> <h3>dbm<a class="headerlink" href="#dbm" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add <a class="reference internal" href="../library/dbm.html#module-dbm.sqlite3" title="dbm.sqlite3: SQLite backend for dbm (All)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.sqlite3</span></code></a>, a new module which implements an SQLite backend, and make it the default <code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm</span></code> backend. (Contributed by Raymond Hettinger and Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/100414">gh-100414</a>.)</p></li> <li><p>Allow removing all items from the database through the new <a class="reference internal" href="../library/dbm.html#dbm.gnu.gdbm.clear" title="dbm.gnu.gdbm.clear"><code class="xref py py-meth docutils literal notranslate"><span class="pre">gdbm.clear()</span></code></a> and <a class="reference internal" href="../library/dbm.html#dbm.ndbm.ndbm.clear" title="dbm.ndbm.ndbm.clear"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndbm.clear()</span></code></a> methods. (Contributed by Donghee Na in <a class="reference external" href="https://github.com/python/cpython/issues/107122">gh-107122</a>.)</p></li> </ul> </section> <section id="dis"> <h3>dis<a class="headerlink" href="#dis" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Change the output of <a class="reference internal" href="../library/dis.html#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> module functions to show logical labels for jump targets and exception handlers, rather than offsets. The offsets can be added with the new <a class="reference internal" href="../library/dis.html#cmdoption-dis-O"><code class="xref std std-option docutils literal notranslate"><span class="pre">-O</span></code></a> command-line option or the <em>show_offsets</em> argument. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/112137">gh-112137</a>.)</p></li> <li><p><a class="reference internal" href="../library/dis.html#dis.get_instructions" title="dis.get_instructions"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_instructions()</span></code></a> no longer represents cache entries as separate instructions. Instead, it returns them as part of the <a class="reference internal" href="../library/dis.html#dis.Instruction" title="dis.Instruction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Instruction</span></code></a>, in the new <em>cache_info</em> field. The <em>show_caches</em> argument to <a class="reference internal" href="../library/dis.html#dis.get_instructions" title="dis.get_instructions"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_instructions()</span></code></a> is deprecated and no longer has any effect. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/112962">gh-112962</a>.)</p></li> </ul> </section> <section id="doctest"> <span id="whatsnew313-doctest"></span><h3>doctest<a class="headerlink" href="#doctest" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p><a class="reference internal" href="../library/doctest.html#module-doctest" title="doctest: Test pieces of code within docstrings."><code class="xref py py-mod docutils literal notranslate"><span class="pre">doctest</span></code></a> output is now colored by default. This can be controlled via the new <span class="target" id="index-36"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_COLORS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_COLORS</span></code></a> environment variable as well as the canonical <a class="reference external" href="https://no-color.org/"><code class="docutils literal notranslate"><span class="pre">NO_COLOR</span></code></a> and <a class="reference external" href="https://force-color.org/"><code class="docutils literal notranslate"><span class="pre">FORCE_COLOR</span></code></a> environment variables. See also <a class="reference internal" href="../using/cmdline.html#using-on-controlling-color"><span class="std std-ref">Controlling color</span></a>. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/117225">gh-117225</a>.)</p></li> <li><p>The <a class="reference internal" href="../library/doctest.html#doctest.DocTestRunner.run" title="doctest.DocTestRunner.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">DocTestRunner.run()</span></code></a> method now counts the number of skipped tests. Add the <a class="reference internal" href="../library/doctest.html#doctest.DocTestRunner.skips" title="doctest.DocTestRunner.skips"><code class="xref py py-attr docutils literal notranslate"><span class="pre">DocTestRunner.skips</span></code></a> and <a class="reference internal" href="../library/doctest.html#doctest.TestResults.skipped" title="doctest.TestResults.skipped"><code class="xref py py-attr docutils literal notranslate"><span class="pre">TestResults.skipped</span></code></a> attributes. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/108794">gh-108794</a>.)</p></li> </ul> </section> <section id="email"> <h3>email<a class="headerlink" href="#email" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Headers with embedded newlines are now quoted on output. The <a class="reference internal" href="../library/email.generator.html#module-email.generator" title="email.generator: Generate flat text email messages from a message structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">generator</span></code></a> will now refuse to serialize (write) headers that are improperly folded or delimited, such that they would be parsed as multiple headers or joined with adjacent data. If you need to turn this safety feature off, set <a class="reference internal" href="../library/email.policy.html#email.policy.Policy.verify_generated_headers" title="email.policy.Policy.verify_generated_headers"><code class="xref py py-attr docutils literal notranslate"><span class="pre">verify_generated_headers</span></code></a>. (Contributed by Bas Bloemsaat and Petr Viktorin in <a class="reference external" href="https://github.com/python/cpython/issues/121650">gh-121650</a>.)</p></li> <li><p><a class="reference internal" href="../library/email.utils.html#email.utils.getaddresses" title="email.utils.getaddresses"><code class="xref py py-func docutils literal notranslate"><span class="pre">getaddresses()</span></code></a> and <a class="reference internal" href="../library/email.utils.html#email.utils.parseaddr" title="email.utils.parseaddr"><code class="xref py py-func docutils literal notranslate"><span class="pre">parseaddr()</span></code></a> now return <code class="docutils literal notranslate"><span class="pre">('',</span> <span class="pre">'')</span></code> pairs in more situations where invalid email addresses are encountered instead of potentially inaccurate values. The two functions have a new optional <em>strict</em> parameter (default <code class="docutils literal notranslate"><span class="pre">True</span></code>). To get the old behavior (accepting malformed input), use <code class="docutils literal notranslate"><span class="pre">strict=False</span></code>. <code class="docutils literal notranslate"><span class="pre">getattr(email.utils,</span> <span class="pre">'supports_strict_parsing',</span> <span class="pre">False)</span></code> can be used to check if the <em>strict</em> parameter is available. (Contributed by Thomas Dwyer and Victor Stinner for <a class="reference external" href="https://github.com/python/cpython/issues/102988">gh-102988</a> to improve the <span class="target" id="index-37"></span><a class="cve reference external" href="https://www.cve.org/CVERecord?id=CVE-2023-27043"><strong>CVE 2023-27043</strong></a> fix.)</p></li> </ul> </section> <section id="fractions"> <h3>fractions<a class="headerlink" href="#fractions" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p><a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> objects now support the standard <a class="reference internal" href="../library/string.html#formatspec"><span class="std std-ref">format specification mini-language</span></a> rules for fill, alignment, sign handling, minimum width, and grouping. (Contributed by Mark Dickinson in <a class="reference external" href="https://github.com/python/cpython/issues/111320">gh-111320</a>.)</p></li> </ul> </section> <section id="glob"> <h3>glob<a class="headerlink" href="#glob" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add <a class="reference internal" href="../library/glob.html#glob.translate" title="glob.translate"><code class="xref py py-func docutils literal notranslate"><span class="pre">translate()</span></code></a>, a function to convert a path specification with shell-style wildcards to a regular expression. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/72904">gh-72904</a>.)</p></li> </ul> </section> <section id="importlib"> <h3>importlib<a class="headerlink" href="#importlib" title="Link to this heading">¶</a></h3> <ul> <li><p>The following functions in <a class="reference internal" href="../library/importlib.resources.html#module-importlib.resources" title="importlib.resources: Package resource reading, opening, and access"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources</span></code></a> now allow accessing a directory (or tree) of resources, using multiple positional arguments (the <em>encoding</em> and <em>errors</em> arguments in the text-reading functions are now keyword-only):</p> <ul class="simple"> <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.is_resource" title="importlib.resources.is_resource"><code class="xref py py-func docutils literal notranslate"><span class="pre">is_resource()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.open_binary" title="importlib.resources.open_binary"><code class="xref py py-func docutils literal notranslate"><span class="pre">open_binary()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.open_text" title="importlib.resources.open_text"><code class="xref py py-func docutils literal notranslate"><span class="pre">open_text()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.path" title="importlib.resources.path"><code class="xref py py-func docutils literal notranslate"><span class="pre">path()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.read_binary" title="importlib.resources.read_binary"><code class="xref py py-func docutils literal notranslate"><span class="pre">read_binary()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.read_text" title="importlib.resources.read_text"><code class="xref py py-func docutils literal notranslate"><span class="pre">read_text()</span></code></a></p></li> </ul> <p>These functions are no longer deprecated and are not scheduled for removal. (Contributed by Petr Viktorin in <a class="reference external" href="https://github.com/python/cpython/issues/116608">gh-116608</a>.)</p> </li> <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.contents" title="importlib.resources.contents"><code class="xref py py-func docutils literal notranslate"><span class="pre">contents()</span></code></a> remains deprecated in favor of the fully-featured <a class="reference internal" href="../library/importlib.resources.abc.html#importlib.resources.abc.Traversable" title="importlib.resources.abc.Traversable"><code class="xref py py-class docutils literal notranslate"><span class="pre">Traversable</span></code></a> API. However, there is now no plan to remove it. (Contributed by Petr Viktorin in <a class="reference external" href="https://github.com/python/cpython/issues/116608">gh-116608</a>.)</p></li> </ul> </section> <section id="io"> <h3>io<a class="headerlink" href="#io" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>The <a class="reference internal" href="../library/io.html#io.IOBase" title="io.IOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">IOBase</span></code></a> finalizer now logs any errors raised by the <a class="reference internal" href="../library/io.html#io.IOBase.close" title="io.IOBase.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> method with <a class="reference internal" href="../library/sys.html#sys.unraisablehook" title="sys.unraisablehook"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.unraisablehook</span></code></a>. Previously, errors were ignored silently by default, and only logged in <a class="reference internal" href="../library/devmode.html#devmode"><span class="std std-ref">Python Development Mode</span></a> or when using a <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">Python debug build</span></a>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/62948">gh-62948</a>.)</p></li> </ul> </section> <section id="ipaddress"> <h3>ipaddress<a class="headerlink" href="#ipaddress" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add the <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Address.ipv6_mapped" title="ipaddress.IPv4Address.ipv6_mapped"><code class="xref py py-attr docutils literal notranslate"><span class="pre">IPv4Address.ipv6_mapped</span></code></a> property, which returns the IPv4-mapped IPv6 address. (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/109466">gh-109466</a>.)</p></li> <li><p>Fix <code class="docutils literal notranslate"><span class="pre">is_global</span></code> and <code class="docutils literal notranslate"><span class="pre">is_private</span></code> behavior in <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Address" title="ipaddress.IPv4Address"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv4Address</span></code></a>, <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Address" title="ipaddress.IPv6Address"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv6Address</span></code></a>, <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv4Network</span></code></a>, and <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv6Network</span></code></a>. (Contributed by Jakub Stasiak in <a class="reference external" href="https://github.com/python/cpython/issues/113171">gh-113171</a>.)</p></li> </ul> </section> <section id="itertools"> <h3>itertools<a class="headerlink" href="#itertools" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p><a class="reference internal" href="../library/itertools.html#itertools.batched" title="itertools.batched"><code class="xref py py-func docutils literal notranslate"><span class="pre">batched()</span></code></a> has a new <em>strict</em> parameter, which raises a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> if the final batch is shorter than the specified batch size. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/113202">gh-113202</a>.)</p></li> </ul> </section> <section id="marshal"> <h3>marshal<a class="headerlink" href="#marshal" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add the <em>allow_code</em> parameter in module functions. Passing <code class="docutils literal notranslate"><span class="pre">allow_code=False</span></code> prevents serialization and de-serialization of code objects which are incompatible between Python versions. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/113626">gh-113626</a>.)</p></li> </ul> </section> <section id="math"> <h3>math<a class="headerlink" href="#math" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>The new function <a class="reference internal" href="../library/math.html#math.fma" title="math.fma"><code class="xref py py-func docutils literal notranslate"><span class="pre">fma()</span></code></a> performs fused multiply-add operations. This computes <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">*</span> <span class="pre">y</span> <span class="pre">+</span> <span class="pre">z</span></code> with only a single round, and so avoids any intermediate loss of precision. It wraps the <code class="docutils literal notranslate"><span class="pre">fma()</span></code> function provided by C99, and follows the specification of the IEEE 754 “fusedMultiplyAdd” operation for special cases. (Contributed by Mark Dickinson and Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/73468">gh-73468</a>.)</p></li> </ul> </section> <section id="mimetypes"> <h3>mimetypes<a class="headerlink" href="#mimetypes" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add the <a class="reference internal" href="../library/mimetypes.html#mimetypes.guess_file_type" title="mimetypes.guess_file_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_file_type()</span></code></a> function to guess a MIME type from a filesystem path. Using paths with <a class="reference internal" href="../library/mimetypes.html#mimetypes.guess_type" title="mimetypes.guess_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_type()</span></code></a> is now <a class="reference internal" href="../glossary.html#term-soft-deprecated"><span class="xref std std-term">soft deprecated</span></a>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/66543">gh-66543</a>.)</p></li> </ul> </section> <section id="mmap"> <h3>mmap<a class="headerlink" href="#mmap" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p><a class="reference internal" href="../library/mmap.html#mmap.mmap" title="mmap.mmap"><code class="xref py py-class docutils literal notranslate"><span class="pre">mmap</span></code></a> is now protected from crashing on Windows when the mapped memory is inaccessible due to file system errors or access violations. (Contributed by Jannis Weigend in <a class="reference external" href="https://github.com/python/cpython/issues/118209">gh-118209</a>.)</p></li> <li><p><a class="reference internal" href="../library/mmap.html#mmap.mmap" title="mmap.mmap"><code class="xref py py-class docutils literal notranslate"><span class="pre">mmap</span></code></a> has a new <a class="reference internal" href="../library/mmap.html#mmap.mmap.seekable" title="mmap.mmap.seekable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">seekable()</span></code></a> method that can be used when a seekable file-like object is required. The <a class="reference internal" href="../library/mmap.html#mmap.mmap.seek" title="mmap.mmap.seek"><code class="xref py py-meth docutils literal notranslate"><span class="pre">seek()</span></code></a> method now returns the new absolute position. (Contributed by Donghee Na and Sylvie Liberman in <a class="reference external" href="https://github.com/python/cpython/issues/111835">gh-111835</a>.)</p></li> <li><p>The new UNIX-only <em>trackfd</em> parameter for <a class="reference internal" href="../library/mmap.html#mmap.mmap" title="mmap.mmap"><code class="xref py py-class docutils literal notranslate"><span class="pre">mmap</span></code></a> controls file descriptor duplication; if false, the file descriptor specified by <em>fileno</em> will not be duplicated. (Contributed by Zackery Spytz and Petr Viktorin in <a class="reference external" href="https://github.com/python/cpython/issues/78502">gh-78502</a>.)</p></li> </ul> </section> <section id="multiprocessing"> <h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>The default number of worker threads and processes is now selected using <a class="reference internal" href="../library/os.html#os.process_cpu_count" title="os.process_cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.process_cpu_count()</span></code></a> instead of <a class="reference internal" href="../library/os.html#os.cpu_count" title="os.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.cpu_count()</span></code></a>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/109649">gh-109649</a>.)</p></li> </ul> </section> <section id="os"> <h3>os<a class="headerlink" href="#os" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add <a class="reference internal" href="../library/os.html#os.process_cpu_count" title="os.process_cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">process_cpu_count()</span></code></a> function to get the number of logical CPU cores usable by the calling thread of the current process. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/109649">gh-109649</a>.)</p></li> <li><p><a class="reference internal" href="../library/os.html#os.cpu_count" title="os.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">cpu_count()</span></code></a> and <a class="reference internal" href="../library/os.html#os.process_cpu_count" title="os.process_cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">process_cpu_count()</span></code></a> can be overridden through the new environment variable <span class="target" id="index-38"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHON_CPU_COUNT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON_CPU_COUNT</span></code></a> or the new command-line option <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">cpu_count</span></code></a>. This option is useful for users who need to limit CPU resources of a container system without having to modify application code or the container itself. (Contributed by Donghee Na in <a class="reference external" href="https://github.com/python/cpython/issues/109595">gh-109595</a>.)</p></li> <li><p>Add a <a class="reference internal" href="../library/os.html#os-timerfd"><span class="std std-ref">low level interface</span></a> to Linux’s <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/timerfd_create(2)">timer file descriptors</a></em> via <a class="reference internal" href="../library/os.html#os.timerfd_create" title="os.timerfd_create"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_create()</span></code></a>, <a class="reference internal" href="../library/os.html#os.timerfd_settime" title="os.timerfd_settime"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_settime()</span></code></a>, <a class="reference internal" href="../library/os.html#os.timerfd_settime_ns" title="os.timerfd_settime_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_settime_ns()</span></code></a>, <a class="reference internal" href="../library/os.html#os.timerfd_gettime" title="os.timerfd_gettime"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_gettime()</span></code></a>, <a class="reference internal" href="../library/os.html#os.timerfd_gettime_ns" title="os.timerfd_gettime_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">timerfd_gettime_ns()</span></code></a>, <a class="reference internal" href="../library/os.html#os.TFD_NONBLOCK" title="os.TFD_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_NONBLOCK</span></code></a>, <a class="reference internal" href="../library/os.html#os.TFD_CLOEXEC" title="os.TFD_CLOEXEC"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_CLOEXEC</span></code></a>, <a class="reference internal" href="../library/os.html#os.TFD_TIMER_ABSTIME" title="os.TFD_TIMER_ABSTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_TIMER_ABSTIME</span></code></a>, and <a class="reference internal" href="../library/os.html#os.TFD_TIMER_CANCEL_ON_SET" title="os.TFD_TIMER_CANCEL_ON_SET"><code class="xref py py-const docutils literal notranslate"><span class="pre">TFD_TIMER_CANCEL_ON_SET</span></code></a> (Contributed by Masaru Tsuchiyama in <a class="reference external" href="https://github.com/python/cpython/issues/108277">gh-108277</a>.)</p></li> <li><p><a class="reference internal" href="../library/os.html#os.lchmod" title="os.lchmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">lchmod()</span></code></a> and the <em>follow_symlinks</em> argument of <a class="reference internal" href="../library/os.html#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">chmod()</span></code></a> are both now available on Windows. Note that the default value of <em>follow_symlinks</em> in <code class="xref py py-func docutils literal notranslate"><span class="pre">lchmod()</span></code> is <code class="docutils literal notranslate"><span class="pre">False</span></code> on Windows. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/59616">gh-59616</a>.)</p></li> <li><p><a class="reference internal" href="../library/os.html#os.fchmod" title="os.fchmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">fchmod()</span></code></a> and support for file descriptors in <a class="reference internal" href="../library/os.html#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">chmod()</span></code></a> are both now available on Windows. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/113191">gh-113191</a>.)</p></li> <li><p>On Windows, <a class="reference internal" href="../library/os.html#os.mkdir" title="os.mkdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">mkdir()</span></code></a> and <a class="reference internal" href="../library/os.html#os.makedirs" title="os.makedirs"><code class="xref py py-func docutils literal notranslate"><span class="pre">makedirs()</span></code></a> now support passing a <em>mode</em> value of <code class="docutils literal notranslate"><span class="pre">0o700</span></code> to apply access control to the new directory. This implicitly affects <a class="reference internal" href="../library/tempfile.html#tempfile.mkdtemp" title="tempfile.mkdtemp"><code class="xref py py-func docutils literal notranslate"><span class="pre">tempfile.mkdtemp()</span></code></a> and is a mitigation for <span class="target" id="index-39"></span><a class="cve reference external" href="https://www.cve.org/CVERecord?id=CVE-2024-4030"><strong>CVE 2024-4030</strong></a>. Other values for <em>mode</em> continue to be ignored. (Contributed by Steve Dower in <a class="reference external" href="https://github.com/python/cpython/issues/118486">gh-118486</a>.)</p></li> <li><p><a class="reference internal" href="../library/os.html#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_spawn()</span></code></a> now accepts <code class="docutils literal notranslate"><span class="pre">None</span></code> for the <em>env</em> argument, which makes the newly spawned process use the current process environment. (Contributed by Jakub Kulik in <a class="reference external" href="https://github.com/python/cpython/issues/113119">gh-113119</a>.)</p></li> <li><p><a class="reference internal" href="../library/os.html#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_spawn()</span></code></a> can now use the <a class="reference internal" href="../library/os.html#os.POSIX_SPAWN_CLOSEFROM" title="os.POSIX_SPAWN_CLOSEFROM"><code class="xref py py-attr docutils literal notranslate"><span class="pre">POSIX_SPAWN_CLOSEFROM</span></code></a> attribute in the <em>file_actions</em> parameter on platforms that support <code class="xref c c-func docutils literal notranslate"><span class="pre">posix_spawn_file_actions_addclosefrom_np()</span></code>. (Contributed by Jakub Kulik in <a class="reference external" href="https://github.com/python/cpython/issues/113117">gh-113117</a>.)</p></li> </ul> </section> <section id="os-path"> <h3>os.path<a class="headerlink" href="#os-path" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add <a class="reference internal" href="../library/os.path.html#os.path.isreserved" title="os.path.isreserved"><code class="xref py py-func docutils literal notranslate"><span class="pre">isreserved()</span></code></a> to check if a path is reserved on the current system. This function is only available on Windows. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/88569">gh-88569</a>.)</p></li> <li><p>On Windows, <a class="reference internal" href="../library/os.path.html#os.path.isabs" title="os.path.isabs"><code class="xref py py-func docutils literal notranslate"><span class="pre">isabs()</span></code></a> no longer considers paths starting with exactly one slash (<code class="docutils literal notranslate"><span class="pre">\</span></code> or <code class="docutils literal notranslate"><span class="pre">/</span></code>) to be absolute. (Contributed by Barney Gale and Jon Foster in <a class="reference external" href="https://github.com/python/cpython/issues/44626">gh-44626</a>.)</p></li> <li><p><a class="reference internal" href="../library/os.path.html#os.path.realpath" title="os.path.realpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">realpath()</span></code></a> now resolves MS-DOS style file names even if the file is not accessible. (Contributed by Moonsik Park in <a class="reference external" href="https://github.com/python/cpython/issues/82367">gh-82367</a>.)</p></li> </ul> </section> <section id="pathlib"> <h3>pathlib<a class="headerlink" href="#pathlib" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add <a class="reference internal" href="../library/pathlib.html#pathlib.UnsupportedOperation" title="pathlib.UnsupportedOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnsupportedOperation</span></code></a>, which is raised instead of <a class="reference internal" href="../library/exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> when a path operation isn’t supported. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/89812">gh-89812</a>.)</p></li> <li><p>Add a new constructor for creating <a class="reference internal" href="../library/pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">Path</span></code></a> objects from ‘file’ URIs (<code class="docutils literal notranslate"><span class="pre">file:///</span></code>), <a class="reference internal" href="../library/pathlib.html#pathlib.Path.from_uri" title="pathlib.Path.from_uri"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.from_uri()</span></code></a>. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/107465">gh-107465</a>.)</p></li> <li><p>Add <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.full_match" title="pathlib.PurePath.full_match"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PurePath.full_match()</span></code></a> for matching paths with shell-style wildcards, including the recursive wildcard “<code class="docutils literal notranslate"><span class="pre">**</span></code>”. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/73435">gh-73435</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.parser" title="pathlib.PurePath.parser"><code class="xref py py-attr docutils literal notranslate"><span class="pre">PurePath.parser</span></code></a> class attribute to store the implementation of <a class="reference internal" href="../library/os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> used for low-level path parsing and joining. This will be either <code class="xref py py-mod docutils literal notranslate"><span class="pre">posixpath</span></code> or <code class="xref py py-mod docutils literal notranslate"><span class="pre">ntpath</span></code>.</p></li> <li><p>Add <em>recurse_symlinks</em> keyword-only argument to <a class="reference internal" href="../library/pathlib.html#pathlib.Path.glob" title="pathlib.Path.glob"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.glob()</span></code></a> and <a class="reference internal" href="../library/pathlib.html#pathlib.Path.rglob" title="pathlib.Path.rglob"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rglob()</span></code></a>. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/77609">gh-77609</a>.)</p></li> <li><p><a class="reference internal" href="../library/pathlib.html#pathlib.Path.glob" title="pathlib.Path.glob"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.glob()</span></code></a> and <a class="reference internal" href="../library/pathlib.html#pathlib.Path.rglob" title="pathlib.Path.rglob"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rglob()</span></code></a> now return files and directories when given a pattern that ends with “<code class="docutils literal notranslate"><span class="pre">**</span></code>”. Previously, only directories were returned. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/70303">gh-70303</a>.)</p></li> <li><p>Add the <em>follow_symlinks</em> keyword-only argument to <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_file" title="pathlib.Path.is_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.is_file</span></code></a>, <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_dir" title="pathlib.Path.is_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.is_dir</span></code></a>, <a class="reference internal" href="../library/pathlib.html#pathlib.Path.owner" title="pathlib.Path.owner"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.owner()</span></code></a>, and <a class="reference internal" href="../library/pathlib.html#pathlib.Path.group" title="pathlib.Path.group"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.group()</span></code></a>. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/105793">gh-105793</a> and Kamil Turek in <a class="reference external" href="https://github.com/python/cpython/issues/107962">gh-107962</a>.)</p></li> </ul> </section> <section id="pdb"> <h3>pdb<a class="headerlink" href="#pdb" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p><a class="reference internal" href="../library/functions.html#breakpoint" title="breakpoint"><code class="xref py py-func docutils literal notranslate"><span class="pre">breakpoint()</span></code></a> and <a class="reference internal" href="../library/pdb.html#pdb.set_trace" title="pdb.set_trace"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_trace()</span></code></a> now enter the debugger immediately rather than on the next line of code to be executed. This change prevents the debugger from breaking outside of the context when <code class="xref py py-func docutils literal notranslate"><span class="pre">breakpoint()</span></code> is positioned at the end of the context. (Contributed by Tian Gao in <a class="reference external" href="https://github.com/python/cpython/issues/118579">gh-118579</a>.)</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">sys.path[0]</span></code> is no longer replaced by the directory of the script being debugged when <a class="reference internal" href="../library/sys.html#sys.flags.safe_path" title="sys.flags.safe_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.flags.safe_path</span></code></a> is set. (Contributed by Tian Gao and Christian Walther in <a class="reference external" href="https://github.com/python/cpython/issues/111762">gh-111762</a>.)</p></li> <li><p><a class="reference internal" href="../library/zipapp.html#module-zipapp" title="zipapp: Manage executable Python zip archives"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipapp</span></code></a> is now supported as a debugging target. (Contributed by Tian Gao in <a class="reference external" href="https://github.com/python/cpython/issues/118501">gh-118501</a>.)</p></li> <li><p>Add ability to move between chained exceptions during post-mortem debugging in <a class="reference internal" href="../library/pdb.html#pdb.pm" title="pdb.pm"><code class="xref py py-func docutils literal notranslate"><span class="pre">pm()</span></code></a> using the new <a class="reference internal" href="../library/pdb.html#pdbcommand-exceptions"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">exceptions</span> <span class="pre">[exc_number]</span></code></a> command for Pdb. (Contributed by Matthias Bussonnier in <a class="reference external" href="https://github.com/python/cpython/issues/106676">gh-106676</a>.)</p></li> <li><p>Expressions and statements whose prefix is a pdb command are now correctly identified and executed. (Contributed by Tian Gao in <a class="reference external" href="https://github.com/python/cpython/issues/108464">gh-108464</a>.)</p></li> </ul> </section> <section id="queue"> <h3>queue<a class="headerlink" href="#queue" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add <a class="reference internal" href="../library/queue.html#queue.Queue.shutdown" title="queue.Queue.shutdown"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Queue.shutdown</span></code></a> and <a class="reference internal" href="../library/queue.html#queue.ShutDown" title="queue.ShutDown"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ShutDown</span></code></a> to manage queue termination. (Contributed by Laurie Opperman and Yves Duprat in <a class="reference external" href="https://github.com/python/cpython/issues/104750">gh-104750</a>.)</p></li> </ul> </section> <section id="random"> <h3>random<a class="headerlink" href="#random" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add a <a class="reference internal" href="../library/random.html#random-cli"><span class="std std-ref">command-line interface</span></a>. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/118131">gh-118131</a>.)</p></li> </ul> </section> <section id="re"> <h3>re<a class="headerlink" href="#re" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Rename <code class="xref py py-exc docutils literal notranslate"><span class="pre">re.error</span></code> to <a class="reference internal" href="../library/re.html#re.PatternError" title="re.PatternError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PatternError</span></code></a> for improved clarity. <code class="xref py py-exc docutils literal notranslate"><span class="pre">re.error</span></code> is kept for backward compatibility.</p></li> </ul> </section> <section id="shutil"> <h3>shutil<a class="headerlink" href="#shutil" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Support the <em>dir_fd</em> and <em>follow_symlinks</em> keyword arguments in <a class="reference internal" href="../library/shutil.html#shutil.chown" title="shutil.chown"><code class="xref py py-func docutils literal notranslate"><span class="pre">chown()</span></code></a>. (Contributed by Berker Peksag and Tahia K in <a class="reference external" href="https://github.com/python/cpython/issues/62308">gh-62308</a>)</p></li> </ul> </section> <section id="site"> <h3>site<a class="headerlink" href="#site" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p><code class="file docutils literal notranslate"><span class="pre">.pth</span></code> files are now decoded using UTF-8 first, and then with the <a class="reference internal" href="../glossary.html#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a> if UTF-8 decoding fails. (Contributed by Inada Naoki in <a class="reference external" href="https://github.com/python/cpython/issues/117802">gh-117802</a>.)</p></li> </ul> </section> <section id="sqlite3"> <h3>sqlite3<a class="headerlink" href="#sqlite3" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>A <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a> is now emitted if a <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection" title="sqlite3.Connection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Connection</span></code></a> object is not <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.close" title="sqlite3.Connection.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">closed</span></code></a> explicitly. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/105539">gh-105539</a>.)</p></li> <li><p>Add the <em>filter</em> keyword-only parameter to <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.iterdump" title="sqlite3.Connection.iterdump"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.iterdump()</span></code></a> for filtering database objects to dump. (Contributed by Mariusz Felisiak in <a class="reference external" href="https://github.com/python/cpython/issues/91602">gh-91602</a>.)</p></li> </ul> </section> <section id="ssl"> <h3>ssl<a class="headerlink" href="#ssl" title="Link to this heading">¶</a></h3> <ul> <li><p>The <a class="reference internal" href="../library/ssl.html#ssl.create_default_context" title="ssl.create_default_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">create_default_context()</span></code></a> API now includes <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_X509_PARTIAL_CHAIN" title="ssl.VERIFY_X509_PARTIAL_CHAIN"><code class="xref py py-data docutils literal notranslate"><span class="pre">VERIFY_X509_PARTIAL_CHAIN</span></code></a> and <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_X509_STRICT" title="ssl.VERIFY_X509_STRICT"><code class="xref py py-data docutils literal notranslate"><span class="pre">VERIFY_X509_STRICT</span></code></a> in its default flags.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p><a class="reference internal" href="../library/ssl.html#ssl.VERIFY_X509_STRICT" title="ssl.VERIFY_X509_STRICT"><code class="xref py py-data docutils literal notranslate"><span class="pre">VERIFY_X509_STRICT</span></code></a> may reject pre-<span class="target" id="index-40"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc5280.html"><strong>RFC 5280</strong></a> or malformed certificates that the underlying OpenSSL implementation might otherwise accept. Whilst disabling this is not recommended, you can do so using:</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">ssl</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">ssl</span><span class="o">.</span><span class="n">create_default_context</span><span class="p">()</span> <span class="n">ctx</span><span class="o">.</span><span class="n">verify_flags</span> <span class="o">&=</span> <span class="o">~</span><span class="n">ssl</span><span class="o">.</span><span class="n">VERIFY_X509_STRICT</span> </pre></div> </div> </div> <p>(Contributed by William Woodruff in <a class="reference external" href="https://github.com/python/cpython/issues/112389">gh-112389</a>.)</p> </li> </ul> </section> <section id="statistics"> <h3>statistics<a class="headerlink" href="#statistics" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add <a class="reference internal" href="../library/statistics.html#statistics.kde" title="statistics.kde"><code class="xref py py-func docutils literal notranslate"><span class="pre">kde()</span></code></a> for kernel density estimation. This makes it possible to estimate a continuous probability density function from a fixed number of discrete samples. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/115863">gh-115863</a>.)</p></li> <li><p>Add <a class="reference internal" href="../library/statistics.html#statistics.kde_random" title="statistics.kde_random"><code class="xref py py-func docutils literal notranslate"><span class="pre">kde_random()</span></code></a> for sampling from an estimated probability density function created by <a class="reference internal" href="../library/statistics.html#statistics.kde" title="statistics.kde"><code class="xref py py-func docutils literal notranslate"><span class="pre">kde()</span></code></a>. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/115863">gh-115863</a>.)</p></li> </ul> </section> <section id="subprocess"> <span id="whatsnew313-subprocess"></span><h3>subprocess<a class="headerlink" href="#subprocess" title="Link to this heading">¶</a></h3> <ul> <li><p>The <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module now uses the <a class="reference internal" href="../library/os.html#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_spawn()</span></code></a> function in more situations.</p> <p>Notably, when <em>close_fds</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code> (the default), <a class="reference internal" href="../library/os.html#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_spawn()</span></code></a> will be used when the C library provides <code class="xref c c-func docutils literal notranslate"><span class="pre">posix_spawn_file_actions_addclosefrom_np()</span></code>, which includes recent versions of Linux, FreeBSD, and Solaris. On Linux, this should perform similarly to the existing Linux <code class="xref c c-func docutils literal notranslate"><span class="pre">vfork()</span></code> based code.</p> <p>A private control knob <code class="xref py py-attr docutils literal notranslate"><span class="pre">subprocess._USE_POSIX_SPAWN</span></code> can be set to <code class="docutils literal notranslate"><span class="pre">False</span></code> if you need to force <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> to never use <a class="reference internal" href="../library/os.html#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_spawn()</span></code></a>. Please report your reason and platform details in the <a class="reference internal" href="../bugs.html#using-the-tracker"><span class="std std-ref">issue tracker</span></a> if you set this so that we can improve our API selection logic for everyone. (Contributed by Jakub Kulik in <a class="reference external" href="https://github.com/python/cpython/issues/113117">gh-113117</a>.)</p> </li> </ul> </section> <section id="sys"> <h3>sys<a class="headerlink" href="#sys" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add the <a class="reference internal" href="../library/sys.html#sys._is_interned" title="sys._is_interned"><code class="xref py py-func docutils literal notranslate"><span class="pre">_is_interned()</span></code></a> function to test if a string was interned. This function is not guaranteed to exist in all implementations of Python. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/78573">gh-78573</a>.)</p></li> </ul> </section> <section id="tempfile"> <h3>tempfile<a class="headerlink" href="#tempfile" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>On Windows, the default mode <code class="docutils literal notranslate"><span class="pre">0o700</span></code> used by <a class="reference internal" href="../library/tempfile.html#tempfile.mkdtemp" title="tempfile.mkdtemp"><code class="xref py py-func docutils literal notranslate"><span class="pre">tempfile.mkdtemp()</span></code></a> now limits access to the new directory due to changes to <a class="reference internal" href="../library/os.html#os.mkdir" title="os.mkdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.mkdir()</span></code></a>. This is a mitigation for <span class="target" id="index-41"></span><a class="cve reference external" href="https://www.cve.org/CVERecord?id=CVE-2024-4030"><strong>CVE 2024-4030</strong></a>. (Contributed by Steve Dower in <a class="reference external" href="https://github.com/python/cpython/issues/118486">gh-118486</a>.)</p></li> </ul> </section> <section id="time"> <h3>time<a class="headerlink" href="#time" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>On Windows, <a class="reference internal" href="../library/time.html#time.monotonic" title="time.monotonic"><code class="xref py py-func docutils literal notranslate"><span class="pre">monotonic()</span></code></a> now uses the <code class="docutils literal notranslate"><span class="pre">QueryPerformanceCounter()</span></code> clock for a resolution of 1 microsecond, instead of the <code class="docutils literal notranslate"><span class="pre">GetTickCount64()</span></code> clock which has a resolution of 15.6 milliseconds. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/88494">gh-88494</a>.)</p></li> <li><p>On Windows, <a class="reference internal" href="../library/time.html#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time()</span></code></a> now uses the <code class="docutils literal notranslate"><span class="pre">GetSystemTimePreciseAsFileTime()</span></code> clock for a resolution of 1 microsecond, instead of the <code class="docutils literal notranslate"><span class="pre">GetSystemTimeAsFileTime()</span></code> clock which has a resolution of 15.6 milliseconds. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/63207">gh-63207</a>.)</p></li> </ul> </section> <section id="tkinter"> <h3>tkinter<a class="headerlink" href="#tkinter" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add <a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> widget methods: <code class="xref py py-meth docutils literal notranslate"><span class="pre">tk_busy_hold()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">tk_busy_configure()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">tk_busy_cget()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">tk_busy_forget()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">tk_busy_current()</span></code>, and <code class="xref py py-meth docutils literal notranslate"><span class="pre">tk_busy_status()</span></code>. (Contributed by Miguel, klappnase and Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/72684">gh-72684</a>.)</p></li> <li><p>The <a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> widget method <code class="xref py py-meth docutils literal notranslate"><span class="pre">wm_attributes()</span></code> now accepts the attribute name without the minus prefix to get window attributes, for example <code class="docutils literal notranslate"><span class="pre">w.wm_attributes('alpha')</span></code> and allows specifying attributes and values to set as keyword arguments, for example <code class="docutils literal notranslate"><span class="pre">w.wm_attributes(alpha=0.5)</span></code>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/43457">gh-43457</a>.)</p></li> <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">wm_attributes()</span></code> can now return attributes as a <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>, by using the new optional keyword-only parameter <em>return_python_dict</em>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/43457">gh-43457</a>.)</p></li> <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">Text.count()</span></code> can now return a simple <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> when the new optional keyword-only parameter <em>return_ints</em> is used. Otherwise, the single count is returned as a 1-tuple or <code class="docutils literal notranslate"><span class="pre">None</span></code>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/97928">gh-97928</a>.)</p></li> <li><p>Support the “vsapi” element type in the <a class="reference internal" href="../library/tkinter.ttk.html#tkinter.ttk.Style.element_create" title="tkinter.ttk.Style.element_create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">element_create()</span></code></a> method of <a class="reference internal" href="../library/tkinter.ttk.html#tkinter.ttk.Style" title="tkinter.ttk.Style"><code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.ttk.Style</span></code></a>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/68166">gh-68166</a>.)</p></li> <li><p>Add the <code class="xref py py-meth docutils literal notranslate"><span class="pre">after_info()</span></code> method for Tkinter widgets. (Contributed by Cheryl Sabella in <a class="reference external" href="https://github.com/python/cpython/issues/77020">gh-77020</a>.)</p></li> <li><p>Add a new <code class="xref py py-meth docutils literal notranslate"><span class="pre">copy_replace()</span></code> method to <code class="xref py py-class docutils literal notranslate"><span class="pre">PhotoImage</span></code> to copy a region from one image to another, possibly with pixel zooming, subsampling, or both. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/118225">gh-118225</a>.)</p></li> <li><p>Add <em>from_coords</em> parameter to the <code class="xref py py-class docutils literal notranslate"><span class="pre">PhotoImage</span></code> methods <code class="xref py py-meth docutils literal notranslate"><span class="pre">copy()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">zoom()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">subsample()</span></code>. Add <em>zoom</em> and <em>subsample</em> parameters to the <code class="xref py py-class docutils literal notranslate"><span class="pre">PhotoImage</span></code> method <code class="xref py py-meth docutils literal notranslate"><span class="pre">copy()</span></code>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/118225">gh-118225</a>.)</p></li> <li><p>Add the <code class="xref py py-class docutils literal notranslate"><span class="pre">PhotoImage</span></code> methods <code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code> to read an image from a file and <code class="xref py py-meth docutils literal notranslate"><span class="pre">data()</span></code> to get the image data. Add <em>background</em> and <em>grayscale</em> parameters to the <code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code> method. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/118271">gh-118271</a>.)</p></li> </ul> </section> <section id="traceback"> <h3>traceback<a class="headerlink" href="#traceback" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add the <a class="reference internal" href="../library/traceback.html#traceback.TracebackException.exc_type_str" title="traceback.TracebackException.exc_type_str"><code class="xref py py-attr docutils literal notranslate"><span class="pre">exc_type_str</span></code></a> attribute to <a class="reference internal" href="../library/traceback.html#traceback.TracebackException" title="traceback.TracebackException"><code class="xref py py-class docutils literal notranslate"><span class="pre">TracebackException</span></code></a>, which holds a string display of the <em>exc_type</em>. Deprecate the <a class="reference internal" href="../library/traceback.html#traceback.TracebackException.exc_type" title="traceback.TracebackException.exc_type"><code class="xref py py-attr docutils literal notranslate"><span class="pre">exc_type</span></code></a> attribute, which holds the type object itself. Add parameter <em>save_exc_type</em> (default <code class="docutils literal notranslate"><span class="pre">True</span></code>) to indicate whether <code class="docutils literal notranslate"><span class="pre">exc_type</span></code> should be saved. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/112332">gh-112332</a>.)</p></li> <li><p>Add a new <em>show_group</em> keyword-only parameter to <a class="reference internal" href="../library/traceback.html#traceback.TracebackException.format_exception_only" title="traceback.TracebackException.format_exception_only"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TracebackException.format_exception_only()</span></code></a> to (recursively) format the nested exceptions of a <a class="reference internal" href="../library/exceptions.html#BaseExceptionGroup" title="BaseExceptionGroup"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseExceptionGroup</span></code></a> instance. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/105292">gh-105292</a>.)</p></li> </ul> </section> <section id="types"> <h3>types<a class="headerlink" href="#types" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p><a class="reference internal" href="../library/types.html#types.SimpleNamespace" title="types.SimpleNamespace"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleNamespace</span></code></a> can now take a single positional argument to initialise the namespace’s arguments. This argument must either be a mapping or an iterable of key-value pairs. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/108191">gh-108191</a>.)</p></li> </ul> </section> <section id="typing"> <h3>typing<a class="headerlink" href="#typing" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p><span class="target" id="index-42"></span><a class="pep reference external" href="https://peps.python.org/pep-0705/"><strong>PEP 705</strong></a>: Add <a class="reference internal" href="../library/typing.html#typing.ReadOnly" title="typing.ReadOnly"><code class="xref py py-data docutils literal notranslate"><span class="pre">ReadOnly</span></code></a>, a special typing construct to mark a <a class="reference internal" href="../library/typing.html#typing.TypedDict" title="typing.TypedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypedDict</span></code></a> item as read-only for type checkers.</p></li> <li><p><span class="target" id="index-43"></span><a class="pep reference external" href="https://peps.python.org/pep-0742/"><strong>PEP 742</strong></a>: Add <a class="reference internal" href="../library/typing.html#typing.TypeIs" title="typing.TypeIs"><code class="xref py py-data docutils literal notranslate"><span class="pre">TypeIs</span></code></a>, a typing construct that can be used to instruct a type checker how to narrow a type.</p></li> <li><p>Add <a class="reference internal" href="../library/typing.html#typing.NoDefault" title="typing.NoDefault"><code class="xref py py-data docutils literal notranslate"><span class="pre">NoDefault</span></code></a>, a sentinel object used to represent the defaults of some parameters in the <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/116126">gh-116126</a>.)</p></li> <li><p>Add <a class="reference internal" href="../library/typing.html#typing.get_protocol_members" title="typing.get_protocol_members"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_protocol_members()</span></code></a> to return the set of members defining a <a class="reference internal" href="../library/typing.html#typing.Protocol" title="typing.Protocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Protocol</span></code></a>. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/104873">gh-104873</a>.)</p></li> <li><p>Add <a class="reference internal" href="../library/typing.html#typing.is_protocol" title="typing.is_protocol"><code class="xref py py-func docutils literal notranslate"><span class="pre">is_protocol()</span></code></a> to check whether a class is a <a class="reference internal" href="../library/typing.html#typing.Protocol" title="typing.Protocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">Protocol</span></code></a>. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/104873">gh-104873</a>.)</p></li> <li><p><a class="reference internal" href="../library/typing.html#typing.ClassVar" title="typing.ClassVar"><code class="xref py py-data docutils literal notranslate"><span class="pre">ClassVar</span></code></a> can now be nested in <a class="reference internal" href="../library/typing.html#typing.Final" title="typing.Final"><code class="xref py py-data docutils literal notranslate"><span class="pre">Final</span></code></a>, and vice versa. (Contributed by Mehdi Drissi in <a class="reference external" href="https://github.com/python/cpython/issues/89547">gh-89547</a>.)</p></li> </ul> </section> <section id="unicodedata"> <h3>unicodedata<a class="headerlink" href="#unicodedata" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Update the Unicode database to <a class="reference external" href="https://www.unicode.org/versions/Unicode15.1.0/">version 15.1.0</a>. (Contributed by James Gerity in <a class="reference external" href="https://github.com/python/cpython/issues/109559">gh-109559</a>.)</p> </li> </ul> </section> <section id="venv"> <h3>venv<a class="headerlink" href="#venv" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add support for creating source control management (SCM) ignore files in a virtual environment’s directory. By default, Git is supported. This is implemented as opt-in via the API, which can be extended to support other SCMs (<a class="reference internal" href="../library/venv.html#venv.EnvBuilder" title="venv.EnvBuilder"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvBuilder</span></code></a> and <a class="reference internal" href="../library/venv.html#venv.create" title="venv.create"><code class="xref py py-func docutils literal notranslate"><span class="pre">create()</span></code></a>), and opt-out via the CLI, using <code class="xref std std-option docutils literal notranslate"><span class="pre">--without-scm-ignore-files</span></code>. (Contributed by Brett Cannon in <a class="reference external" href="https://github.com/python/cpython/issues/108125">gh-108125</a>.)</p></li> </ul> </section> <section id="warnings"> <h3>warnings<a class="headerlink" href="#warnings" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p><span class="target" id="index-44"></span><a class="pep reference external" href="https://peps.python.org/pep-0702/"><strong>PEP 702</strong></a>: The new <a class="reference internal" href="../library/warnings.html#warnings.deprecated" title="warnings.deprecated"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.deprecated()</span></code></a> decorator provides a way to communicate deprecations to a <a class="reference internal" href="../glossary.html#term-static-type-checker"><span class="xref std std-term">static type checker</span></a> and to warn on usage of deprecated classes and functions. A <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> may also be emitted when a decorated function or class is used at runtime. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/104003">gh-104003</a>.)</p></li> </ul> </section> <section id="xml"> <h3>xml<a class="headerlink" href="#xml" title="Link to this heading">¶</a></h3> <ul> <li><p>Allow controlling Expat >=2.6.0 reparse deferral (<span class="target" id="index-45"></span><a class="cve reference external" href="https://www.cve.org/CVERecord?id=CVE-2023-52425"><strong>CVE 2023-52425</strong></a>) by adding five new methods:</p> <ul class="simple"> <li><p><a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLParser.flush" title="xml.etree.ElementTree.XMLParser.flush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">xml.etree.ElementTree.XMLParser.flush()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLPullParser.flush" title="xml.etree.ElementTree.XMLPullParser.flush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">xml.etree.ElementTree.XMLPullParser.flush()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/pyexpat.html#xml.parsers.expat.xmlparser.GetReparseDeferralEnabled" title="xml.parsers.expat.xmlparser.GetReparseDeferralEnabled"><code class="xref py py-meth docutils literal notranslate"><span class="pre">xml.parsers.expat.xmlparser.GetReparseDeferralEnabled()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/pyexpat.html#xml.parsers.expat.xmlparser.SetReparseDeferralEnabled" title="xml.parsers.expat.xmlparser.SetReparseDeferralEnabled"><code class="xref py py-meth docutils literal notranslate"><span class="pre">xml.parsers.expat.xmlparser.SetReparseDeferralEnabled()</span></code></a></p></li> <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">xml.sax.expatreader.ExpatParser.flush()</span></code></p></li> </ul> <p>(Contributed by Sebastian Pipping in <a class="reference external" href="https://github.com/python/cpython/issues/115623">gh-115623</a>.)</p> </li> <li><p>Add the <code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code> method for the iterator returned by <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.iterparse" title="xml.etree.ElementTree.iterparse"><code class="xref py py-func docutils literal notranslate"><span class="pre">iterparse()</span></code></a> for explicit cleanup. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/69893">gh-69893</a>.)</p></li> </ul> </section> <section id="zipimport"> <h3>zipimport<a class="headerlink" href="#zipimport" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Add support for <a class="reference external" href="https://en.wikipedia.org/wiki/Zip_(file_format)#ZIP64">ZIP64</a> format files. Everybody loves huge data, right? (Contributed by Tim Hatch in <a class="reference external" href="https://github.com/python/cpython/issues/94146">gh-94146</a>.)</p> </li> </ul> </section> </section> <section id="optimizations"> <h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading">¶</a></h2> <ul class="simple"> <li><p>Several standard library modules have had their import times significantly improved. For example, the import time of the <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module has been reduced by around a third by removing dependencies on <a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a> and <a class="reference internal" href="../library/contextlib.html#module-contextlib" title="contextlib: Utilities for with-statement contexts."><code class="xref py py-mod docutils literal notranslate"><span class="pre">contextlib</span></code></a>. Other modules to enjoy import-time speedups include <a class="reference internal" href="../library/email.utils.html#module-email.utils" title="email.utils: Miscellaneous email package utilities."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.utils</span></code></a>, <a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a>, <a class="reference internal" href="../library/functools.html#module-functools" title="functools: Higher-order functions and operations on callable objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">functools</span></code></a>, <a class="reference internal" href="../library/importlib.metadata.html#module-importlib.metadata" title="importlib.metadata: Accessing package metadata"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code></a>, and <a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a>. (Contributed by Alex Waygood, Shantanu Jain, Adam Turner, Daniel Hollas, and others in <a class="reference external" href="https://github.com/python/cpython/issues/109653">gh-109653</a>.)</p></li> <li><p><a class="reference internal" href="../library/textwrap.html#textwrap.indent" title="textwrap.indent"><code class="xref py py-func docutils literal notranslate"><span class="pre">textwrap.indent()</span></code></a> is now around 30% faster than before for large input. (Contributed by Inada Naoki in <a class="reference external" href="https://github.com/python/cpython/issues/107369">gh-107369</a>.)</p></li> <li><p>The <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module now uses the <a class="reference internal" href="../library/os.html#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_spawn()</span></code></a> function in more situations, including when <em>close_fds</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code> (the default) on many modern platforms. This should provide a notable performance increase when launching processes on FreeBSD and Solaris. See the <a class="reference internal" href="#whatsnew313-subprocess"><span class="std std-ref">subprocess</span></a> section above for details. (Contributed by Jakub Kulik in <a class="reference external" href="https://github.com/python/cpython/issues/113117">gh-113117</a>.)</p></li> </ul> </section> <section id="removed-modules-and-apis"> <h2>Removed Modules And APIs<a class="headerlink" href="#removed-modules-and-apis" title="Link to this heading">¶</a></h2> <section id="pep-594-remove-dead-batteries-from-the-standard-library"> <span id="whatsnew313-pep594"></span><h3>PEP 594: Remove “dead batteries” from the standard library<a class="headerlink" href="#pep-594-remove-dead-batteries-from-the-standard-library" title="Link to this heading">¶</a></h3> <p><span class="target" id="index-46"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a> proposed removing 19 modules from the standard library, colloquially referred to as ‘dead batteries’ due to their historic, obsolete, or insecure status. All of the following modules were deprecated in Python 3.11, and are now removed:</p> <ul> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">aifc</span></code></p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code></p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">chunk</span></code></p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">cgi</span></code> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">cgitb</span></code></p> <ul> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">cgi.FieldStorage</span></code> can typically be replaced with <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.parse_qsl" title="urllib.parse.parse_qsl"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.parse_qsl()</span></code></a> for <code class="docutils literal notranslate"><span class="pre">GET</span></code> and <code class="docutils literal notranslate"><span class="pre">HEAD</span></code> requests, and the <a class="reference internal" href="../library/email.message.html#module-email.message" title="email.message: The base class representing email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.message</span></code></a> module or the <a class="extlink-pypi reference external" href="https://pypi.org/project/multipart/">multipart</a> library for <code class="docutils literal notranslate"><span class="pre">POST</span></code> and <code class="docutils literal notranslate"><span class="pre">PUT</span></code> requests.</p></li> <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.parse()</span></code> can be replaced by calling <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.parse_qs" title="urllib.parse.parse_qs"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.parse_qs()</span></code></a> directly on the desired query string, unless the input is <code class="docutils literal notranslate"><span class="pre">multipart/form-data</span></code>, which should be replaced as described below for <code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.parse_multipart()</span></code>.</p></li> <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.parse_header()</span></code> can be replaced with the functionality in the <a class="reference internal" href="../library/email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a> package, which implements the same MIME RFCs. For example, with <a class="reference internal" href="../library/email.message.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">email.message.EmailMessage</span></code></a>:</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">email.message</span> <span class="kn">import</span> <span class="n">EmailMessage</span> <span class="n">msg</span> <span class="o">=</span> <span class="n">EmailMessage</span><span class="p">()</span> <span class="n">msg</span><span class="p">[</span><span class="s1">'content-type'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'application/json; charset="utf8"'</span> <span class="n">main</span><span class="p">,</span> <span class="n">params</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">get_content_type</span><span class="p">(),</span> <span class="n">msg</span><span class="p">[</span><span class="s1">'content-type'</span><span class="p">]</span><span class="o">.</span><span class="n">params</span> </pre></div> </div> </li> <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.parse_multipart()</span></code> can be replaced with the functionality in the <a class="reference internal" href="../library/email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a> package, which implements the same MIME RFCs, or with the <a class="extlink-pypi reference external" href="https://pypi.org/project/multipart/">multipart</a> library. For example, the <a class="reference internal" href="../library/email.message.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">email.message.EmailMessage</span></code></a> and <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">email.message.Message</span></code></a> classes.</p></li> </ul> </li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">crypt</span></code> and the private <code class="xref py py-mod docutils literal notranslate"><span class="pre">_crypt</span></code> extension. The <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> module may be an appropriate replacement when simply hashing a value is required. Otherwise, various third-party libraries on PyPI are available:</p> <ul class="simple"> <li><p><a class="extlink-pypi reference external" href="https://pypi.org/project/bcrypt/">bcrypt</a>: Modern password hashing for your software and your servers.</p></li> <li><p><a class="extlink-pypi reference external" href="https://pypi.org/project/passlib/">passlib</a>: Comprehensive password hashing framework supporting over 30 schemes.</p></li> <li><p><a class="extlink-pypi reference external" href="https://pypi.org/project/argon2-cffi/">argon2-cffi</a>: The secure Argon2 password hashing algorithm.</p></li> <li><p><a class="extlink-pypi reference external" href="https://pypi.org/project/legacycrypt/">legacycrypt</a>: <a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a> wrapper to the POSIX crypt library call and associated functionality.</p></li> <li><p><a class="extlink-pypi reference external" href="https://pypi.org/project/crypt_r/">crypt_r</a>: Fork of the <code class="xref py py-mod docutils literal notranslate"><span class="pre">crypt</span></code> module, wrapper to the <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/crypt_r(3)">crypt_r(3)</a></em> library call and associated functionality.</p></li> </ul> </li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">imghdr</span></code>: The <a class="extlink-pypi reference external" href="https://pypi.org/project/filetype/">filetype</a>, <a class="extlink-pypi reference external" href="https://pypi.org/project/puremagic/">puremagic</a>, or <a class="extlink-pypi reference external" href="https://pypi.org/project/python-magic/">python-magic</a> libraries should be used as replacements. For example, the <code class="xref py py-func docutils literal notranslate"><span class="pre">puremagic.what()</span></code> function can be used to replace the <code class="xref py py-func docutils literal notranslate"><span class="pre">imghdr.what()</span></code> function for all file formats that were supported by <code class="xref py py-mod docutils literal notranslate"><span class="pre">imghdr</span></code>.</p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">mailcap</span></code>: Use the <a class="reference internal" href="../library/mimetypes.html#module-mimetypes" title="mimetypes: Mapping of filename extensions to MIME types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">mimetypes</span></code></a> module instead.</p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">msilib</span></code></p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">nis</span></code></p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">nntplib</span></code>: Use the <a class="extlink-pypi reference external" href="https://pypi.org/project/pynntp/">pynntp</a> library from PyPI instead.</p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code>: For audio playback, use the <a class="extlink-pypi reference external" href="https://pypi.org/project/pygame/">pygame</a> library from PyPI instead.</p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code>: Use the <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module instead. Use <a class="reference internal" href="../library/shlex.html#shlex.quote" title="shlex.quote"><code class="xref py py-func docutils literal notranslate"><span class="pre">shlex.quote()</span></code></a> to replace the undocumented <code class="docutils literal notranslate"><span class="pre">pipes.quote</span></code> function.</p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">sndhdr</span></code>: The <a class="extlink-pypi reference external" href="https://pypi.org/project/filetype/">filetype</a>, <a class="extlink-pypi reference external" href="https://pypi.org/project/puremagic/">puremagic</a>, or <a class="extlink-pypi reference external" href="https://pypi.org/project/python-magic/">python-magic</a> libraries should be used as replacements.</p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">spwd</span></code>: Use the <a class="extlink-pypi reference external" href="https://pypi.org/project/python-pam/">python-pam</a> library from PyPI instead.</p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code></p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">telnetlib</span></code>, Use the <a class="extlink-pypi reference external" href="https://pypi.org/project/telnetlib3/">telnetlib3</a> or <a class="extlink-pypi reference external" href="https://pypi.org/project/Exscript/">Exscript</a> libraries from PyPI instead.</p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">uu</span></code>: Use the <a class="reference internal" href="../library/base64.html#module-base64" title="base64: RFC 4648: Base16, Base32, Base64 Data Encodings; Base85 and Ascii85"><code class="xref py py-mod docutils literal notranslate"><span class="pre">base64</span></code></a> module instead, as a modern alternative.</p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">xdrlib</span></code></p></li> </ul> <p>(Contributed by Victor Stinner and Zachary Ware in <a class="reference external" href="https://github.com/python/cpython/issues/104773">gh-104773</a> and <a class="reference external" href="https://github.com/python/cpython/issues/104780">gh-104780</a>.)</p> </section> <section id="to3"> <h3>2to3<a class="headerlink" href="#to3" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Remove the <strong class="program">2to3</strong> program and the <code class="xref py py-mod docutils literal notranslate"><span class="pre">lib2to3</span></code> module, previously deprecated in Python 3.11. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/104780">gh-104780</a>.)</p></li> </ul> </section> <section id="builtins"> <h3>builtins<a class="headerlink" href="#builtins" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Remove support for chained <a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">classmethod</span></code></a> descriptors (introduced in <a class="reference external" href="https://github.com/python/cpython/issues/63272">gh-63272</a>). These can no longer be used to wrap other descriptors, such as <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-class docutils literal notranslate"><span class="pre">property</span></code></a>. The core design of this feature was flawed and led to several problems. To “pass-through” a <a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">classmethod</span></code></a>, consider using the <code class="xref py py-attr docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute that was added in Python 3.10. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/89519">gh-89519</a>.)</p></li> <li><p>Raise a <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> when calling <a class="reference internal" href="../reference/datamodel.html#frame.clear" title="frame.clear"><code class="xref py py-meth docutils literal notranslate"><span class="pre">frame.clear()</span></code></a> on a suspended frame (as has always been the case for an executing frame). (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/79932">gh-79932</a>.)</p></li> </ul> </section> <section id="id3"> <h3>configparser<a class="headerlink" href="#id3" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Remove the undocumented <code class="xref py py-class docutils literal notranslate"><span class="pre">LegacyInterpolation</span></code> class, deprecated in the docstring since Python 3.2, and at runtime since Python 3.11. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/104886">gh-104886</a>.)</p></li> </ul> </section> <section id="importlib-metadata"> <h3>importlib.metadata<a class="headerlink" href="#importlib-metadata" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Remove deprecated subscript (<a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a>) access for <a class="reference internal" href="../library/importlib.metadata.html#entry-points"><span class="std std-ref">EntryPoint</span></a> objects. (Contributed by Jason R. Coombs in <a class="reference external" href="https://github.com/python/cpython/issues/113175">gh-113175</a>.)</p></li> </ul> </section> <section id="locale"> <h3>locale<a class="headerlink" href="#locale" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Remove the <code class="xref py py-func docutils literal notranslate"><span class="pre">locale.resetlocale()</span></code> function, deprecated in Python 3.11. Use <code class="docutils literal notranslate"><span class="pre">locale.setlocale(locale.LC_ALL,</span> <span class="pre">"")</span></code> instead. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/104783">gh-104783</a>.)</p></li> </ul> </section> <section id="opcode"> <h3>opcode<a class="headerlink" href="#opcode" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Move <code class="xref py py-attr docutils literal notranslate"><span class="pre">opcode.ENABLE_SPECIALIZATION</span></code> to <code class="xref py py-attr docutils literal notranslate"><span class="pre">_opcode.ENABLE_SPECIALIZATION</span></code>. This field was added in 3.12, it was never documented, and is not intended for external use. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/105481">gh-105481</a>.)</p></li> <li><p>Remove <code class="xref py py-func docutils literal notranslate"><span class="pre">opcode.is_pseudo()</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">opcode.MIN_PSEUDO_OPCODE</span></code>, and <code class="xref py py-attr docutils literal notranslate"><span class="pre">opcode.MAX_PSEUDO_OPCODE</span></code>, which were added in Python 3.12, but were neither documented nor exposed through <a class="reference internal" href="../library/dis.html#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a>, and were not intended to be used externally. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/105481">gh-105481</a>.)</p></li> </ul> </section> <section id="id4"> <h3>pathlib<a class="headerlink" href="#id4" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Remove the ability to use <a class="reference internal" href="../library/pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">Path</span></code></a> objects as context managers. This functionality was deprecated and has had no effect since Python 3.9. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/83863">gh-83863</a>.)</p></li> </ul> </section> <section id="id5"> <h3>re<a class="headerlink" href="#id5" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Remove the undocumented, deprecated, and broken <code class="xref py py-func docutils literal notranslate"><span class="pre">re.template()</span></code> function and <code class="xref py py-attr docutils literal notranslate"><span class="pre">re.TEMPLATE</span></code> / <code class="xref py py-attr docutils literal notranslate"><span class="pre">re.T</span></code> flag. (Contributed by Serhiy Storchaka and Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/105687">gh-105687</a>.)</p></li> </ul> </section> <section id="tkinter-tix"> <h3>tkinter.tix<a class="headerlink" href="#tkinter-tix" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Remove the <code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.tix</span></code> module, deprecated in Python 3.6. The third-party Tix library which the module wrapped is unmaintained. (Contributed by Zachary Ware in <a class="reference external" href="https://github.com/python/cpython/issues/75552">gh-75552</a>.)</p></li> </ul> </section> <section id="turtle"> <h3>turtle<a class="headerlink" href="#turtle" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Remove the <code class="xref py py-meth docutils literal notranslate"><span class="pre">RawTurtle.settiltangle()</span></code> method, deprecated in the documentation since Python 3.1 and at runtime since Python 3.11. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/104876">gh-104876</a>.)</p></li> </ul> </section> <section id="id6"> <h3>typing<a class="headerlink" href="#id6" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Remove the <code class="xref py py-mod docutils literal notranslate"><span class="pre">typing.io</span></code> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">typing.re</span></code> namespaces, deprecated since Python 3.8. The items in those namespaces can be imported directly from the <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module. (Contributed by Sebastian Rittau in <a class="reference external" href="https://github.com/python/cpython/issues/92871">gh-92871</a>.)</p></li> <li><p>Remove the keyword-argument method of creating <a class="reference internal" href="../library/typing.html#typing.TypedDict" title="typing.TypedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypedDict</span></code></a> types, deprecated in Python 3.11. (Contributed by Tomas Roun in <a class="reference external" href="https://github.com/python/cpython/issues/104786">gh-104786</a>.)</p></li> </ul> </section> <section id="unittest"> <h3>unittest<a class="headerlink" href="#unittest" title="Link to this heading">¶</a></h3> <ul> <li><p>Remove the following <a class="reference internal" href="../library/unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code></a> functions, deprecated in Python 3.11:</p> <ul class="simple"> <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.findTestCases()</span></code></p></li> <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.makeSuite()</span></code></p></li> <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.getTestCaseNames()</span></code></p></li> </ul> <p>Use <a class="reference internal" href="../library/unittest.html#unittest.TestLoader" title="unittest.TestLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestLoader</span></code></a> methods instead:</p> <ul class="simple"> <li><p><a class="reference internal" href="../library/unittest.html#unittest.TestLoader.loadTestsFromModule" title="unittest.TestLoader.loadTestsFromModule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loadTestsFromModule()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/unittest.html#unittest.TestLoader.loadTestsFromTestCase" title="unittest.TestLoader.loadTestsFromTestCase"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loadTestsFromTestCase()</span></code></a></p></li> <li><p><a class="reference internal" href="../library/unittest.html#unittest.TestLoader.getTestCaseNames" title="unittest.TestLoader.getTestCaseNames"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getTestCaseNames()</span></code></a></p></li> </ul> <p>(Contributed by Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/104835">gh-104835</a>.)</p> </li> <li><p>Remove the untested and undocumented <code class="xref py py-meth docutils literal notranslate"><span class="pre">TestProgram.usageExit()</span></code> method, deprecated in Python 3.11. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/104992">gh-104992</a>.)</p></li> </ul> </section> <section id="urllib"> <h3>urllib<a class="headerlink" href="#urllib" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Remove the <em>cafile</em>, <em>capath</em>, and <em>cadefault</em> parameters of the <a class="reference internal" href="../library/urllib.request.html#urllib.request.urlopen" title="urllib.request.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.request.urlopen()</span></code></a> function, deprecated in Python 3.6. Use the <em>context</em> parameter instead with an <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLContext</span></code></a> instance. The <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.load_cert_chain" title="ssl.SSLContext.load_cert_chain"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLContext.load_cert_chain()</span></code></a> function can be used to load specific certificates, or let <a class="reference internal" href="../library/ssl.html#ssl.create_default_context" title="ssl.create_default_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.create_default_context()</span></code></a> select the operating system’s trusted certificate authority (CA) certificates. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105382">gh-105382</a>.)</p></li> </ul> </section> <section id="webbrowser"> <h3>webbrowser<a class="headerlink" href="#webbrowser" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>Remove the untested and undocumented <code class="xref py py-class docutils literal notranslate"><span class="pre">MacOSX</span></code> class, deprecated in Python 3.11. Use the <code class="xref py py-class docutils literal notranslate"><span class="pre">MacOSXOSAScript</span></code> class (introduced in Python 3.2) instead. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/104804">gh-104804</a>.)</p></li> <li><p>Remove the deprecated <code class="xref py py-attr docutils literal notranslate"><span class="pre">MacOSXOSAScript._name</span></code> attribute. Use the <a class="reference internal" href="../library/webbrowser.html#webbrowser.controller.name" title="webbrowser.controller.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">MacOSXOSAScript.name</span></code></a> attribute instead. (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/105546">gh-105546</a>.)</p></li> </ul> </section> </section> <section id="new-deprecations"> <h2>New Deprecations<a class="headerlink" href="#new-deprecations" title="Link to this heading">¶</a></h2> <ul class="simple"> <li><p><a class="reference internal" href="../reference/datamodel.html#user-defined-funcs"><span class="std std-ref">User-defined functions</span></a>:</p> <ul> <li><p>Deprecate assignment to a function’s <a class="reference internal" href="../reference/datamodel.html#function.__code__" title="function.__code__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__code__</span></code></a> attribute, where the new code object’s type does not match the function’s type. The different types are: plain function, generator, async generator, and coroutine. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/81137">gh-81137</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/array.html#module-array" title="array: Space efficient arrays of uniformly typed numeric values."><code class="xref py py-mod docutils literal notranslate"><span class="pre">array</span></code></a>:</p> <ul> <li><p>Deprecate the <code class="docutils literal notranslate"><span class="pre">'u'</span></code> format code (<code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code>) at runtime. This format code has been deprecated in documentation since Python 3.3, and will be removed in Python 3.16. Use the <code class="docutils literal notranslate"><span class="pre">'w'</span></code> format code (<a class="reference internal" href="../c-api/unicode.html#c.Py_UCS4" title="Py_UCS4"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UCS4</span></code></a>) for Unicode characters instead. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/80480">gh-80480</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a>:</p> <ul> <li><p>Deprecate the undocumented <code class="xref py py-func docutils literal notranslate"><span class="pre">SetPointerType()</span></code> function, to be removed in Python 3.15. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105733">gh-105733</a>.)</p></li> <li><p><a class="reference internal" href="../glossary.html#term-soft-deprecated"><span class="xref std std-term">Soft-deprecate</span></a> the <a class="reference internal" href="../library/ctypes.html#ctypes.ARRAY" title="ctypes.ARRAY"><code class="xref py py-func docutils literal notranslate"><span class="pre">ARRAY()</span></code></a> function in favour of <code class="docutils literal notranslate"><span class="pre">type</span> <span class="pre">*</span> <span class="pre">length</span></code> multiplication. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105733">gh-105733</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/decimal.html#module-decimal" title="decimal: Implementation of the General Decimal Arithmetic Specification."><code class="xref py py-mod docutils literal notranslate"><span class="pre">decimal</span></code></a>:</p> <ul> <li><p>Deprecate the non-standard and undocumented <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">Decimal</span></code></a> format specifier <code class="docutils literal notranslate"><span class="pre">'N'</span></code>, which is only supported in the <code class="xref py py-mod docutils literal notranslate"><span class="pre">decimal</span></code> module’s C implementation. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/89902">gh-89902</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/dis.html#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a>:</p> <ul> <li><p>Deprecate the <code class="xref py py-attr docutils literal notranslate"><span class="pre">HAVE_ARGUMENT</span></code> separator. Check membership in <a class="reference internal" href="../library/dis.html#dis.hasarg" title="dis.hasarg"><code class="xref py py-data docutils literal notranslate"><span class="pre">hasarg</span></code></a> instead. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/109319">gh-109319</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/getopt.html#module-getopt" title="getopt: Portable parser for command line options; support both short and long option names."><code class="xref py py-mod docutils literal notranslate"><span class="pre">getopt</span></code></a> and <a class="reference internal" href="../library/optparse.html#module-optparse" title="optparse: Command-line option parsing library. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">optparse</span></code></a>:</p> <ul> <li><p>Both modules are now <a class="reference internal" href="../glossary.html#term-soft-deprecated"><span class="xref std std-term">soft deprecated</span></a>, with <a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a> preferred for new projects. This is a new soft-deprecation for the <code class="xref py py-mod docutils literal notranslate"><span class="pre">getopt</span></code> module, whereas the <code class="xref py py-mod docutils literal notranslate"><span class="pre">optparse</span></code> module was already <em>de facto</em> soft deprecated. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/106535">gh-106535</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/gettext.html#module-gettext" title="gettext: Multilingual internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gettext</span></code></a>:</p> <ul> <li><p>Deprecate non-integer numbers as arguments to functions and methods that consider plural forms in the <code class="xref py py-mod docutils literal notranslate"><span class="pre">gettext</span></code> module, even if no translation was found. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/88434">gh-88434</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/glob.html#module-glob" title="glob: Unix shell style pathname pattern expansion."><code class="xref py py-mod docutils literal notranslate"><span class="pre">glob</span></code></a>:</p> <ul> <li><p>Deprecate the undocumented <code class="xref py py-func docutils literal notranslate"><span class="pre">glob0()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">glob1()</span></code> functions. Use <a class="reference internal" href="../library/glob.html#glob.glob" title="glob.glob"><code class="xref py py-func docutils literal notranslate"><span class="pre">glob()</span></code></a> and pass a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> specifying the root directory to the <em>root_dir</em> parameter instead. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/117337">gh-117337</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/http.server.html#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a>:</p> <ul> <li><p>Deprecate <a class="reference internal" href="../library/http.server.html#http.server.CGIHTTPRequestHandler" title="http.server.CGIHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHTTPRequestHandler</span></code></a>, to be removed in Python 3.15. Process-based CGI HTTP servers have been out of favor for a very long time. This code was outdated, unmaintained, and rarely used. It has a high potential for both security and functionality bugs. (Contributed by Gregory P. Smith in <a class="reference external" href="https://github.com/python/cpython/issues/109096">gh-109096</a>.)</p></li> <li><p>Deprecate the <code class="xref std std-option docutils literal notranslate"><span class="pre">--cgi</span></code> flag to the <strong class="program">python -m http.server</strong> command-line interface, to be removed in Python 3.15. (Contributed by Gregory P. Smith in <a class="reference external" href="https://github.com/python/cpython/issues/109096">gh-109096</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/mimetypes.html#module-mimetypes" title="mimetypes: Mapping of filename extensions to MIME types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">mimetypes</span></code></a>:</p> <ul> <li><p><a class="reference internal" href="../glossary.html#term-soft-deprecated"><span class="xref std std-term">Soft-deprecate</span></a> file path arguments to <a class="reference internal" href="../library/mimetypes.html#mimetypes.guess_type" title="mimetypes.guess_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_type()</span></code></a>, use <a class="reference internal" href="../library/mimetypes.html#mimetypes.guess_file_type" title="mimetypes.guess_file_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_file_type()</span></code></a> instead. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/66543">gh-66543</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a>:</p> <ul> <li><p>Deprecate passing the optional <em>maxsplit</em>, <em>count</em>, or <em>flags</em> arguments as positional arguments to the module-level <a class="reference internal" href="../library/re.html#re.split" title="re.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">split()</span></code></a>, <a class="reference internal" href="../library/re.html#re.sub" title="re.sub"><code class="xref py py-func docutils literal notranslate"><span class="pre">sub()</span></code></a>, and <a class="reference internal" href="../library/re.html#re.subn" title="re.subn"><code class="xref py py-func docutils literal notranslate"><span class="pre">subn()</span></code></a> functions. These parameters will become <a class="reference internal" href="../glossary.html#keyword-only-parameter"><span class="std std-ref">keyword-only</span></a> in a future version of Python. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/56166">gh-56166</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a>:</p> <ul> <li><p>Deprecate <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.is_reserved" title="pathlib.PurePath.is_reserved"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PurePath.is_reserved()</span></code></a>, to be removed in Python 3.15. Use <a class="reference internal" href="../library/os.path.html#os.path.isreserved" title="os.path.isreserved"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.isreserved()</span></code></a> to detect reserved paths on Windows. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/88569">gh-88569</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code></a>:</p> <ul> <li><p>Deprecate <a class="reference internal" href="../library/platform.html#platform.java_ver" title="platform.java_ver"><code class="xref py py-func docutils literal notranslate"><span class="pre">java_ver()</span></code></a>, to be removed in Python 3.15. This function is only useful for Jython support, has a confusing API, and is largely untested. (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/116349">gh-116349</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a>:</p> <ul> <li><p>Deprecate the undocumented <code class="xref py py-func docutils literal notranslate"><span class="pre">ispackage()</span></code> function. (Contributed by Zackery Spytz in <a class="reference external" href="https://github.com/python/cpython/issues/64020">gh-64020</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/sqlite3.html#module-sqlite3" title="sqlite3: A DB-API 2.0 implementation using SQLite 3.x."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlite3</span></code></a>:</p> <ul> <li><p>Deprecate passing more than one positional argument to the <a class="reference internal" href="../library/sqlite3.html#sqlite3.connect" title="sqlite3.connect"><code class="xref py py-func docutils literal notranslate"><span class="pre">connect()</span></code></a> function and the <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection" title="sqlite3.Connection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Connection</span></code></a> constructor. The remaining parameters will become keyword-only in Python 3.15. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/107948">gh-107948</a>.)</p></li> <li><p>Deprecate passing name, number of arguments, and the callable as keyword arguments for <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.create_function" title="sqlite3.Connection.create_function"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.create_function()</span></code></a> and <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.create_aggregate" title="sqlite3.Connection.create_aggregate"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Connection.create_aggregate()</span></code></a> These parameters will become positional-only in Python 3.15. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/108278">gh-108278</a>.)</p></li> <li><p>Deprecate passing the callback callable by keyword for the <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.set_authorizer" title="sqlite3.Connection.set_authorizer"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_authorizer()</span></code></a>, <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.set_progress_handler" title="sqlite3.Connection.set_progress_handler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_progress_handler()</span></code></a>, and <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.set_trace_callback" title="sqlite3.Connection.set_trace_callback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_trace_callback()</span></code></a> <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection" title="sqlite3.Connection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Connection</span></code></a> methods. The callback callables will become positional-only in Python 3.15. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/108278">gh-108278</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a>:</p> <ul> <li><p>Deprecate the <a class="reference internal" href="../library/sys.html#sys._enablelegacywindowsfsencoding" title="sys._enablelegacywindowsfsencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">_enablelegacywindowsfsencoding()</span></code></a> function, to be removed in Python 3.16. Use the <span class="target" id="index-47"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONLEGACYWINDOWSFSENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONLEGACYWINDOWSFSENCODING</span></code></a> environment variable instead. (Contributed by Inada Naoki in <a class="reference external" href="https://github.com/python/cpython/issues/73427">gh-73427</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a>:</p> <ul> <li><p>Deprecate the undocumented and unused <code class="xref py py-attr docutils literal notranslate"><span class="pre">TarFile.tarfile</span></code> attribute, to be removed in Python 3.16. (Contributed in <a class="reference external" href="https://github.com/python/cpython/issues/115256">gh-115256</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/traceback.html#module-traceback" title="traceback: Print or retrieve a stack traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">traceback</span></code></a>:</p> <ul> <li><p>Deprecate the <a class="reference internal" href="../library/traceback.html#traceback.TracebackException.exc_type" title="traceback.TracebackException.exc_type"><code class="xref py py-attr docutils literal notranslate"><span class="pre">TracebackException.exc_type</span></code></a> attribute. Use <a class="reference internal" href="../library/traceback.html#traceback.TracebackException.exc_type_str" title="traceback.TracebackException.exc_type_str"><code class="xref py py-attr docutils literal notranslate"><span class="pre">TracebackException.exc_type_str</span></code></a> instead. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/112332">gh-112332</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a>:</p> <ul> <li><p>Deprecate the undocumented keyword argument syntax for creating <a class="reference internal" href="../library/typing.html#typing.NamedTuple" title="typing.NamedTuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">NamedTuple</span></code></a> classes (e.g. <code class="docutils literal notranslate"><span class="pre">Point</span> <span class="pre">=</span> <span class="pre">NamedTuple("Point",</span> <span class="pre">x=int,</span> <span class="pre">y=int)</span></code>), to be removed in Python 3.15. Use the class-based syntax or the functional syntax instead. (Contributed by Alex Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/105566">gh-105566</a>.)</p></li> <li><p>Deprecate omitting the <em>fields</em> parameter when creating a <a class="reference internal" href="../library/typing.html#typing.NamedTuple" title="typing.NamedTuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">NamedTuple</span></code></a> or <a class="reference internal" href="../library/typing.html#typing.TypedDict" title="typing.TypedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.TypedDict</span></code></a> class, and deprecate passing <code class="docutils literal notranslate"><span class="pre">None</span></code> to the <em>fields</em> parameter of both types. Python 3.15 will require a valid sequence for the <em>fields</em> parameter. To create a NamedTuple class with zero fields, use <code class="docutils literal notranslate"><span class="pre">class</span> <span class="pre">NT(NamedTuple):</span> <span class="pre">pass</span></code> or <code class="docutils literal notranslate"><span class="pre">NT</span> <span class="pre">=</span> <span class="pre">NamedTuple("NT",</span> <span class="pre">())</span></code>. To create a TypedDict class with zero fields, use <code class="docutils literal notranslate"><span class="pre">class</span> <span class="pre">TD(TypedDict):</span> <span class="pre">pass</span></code> or <code class="docutils literal notranslate"><span class="pre">TD</span> <span class="pre">=</span> <span class="pre">TypedDict("TD",</span> <span class="pre">{})</span></code>. (Contributed by Alex Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/105566">gh-105566</a> and <a class="reference external" href="https://github.com/python/cpython/issues/105570">gh-105570</a>.)</p></li> <li><p>Deprecate the <a class="reference internal" href="../library/typing.html#typing.no_type_check_decorator" title="typing.no_type_check_decorator"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.no_type_check_decorator()</span></code></a> decorator function, to be removed in in Python 3.15. After eight years in the <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module, it has yet to be supported by any major type checker. (Contributed by Alex Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/106309">gh-106309</a>.)</p></li> <li><p>Deprecate <a class="reference internal" href="../library/typing.html#typing.AnyStr" title="typing.AnyStr"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.AnyStr</span></code></a>. In Python 3.16, it will be removed from <code class="docutils literal notranslate"><span class="pre">typing.__all__</span></code>, and a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> will be emitted at runtime when it is imported or accessed. It will be removed entirely in Python 3.18. Use the new <a class="reference internal" href="../reference/compound_stmts.html#type-params"><span class="std std-ref">type parameter syntax</span></a> instead. (Contributed by Michael The in <a class="reference external" href="https://github.com/python/cpython/issues/107116">gh-107116</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/wave.html#module-wave" title="wave: Provide an interface to the WAV sound format."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wave</span></code></a>:</p> <ul> <li><p>Deprecate the <a class="reference internal" href="../library/wave.html#wave.Wave_read.getmark" title="wave.Wave_read.getmark"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getmark()</span></code></a>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">setmark()</span></code>, and <a class="reference internal" href="../library/wave.html#wave.Wave_read.getmarkers" title="wave.Wave_read.getmarkers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getmarkers()</span></code></a> methods of the <a class="reference internal" href="../library/wave.html#wave.Wave_read" title="wave.Wave_read"><code class="xref py py-class docutils literal notranslate"><span class="pre">Wave_read</span></code></a> and <a class="reference internal" href="../library/wave.html#wave.Wave_write" title="wave.Wave_write"><code class="xref py py-class docutils literal notranslate"><span class="pre">Wave_write</span></code></a> classes, to be removed in Python 3.15. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105096">gh-105096</a>.)</p></li> </ul> </li> </ul> <section id="pending-removal-in-python-3-14"> <h3>Pending Removal in Python 3.14<a class="headerlink" href="#pending-removal-in-python-3-14" title="Link to this heading">¶</a></h3> <ul> <li><p><a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a>: The <em>type</em>, <em>choices</em>, and <em>metavar</em> parameters of <code class="xref py py-class docutils literal notranslate"><span class="pre">argparse.BooleanOptionalAction</span></code> are deprecated and will be removed in 3.14. (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/92248">gh-92248</a>.)</p></li> <li><p><a class="reference internal" href="../library/ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a>: The following features have been deprecated in documentation since Python 3.8, now cause a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> to be emitted at runtime when they are accessed or used, and will be removed in Python 3.14:</p> <ul class="simple"> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Num</span></code></p></li> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Str</span></code></p></li> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Bytes</span></code></p></li> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.NameConstant</span></code></p></li> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Ellipsis</span></code></p></li> </ul> <p>Use <a class="reference internal" href="../library/ast.html#ast.Constant" title="ast.Constant"><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Constant</span></code></a> instead. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/90953">gh-90953</a>.)</p> </li> <li><p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a>:</p> <ul class="simple"> <li><p>The child watcher classes <a class="reference internal" href="../library/asyncio-policy.html#asyncio.MultiLoopChildWatcher" title="asyncio.MultiLoopChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">MultiLoopChildWatcher</span></code></a>, <a class="reference internal" href="../library/asyncio-policy.html#asyncio.FastChildWatcher" title="asyncio.FastChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">FastChildWatcher</span></code></a>, <a class="reference internal" href="../library/asyncio-policy.html#asyncio.AbstractChildWatcher" title="asyncio.AbstractChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">AbstractChildWatcher</span></code></a> and <a class="reference internal" href="../library/asyncio-policy.html#asyncio.SafeChildWatcher" title="asyncio.SafeChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">SafeChildWatcher</span></code></a> are deprecated and will be removed in Python 3.14. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/94597">gh-94597</a>.)</p></li> <li><p><a class="reference internal" href="../library/asyncio-policy.html#asyncio.set_child_watcher" title="asyncio.set_child_watcher"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.set_child_watcher()</span></code></a>, <a class="reference internal" href="../library/asyncio-policy.html#asyncio.get_child_watcher" title="asyncio.get_child_watcher"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.get_child_watcher()</span></code></a>, <a class="reference internal" href="../library/asyncio-policy.html#asyncio.AbstractEventLoopPolicy.set_child_watcher" title="asyncio.AbstractEventLoopPolicy.set_child_watcher"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.AbstractEventLoopPolicy.set_child_watcher()</span></code></a> and <a class="reference internal" href="../library/asyncio-policy.html#asyncio.AbstractEventLoopPolicy.get_child_watcher" title="asyncio.AbstractEventLoopPolicy.get_child_watcher"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.AbstractEventLoopPolicy.get_child_watcher()</span></code></a> are deprecated and will be removed in Python 3.14. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/94597">gh-94597</a>.)</p></li> <li><p>The <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.get_event_loop" title="asyncio.get_event_loop"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_event_loop()</span></code></a> method of the default event loop policy now emits a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> if there is no current event loop set and it decides to create one. (Contributed by Serhiy Storchaka and Guido van Rossum in <a class="reference external" href="https://github.com/python/cpython/issues/100160">gh-100160</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a>: Deprecated <a class="reference internal" href="../library/collections.abc.html#collections.abc.ByteString" title="collections.abc.ByteString"><code class="xref py py-class docutils literal notranslate"><span class="pre">ByteString</span></code></a>. Prefer <code class="xref py py-class docutils literal notranslate"><span class="pre">Sequence</span></code> or <a class="reference internal" href="../library/collections.abc.html#collections.abc.Buffer" title="collections.abc.Buffer"><code class="xref py py-class docutils literal notranslate"><span class="pre">Buffer</span></code></a>. For use in typing, prefer a union, like <code class="docutils literal notranslate"><span class="pre">bytes</span> <span class="pre">|</span> <span class="pre">bytearray</span></code>, or <a class="reference internal" href="../library/collections.abc.html#collections.abc.Buffer" title="collections.abc.Buffer"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Buffer</span></code></a>. (Contributed by Shantanu Jain in <a class="reference external" href="https://github.com/python/cpython/issues/91896">gh-91896</a>.)</p></li> <li><p><a class="reference internal" href="../library/email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a>: Deprecated the <em>isdst</em> parameter in <a class="reference internal" href="../library/email.utils.html#email.utils.localtime" title="email.utils.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">email.utils.localtime()</span></code></a>. (Contributed by Alan Williams in <a class="reference external" href="https://github.com/python/cpython/issues/72346">gh-72346</a>.)</p></li> <li><p><a class="reference internal" href="../library/importlib.html#module-importlib.abc" title="importlib.abc: Abstract base classes related to import"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.abc</span></code></a> deprecated classes:</p> <ul class="simple"> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.ResourceReader</span></code></p></li> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.Traversable</span></code></p></li> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.TraversableResources</span></code></p></li> </ul> <p>Use <a class="reference internal" href="../library/importlib.resources.abc.html#module-importlib.resources.abc" title="importlib.resources.abc: Abstract base classes for resources"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources.abc</span></code></a> classes instead:</p> <ul class="simple"> <li><p><a class="reference internal" href="../library/importlib.resources.abc.html#importlib.resources.abc.Traversable" title="importlib.resources.abc.Traversable"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.resources.abc.Traversable</span></code></a></p></li> <li><p><a class="reference internal" href="../library/importlib.resources.abc.html#importlib.resources.abc.TraversableResources" title="importlib.resources.abc.TraversableResources"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.resources.abc.TraversableResources</span></code></a></p></li> </ul> <p>(Contributed by Jason R. Coombs and Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/93963">gh-93963</a>.)</p> </li> <li><p><a class="reference internal" href="../library/itertools.html#module-itertools" title="itertools: Functions creating iterators for efficient looping."><code class="xref py py-mod docutils literal notranslate"><span class="pre">itertools</span></code></a> had undocumented, inefficient, historically buggy, and inconsistent support for copy, deepcopy, and pickle operations. This will be removed in 3.14 for a significant reduction in code volume and maintenance burden. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/101588">gh-101588</a>.)</p></li> <li><p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a>: The default start method will change to a safer one on Linux, BSDs, and other non-macOS POSIX platforms where <code class="docutils literal notranslate"><span class="pre">'fork'</span></code> is currently the default (<a class="reference external" href="https://github.com/python/cpython/issues/84559">gh-84559</a>). Adding a runtime warning about this was deemed too disruptive as the majority of code is not expected to care. Use the <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.get_context" title="multiprocessing.get_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_context()</span></code></a> or <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.set_start_method" title="multiprocessing.set_start_method"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_start_method()</span></code></a> APIs to explicitly specify when your code <em>requires</em> <code class="docutils literal notranslate"><span class="pre">'fork'</span></code>. See <a class="reference internal" href="../library/multiprocessing.html#multiprocessing-start-methods"><span class="std std-ref">Contexts and start methods</span></a>.</p></li> <li><p><a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a>: <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.is_relative_to" title="pathlib.PurePath.is_relative_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_relative_to()</span></code></a> and <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.relative_to" title="pathlib.PurePath.relative_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">relative_to()</span></code></a>: passing additional arguments is deprecated.</p></li> <li><p><a class="reference internal" href="../library/pkgutil.html#module-pkgutil" title="pkgutil: Utilities for the import system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pkgutil</span></code></a>: <a class="reference internal" href="../library/pkgutil.html#pkgutil.find_loader" title="pkgutil.find_loader"><code class="xref py py-func docutils literal notranslate"><span class="pre">find_loader()</span></code></a> and <a class="reference internal" href="../library/pkgutil.html#pkgutil.get_loader" title="pkgutil.get_loader"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_loader()</span></code></a> now raise <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>; use <a class="reference internal" href="../library/importlib.html#importlib.util.find_spec" title="importlib.util.find_spec"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.find_spec()</span></code></a> instead. (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/97850">gh-97850</a>.)</p></li> <li><p><a class="reference internal" href="../library/pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Unix. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pty</span></code></a>:</p> <ul class="simple"> <li><p><code class="docutils literal notranslate"><span class="pre">master_open()</span></code>: use <a class="reference internal" href="../library/pty.html#pty.openpty" title="pty.openpty"><code class="xref py py-func docutils literal notranslate"><span class="pre">pty.openpty()</span></code></a>.</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">slave_open()</span></code>: use <a class="reference internal" href="../library/pty.html#pty.openpty" title="pty.openpty"><code class="xref py py-func docutils literal notranslate"><span class="pre">pty.openpty()</span></code></a>.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/sqlite3.html#module-sqlite3" title="sqlite3: A DB-API 2.0 implementation using SQLite 3.x."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlite3</span></code></a>:</p> <ul class="simple"> <li><p><a class="reference internal" href="../library/sqlite3.html#sqlite3.version" title="sqlite3.version"><code class="xref py py-data docutils literal notranslate"><span class="pre">version</span></code></a> and <a class="reference internal" href="../library/sqlite3.html#sqlite3.version_info" title="sqlite3.version_info"><code class="xref py py-data docutils literal notranslate"><span class="pre">version_info</span></code></a>.</p></li> <li><p><a class="reference internal" href="../library/sqlite3.html#sqlite3.Cursor.execute" title="sqlite3.Cursor.execute"><code class="xref py py-meth docutils literal notranslate"><span class="pre">execute()</span></code></a> and <a class="reference internal" href="../library/sqlite3.html#sqlite3.Cursor.executemany" title="sqlite3.Cursor.executemany"><code class="xref py py-meth docutils literal notranslate"><span class="pre">executemany()</span></code></a> if <a class="reference internal" href="../library/sqlite3.html#sqlite3-placeholders"><span class="std std-ref">named placeholders</span></a> are used and <em>parameters</em> is a sequence instead of a <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a>: <a class="reference internal" href="../library/typing.html#typing.ByteString" title="typing.ByteString"><code class="xref py py-class docutils literal notranslate"><span class="pre">ByteString</span></code></a>, deprecated since Python 3.9, now causes a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> to be emitted when it is used.</p></li> <li><p><a class="reference internal" href="../library/urllib.html#module-urllib" title="urllib"><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib</span></code></a>: <code class="xref py py-class docutils literal notranslate"><span class="pre">urllib.parse.Quoter</span></code> is deprecated: it was not intended to be a public API. (Contributed by Gregory P. Smith in <a class="reference external" href="https://github.com/python/cpython/issues/88168">gh-88168</a>.)</p></li> </ul> </section> <section id="pending-removal-in-python-3-15"> <h3>Pending Removal in Python 3.15<a class="headerlink" href="#pending-removal-in-python-3-15" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>The import system:</p> <ul> <li><p>Setting <a class="reference internal" href="../reference/datamodel.html#module.__cached__" title="module.__cached__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__cached__</span></code></a> on a module while failing to set <a class="reference internal" href="../library/importlib.html#importlib.machinery.ModuleSpec.cached" title="importlib.machinery.ModuleSpec.cached"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__spec__.cached</span></code></a> is deprecated. In Python 3.15, <code class="xref py py-attr docutils literal notranslate"><span class="pre">__cached__</span></code> will cease to be set or take into consideration by the import system or standard library. (<a class="reference external" href="https://github.com/python/cpython/issues/97879">gh-97879</a>)</p></li> <li><p>Setting <a class="reference internal" href="../reference/datamodel.html#module.__package__" title="module.__package__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__package__</span></code></a> on a module while failing to set <a class="reference internal" href="../library/importlib.html#importlib.machinery.ModuleSpec.parent" title="importlib.machinery.ModuleSpec.parent"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__spec__.parent</span></code></a> is deprecated. In Python 3.15, <code class="xref py py-attr docutils literal notranslate"><span class="pre">__package__</span></code> will cease to be set or take into consideration by the import system or standard library. (<a class="reference external" href="https://github.com/python/cpython/issues/97879">gh-97879</a>)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a>:</p> <ul> <li><p>The undocumented <code class="xref py py-func docutils literal notranslate"><span class="pre">ctypes.SetPointerType()</span></code> function has been deprecated since Python 3.13.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/http.server.html#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a>:</p> <ul> <li><p>The obsolete and rarely used <a class="reference internal" href="../library/http.server.html#http.server.CGIHTTPRequestHandler" title="http.server.CGIHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CGIHTTPRequestHandler</span></code></a> has been deprecated since Python 3.13. No direct replacement exists. <em>Anything</em> is better than CGI to interface a web server with a request handler.</p></li> <li><p>The <code class="xref std std-option docutils literal notranslate"><span class="pre">--cgi</span></code> flag to the <strong class="program">python -m http.server</strong> command-line interface has been deprecated since Python 3.13.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/locale.html#module-locale" title="locale: Internationalization services."><code class="xref py py-class docutils literal notranslate"><span class="pre">locale</span></code></a>:</p> <ul> <li><p>The <a class="reference internal" href="../library/locale.html#locale.getdefaultlocale" title="locale.getdefaultlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">getdefaultlocale()</span></code></a> function has been deprecated since Python 3.11. Its removal was originally planned for Python 3.13 (<a class="reference external" href="https://github.com/python/cpython/issues/90817">gh-90817</a>), but has been postponed to Python 3.15. Use <a class="reference internal" href="../library/locale.html#locale.getlocale" title="locale.getlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">getlocale()</span></code></a>, <a class="reference internal" href="../library/locale.html#locale.setlocale" title="locale.setlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">setlocale()</span></code></a>, and <a class="reference internal" href="../library/locale.html#locale.getencoding" title="locale.getencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">getencoding()</span></code></a> instead. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/111187">gh-111187</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a>:</p> <ul> <li><p><a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.is_reserved" title="pathlib.PurePath.is_reserved"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PurePath.is_reserved()</span></code></a> has been deprecated since Python 3.13. Use <a class="reference internal" href="../library/os.path.html#os.path.isreserved" title="os.path.isreserved"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.isreserved()</span></code></a> to detect reserved paths on Windows.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code></a>:</p> <ul> <li><p><a class="reference internal" href="../library/platform.html#platform.java_ver" title="platform.java_ver"><code class="xref py py-func docutils literal notranslate"><span class="pre">java_ver()</span></code></a> has been deprecated since Python 3.13. This function is only useful for Jython support, has a confusing API, and is largely untested.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a>:</p> <ul> <li><p><a class="reference internal" href="../library/threading.html#threading.RLock" title="threading.RLock"><code class="xref py py-func docutils literal notranslate"><span class="pre">RLock()</span></code></a> will take no arguments in Python 3.15. Passing any arguments has been deprecated since Python 3.14, as the Python version does not permit any arguments, but the C version allows any number of positional or keyword arguments, ignoring every argument.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/types.html#module-types" title="types: Names for built-in types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">types</span></code></a>:</p> <ul> <li><p><a class="reference internal" href="../library/types.html#types.CodeType" title="types.CodeType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.CodeType</span></code></a>: Accessing <a class="reference internal" href="../reference/datamodel.html#codeobject.co_lnotab" title="codeobject.co_lnotab"><code class="xref py py-attr docutils literal notranslate"><span class="pre">co_lnotab</span></code></a> was deprecated in <span class="target" id="index-48"></span><a class="pep reference external" href="https://peps.python.org/pep-0626/"><strong>PEP 626</strong></a> since 3.10 and was planned to be removed in 3.12, but it only got a proper <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> in 3.12. May be removed in 3.15. (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/101866">gh-101866</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a>:</p> <ul> <li><p>The undocumented keyword argument syntax for creating <a class="reference internal" href="../library/typing.html#typing.NamedTuple" title="typing.NamedTuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">NamedTuple</span></code></a> classes (e.g. <code class="docutils literal notranslate"><span class="pre">Point</span> <span class="pre">=</span> <span class="pre">NamedTuple("Point",</span> <span class="pre">x=int,</span> <span class="pre">y=int)</span></code>) has been deprecated since Python 3.13. Use the class-based syntax or the functional syntax instead.</p></li> <li><p>The <a class="reference internal" href="../library/typing.html#typing.no_type_check_decorator" title="typing.no_type_check_decorator"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.no_type_check_decorator()</span></code></a> decorator function has been deprecated since Python 3.13. After eight years in the <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module, it has yet to be supported by any major type checker.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/wave.html#module-wave" title="wave: Provide an interface to the WAV sound format."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wave</span></code></a>:</p> <ul> <li><p>The <a class="reference internal" href="../library/wave.html#wave.Wave_read.getmark" title="wave.Wave_read.getmark"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getmark()</span></code></a>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">setmark()</span></code>, and <a class="reference internal" href="../library/wave.html#wave.Wave_read.getmarkers" title="wave.Wave_read.getmarkers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getmarkers()</span></code></a> methods of the <a class="reference internal" href="../library/wave.html#wave.Wave_read" title="wave.Wave_read"><code class="xref py py-class docutils literal notranslate"><span class="pre">Wave_read</span></code></a> and <a class="reference internal" href="../library/wave.html#wave.Wave_write" title="wave.Wave_write"><code class="xref py py-class docutils literal notranslate"><span class="pre">Wave_write</span></code></a> classes have been deprecated since Python 3.13.</p></li> </ul> </li> </ul> </section> <section id="pending-removal-in-python-3-16"> <h3>Pending removal in Python 3.16<a class="headerlink" href="#pending-removal-in-python-3-16" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>The import system:</p> <ul> <li><p>Setting <a class="reference internal" href="../reference/datamodel.html#module.__loader__" title="module.__loader__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__loader__</span></code></a> on a module while failing to set <a class="reference internal" href="../library/importlib.html#importlib.machinery.ModuleSpec.loader" title="importlib.machinery.ModuleSpec.loader"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__spec__.loader</span></code></a> is deprecated. In Python 3.16, <code class="xref py py-attr docutils literal notranslate"><span class="pre">__loader__</span></code> will cease to be set or taken into consideration by the import system or the standard library.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/array.html#module-array" title="array: Space efficient arrays of uniformly typed numeric values."><code class="xref py py-mod docutils literal notranslate"><span class="pre">array</span></code></a>:</p> <ul> <li><p>The <code class="docutils literal notranslate"><span class="pre">'u'</span></code> format code (<code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code>) has been deprecated in documentation since Python 3.3 and at runtime since Python 3.13. Use the <code class="docutils literal notranslate"><span class="pre">'w'</span></code> format code (<a class="reference internal" href="../c-api/unicode.html#c.Py_UCS4" title="Py_UCS4"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UCS4</span></code></a>) for Unicode characters instead.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a>:</p> <ul> <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.iscoroutinefunction()</span></code> is deprecated and will be removed in Python 3.16, use <a class="reference internal" href="../library/inspect.html#inspect.iscoroutinefunction" title="inspect.iscoroutinefunction"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.iscoroutinefunction()</span></code></a> instead. (Contributed by Jiahao Li and Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/122875">gh-122875</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/builtins.html#module-builtins" title="builtins: The module that provides the built-in namespace."><code class="xref py py-mod docutils literal notranslate"><span class="pre">builtins</span></code></a>:</p> <ul> <li><p>Bitwise inversion on boolean types, <code class="docutils literal notranslate"><span class="pre">~True</span></code> or <code class="docutils literal notranslate"><span class="pre">~False</span></code> has been deprecated since Python 3.12, as it produces surprising and unintuitive results (<code class="docutils literal notranslate"><span class="pre">-2</span></code> and <code class="docutils literal notranslate"><span class="pre">-1</span></code>). Use <code class="docutils literal notranslate"><span class="pre">not</span> <span class="pre">x</span></code> instead for the logical negation of a Boolean. In the rare case that you need the bitwise inversion of the underlying integer, convert to <code class="docutils literal notranslate"><span class="pre">int</span></code> explicitly (<code class="docutils literal notranslate"><span class="pre">~int(x)</span></code>).</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/shutil.html#module-shutil" title="shutil: High-level file operations, including copying."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shutil</span></code></a>:</p> <ul> <li><p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">ExecError</span></code> exception has been deprecated since Python 3.14. It has not been used by any function in <code class="xref py py-mod docutils literal notranslate"><span class="pre">shutil</span></code> since Python 3.4, and is now an alias of <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/symtable.html#module-symtable" title="symtable: Interface to the compiler's internal symbol tables."><code class="xref py py-mod docutils literal notranslate"><span class="pre">symtable</span></code></a>:</p> <ul> <li><p>The <a class="reference internal" href="../library/symtable.html#symtable.Class.get_methods" title="symtable.Class.get_methods"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Class.get_methods</span></code></a> method has been deprecated since Python 3.14.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a>:</p> <ul> <li><p>The <a class="reference internal" href="../library/sys.html#sys._enablelegacywindowsfsencoding" title="sys._enablelegacywindowsfsencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">_enablelegacywindowsfsencoding()</span></code></a> function has been deprecated since Python 3.13. Use the <span class="target" id="index-49"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONLEGACYWINDOWSFSENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONLEGACYWINDOWSFSENCODING</span></code></a> environment variable instead.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a>:</p> <ul> <li><p>The undocumented and unused <code class="xref py py-attr docutils literal notranslate"><span class="pre">TarFile.tarfile</span></code> attribute has been deprecated since Python 3.13.</p></li> </ul> </li> </ul> </section> <section id="pending-removal-in-future-versions"> <h3>Pending Removal in Future Versions<a class="headerlink" href="#pending-removal-in-future-versions" title="Link to this heading">¶</a></h3> <p>The following APIs will be removed in the future, although there is currently no date scheduled for their removal.</p> <ul class="simple"> <li><p><a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a>: Nesting argument groups and nesting mutually exclusive groups are deprecated.</p></li> <li><p><a class="reference internal" href="../library/array.html#module-array" title="array: Space efficient arrays of uniformly typed numeric values."><code class="xref py py-mod docutils literal notranslate"><span class="pre">array</span></code></a>’s <code class="docutils literal notranslate"><span class="pre">'u'</span></code> format code (<a class="reference external" href="https://github.com/python/cpython/issues/57281">gh-57281</a>)</p></li> <li><p><a class="reference internal" href="../library/builtins.html#module-builtins" title="builtins: The module that provides the built-in namespace."><code class="xref py py-mod docutils literal notranslate"><span class="pre">builtins</span></code></a>:</p> <ul> <li><p><code class="docutils literal notranslate"><span class="pre">bool(NotImplemented)</span></code>.</p></li> <li><p>Generators: <code class="docutils literal notranslate"><span class="pre">throw(type,</span> <span class="pre">exc,</span> <span class="pre">tb)</span></code> and <code class="docutils literal notranslate"><span class="pre">athrow(type,</span> <span class="pre">exc,</span> <span class="pre">tb)</span></code> signature is deprecated: use <code class="docutils literal notranslate"><span class="pre">throw(exc)</span></code> and <code class="docutils literal notranslate"><span class="pre">athrow(exc)</span></code> instead, the single argument signature.</p></li> <li><p>Currently Python accepts numeric literals immediately followed by keywords, for example <code class="docutils literal notranslate"><span class="pre">0in</span> <span class="pre">x</span></code>, <code class="docutils literal notranslate"><span class="pre">1or</span> <span class="pre">x</span></code>, <code class="docutils literal notranslate"><span class="pre">0if</span> <span class="pre">1else</span> <span class="pre">2</span></code>. It allows confusing and ambiguous expressions like <code class="docutils literal notranslate"><span class="pre">[0x1for</span> <span class="pre">x</span> <span class="pre">in</span> <span class="pre">y]</span></code> (which can be interpreted as <code class="docutils literal notranslate"><span class="pre">[0x1</span> <span class="pre">for</span> <span class="pre">x</span> <span class="pre">in</span> <span class="pre">y]</span></code> or <code class="docutils literal notranslate"><span class="pre">[0x1f</span> <span class="pre">or</span> <span class="pre">x</span> <span class="pre">in</span> <span class="pre">y]</span></code>). A syntax warning is raised if the numeric literal is immediately followed by one of keywords <a class="reference internal" href="../reference/expressions.html#and"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">and</span></code></a>, <a class="reference internal" href="../reference/compound_stmts.html#else"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">else</span></code></a>, <a class="reference internal" href="../reference/compound_stmts.html#for"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">for</span></code></a>, <a class="reference internal" href="../reference/compound_stmts.html#if"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">if</span></code></a>, <a class="reference internal" href="../reference/expressions.html#in"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">in</span></code></a>, <a class="reference internal" href="../reference/expressions.html#is"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">is</span></code></a> and <a class="reference internal" href="../reference/expressions.html#or"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">or</span></code></a>. In a future release it will be changed to a syntax error. (<a class="reference external" href="https://github.com/python/cpython/issues/87999">gh-87999</a>)</p></li> <li><p>Support for <code class="docutils literal notranslate"><span class="pre">__index__()</span></code> and <code class="docutils literal notranslate"><span class="pre">__int__()</span></code> method returning non-int type: these methods will be required to return an instance of a strict subclass of <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>.</p></li> <li><p>Support for <code class="docutils literal notranslate"><span class="pre">__float__()</span></code> method returning a strict subclass of <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>: these methods will be required to return an instance of <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>.</p></li> <li><p>Support for <code class="docutils literal notranslate"><span class="pre">__complex__()</span></code> method returning a strict subclass of <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a>: these methods will be required to return an instance of <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a>.</p></li> <li><p>Delegation of <code class="docutils literal notranslate"><span class="pre">int()</span></code> to <code class="docutils literal notranslate"><span class="pre">__trunc__()</span></code> method.</p></li> <li><p>Passing a complex number as the <em>real</em> or <em>imag</em> argument in the <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-func docutils literal notranslate"><span class="pre">complex()</span></code></a> constructor is now deprecated; it should only be passed as a single positional argument. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/109218">gh-109218</a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/calendar.html#module-calendar" title="calendar: Functions for working with calendars, including some emulation of the Unix cal program."><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code></a>: <code class="docutils literal notranslate"><span class="pre">calendar.January</span></code> and <code class="docutils literal notranslate"><span class="pre">calendar.February</span></code> constants are deprecated and replaced by <a class="reference internal" href="../library/calendar.html#calendar.JANUARY" title="calendar.JANUARY"><code class="xref py py-data docutils literal notranslate"><span class="pre">calendar.JANUARY</span></code></a> and <a class="reference internal" href="../library/calendar.html#calendar.FEBRUARY" title="calendar.FEBRUARY"><code class="xref py py-data docutils literal notranslate"><span class="pre">calendar.FEBRUARY</span></code></a>. (Contributed by Prince Roshan in <a class="reference external" href="https://github.com/python/cpython/issues/103636">gh-103636</a>.)</p></li> <li><p><a class="reference internal" href="../reference/datamodel.html#codeobject.co_lnotab" title="codeobject.co_lnotab"><code class="xref py py-attr docutils literal notranslate"><span class="pre">codeobject.co_lnotab</span></code></a>: use the <a class="reference internal" href="../reference/datamodel.html#codeobject.co_lines" title="codeobject.co_lines"><code class="xref py py-meth docutils literal notranslate"><span class="pre">codeobject.co_lines()</span></code></a> method instead.</p></li> <li><p><a class="reference internal" href="../library/datetime.html#module-datetime" title="datetime: Basic date and time types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code></a>:</p> <ul> <li><p><a class="reference internal" href="../library/datetime.html#datetime.datetime.utcnow" title="datetime.datetime.utcnow"><code class="xref py py-meth docutils literal notranslate"><span class="pre">utcnow()</span></code></a>: use <code class="docutils literal notranslate"><span class="pre">datetime.datetime.now(tz=datetime.UTC)</span></code>.</p></li> <li><p><a class="reference internal" href="../library/datetime.html#datetime.datetime.utcfromtimestamp" title="datetime.datetime.utcfromtimestamp"><code class="xref py py-meth docutils literal notranslate"><span class="pre">utcfromtimestamp()</span></code></a>: use <code class="docutils literal notranslate"><span class="pre">datetime.datetime.fromtimestamp(timestamp,</span> <span class="pre">tz=datetime.UTC)</span></code>.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/gettext.html#module-gettext" title="gettext: Multilingual internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gettext</span></code></a>: Plural value must be an integer.</p></li> <li><p><a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a>:</p> <ul> <li><p><code class="docutils literal notranslate"><span class="pre">load_module()</span></code> method: use <code class="docutils literal notranslate"><span class="pre">exec_module()</span></code> instead.</p></li> <li><p><a class="reference internal" href="../library/importlib.html#importlib.util.cache_from_source" title="importlib.util.cache_from_source"><code class="xref py py-func docutils literal notranslate"><span class="pre">cache_from_source()</span></code></a> <em>debug_override</em> parameter is deprecated: use the <em>optimization</em> parameter instead.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/importlib.metadata.html#module-importlib.metadata" title="importlib.metadata: Accessing package metadata"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code></a>:</p> <ul> <li><p><code class="docutils literal notranslate"><span class="pre">EntryPoints</span></code> tuple interface.</p></li> <li><p>Implicit <code class="docutils literal notranslate"><span class="pre">None</span></code> on return values.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/logging.html#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a>: the <code class="docutils literal notranslate"><span class="pre">warn()</span></code> method has been deprecated since Python 3.3, use <a class="reference internal" href="../library/logging.html#logging.warning" title="logging.warning"><code class="xref py py-meth docutils literal notranslate"><span class="pre">warning()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../library/mailbox.html#module-mailbox" title="mailbox: Manipulate mailboxes in various formats"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mailbox</span></code></a>: Use of StringIO input and text mode is deprecated, use BytesIO and binary mode instead.</p></li> <li><p><a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a>: Calling <a class="reference internal" href="../library/os.html#os.register_at_fork" title="os.register_at_fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.register_at_fork()</span></code></a> in multi-threaded process.</p></li> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">pydoc.ErrorDuringImport</span></code>: A tuple value for <em>exc_info</em> parameter is deprecated, use an exception instance.</p></li> <li><p><a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a>: 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 in <a class="reference external" href="https://github.com/python/cpython/issues/91760">gh-91760</a>.)</p></li> <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">sre_compile</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">sre_constants</span></code> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">sre_parse</span></code> modules.</p></li> <li><p><a class="reference internal" href="../library/shutil.html#module-shutil" title="shutil: High-level file operations, including copying."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shutil</span></code></a>: <a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">rmtree()</span></code></a>’s <em>onerror</em> parameter is deprecated in Python 3.12; use the <em>onexc</em> parameter instead.</p></li> <li><p><a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a> options and protocols:</p> <ul> <li><p><a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> without protocol argument is deprecated.</p></li> <li><p><a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a>: <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_npn_protocols" title="ssl.SSLContext.set_npn_protocols"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_npn_protocols()</span></code></a> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">selected_npn_protocol()</span></code> are deprecated: use ALPN instead.</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">ssl.OP_NO_SSL*</span></code> options</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">ssl.OP_NO_TLS*</span></code> options</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">ssl.PROTOCOL_SSLv3</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">ssl.PROTOCOL_TLS</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">ssl.PROTOCOL_TLSv1</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">ssl.PROTOCOL_TLSv1_1</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">ssl.PROTOCOL_TLSv1_2</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">ssl.TLSVersion.SSLv3</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">ssl.TLSVersion.TLSv1</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">ssl.TLSVersion.TLSv1_1</span></code></p></li> </ul> </li> <li><p><a class="reference internal" href="../library/sysconfig.html#sysconfig.is_python_build" title="sysconfig.is_python_build"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconfig.is_python_build()</span></code></a> <em>check_home</em> parameter is deprecated and ignored.</p></li> <li><p><a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a> methods:</p> <ul> <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Condition.notifyAll()</span></code>: use <a class="reference internal" href="../library/threading.html#threading.Condition.notify_all" title="threading.Condition.notify_all"><code class="xref py py-meth docutils literal notranslate"><span class="pre">notify_all()</span></code></a>.</p></li> <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Event.isSet()</span></code>: use <a class="reference internal" href="../library/threading.html#threading.Event.is_set" title="threading.Event.is_set"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_set()</span></code></a>.</p></li> <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Thread.isDaemon()</span></code>, <a class="reference internal" href="../library/threading.html#threading.Thread.setDaemon" title="threading.Thread.setDaemon"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Thread.setDaemon()</span></code></a>: use <a class="reference internal" href="../library/threading.html#threading.Thread.daemon" title="threading.Thread.daemon"><code class="xref py py-attr docutils literal notranslate"><span class="pre">threading.Thread.daemon</span></code></a> attribute.</p></li> <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Thread.getName()</span></code>, <a class="reference internal" href="../library/threading.html#threading.Thread.setName" title="threading.Thread.setName"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Thread.setName()</span></code></a>: use <a class="reference internal" href="../library/threading.html#threading.Thread.name" title="threading.Thread.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">threading.Thread.name</span></code></a> attribute.</p></li> <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.currentThread()</span></code>: use <a class="reference internal" href="../library/threading.html#threading.current_thread" title="threading.current_thread"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.current_thread()</span></code></a>.</p></li> <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.activeCount()</span></code>: use <a class="reference internal" href="../library/threading.html#threading.active_count" title="threading.active_count"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.active_count()</span></code></a>.</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/typing.html#typing.Text" title="typing.Text"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Text</span></code></a> (<a class="reference external" href="https://github.com/python/cpython/issues/92332">gh-92332</a>).</p></li> <li><p><a class="reference internal" href="../library/unittest.html#unittest.IsolatedAsyncioTestCase" title="unittest.IsolatedAsyncioTestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">unittest.IsolatedAsyncioTestCase</span></code></a>: it is deprecated to return a value that is not <code class="docutils literal notranslate"><span class="pre">None</span></code> from a test case.</p></li> <li><p><a class="reference internal" href="../library/urllib.parse.html#module-urllib.parse" title="urllib.parse: Parse URLs into or assemble them from components."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.parse</span></code></a> deprecated functions: <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.urlparse" title="urllib.parse.urlparse"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlparse()</span></code></a> instead</p> <ul> <li><p><code class="docutils literal notranslate"><span class="pre">splitattr()</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">splithost()</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">splitnport()</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">splitpasswd()</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">splitport()</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">splitquery()</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">splittag()</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">splittype()</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">splituser()</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">splitvalue()</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">to_bytes()</span></code></p></li> </ul> </li> <li><p><a class="reference internal" href="../library/urllib.request.html#module-urllib.request" title="urllib.request: Extensible library for opening URLs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request</span></code></a>: <a class="reference internal" href="../library/urllib.request.html#urllib.request.URLopener" title="urllib.request.URLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">URLopener</span></code></a> and <a class="reference internal" href="../library/urllib.request.html#urllib.request.FancyURLopener" title="urllib.request.FancyURLopener"><code class="xref py py-class docutils literal notranslate"><span class="pre">FancyURLopener</span></code></a> style of invoking requests is deprecated. Use newer <a class="reference internal" href="../library/urllib.request.html#urllib.request.urlopen" title="urllib.request.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlopen()</span></code></a> functions and methods.</p></li> <li><p><a class="reference internal" href="../library/wsgiref.html#module-wsgiref" title="wsgiref: WSGI Utilities and Reference Implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref</span></code></a>: <code class="docutils literal notranslate"><span class="pre">SimpleHandler.stdout.write()</span></code> should not do partial writes.</p></li> <li><p><a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code></a>: Testing the truth value of an <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.Element" title="xml.etree.ElementTree.Element"><code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code></a> is deprecated. In a future release it will always return <code class="docutils literal notranslate"><span class="pre">True</span></code>. Prefer explicit <code class="docutils literal notranslate"><span class="pre">len(elem)</span></code> or <code class="docutils literal notranslate"><span class="pre">elem</span> <span class="pre">is</span> <span class="pre">not</span> <span class="pre">None</span></code> tests instead.</p></li> <li><p><a class="reference internal" href="../library/zipimport.html#zipimport.zipimporter.load_module" title="zipimport.zipimporter.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">zipimport.zipimporter.load_module()</span></code></a> is deprecated: use <a class="reference internal" href="../library/zipimport.html#zipimport.zipimporter.exec_module" title="zipimport.zipimporter.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exec_module()</span></code></a> instead.</p></li> </ul> </section> </section> <section id="cpython-bytecode-changes"> <h2>CPython Bytecode Changes<a class="headerlink" href="#cpython-bytecode-changes" title="Link to this heading">¶</a></h2> <ul class="simple"> <li><p>The oparg of <a class="reference internal" href="../library/dis.html#opcode-YIELD_VALUE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">YIELD_VALUE</span></code></a> is now <code class="docutils literal notranslate"><span class="pre">1</span></code> if the yield is part of a yield-from or await, and <code class="docutils literal notranslate"><span class="pre">0</span></code> otherwise. The oparg of <a class="reference internal" href="../library/dis.html#opcode-RESUME"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">RESUME</span></code></a> was changed to add a bit indicating if the except-depth is 1, which is needed to optimize closing of generators. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/111354">gh-111354</a>.)</p></li> </ul> </section> <section id="c-api-changes"> <h2>C API Changes<a class="headerlink" href="#c-api-changes" title="Link to this heading">¶</a></h2> <section id="id7"> <h3>New Features<a class="headerlink" href="#id7" title="Link to this heading">¶</a></h3> <ul> <li><p>Add the <a class="reference internal" href="../c-api/monitoring.html#c-api-monitoring"><span class="std std-ref">PyMonitoring C API</span></a> for generating <span class="target" id="index-50"></span><a class="pep reference external" href="https://peps.python.org/pep-0669/"><strong>PEP 669</strong></a> monitoring events:</p> <ul class="simple"> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoringState" title="PyMonitoringState"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyMonitoringState</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FirePyStartEvent" title="PyMonitoring_FirePyStartEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FirePyStartEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FirePyResumeEvent" title="PyMonitoring_FirePyResumeEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FirePyResumeEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FirePyReturnEvent" title="PyMonitoring_FirePyReturnEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FirePyReturnEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FirePyYieldEvent" title="PyMonitoring_FirePyYieldEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FirePyYieldEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FireCallEvent" title="PyMonitoring_FireCallEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FireCallEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FireLineEvent" title="PyMonitoring_FireLineEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FireLineEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FireJumpEvent" title="PyMonitoring_FireJumpEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FireJumpEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FireBranchEvent" title="PyMonitoring_FireBranchEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FireBranchEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FireCReturnEvent" title="PyMonitoring_FireCReturnEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FireCReturnEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FirePyThrowEvent" title="PyMonitoring_FirePyThrowEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FirePyThrowEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FireRaiseEvent" title="PyMonitoring_FireRaiseEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FireRaiseEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FireCRaiseEvent" title="PyMonitoring_FireCRaiseEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FireCRaiseEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FireReraiseEvent" title="PyMonitoring_FireReraiseEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FireReraiseEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FireExceptionHandledEvent" title="PyMonitoring_FireExceptionHandledEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FireExceptionHandledEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FirePyUnwindEvent" title="PyMonitoring_FirePyUnwindEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FirePyUnwindEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_FireStopIterationEvent" title="PyMonitoring_FireStopIterationEvent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_FireStopIterationEvent()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_EnterScope" title="PyMonitoring_EnterScope"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_EnterScope()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/monitoring.html#c.PyMonitoring_ExitScope" title="PyMonitoring_ExitScope"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMonitoring_ExitScope()</span></code></a></p></li> </ul> <p>(Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/111997">gh-111997</a>).</p> </li> <li><p>Add <a class="reference internal" href="../c-api/init.html#c.PyMutex" title="PyMutex"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyMutex</span></code></a>, a lightweight mutex that occupies a single byte, and the new <a class="reference internal" href="../c-api/init.html#c.PyMutex_Lock" title="PyMutex_Lock"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMutex_Lock()</span></code></a> and <a class="reference internal" href="../c-api/init.html#c.PyMutex_Unlock" title="PyMutex_Unlock"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMutex_Unlock()</span></code></a> functions. <code class="xref c c-func docutils literal notranslate"><span class="pre">PyMutex_Lock()</span></code> will release the <a class="reference internal" href="../glossary.html#term-GIL"><span class="xref std std-term">GIL</span></a> (if currently held) if the operation needs to block. (Contributed by Sam Gross in <a class="reference external" href="https://github.com/python/cpython/issues/108724">gh-108724</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/time.html#c-api-time"><span class="std std-ref">PyTime C API</span></a> to provide access to system clocks:</p> <ul class="simple"> <li><p><a class="reference internal" href="../c-api/time.html#c.PyTime_t" title="PyTime_t"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyTime_t</span></code></a>.</p></li> <li><p><a class="reference internal" href="../c-api/time.html#c.PyTime_MIN" title="PyTime_MIN"><code class="xref c c-var docutils literal notranslate"><span class="pre">PyTime_MIN</span></code></a> and <a class="reference internal" href="../c-api/time.html#c.PyTime_MAX" title="PyTime_MAX"><code class="xref c c-var docutils literal notranslate"><span class="pre">PyTime_MAX</span></code></a>.</p></li> <li><p><a class="reference internal" href="../c-api/time.html#c.PyTime_AsSecondsDouble" title="PyTime_AsSecondsDouble"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTime_AsSecondsDouble()</span></code></a>.</p></li> <li><p><a class="reference internal" href="../c-api/time.html#c.PyTime_Monotonic" title="PyTime_Monotonic"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTime_Monotonic()</span></code></a>.</p></li> <li><p><a class="reference internal" href="../c-api/time.html#c.PyTime_MonotonicRaw" title="PyTime_MonotonicRaw"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTime_MonotonicRaw()</span></code></a>.</p></li> <li><p><a class="reference internal" href="../c-api/time.html#c.PyTime_PerfCounter" title="PyTime_PerfCounter"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTime_PerfCounter()</span></code></a>.</p></li> <li><p><a class="reference internal" href="../c-api/time.html#c.PyTime_PerfCounterRaw" title="PyTime_PerfCounterRaw"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTime_PerfCounterRaw()</span></code></a>.</p></li> <li><p><a class="reference internal" href="../c-api/time.html#c.PyTime_Time" title="PyTime_Time"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTime_Time()</span></code></a>.</p></li> <li><p><a class="reference internal" href="../c-api/time.html#c.PyTime_TimeRaw" title="PyTime_TimeRaw"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTime_TimeRaw()</span></code></a>.</p></li> </ul> <p>(Contributed by Victor Stinner and Petr Viktorin in <a class="reference external" href="https://github.com/python/cpython/issues/110850">gh-110850</a>.)</p> </li> <li><p>Add the <a class="reference internal" href="../c-api/dict.html#c.PyDict_ContainsString" title="PyDict_ContainsString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_ContainsString()</span></code></a> function with the same behavior as <a class="reference internal" href="../c-api/dict.html#c.PyDict_Contains" title="PyDict_Contains"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_Contains()</span></code></a>, but <em>key</em> is specified as a <span class="c-expr sig sig-inline c"><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="p">*</span></span> UTF-8 encoded bytes string, rather than a <span class="c-expr sig sig-inline c"><a class="reference internal" href="../c-api/structures.html#c.PyObject" title="PyObject"><span class="n">PyObject</span></a><span class="p">*</span></span>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/108314">gh-108314</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/dict.html#c.PyDict_GetItemRef" title="PyDict_GetItemRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_GetItemRef()</span></code></a> and <a class="reference internal" href="../c-api/dict.html#c.PyDict_GetItemStringRef" title="PyDict_GetItemStringRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_GetItemStringRef()</span></code></a> functions, which behave similarly to <a class="reference internal" href="../c-api/dict.html#c.PyDict_GetItemWithError" title="PyDict_GetItemWithError"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_GetItemWithError()</span></code></a>, but return a <a class="reference internal" href="../glossary.html#term-strong-reference"><span class="xref std std-term">strong reference</span></a> instead of a <a class="reference internal" href="../glossary.html#term-borrowed-reference"><span class="xref std std-term">borrowed reference</span></a>. Moreover, these functions return <code class="docutils literal notranslate"><span class="pre">-1</span></code> on error, removing the need to check <code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Occurred()</span></code>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/106004">gh-106004</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/dict.html#c.PyDict_SetDefaultRef" title="PyDict_SetDefaultRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_SetDefaultRef()</span></code></a> function, which behaves similarly to <a class="reference internal" href="../c-api/dict.html#c.PyDict_SetDefault" title="PyDict_SetDefault"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_SetDefault()</span></code></a>, but returns a <a class="reference internal" href="../glossary.html#term-strong-reference"><span class="xref std std-term">strong reference</span></a> instead of a <a class="reference internal" href="../glossary.html#term-borrowed-reference"><span class="xref std std-term">borrowed reference</span></a>. This function returns <code class="docutils literal notranslate"><span class="pre">-1</span></code> on error, <code class="docutils literal notranslate"><span class="pre">0</span></code> on insertion, and <code class="docutils literal notranslate"><span class="pre">1</span></code> if the key was already present in the dictionary. (Contributed by Sam Gross in <a class="reference external" href="https://github.com/python/cpython/issues/112066">gh-112066</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/dict.html#c.PyDict_Pop" title="PyDict_Pop"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_Pop()</span></code></a> and <a class="reference internal" href="../c-api/dict.html#c.PyDict_PopString" title="PyDict_PopString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_PopString()</span></code></a> functions to remove a key from a dictionary and optionally return the removed value. This is similar to <a class="reference internal" href="../library/stdtypes.html#dict.pop" title="dict.pop"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.pop()</span></code></a>, though there is no default value, and <a class="reference internal" href="../library/exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> is not raised for missing keys. (Contributed by Stefan Behnel and Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/111262">gh-111262</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/mapping.html#c.PyMapping_GetOptionalItem" title="PyMapping_GetOptionalItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMapping_GetOptionalItem()</span></code></a> and <a class="reference internal" href="../c-api/mapping.html#c.PyMapping_GetOptionalItemString" title="PyMapping_GetOptionalItemString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMapping_GetOptionalItemString()</span></code></a> functions as alternatives to <a class="reference internal" href="../c-api/object.html#c.PyObject_GetItem" title="PyObject_GetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetItem()</span></code></a> and <a class="reference internal" href="../c-api/mapping.html#c.PyMapping_GetItemString" title="PyMapping_GetItemString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMapping_GetItemString()</span></code></a> respectively. The new functions do not raise <a class="reference internal" href="../library/exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> if the requested key is missing from the mapping. These variants are more convenient and faster if a missing key should not be treated as a failure. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/106307">gh-106307</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/object.html#c.PyObject_GetOptionalAttr" title="PyObject_GetOptionalAttr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetOptionalAttr()</span></code></a> and <a class="reference internal" href="../c-api/object.html#c.PyObject_GetOptionalAttrString" title="PyObject_GetOptionalAttrString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetOptionalAttrString()</span></code></a> functions as alternatives to <a class="reference internal" href="../c-api/object.html#c.PyObject_GetAttr" title="PyObject_GetAttr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetAttr()</span></code></a> and <a class="reference internal" href="../c-api/object.html#c.PyObject_GetAttrString" title="PyObject_GetAttrString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetAttrString()</span></code></a> respectively. The new functions do not raise <a class="reference internal" href="../library/exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a> if the requested attribute is not found on the object. These variants are more convenient and faster if the missing attribute should not be treated as a failure. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/106521">gh-106521</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_FormatUnraisable" title="PyErr_FormatUnraisable"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_FormatUnraisable()</span></code></a> function as an extension to <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_WriteUnraisable" title="PyErr_WriteUnraisable"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_WriteUnraisable()</span></code></a> that allows customizing the warning message. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/108082">gh-108082</a>.)</p></li> <li><p>Add new functions that return a <a class="reference internal" href="../glossary.html#term-strong-reference"><span class="xref std std-term">strong reference</span></a> instead of a <a class="reference internal" href="../glossary.html#term-borrowed-reference"><span class="xref std std-term">borrowed reference</span></a> for frame locals, globals, and builtins, as part of <a class="reference internal" href="#whatsnew313-locals-semantics"><span class="std std-ref">PEP 667</span></a>:</p> <ul class="simple"> <li><p><a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetFrameBuiltins" title="PyEval_GetFrameBuiltins"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetFrameBuiltins()</span></code></a> replaces <a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetBuiltins" title="PyEval_GetBuiltins"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetBuiltins()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetFrameGlobals" title="PyEval_GetFrameGlobals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetFrameGlobals()</span></code></a> replaces <a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetGlobals" title="PyEval_GetGlobals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetGlobals()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetFrameLocals" title="PyEval_GetFrameLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetFrameLocals()</span></code></a> replaces <a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetLocals" title="PyEval_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetLocals()</span></code></a></p></li> </ul> <p>(Contributed by Mark Shannon and Tian Gao in <a class="reference external" href="https://github.com/python/cpython/issues/74929">gh-74929</a>.)</p> </li> <li><p>Add the <a class="reference internal" href="../c-api/object.html#c.Py_GetConstant" title="Py_GetConstant"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetConstant()</span></code></a> and <a class="reference internal" href="../c-api/object.html#c.Py_GetConstantBorrowed" title="Py_GetConstantBorrowed"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetConstantBorrowed()</span></code></a> functions to get <a class="reference internal" href="../glossary.html#term-strong-reference"><span class="xref std std-term">strong</span></a> or <a class="reference internal" href="../glossary.html#term-borrowed-reference"><span class="xref std std-term">borrowed</span></a> references to constants. For example, <code class="docutils literal notranslate"><span class="pre">Py_GetConstant(Py_CONSTANT_ZERO)</span></code> returns a strong reference to the constant zero. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/115754">gh-115754</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/import.html#c.PyImport_AddModuleRef" title="PyImport_AddModuleRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_AddModuleRef()</span></code></a> function as a replacement for <a class="reference internal" href="../c-api/import.html#c.PyImport_AddModule" title="PyImport_AddModule"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_AddModule()</span></code></a> that returns a <a class="reference internal" href="../glossary.html#term-strong-reference"><span class="xref std std-term">strong reference</span></a> instead of a <a class="reference internal" href="../glossary.html#term-borrowed-reference"><span class="xref std std-term">borrowed reference</span></a>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105922">gh-105922</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/init.html#c.Py_IsFinalizing" title="Py_IsFinalizing"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_IsFinalizing()</span></code></a> function to check whether the main Python interpreter is <a class="reference internal" href="../glossary.html#term-interpreter-shutdown"><span class="xref std std-term">shutting down</span></a>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/108014">gh-108014</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/list.html#c.PyList_GetItemRef" title="PyList_GetItemRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyList_GetItemRef()</span></code></a> function as a replacement for <a class="reference internal" href="../c-api/list.html#c.PyList_GetItem" title="PyList_GetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyList_GetItem()</span></code></a> that returns a <a class="reference internal" href="../glossary.html#term-strong-reference"><span class="xref std std-term">strong reference</span></a> instead of a <a class="reference internal" href="../glossary.html#term-borrowed-reference"><span class="xref std std-term">borrowed reference</span></a>. (Contributed by Sam Gross in <a class="reference external" href="https://github.com/python/cpython/issues/114329">gh-114329</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/list.html#c.PyList_Extend" title="PyList_Extend"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyList_Extend()</span></code></a> and <a class="reference internal" href="../c-api/list.html#c.PyList_Clear" title="PyList_Clear"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyList_Clear()</span></code></a> functions, mirroring the Python <code class="xref py py-meth docutils literal notranslate"><span class="pre">list.extend()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">list.clear()</span></code> methods. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/111138">gh-111138</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/long.html#c.PyLong_AsInt" title="PyLong_AsInt"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyLong_AsInt()</span></code></a> function. It behaves similarly to <a class="reference internal" href="../c-api/long.html#c.PyLong_AsLong" title="PyLong_AsLong"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyLong_AsLong()</span></code></a>, but stores the result in a C <span class="c-expr sig sig-inline c"><span class="kt">int</span></span> instead of a C <span class="c-expr sig sig-inline c"><span class="kt">long</span></span>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/108014">gh-108014</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/long.html#c.PyLong_AsNativeBytes" title="PyLong_AsNativeBytes"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyLong_AsNativeBytes()</span></code></a>, <a class="reference internal" href="../c-api/long.html#c.PyLong_FromNativeBytes" title="PyLong_FromNativeBytes"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyLong_FromNativeBytes()</span></code></a>, and <a class="reference internal" href="../c-api/long.html#c.PyLong_FromUnsignedNativeBytes" title="PyLong_FromUnsignedNativeBytes"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyLong_FromUnsignedNativeBytes()</span></code></a> functions to simplify converting between native integer types and Python <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> objects. (Contributed by Steve Dower in <a class="reference external" href="https://github.com/python/cpython/issues/111140">gh-111140</a>.)</p></li> <li><p>Add <a class="reference internal" href="../c-api/module.html#c.PyModule_Add" title="PyModule_Add"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_Add()</span></code></a> function, which is similar to <a class="reference internal" href="../c-api/module.html#c.PyModule_AddObjectRef" title="PyModule_AddObjectRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_AddObjectRef()</span></code></a> and <a class="reference internal" href="../c-api/module.html#c.PyModule_AddObject" title="PyModule_AddObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_AddObject()</span></code></a>, but always steals a reference to the value. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/86493">gh-86493</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/hash.html#c.PyObject_GenericHash" title="PyObject_GenericHash"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GenericHash()</span></code></a> function that implements the default hashing function of a Python object. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/113024">gh-113024</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/hash.html#c.Py_HashPointer" title="Py_HashPointer"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_HashPointer()</span></code></a> function to hash a raw pointer. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/111545">gh-111545</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/object.html#c.PyObject_VisitManagedDict" title="PyObject_VisitManagedDict"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_VisitManagedDict()</span></code></a> and <a class="reference internal" href="../c-api/object.html#c.PyObject_ClearManagedDict" title="PyObject_ClearManagedDict"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_ClearManagedDict()</span></code></a> functions. which must be called by the traverse and clear functions of a type using the <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_MANAGED_DICT" title="Py_TPFLAGS_MANAGED_DICT"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_MANAGED_DICT</span></code></a> flag. The <a class="reference external" href="https://github.com/python/pythoncapi-compat/">pythoncapi-compat project</a> can be used to use these functions with Python 3.11 and 3.12. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/107073">gh-107073</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/init.html#c.PyRefTracer_SetTracer" title="PyRefTracer_SetTracer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRefTracer_SetTracer()</span></code></a> and <a class="reference internal" href="../c-api/init.html#c.PyRefTracer_GetTracer" title="PyRefTracer_GetTracer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyRefTracer_GetTracer()</span></code></a> functions, which enable tracking object creation and destruction in the same way that the <a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a> module does. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/93502">gh-93502</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/sys.html#c.PySys_AuditTuple" title="PySys_AuditTuple"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AuditTuple()</span></code></a> function as an alternative to <a class="reference internal" href="../c-api/sys.html#c.PySys_Audit" title="PySys_Audit"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_Audit()</span></code></a> that takes event arguments as a Python <a class="reference internal" href="../library/stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a> object. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/85283">gh-85283</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/init.html#c.PyThreadState_GetUnchecked" title="PyThreadState_GetUnchecked"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_GetUnchecked()</span></code></a> function as an alternative to <a class="reference internal" href="../c-api/init.html#c.PyThreadState_Get" title="PyThreadState_Get"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_Get()</span></code></a> that doesn’t kill the process with a fatal error if it is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>. The caller is responsible for checking if the result is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/108867">gh-108867</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/type.html#c.PyType_GetFullyQualifiedName" title="PyType_GetFullyQualifiedName"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetFullyQualifiedName()</span></code></a> function to get the type’s fully qualified name. The module name is prepended if <a class="reference internal" href="../reference/datamodel.html#type.__module__" title="type.__module__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">type.__module__</span></code></a> is a string and is not equal to either <code class="docutils literal notranslate"><span class="pre">'builtins'</span></code> or <code class="docutils literal notranslate"><span class="pre">'__main__'</span></code>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/111696">gh-111696</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/type.html#c.PyType_GetModuleName" title="PyType_GetModuleName"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetModuleName()</span></code></a> function to get the type’s module name. This is equivalent to getting the <a class="reference internal" href="../reference/datamodel.html#type.__module__" title="type.__module__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">type.__module__</span></code></a> attribute. (Contributed by Eric Snow and Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/111696">gh-111696</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EqualToUTF8AndSize" title="PyUnicode_EqualToUTF8AndSize"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EqualToUTF8AndSize()</span></code></a> and <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EqualToUTF8" title="PyUnicode_EqualToUTF8"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EqualToUTF8()</span></code></a> functions to compare a Unicode object with a <span class="c-expr sig sig-inline c"><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="p">*</span></span> UTF-8 encoded string and <code class="docutils literal notranslate"><span class="pre">1</span></code> if they are equal or <code class="docutils literal notranslate"><span class="pre">0</span></code> otherwise. These functions do not raise exceptions. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/110289">gh-110289</a>.)</p></li> <li><p>Add the <a class="reference internal" href="../c-api/weakref.html#c.PyWeakref_GetRef" title="PyWeakref_GetRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWeakref_GetRef()</span></code></a> function as an alternative to <a class="reference internal" href="../c-api/weakref.html#c.PyWeakref_GetObject" title="PyWeakref_GetObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWeakref_GetObject()</span></code></a> that returns a <a class="reference internal" href="../glossary.html#term-strong-reference"><span class="xref std std-term">strong reference</span></a> or <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if the referent is no longer live. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105927">gh-105927</a>.)</p></li> <li><p>Add fixed variants of functions which silently ignore errors:</p> <ul class="simple"> <li><p><a class="reference internal" href="../c-api/object.html#c.PyObject_HasAttrWithError" title="PyObject_HasAttrWithError"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_HasAttrWithError()</span></code></a> replaces <a class="reference internal" href="../c-api/object.html#c.PyObject_HasAttr" title="PyObject_HasAttr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_HasAttr()</span></code></a>.</p></li> <li><p><a class="reference internal" href="../c-api/object.html#c.PyObject_HasAttrStringWithError" title="PyObject_HasAttrStringWithError"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_HasAttrStringWithError()</span></code></a> replaces <a class="reference internal" href="../c-api/object.html#c.PyObject_HasAttrString" title="PyObject_HasAttrString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_HasAttrString()</span></code></a>.</p></li> <li><p><a class="reference internal" href="../c-api/mapping.html#c.PyMapping_HasKeyWithError" title="PyMapping_HasKeyWithError"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMapping_HasKeyWithError()</span></code></a> replaces <a class="reference internal" href="../c-api/mapping.html#c.PyMapping_HasKey" title="PyMapping_HasKey"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMapping_HasKey()</span></code></a>.</p></li> <li><p><a class="reference internal" href="../c-api/mapping.html#c.PyMapping_HasKeyStringWithError" title="PyMapping_HasKeyStringWithError"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMapping_HasKeyStringWithError()</span></code></a> replaces <a class="reference internal" href="../c-api/mapping.html#c.PyMapping_HasKeyString" title="PyMapping_HasKeyString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMapping_HasKeyString()</span></code></a>.</p></li> </ul> <p>The new functions return <code class="docutils literal notranslate"><span class="pre">-1</span></code> for errors and the standard <code class="docutils literal notranslate"><span class="pre">1</span></code> for true and <code class="docutils literal notranslate"><span class="pre">0</span></code> for false.</p> <p>(Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/108511">gh-108511</a>.)</p> </li> </ul> </section> <section id="changed-c-apis"> <h3>Changed C APIs<a class="headerlink" href="#changed-c-apis" title="Link to this heading">¶</a></h3> <ul> <li><p>The <em>keywords</em> parameter of <a class="reference internal" href="../c-api/arg.html#c.PyArg_ParseTupleAndKeywords" title="PyArg_ParseTupleAndKeywords"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTupleAndKeywords()</span></code></a> and <a class="reference internal" href="../c-api/arg.html#c.PyArg_VaParseTupleAndKeywords" title="PyArg_VaParseTupleAndKeywords"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_VaParseTupleAndKeywords()</span></code></a> now has type <span class="c-expr sig sig-inline c"><span class="kt">char</span><span class="w"> </span><span class="p">*</span><span class="k">const</span><span class="p">*</span></span> in C and <span class="c-expr sig sig-inline c"><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="p">*</span><span class="k">const</span><span class="p">*</span></span> in C++, instead of <span class="c-expr sig sig-inline c"><span class="kt">char</span><span class="p">*</span><span class="p">*</span></span>. In C++, this makes these functions compatible with arguments of type <span class="c-expr sig sig-inline c"><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="p">*</span><span class="k">const</span><span class="p">*</span></span>, <span class="c-expr sig sig-inline c"><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="p">*</span><span class="p">*</span></span>, or <span class="c-expr sig sig-inline c"><span class="kt">char</span><span class="w"> </span><span class="p">*</span><span class="k">const</span><span class="p">*</span></span> without an explicit type cast. In C, the functions only support arguments of type <span class="c-expr sig sig-inline c"><span class="kt">char</span><span class="w"> </span><span class="p">*</span><span class="k">const</span><span class="p">*</span></span>. This can be overridden with the <a class="reference internal" href="../c-api/arg.html#c.PY_CXX_CONST" title="PY_CXX_CONST"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PY_CXX_CONST</span></code></a> macro. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/65210">gh-65210</a>.)</p></li> <li><p><a class="reference internal" href="../c-api/arg.html#c.PyArg_ParseTupleAndKeywords" title="PyArg_ParseTupleAndKeywords"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTupleAndKeywords()</span></code></a> now supports non-ASCII keyword parameter names. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/110815">gh-110815</a>.)</p></li> <li><p>The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_GetFirstFree()</span></code> function is now unstable API and is now named <a class="reference internal" href="../c-api/code.html#c.PyUnstable_Code_GetFirstFree" title="PyUnstable_Code_GetFirstFree"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnstable_Code_GetFirstFree()</span></code></a>. (Contributed by Bogdan Romanyuk in <a class="reference external" href="https://github.com/python/cpython/issues/115781">gh-115781</a>.)</p></li> <li><p>The <a class="reference internal" href="../c-api/dict.html#c.PyDict_GetItem" title="PyDict_GetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_GetItem()</span></code></a>, <a class="reference internal" href="../c-api/dict.html#c.PyDict_GetItemString" title="PyDict_GetItemString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_GetItemString()</span></code></a>, <a class="reference internal" href="../c-api/mapping.html#c.PyMapping_HasKey" title="PyMapping_HasKey"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMapping_HasKey()</span></code></a>, <a class="reference internal" href="../c-api/mapping.html#c.PyMapping_HasKeyString" title="PyMapping_HasKeyString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMapping_HasKeyString()</span></code></a>, <a class="reference internal" href="../c-api/object.html#c.PyObject_HasAttr" title="PyObject_HasAttr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_HasAttr()</span></code></a>, <a class="reference internal" href="../c-api/object.html#c.PyObject_HasAttrString" title="PyObject_HasAttrString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_HasAttrString()</span></code></a>, and <a class="reference internal" href="../c-api/sys.html#c.PySys_GetObject" title="PySys_GetObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_GetObject()</span></code></a> functions, each of which clears all errors which occurred when calling them now reports these errors using <a class="reference internal" href="../library/sys.html#sys.unraisablehook" title="sys.unraisablehook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.unraisablehook()</span></code></a>. You may replace them with other functions as recommended in the documentation. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/106672">gh-106672</a>.)</p></li> <li><p>Add support for the <code class="docutils literal notranslate"><span class="pre">%T</span></code>, <code class="docutils literal notranslate"><span class="pre">%#T</span></code>, <code class="docutils literal notranslate"><span class="pre">%N</span></code> and <code class="docutils literal notranslate"><span class="pre">%#N</span></code> formats to <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a>:</p> <ul class="simple"> <li><p><code class="docutils literal notranslate"><span class="pre">%T</span></code>: Get the fully qualified name of an object type</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">%#T</span></code>: As above, but use a colon as the separator</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">%N</span></code>: Get the fully qualified name of a type</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">%#N</span></code>: As above, but use a colon as the separator</p></li> </ul> <p>See <span class="target" id="index-51"></span><a class="pep reference external" href="https://peps.python.org/pep-0737/"><strong>PEP 737</strong></a> for more information. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/111696">gh-111696</a>.)</p> </li> <li><p>You no longer have to define the <code class="docutils literal notranslate"><span class="pre">PY_SSIZE_T_CLEAN</span></code> macro before including <code class="file docutils literal notranslate"><span class="pre">Python.h</span></code> when using <code class="docutils literal notranslate"><span class="pre">#</span></code> formats in <a class="reference internal" href="../c-api/arg.html#arg-parsing-string-and-buffers"><span class="std std-ref">format codes</span></a>. APIs accepting the format codes always use <code class="docutils literal notranslate"><span class="pre">Py_ssize_t</span></code> for <code class="docutils literal notranslate"><span class="pre">#</span></code> formats. (Contributed by Inada Naoki in <a class="reference external" href="https://github.com/python/cpython/issues/104922">gh-104922</a>.)</p></li> <li><p>If Python is built in <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug mode</span></a> or <a class="reference internal" href="../using/configure.html#cmdoption-with-assertions"><code class="xref std std-option docutils literal notranslate"><span class="pre">with</span> <span class="pre">assertions</span></code></a>, <a class="reference internal" href="../c-api/tuple.html#c.PyTuple_SET_ITEM" title="PyTuple_SET_ITEM"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTuple_SET_ITEM()</span></code></a> and <a class="reference internal" href="../c-api/list.html#c.PyList_SET_ITEM" title="PyList_SET_ITEM"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyList_SET_ITEM()</span></code></a> now check the index argument with an assertion. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/106168">gh-106168</a>.)</p></li> </ul> </section> <section id="limited-c-api-changes"> <h3>Limited C API Changes<a class="headerlink" href="#limited-c-api-changes" title="Link to this heading">¶</a></h3> <ul> <li><p>The following functions are now included in the Limited C API:</p> <ul class="simple"> <li><p><a class="reference internal" href="../c-api/memory.html#c.PyMem_RawMalloc" title="PyMem_RawMalloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawMalloc()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/memory.html#c.PyMem_RawCalloc" title="PyMem_RawCalloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawCalloc()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/memory.html#c.PyMem_RawRealloc" title="PyMem_RawRealloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawRealloc()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/memory.html#c.PyMem_RawFree" title="PyMem_RawFree"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawFree()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/sys.html#c.PySys_Audit" title="PySys_Audit"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_Audit()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/sys.html#c.PySys_AuditTuple" title="PySys_AuditTuple"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AuditTuple()</span></code></a></p></li> <li><p><a class="reference internal" href="../c-api/type.html#c.PyType_GetModuleByDef" title="PyType_GetModuleByDef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetModuleByDef()</span></code></a></p></li> </ul> <p>(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/85283">gh-85283</a>, <a class="reference external" href="https://github.com/python/cpython/issues/85283">gh-85283</a>, and <a class="reference external" href="https://github.com/python/cpython/issues/116936">gh-116936</a>.)</p> </li> <li><p>Python built with <a class="reference internal" href="../using/configure.html#cmdoption-with-trace-refs"><code class="xref std std-option docutils literal notranslate"><span class="pre">--with-trace-refs</span></code></a> (tracing references) now supports the <a class="reference internal" href="../c-api/stable.html#limited-c-api"><span class="std std-ref">Limited API</span></a>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/108634">gh-108634</a>.)</p></li> </ul> </section> <section id="removed-c-apis"> <h3>Removed C APIs<a class="headerlink" href="#removed-c-apis" title="Link to this heading">¶</a></h3> <ul> <li><p>Remove several functions, macros, variables, etc with names prefixed by <code class="docutils literal notranslate"><span class="pre">_Py</span></code> or <code class="docutils literal notranslate"><span class="pre">_PY</span></code> (which are considered private). If your project is affected by one of these removals and you believe that the removed API should remain available, please <a class="reference internal" href="../bugs.html#using-the-tracker"><span class="std std-ref">open a new issue</span></a> to request a public C API and add <code class="docutils literal notranslate"><span class="pre">cc:</span> <span class="pre">@vstinner</span></code> to the issue to notify Victor Stinner. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/106320">gh-106320</a>.)</p></li> <li><p>Remove old buffer protocols deprecated in Python 3.0. Use <a class="reference internal" href="../c-api/buffer.html#bufferobjects"><span class="std std-ref">Buffer Protocol</span></a> instead.</p> <ul> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CheckReadBuffer()</span></code>: Use <a class="reference internal" href="../c-api/buffer.html#c.PyObject_CheckBuffer" title="PyObject_CheckBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CheckBuffer()</span></code></a> to test whether the object supports the buffer protocol. Note that <a class="reference internal" href="../c-api/buffer.html#c.PyObject_CheckBuffer" title="PyObject_CheckBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CheckBuffer()</span></code></a> doesn’t guarantee that <a class="reference internal" href="../c-api/buffer.html#c.PyObject_GetBuffer" title="PyObject_GetBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetBuffer()</span></code></a> will succeed. To test if the object is actually readable, see the next example of <a class="reference internal" href="../c-api/buffer.html#c.PyObject_GetBuffer" title="PyObject_GetBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetBuffer()</span></code></a>.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_AsCharBuffer()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_AsReadBuffer()</span></code>: Use <a class="reference internal" href="../c-api/buffer.html#c.PyObject_GetBuffer" title="PyObject_GetBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetBuffer()</span></code></a> and <a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_Release" title="PyBuffer_Release"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_Release()</span></code></a> instead:</p> <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">Py_buffer</span><span class="w"> </span><span class="n">view</span><span class="p">;</span> <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyObject_GetBuffer</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">view</span><span class="p">,</span><span class="w"> </span><span class="n">PyBUF_SIMPLE</span><span class="p">)</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span> <span class="p">}</span> <span class="c1">// Use `view.buf` and `view.len` to read from the buffer.</span> <span class="c1">// You may need to cast buf as `(const char*)view.buf`.</span> <span class="n">PyBuffer_Release</span><span class="p">(</span><span class="o">&</span><span class="n">view</span><span class="p">);</span> </pre></div> </div> </li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_AsWriteBuffer()</span></code>: Use <a class="reference internal" href="../c-api/buffer.html#c.PyObject_GetBuffer" title="PyObject_GetBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetBuffer()</span></code></a> and <a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_Release" title="PyBuffer_Release"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_Release()</span></code></a> instead:</p> <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">Py_buffer</span><span class="w"> </span><span class="n">view</span><span class="p">;</span> <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyObject_GetBuffer</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">view</span><span class="p">,</span><span class="w"> </span><span class="n">PyBUF_WRITABLE</span><span class="p">)</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span> <span class="p">}</span> <span class="c1">// Use `view.buf` and `view.len` to write to the buffer.</span> <span class="n">PyBuffer_Release</span><span class="p">(</span><span class="o">&</span><span class="n">view</span><span class="p">);</span> </pre></div> </div> </li> </ul> <p>(Contributed by Inada Naoki in <a class="reference external" href="https://github.com/python/cpython/issues/85275">gh-85275</a>.)</p> </li> <li><p>Remove various functions deprecated in Python 3.9:</p> <ul> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_CallObject()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_CallObjectWithKeywords()</span></code>: Use <a class="reference internal" href="../c-api/call.html#c.PyObject_CallNoArgs" title="PyObject_CallNoArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CallNoArgs()</span></code></a> or <a class="reference internal" href="../c-api/call.html#c.PyObject_Call" title="PyObject_Call"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Call()</span></code></a> instead.</p> <div class="admonition warning"> <p class="admonition-title">Warning</p> <p>In <a class="reference internal" href="../c-api/call.html#c.PyObject_Call" title="PyObject_Call"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Call()</span></code></a>, positional arguments must be a <a class="reference internal" href="../library/stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a> and must not be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, and keyword arguments must be a <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> or <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, whereas the removed functions checked argument types and accepted <code class="docutils literal notranslate"><span class="pre">NULL</span></code> positional and keyword arguments. To replace <code class="docutils literal notranslate"><span class="pre">PyEval_CallObjectWithKeywords(func,</span> <span class="pre">NULL,</span> <span class="pre">kwargs)</span></code> with <a class="reference internal" href="../c-api/call.html#c.PyObject_Call" title="PyObject_Call"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Call()</span></code></a>, pass an empty tuple as positional arguments using <a class="reference internal" href="../c-api/tuple.html#c.PyTuple_New" title="PyTuple_New"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTuple_New(0)</span></code></a>.</p> </div> </li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_CallFunction()</span></code>: Use <a class="reference internal" href="../c-api/call.html#c.PyObject_CallFunction" title="PyObject_CallFunction"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CallFunction()</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_CallMethod()</span></code>: Use <a class="reference internal" href="../c-api/call.html#c.PyObject_CallMethod" title="PyObject_CallMethod"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CallMethod()</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCFunction_Call()</span></code>: Use <a class="reference internal" href="../c-api/call.html#c.PyObject_Call" title="PyObject_Call"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Call()</span></code></a> instead.</p></li> </ul> <p>(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105107">gh-105107</a>.)</p> </li> <li><p>Remove the following old functions to configure the Python initialization, deprecated in Python 3.11:</p> <ul class="simple"> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddWarnOptionUnicode()</span></code>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.warnoptions" title="PyConfig.warnoptions"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.warnoptions</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddWarnOption()</span></code>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.warnoptions" title="PyConfig.warnoptions"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.warnoptions</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddXOption()</span></code>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.xoptions" title="PyConfig.xoptions"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.xoptions</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_HasWarnOptions()</span></code>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.xoptions" title="PyConfig.xoptions"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.xoptions</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_SetPath()</span></code>: Set <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths" title="PyConfig.module_search_paths"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetPath()</span></code>: Set <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths" title="PyConfig.module_search_paths"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetStandardStreamEncoding()</span></code>: Set <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.stdio_encoding" title="PyConfig.stdio_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.stdio_encoding</span></code></a> instead, and set also maybe <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.legacy_windows_stdio" title="PyConfig.legacy_windows_stdio"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.legacy_windows_stdio</span></code></a> (on Windows).</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">_Py_SetProgramFullPath()</span></code>: Set <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.executable" title="PyConfig.executable"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.executable</span></code></a> instead.</p></li> </ul> <p>Use the new <a class="reference internal" href="../c-api/init_config.html#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a> API of the <a class="reference internal" href="../c-api/init_config.html#init-config"><span class="std std-ref">Python Initialization Configuration</span></a> instead (<span class="target" id="index-52"></span><a class="pep reference external" href="https://peps.python.org/pep-0587/"><strong>PEP 587</strong></a>), added to Python 3.8. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105145">gh-105145</a>.)</p> </li> <li><p>Remove <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_AcquireLock()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_ReleaseLock()</span></code> functions, deprecated in Python 3.2. They didn’t update the current thread state. They can be replaced with:</p> <ul class="simple"> <li><p><a class="reference internal" href="../c-api/init.html#c.PyEval_SaveThread" title="PyEval_SaveThread"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_SaveThread()</span></code></a> and <a class="reference internal" href="../c-api/init.html#c.PyEval_RestoreThread" title="PyEval_RestoreThread"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_RestoreThread()</span></code></a>;</p></li> <li><p>low-level <a class="reference internal" href="../c-api/init.html#c.PyEval_AcquireThread" title="PyEval_AcquireThread"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_AcquireThread()</span></code></a> and <a class="reference internal" href="../c-api/init.html#c.PyEval_RestoreThread" title="PyEval_RestoreThread"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_RestoreThread()</span></code></a>;</p></li> <li><p>or <a class="reference internal" href="../c-api/init.html#c.PyGILState_Ensure" title="PyGILState_Ensure"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyGILState_Ensure()</span></code></a> and <a class="reference internal" href="../c-api/init.html#c.PyGILState_Release" title="PyGILState_Release"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyGILState_Release()</span></code></a>.</p></li> </ul> <p>(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105182">gh-105182</a>.)</p> </li> <li><p>Remove the <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_ThreadsInitialized()</span></code> function, deprecated in Python 3.9. Since Python 3.7, <code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code> always creates the GIL: calling <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_InitThreads()</span></code> does nothing and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_ThreadsInitialized()</span></code> always returns non-zero. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105182">gh-105182</a>.)</p></li> <li><p>Remove the <code class="xref c c-func docutils literal notranslate"><span class="pre">_PyInterpreterState_Get()</span></code> alias to <a class="reference internal" href="../c-api/init.html#c.PyInterpreterState_Get" title="PyInterpreterState_Get"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyInterpreterState_Get()</span></code></a> which was kept for backward compatibility with Python 3.8. The <a class="reference external" href="https://github.com/python/pythoncapi-compat/">pythoncapi-compat project</a> can be used to get <a class="reference internal" href="../c-api/init.html#c.PyInterpreterState_Get" title="PyInterpreterState_Get"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyInterpreterState_Get()</span></code></a> on Python 3.8 and older. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/106320">gh-106320</a>.)</p></li> <li><p>Remove the private <code class="xref c c-func docutils literal notranslate"><span class="pre">_PyObject_FastCall()</span></code> function: use <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Vectorcall()</span></code> which is available since Python 3.8 (<span class="target" id="index-53"></span><a class="pep reference external" href="https://peps.python.org/pep-0590/"><strong>PEP 590</strong></a>). (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/106023">gh-106023</a>.)</p></li> <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">cpython/pytime.h</span></code> header file, which only contained private functions. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/106316">gh-106316</a>.)</p></li> <li><p>Remove the undocumented <code class="docutils literal notranslate"><span class="pre">PY_TIMEOUT_MAX</span></code> constant from the limited C API. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/110014">gh-110014</a>.)</p></li> <li><p>Remove the old trashcan macros <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_SAFE_BEGIN</span></code> and <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_SAFE_END</span></code>. Replace both with the new macros <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_BEGIN</span></code> and <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_END</span></code>. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/105111">gh-105111</a>.)</p></li> </ul> </section> <section id="deprecated-c-apis"> <h3>Deprecated C APIs<a class="headerlink" href="#deprecated-c-apis" title="Link to this heading">¶</a></h3> <ul> <li><p>Deprecate old Python initialization functions:</p> <ul class="simple"> <li><p><a class="reference internal" href="../c-api/sys.html#c.PySys_ResetWarnOptions" title="PySys_ResetWarnOptions"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_ResetWarnOptions()</span></code></a>: Clear <a class="reference internal" href="../library/sys.html#sys.warnoptions" title="sys.warnoptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.warnoptions</span></code></a> and <code class="xref py py-data docutils literal notranslate"><span class="pre">warnings.filters</span></code> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetExecPrefix" title="Py_GetExecPrefix"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetExecPrefix()</span></code></a>: Get <a class="reference internal" href="../library/sys.html#sys.exec_prefix" title="sys.exec_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.exec_prefix</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetPath" title="Py_GetPath"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetPath()</span></code></a>: Get <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetPrefix" title="Py_GetPrefix"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetPrefix()</span></code></a>: Get <a class="reference internal" href="../library/sys.html#sys.prefix" title="sys.prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.prefix</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetProgramFullPath" title="Py_GetProgramFullPath"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetProgramFullPath()</span></code></a>: Get <a class="reference internal" href="../library/sys.html#sys.executable" title="sys.executable"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.executable</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetProgramName" title="Py_GetProgramName"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetProgramName()</span></code></a>: Get <a class="reference internal" href="../library/sys.html#sys.executable" title="sys.executable"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.executable</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetPythonHome" title="Py_GetPythonHome"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetPythonHome()</span></code></a>: Get <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.home" title="PyConfig.home"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.home</span></code></a> or the <span class="target" id="index-54"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHOME</span></code></a> environment variable instead.</p></li> </ul> <p>(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105145">gh-105145</a>.)</p> </li> <li><p><a class="reference internal" href="../glossary.html#term-soft-deprecated"><span class="xref std std-term">Soft deprecate</span></a> the <a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetBuiltins" title="PyEval_GetBuiltins"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetBuiltins()</span></code></a>, <a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetGlobals" title="PyEval_GetGlobals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetGlobals()</span></code></a>, and <a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetLocals" title="PyEval_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetLocals()</span></code></a> functions, which return a <a class="reference internal" href="../glossary.html#term-borrowed-reference"><span class="xref std std-term">borrowed reference</span></a>. (Soft deprecated as part of <span class="target" id="index-55"></span><a class="pep reference external" href="https://peps.python.org/pep-0667/"><strong>PEP 667</strong></a>.)</p></li> <li><p>Deprecate the <a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModuleNoBlock" title="PyImport_ImportModuleNoBlock"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModuleNoBlock()</span></code></a> function, which is just an alias to <a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModule" title="PyImport_ImportModule"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModule()</span></code></a> since Python 3.3. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105396">gh-105396</a>.)</p></li> <li><p><a class="reference internal" href="../glossary.html#term-soft-deprecated"><span class="xref std std-term">Soft deprecate</span></a> the <a class="reference internal" href="../c-api/module.html#c.PyModule_AddObject" title="PyModule_AddObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_AddObject()</span></code></a> function. It should be replaced with <a class="reference internal" href="../c-api/module.html#c.PyModule_Add" title="PyModule_Add"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_Add()</span></code></a> or <a class="reference internal" href="../c-api/module.html#c.PyModule_AddObjectRef" title="PyModule_AddObjectRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_AddObjectRef()</span></code></a>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/86493">gh-86493</a>.)</p></li> <li><p>Deprecate the old <code class="docutils literal notranslate"><span class="pre">Py_UNICODE</span></code> and <code class="docutils literal notranslate"><span class="pre">PY_UNICODE_TYPE</span></code> types and the <code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_WIDE</span></code> define. Use the <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code> type directly instead. Since Python 3.3, <code class="docutils literal notranslate"><span class="pre">Py_UNICODE</span></code> and <code class="docutils literal notranslate"><span class="pre">PY_UNICODE_TYPE</span></code> are just aliases to <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105156">gh-105156</a>.)</p></li> <li><p>Deprecate the <a class="reference internal" href="../c-api/weakref.html#c.PyWeakref_GetObject" title="PyWeakref_GetObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWeakref_GetObject()</span></code></a> and <a class="reference internal" href="../c-api/weakref.html#c.PyWeakref_GET_OBJECT" title="PyWeakref_GET_OBJECT"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWeakref_GET_OBJECT()</span></code></a> functions, which return a <a class="reference internal" href="../glossary.html#term-borrowed-reference"><span class="xref std std-term">borrowed reference</span></a>. Replace them with the new <a class="reference internal" href="../c-api/weakref.html#c.PyWeakref_GetRef" title="PyWeakref_GetRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWeakref_GetRef()</span></code></a> function, which returns a <a class="reference internal" href="../glossary.html#term-strong-reference"><span class="xref std std-term">strong reference</span></a>. The <a class="reference external" href="https://github.com/python/pythoncapi-compat/">pythoncapi-compat project</a> can be used to get <a class="reference internal" href="../c-api/weakref.html#c.PyWeakref_GetRef" title="PyWeakref_GetRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWeakref_GetRef()</span></code></a> on Python 3.12 and older. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105927">gh-105927</a>.)</p></li> </ul> <section id="id8"> <h4>Pending Removal in Python 3.14<a class="headerlink" href="#id8" title="Link to this heading">¶</a></h4> <ul> <li><p>The <code class="docutils literal notranslate"><span class="pre">ma_version_tag</span></code> field in <a class="reference internal" href="../c-api/dict.html#c.PyDictObject" title="PyDictObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyDictObject</span></code></a> for extension modules (<span class="target" id="index-56"></span><a class="pep reference external" href="https://peps.python.org/pep-0699/"><strong>PEP 699</strong></a>; <a class="reference external" href="https://github.com/python/cpython/issues/101193">gh-101193</a>).</p></li> <li><p>Creating <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_IMMUTABLETYPE" title="Py_TPFLAGS_IMMUTABLETYPE"><code class="xref c c-data docutils literal notranslate"><span class="pre">immutable</span> <span class="pre">types</span></code></a> with mutable bases (<a class="reference external" href="https://github.com/python/cpython/issues/95388">gh-95388</a>).</p></li> <li><p>Functions to configure Python’s initialization, deprecated in Python 3.11:</p> <ul class="simple"> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_SetArgvEx()</span></code>: Set <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.argv</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_SetArgv()</span></code>: Set <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.argv</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetProgramName()</span></code>: Set <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.program_name" title="PyConfig.program_name"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.program_name</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetPythonHome()</span></code>: Set <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.home" title="PyConfig.home"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.home</span></code></a> instead.</p></li> </ul> <p>The <a class="reference internal" href="../c-api/init.html#c.Py_InitializeFromConfig" title="Py_InitializeFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_InitializeFromConfig()</span></code></a> API should be used with <a class="reference internal" href="../c-api/init_config.html#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a> instead.</p> </li> <li><p>Global configuration variables:</p> <ul class="simple"> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_DebugFlag" title="Py_DebugFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_DebugFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.parser_debug" title="PyConfig.parser_debug"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.parser_debug</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_VerboseFlag" title="Py_VerboseFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_VerboseFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.verbose" title="PyConfig.verbose"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.verbose</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_QuietFlag" title="Py_QuietFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_QuietFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.quiet" title="PyConfig.quiet"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.quiet</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_InteractiveFlag" title="Py_InteractiveFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_InteractiveFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.interactive" title="PyConfig.interactive"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.interactive</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_InspectFlag" title="Py_InspectFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_InspectFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.inspect" title="PyConfig.inspect"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.inspect</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_OptimizeFlag" title="Py_OptimizeFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_OptimizeFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.optimization_level" title="PyConfig.optimization_level"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.optimization_level</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_NoSiteFlag" title="Py_NoSiteFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_NoSiteFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.site_import" title="PyConfig.site_import"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.site_import</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_BytesWarningFlag" title="Py_BytesWarningFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_BytesWarningFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.bytes_warning" title="PyConfig.bytes_warning"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.bytes_warning</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_FrozenFlag" title="Py_FrozenFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_FrozenFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.pathconfig_warnings" title="PyConfig.pathconfig_warnings"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.pathconfig_warnings</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_IgnoreEnvironmentFlag" title="Py_IgnoreEnvironmentFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_IgnoreEnvironmentFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.use_environment" title="PyConfig.use_environment"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.use_environment</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_DontWriteBytecodeFlag" title="Py_DontWriteBytecodeFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_DontWriteBytecodeFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.write_bytecode" title="PyConfig.write_bytecode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.write_bytecode</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_NoUserSiteDirectory" title="Py_NoUserSiteDirectory"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_NoUserSiteDirectory</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.user_site_directory" title="PyConfig.user_site_directory"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.user_site_directory</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_UnbufferedStdioFlag" title="Py_UnbufferedStdioFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_UnbufferedStdioFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.buffered_stdio" title="PyConfig.buffered_stdio"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.buffered_stdio</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_HashRandomizationFlag" title="Py_HashRandomizationFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_HashRandomizationFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.use_hash_seed" title="PyConfig.use_hash_seed"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.use_hash_seed</span></code></a> and <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.hash_seed" title="PyConfig.hash_seed"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.hash_seed</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_IsolatedFlag" title="Py_IsolatedFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_IsolatedFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.isolated" title="PyConfig.isolated"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.isolated</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_LegacyWindowsFSEncodingFlag" title="Py_LegacyWindowsFSEncodingFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_LegacyWindowsFSEncodingFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig.legacy_windows_fs_encoding" title="PyPreConfig.legacy_windows_fs_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.legacy_windows_fs_encoding</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_LegacyWindowsStdioFlag" title="Py_LegacyWindowsStdioFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_LegacyWindowsStdioFlag</span></code></a>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.legacy_windows_stdio" title="PyConfig.legacy_windows_stdio"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.legacy_windows_stdio</span></code></a> instead.</p></li> <li><p><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_FileSystemDefaultEncoding</span></code>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.filesystem_encoding</span></code></a> instead.</p></li> <li><p><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_HasFileSystemDefaultEncoding</span></code>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.filesystem_encoding</span></code></a> instead.</p></li> <li><p><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_FileSystemDefaultEncodeErrors</span></code>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_errors" title="PyConfig.filesystem_errors"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.filesystem_errors</span></code></a> instead.</p></li> <li><p><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_UTF8Mode</span></code>: Use <a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig.utf8_mode" title="PyPreConfig.utf8_mode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.utf8_mode</span></code></a> instead. (see <a class="reference internal" href="../c-api/init_config.html#c.Py_PreInitialize" title="Py_PreInitialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitialize()</span></code></a>)</p></li> </ul> <p>The <a class="reference internal" href="../c-api/init.html#c.Py_InitializeFromConfig" title="Py_InitializeFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_InitializeFromConfig()</span></code></a> API should be used with <a class="reference internal" href="../c-api/init_config.html#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a> instead.</p> </li> </ul> </section> <section id="id9"> <h4>Pending Removal in Python 3.15<a class="headerlink" href="#id9" title="Link to this heading">¶</a></h4> <ul class="simple"> <li><p>The bundled copy of <code class="docutils literal notranslate"><span class="pre">libmpdecimal</span></code>.</p></li> <li><p>The <a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModuleNoBlock" title="PyImport_ImportModuleNoBlock"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModuleNoBlock()</span></code></a>: Use <a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModule" title="PyImport_ImportModule"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModule()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/weakref.html#c.PyWeakref_GetObject" title="PyWeakref_GetObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWeakref_GetObject()</span></code></a> and <a class="reference internal" href="../c-api/weakref.html#c.PyWeakref_GET_OBJECT" title="PyWeakref_GET_OBJECT"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWeakref_GET_OBJECT()</span></code></a>: Use <a class="reference internal" href="../c-api/weakref.html#c.PyWeakref_GetRef" title="PyWeakref_GetRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWeakref_GetRef()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/unicode.html#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE</span></code></a> type and the <code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_WIDE</span></code> macro: Use <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code> instead.</p></li> <li><p>Python initialization functions:</p> <ul> <li><p><a class="reference internal" href="../c-api/sys.html#c.PySys_ResetWarnOptions" title="PySys_ResetWarnOptions"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_ResetWarnOptions()</span></code></a>: Clear <a class="reference internal" href="../library/sys.html#sys.warnoptions" title="sys.warnoptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.warnoptions</span></code></a> and <code class="xref py py-data docutils literal notranslate"><span class="pre">warnings.filters</span></code> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetExecPrefix" title="Py_GetExecPrefix"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetExecPrefix()</span></code></a>: Get <a class="reference internal" href="../library/sys.html#sys.base_exec_prefix" title="sys.base_exec_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.base_exec_prefix</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.exec_prefix" title="sys.exec_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.exec_prefix</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetPath" title="Py_GetPath"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetPath()</span></code></a>: Get <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetPrefix" title="Py_GetPrefix"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetPrefix()</span></code></a>: Get <a class="reference internal" href="../library/sys.html#sys.base_prefix" title="sys.base_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.base_prefix</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.prefix" title="sys.prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.prefix</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetProgramFullPath" title="Py_GetProgramFullPath"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetProgramFullPath()</span></code></a>: Get <a class="reference internal" href="../library/sys.html#sys.executable" title="sys.executable"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.executable</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetProgramName" title="Py_GetProgramName"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetProgramName()</span></code></a>: Get <a class="reference internal" href="../library/sys.html#sys.executable" title="sys.executable"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.executable</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetPythonHome" title="Py_GetPythonHome"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetPythonHome()</span></code></a>: Get <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.home" title="PyConfig.home"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.home</span></code></a> or the <span class="target" id="index-57"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHOME</span></code></a> environment variable instead.</p></li> </ul> </li> </ul> </section> <section id="id10"> <h4>Pending Removal in Future Versions<a class="headerlink" href="#id10" title="Link to this heading">¶</a></h4> <p>The following APIs are deprecated and will be removed, although there is currently no date scheduled for their removal.</p> <ul class="simple"> <li><p><a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_HAVE_FINALIZE" title="Py_TPFLAGS_HAVE_FINALIZE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_HAVE_FINALIZE</span></code></a>: Unneeded since Python 3.8.</p></li> <li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Fetch" title="PyErr_Fetch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Fetch()</span></code></a>: Use <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_GetRaisedException" title="PyErr_GetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetRaisedException()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_NormalizeException" title="PyErr_NormalizeException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_NormalizeException()</span></code></a>: Use <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_GetRaisedException" title="PyErr_GetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetRaisedException()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Restore" title="PyErr_Restore"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Restore()</span></code></a>: Use <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetRaisedException" title="PyErr_SetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetRaisedException()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/module.html#c.PyModule_GetFilename" title="PyModule_GetFilename"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_GetFilename()</span></code></a>: Use <a class="reference internal" href="../c-api/module.html#c.PyModule_GetFilenameObject" title="PyModule_GetFilenameObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_GetFilenameObject()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork" title="PyOS_AfterFork"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork()</span></code></a>: Use <a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork_Child" title="PyOS_AfterFork_Child"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Child()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/slice.html#c.PySlice_GetIndicesEx" title="PySlice_GetIndicesEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_GetIndicesEx()</span></code></a>: Use <a class="reference internal" href="../c-api/slice.html#c.PySlice_Unpack" title="PySlice_Unpack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_Unpack()</span></code></a> and <a class="reference internal" href="../c-api/slice.html#c.PySlice_AdjustIndices" title="PySlice_AdjustIndices"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_AdjustIndices()</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsDecodedObject()</span></code>: Use <a class="reference internal" href="../c-api/codec.html#c.PyCodec_Decode" title="PyCodec_Decode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCodec_Decode()</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsDecodedUnicode()</span></code>: Use <a class="reference internal" href="../c-api/codec.html#c.PyCodec_Decode" title="PyCodec_Decode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCodec_Decode()</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsEncodedObject()</span></code>: Use <a class="reference internal" href="../c-api/codec.html#c.PyCodec_Encode" title="PyCodec_Encode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCodec_Encode()</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsEncodedUnicode()</span></code>: Use <a class="reference internal" href="../c-api/codec.html#c.PyCodec_Encode" title="PyCodec_Encode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCodec_Encode()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_READY" title="PyUnicode_READY"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_READY()</span></code></a>: Unneeded since Python 3.12</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Display()</span></code>: Use <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_DisplayException" title="PyErr_DisplayException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_DisplayException()</span></code></a> instead.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions()</span></code>: Use <code class="xref c c-func docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions1()</span></code> instead.</p></li> <li><p><code class="xref c c-member docutils literal notranslate"><span class="pre">PyBytesObject.ob_shash</span></code> member: call <a class="reference internal" href="../c-api/object.html#c.PyObject_Hash" title="PyObject_Hash"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Hash()</span></code></a> instead.</p></li> <li><p><code class="xref c c-member docutils literal notranslate"><span class="pre">PyDictObject.ma_version_tag</span></code> member.</p></li> <li><p>Thread Local Storage (TLS) API:</p> <ul> <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_create_key" title="PyThread_create_key"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_create_key()</span></code></a>: Use <a class="reference internal" href="../c-api/init.html#c.PyThread_tss_alloc" title="PyThread_tss_alloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_tss_alloc()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_delete_key" title="PyThread_delete_key"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_delete_key()</span></code></a>: Use <a class="reference internal" href="../c-api/init.html#c.PyThread_tss_free" title="PyThread_tss_free"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_tss_free()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_set_key_value" title="PyThread_set_key_value"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_set_key_value()</span></code></a>: Use <a class="reference internal" href="../c-api/init.html#c.PyThread_tss_set" title="PyThread_tss_set"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_tss_set()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_get_key_value" title="PyThread_get_key_value"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_get_key_value()</span></code></a>: Use <a class="reference internal" href="../c-api/init.html#c.PyThread_tss_get" title="PyThread_tss_get"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_tss_get()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_delete_key_value" title="PyThread_delete_key_value"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_delete_key_value()</span></code></a>: Use <a class="reference internal" href="../c-api/init.html#c.PyThread_tss_delete" title="PyThread_tss_delete"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_tss_delete()</span></code></a> instead.</p></li> <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_ReInitTLS" title="PyThread_ReInitTLS"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_ReInitTLS()</span></code></a>: Unneeded since Python 3.7.</p></li> </ul> </li> </ul> </section> </section> </section> <section id="build-changes"> <h2>Build Changes<a class="headerlink" href="#build-changes" title="Link to this heading">¶</a></h2> <ul class="simple"> <li><p><code class="docutils literal notranslate"><span class="pre">arm64-apple-ios</span></code> and <code class="docutils literal notranslate"><span class="pre">arm64-apple-ios-simulator</span></code> are both now <span class="target" id="index-58"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/"><strong>PEP 11</strong></a> tier 3 platforms. (<a class="reference internal" href="#whatsnew313-platform-support"><span class="std std-ref">PEP 730</span></a> written and implementation contributed by Russell Keith-Magee in <a class="reference external" href="https://github.com/python/cpython/issues/114099">gh-114099</a>.)</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">aarch64-linux-android</span></code> and <code class="docutils literal notranslate"><span class="pre">x86_64-linux-android</span></code> are both now <span class="target" id="index-59"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/"><strong>PEP 11</strong></a> tier 3 platforms. (<a class="reference internal" href="#whatsnew313-platform-support"><span class="std std-ref">PEP 738</span></a> written and implementation contributed by Malcolm Smith in <a class="reference external" href="https://github.com/python/cpython/issues/116622">gh-116622</a>.)</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">wasm32-wasi</span></code> is now a <span class="target" id="index-60"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/"><strong>PEP 11</strong></a> tier 2 platform. (Contributed by Brett Cannon in <a class="reference external" href="https://github.com/python/cpython/issues/115192">gh-115192</a>.)</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">wasm32-emscripten</span></code> is no longer a <span class="target" id="index-61"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/"><strong>PEP 11</strong></a> supported platform. (Contributed by Brett Cannon in <a class="reference external" href="https://github.com/python/cpython/issues/115192">gh-115192</a>.)</p></li> <li><p>Building CPython now requires a compiler with support for the C11 atomic library, GCC built-in atomic functions, or MSVC interlocked intrinsics.</p></li> <li><p>Autoconf 2.71 and aclocal 1.16.5 are now required to regenerate the <code class="file docutils literal notranslate"><span class="pre">configure</span></code> script. (Contributed by Christian Heimes in <a class="reference external" href="https://github.com/python/cpython/issues/89886">gh-89886</a> and by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/112090">gh-112090</a>.)</p></li> <li><p>SQLite 3.15.2 or newer is required to build the <a class="reference internal" href="../library/sqlite3.html#module-sqlite3" title="sqlite3: A DB-API 2.0 implementation using SQLite 3.x."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlite3</span></code></a> extension module. (Contributed by Erlend Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/105875">gh-105875</a>.)</p></li> <li><p>CPython now bundles the <a class="reference external" href="https://github.com/microsoft/mimalloc/">mimalloc library</a> by default. It is licensed under the MIT license; see <a class="reference internal" href="../license.html#mimalloc-license"><span class="std std-ref">mimalloc license</span></a>. The bundled mimalloc has custom changes, see <a class="reference external" href="https://github.com/python/cpython/issues/113141">gh-113141</a> for details. (Contributed by Dino Viehland in <a class="reference external" href="https://github.com/python/cpython/issues/109914">gh-109914</a>.)</p> </li> <li><p>The <code class="file docutils literal notranslate"><span class="pre">configure</span></code> option <a class="reference internal" href="../using/configure.html#cmdoption-with-system-libmpdec"><code class="xref std std-option docutils literal notranslate"><span class="pre">--with-system-libmpdec</span></code></a> now defaults to <code class="docutils literal notranslate"><span class="pre">yes</span></code>. The bundled copy of <code class="docutils literal notranslate"><span class="pre">libmpdecimal</span></code> will be removed in Python 3.15.</p></li> <li><p>Python built with <code class="file docutils literal notranslate"><span class="pre">configure</span></code> <a class="reference internal" href="../using/configure.html#cmdoption-with-trace-refs"><code class="xref std std-option docutils literal notranslate"><span class="pre">--with-trace-refs</span></code></a> (tracing references) is now ABI compatible with the Python release build and <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug build</span></a>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/108634">gh-108634</a>.)</p></li> <li><p>On POSIX systems, the pkg-config (<code class="docutils literal notranslate"><span class="pre">.pc</span></code>) filenames now include the ABI flags. For example, the free-threaded build generates <code class="docutils literal notranslate"><span class="pre">python-3.13t.pc</span></code> and the debug build generates <code class="docutils literal notranslate"><span class="pre">python-3.13d.pc</span></code>.</p></li> <li><p>The <code class="docutils literal notranslate"><span class="pre">errno</span></code>, <code class="docutils literal notranslate"><span class="pre">fcntl</span></code>, <code class="docutils literal notranslate"><span class="pre">grp</span></code>, <code class="docutils literal notranslate"><span class="pre">md5</span></code>, <code class="docutils literal notranslate"><span class="pre">pwd</span></code>, <code class="docutils literal notranslate"><span class="pre">resource</span></code>, <code class="docutils literal notranslate"><span class="pre">termios</span></code>, <code class="docutils literal notranslate"><span class="pre">winsound</span></code>, <code class="docutils literal notranslate"><span class="pre">_ctypes_test</span></code>, <code class="docutils literal notranslate"><span class="pre">_multiprocessing.posixshmem</span></code>, <code class="docutils literal notranslate"><span class="pre">_scproxy</span></code>, <code class="docutils literal notranslate"><span class="pre">_stat</span></code>, <code class="docutils literal notranslate"><span class="pre">_statistics</span></code>, <code class="docutils literal notranslate"><span class="pre">_testconsole</span></code>, <code class="docutils literal notranslate"><span class="pre">_testimportmultiple</span></code> and <code class="docutils literal notranslate"><span class="pre">_uuid</span></code> C extensions are now built with the <a class="reference internal" href="../c-api/stable.html#limited-c-api"><span class="std std-ref">limited C API</span></a>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/85283">gh-85283</a>.)</p></li> </ul> </section> <section id="porting-to-python-3-13"> <h2>Porting to Python 3.13<a class="headerlink" href="#porting-to-python-3-13" title="Link to this heading">¶</a></h2> <p>This section lists previously described changes and other bugfixes that may require changes to your code.</p> <section id="changes-in-the-python-api"> <h3>Changes in the Python API<a class="headerlink" href="#changes-in-the-python-api" title="Link to this heading">¶</a></h3> <ul id="pep667-porting-notes-py"> <li><p><a class="reference internal" href="#whatsnew313-locals-semantics"><span class="std std-ref">PEP 667</span></a> introduces several changes to the semantics of <a class="reference internal" href="../library/functions.html#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#frame.f_locals" title="frame.f_locals"><code class="xref py py-attr docutils literal notranslate"><span class="pre">f_locals</span></code></a>:</p> <ul class="simple"> <li><p>Calling <a class="reference internal" href="../library/functions.html#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> in an <a class="reference internal" href="../glossary.html#term-optimized-scope"><span class="xref std std-term">optimized scope</span></a> now produces an independent snapshot on each call, and hence no longer implicitly updates previously returned references. Obtaining the legacy CPython behavior now requires explicit calls to update the initially returned dictionary with the results of subsequent calls to <code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code>. Code execution functions that implicitly target <code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code> (such as <code class="docutils literal notranslate"><span class="pre">exec</span></code> and <code class="docutils literal notranslate"><span class="pre">eval</span></code>) must be passed an explicit namespace to access their results in an optimized scope. (Changed as part of <span class="target" id="index-62"></span><a class="pep reference external" href="https://peps.python.org/pep-0667/"><strong>PEP 667</strong></a>.)</p></li> <li><p>Calling <a class="reference internal" href="../library/functions.html#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> from a comprehension at module or class scope (including via <code class="docutils literal notranslate"><span class="pre">exec</span></code> or <code class="docutils literal notranslate"><span class="pre">eval</span></code>) once more behaves as if the comprehension were running as an independent nested function (i.e. the local variables from the containing scope are not included). In Python 3.12, this had changed to include the local variables from the containing scope when implementing <span class="target" id="index-63"></span><a class="pep reference external" href="https://peps.python.org/pep-0709/"><strong>PEP 709</strong></a>. (Changed as part of <span class="target" id="index-64"></span><a class="pep reference external" href="https://peps.python.org/pep-0667/"><strong>PEP 667</strong></a>.)</p></li> <li><p>Accessing <a class="reference internal" href="../reference/datamodel.html#frame.f_locals" title="frame.f_locals"><code class="xref py py-attr docutils literal notranslate"><span class="pre">FrameType.f_locals</span></code></a> in an <a class="reference internal" href="../glossary.html#term-optimized-scope"><span class="xref std std-term">optimized scope</span></a> now returns a write-through proxy rather than a snapshot that gets updated at ill-specified times. If a snapshot is desired, it must be created explicitly with <code class="docutils literal notranslate"><span class="pre">dict</span></code> or the proxy’s <code class="docutils literal notranslate"><span class="pre">.copy()</span></code> method. (Changed as part of <span class="target" id="index-65"></span><a class="pep reference external" href="https://peps.python.org/pep-0667/"><strong>PEP 667</strong></a>.)</p></li> </ul> </li> <li><p><a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-class docutils literal notranslate"><span class="pre">functools.partial</span></code></a> now emits a <a class="reference internal" href="../library/exceptions.html#FutureWarning" title="FutureWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FutureWarning</span></code></a> when used as a method. The behavior will change in future Python versions. Wrap it in <a class="reference internal" href="../library/functions.html#staticmethod" title="staticmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">staticmethod()</span></code></a> if you want to preserve the old behavior. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/121027">gh-121027</a>.)</p></li> <li><p>An <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is now raised by <a class="reference internal" href="../library/getpass.html#getpass.getuser" title="getpass.getuser"><code class="xref py py-func docutils literal notranslate"><span class="pre">getpass.getuser()</span></code></a> for any failure to retrieve a username, instead of <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> on non-Unix platforms or <a class="reference internal" href="../library/exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> on Unix platforms where the password database is empty.</p></li> <li><p>The value of the <code class="xref py py-attr docutils literal notranslate"><span class="pre">mode</span></code> attribute of <a class="reference internal" href="../library/gzip.html#gzip.GzipFile" title="gzip.GzipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">gzip.GzipFile</span></code></a> is now a string (<code class="docutils literal notranslate"><span class="pre">'rb'</span></code> or <code class="docutils literal notranslate"><span class="pre">'wb'</span></code>) instead of an integer (<code class="docutils literal notranslate"><span class="pre">1</span></code> or <code class="docutils literal notranslate"><span class="pre">2</span></code>). The value of the <code class="xref py py-attr docutils literal notranslate"><span class="pre">mode</span></code> attribute of the readable file-like object returned by <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile.open" title="zipfile.ZipFile.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">zipfile.ZipFile.open()</span></code></a> is now <code class="docutils literal notranslate"><span class="pre">'rb'</span></code> instead of <code class="docutils literal notranslate"><span class="pre">'r'</span></code>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/115961">gh-115961</a>.)</p></li> <li><p><a class="reference internal" href="../library/mailbox.html#mailbox.Maildir" title="mailbox.Maildir"><code class="xref py py-class docutils literal notranslate"><span class="pre">mailbox.Maildir</span></code></a> now ignores files with a leading dot (<code class="docutils literal notranslate"><span class="pre">.</span></code>). (Contributed by Zackery Spytz in <a class="reference external" href="https://github.com/python/cpython/issues/65559">gh-65559</a>.)</p></li> <li><p><a class="reference internal" href="../library/pathlib.html#pathlib.Path.glob" title="pathlib.Path.glob"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.glob()</span></code></a> and <a class="reference internal" href="../library/pathlib.html#pathlib.Path.rglob" title="pathlib.Path.rglob"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rglob()</span></code></a> now return both files and directories if a pattern that ends with “<code class="docutils literal notranslate"><span class="pre">**</span></code>” is given, rather than directories only. Add a trailing slash to keep the previous behavior and only match directories.</p></li> <li><p>The <a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a> module now expects the <code class="xref py py-mod docutils literal notranslate"><span class="pre">_thread</span></code> module to have an <code class="xref py py-func docutils literal notranslate"><span class="pre">_is_main_interpreter()</span></code> function. This function takes no arguments and returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if the current interpreter is the main interpreter.</p> <p>Any library or application that provides a custom <code class="xref py py-mod docutils literal notranslate"><span class="pre">_thread</span></code> module must provide <code class="xref py py-func docutils literal notranslate"><span class="pre">_is_main_interpreter()</span></code>, just like the module’s other “private” attributes. (<a class="reference external" href="https://github.com/python/cpython/issues/112826">gh-112826</a>.)</p> </li> </ul> </section> <section id="changes-in-the-c-api"> <h3>Changes in the C API<a class="headerlink" href="#changes-in-the-c-api" title="Link to this heading">¶</a></h3> <ul> <li><p><code class="docutils literal notranslate"><span class="pre">Python.h</span></code> no longer includes the <code class="docutils literal notranslate"><span class="pre"><ieeefp.h></span></code> standard header. It was included for the <code class="xref c c-func docutils literal notranslate"><span class="pre">finite()</span></code> function which is now provided by the <code class="docutils literal notranslate"><span class="pre"><math.h></span></code> header. It should now be included explicitly if needed. Remove also the <code class="docutils literal notranslate"><span class="pre">HAVE_IEEEFP_H</span></code> macro. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/108765">gh-108765</a>.)</p></li> <li><p><code class="docutils literal notranslate"><span class="pre">Python.h</span></code> no longer includes these standard header files: <code class="docutils literal notranslate"><span class="pre"><time.h></span></code>, <code class="docutils literal notranslate"><span class="pre"><sys/select.h></span></code> and <code class="docutils literal notranslate"><span class="pre"><sys/time.h></span></code>. If needed, they should now be included explicitly. For example, <code class="docutils literal notranslate"><span class="pre"><time.h></span></code> provides the <code class="xref c c-func docutils literal notranslate"><span class="pre">clock()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">gmtime()</span></code> functions, <code class="docutils literal notranslate"><span class="pre"><sys/select.h></span></code> provides the <code class="xref c c-func docutils literal notranslate"><span class="pre">select()</span></code> function, and <code class="docutils literal notranslate"><span class="pre"><sys/time.h></span></code> provides the <code class="xref c c-func docutils literal notranslate"><span class="pre">futimes()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">gettimeofday()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">setitimer()</span></code> functions. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/108765">gh-108765</a>.)</p></li> <li><p>On Windows, <code class="docutils literal notranslate"><span class="pre">Python.h</span></code> no longer includes the <code class="docutils literal notranslate"><span class="pre"><stddef.h></span></code> standard header file. If needed, it should now be included explicitly. For example, it provides <code class="xref c c-func docutils literal notranslate"><span class="pre">offsetof()</span></code> function, and <code class="docutils literal notranslate"><span class="pre">size_t</span></code> and <code class="docutils literal notranslate"><span class="pre">ptrdiff_t</span></code> types. Including <code class="docutils literal notranslate"><span class="pre"><stddef.h></span></code> explicitly was already needed by all other platforms, the <code class="docutils literal notranslate"><span class="pre">HAVE_STDDEF_H</span></code> macro is only defined on Windows. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/108765">gh-108765</a>.)</p></li> <li><p>If the <a class="reference internal" href="../c-api/stable.html#c.Py_LIMITED_API" title="Py_LIMITED_API"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code></a> macro is defined, <code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_BUILD_CORE</span></code>, <code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_BUILD_CORE_BUILTIN</span></code> and <code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_BUILD_CORE_MODULE</span></code> macros are now undefined by <code class="docutils literal notranslate"><span class="pre"><Python.h></span></code>. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/85283">gh-85283</a>.)</p></li> <li><p>The old trashcan macros <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_SAFE_BEGIN</span></code> and <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_SAFE_END</span></code> were removed. They should be replaced by the new macros <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_BEGIN</span></code> and <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_END</span></code>.</p> <p>A <code class="docutils literal notranslate"><span class="pre">tp_dealloc</span></code> function that has the old macros, such as:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">static</span> <span class="n">void</span> <span class="n">mytype_dealloc</span><span class="p">(</span><span class="n">mytype</span> <span class="o">*</span><span class="n">p</span><span class="p">)</span> <span class="p">{</span> <span class="n">PyObject_GC_UnTrack</span><span class="p">(</span><span class="n">p</span><span class="p">);</span> <span class="n">Py_TRASHCAN_SAFE_BEGIN</span><span class="p">(</span><span class="n">p</span><span class="p">);</span> <span class="o">...</span> <span class="n">Py_TRASHCAN_SAFE_END</span> <span class="p">}</span> </pre></div> </div> <p>should migrate to the new macros as follows:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">static</span> <span class="n">void</span> <span class="n">mytype_dealloc</span><span class="p">(</span><span class="n">mytype</span> <span class="o">*</span><span class="n">p</span><span class="p">)</span> <span class="p">{</span> <span class="n">PyObject_GC_UnTrack</span><span class="p">(</span><span class="n">p</span><span class="p">);</span> <span class="n">Py_TRASHCAN_BEGIN</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">mytype_dealloc</span><span class="p">)</span> <span class="o">...</span> <span class="n">Py_TRASHCAN_END</span> <span class="p">}</span> </pre></div> </div> <p>Note that <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_BEGIN</span></code> has a second argument which should be the deallocation function it is in. The new macros were added in Python 3.8 and the old macros were deprecated in Python 3.11. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/105111">gh-105111</a>.)</p> </li> </ul> <ul class="simple" id="pep667-porting-notes-c"> <li><p><a class="reference internal" href="#whatsnew313-locals-semantics"><span class="std std-ref">PEP 667</span></a> introduces several changes to frame-related functions:</p> <ul> <li><p>The effects of mutating the dictionary returned from <a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetLocals" title="PyEval_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetLocals()</span></code></a> in an <a class="reference internal" href="../glossary.html#term-optimized-scope"><span class="xref std std-term">optimized scope</span></a> have changed. New dict entries added this way will now <em>only</em> be visible to subsequent <a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetLocals" title="PyEval_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetLocals()</span></code></a> calls in that frame, as <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLocals()</span></code></a>, <a class="reference internal" href="../library/functions.html#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a>, and <a class="reference internal" href="../reference/datamodel.html#frame.f_locals" title="frame.f_locals"><code class="xref py py-attr docutils literal notranslate"><span class="pre">FrameType.f_locals</span></code></a> no longer access the same underlying cached dictionary. Changes made to entries for actual variable names and names added via the write-through proxy interfaces will be overwritten on subsequent calls to <a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetLocals" title="PyEval_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetLocals()</span></code></a> in that frame. The recommended code update depends on how the function was being used, so refer to the deprecation notice on the function for details.</p></li> <li><p>Calling <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLocals()</span></code></a> in an <a class="reference internal" href="../glossary.html#term-optimized-scope"><span class="xref std std-term">optimized scope</span></a> now returns a write-through proxy rather than a snapshot that gets updated at ill-specified times. If a snapshot is desired, it must be created explicitly (e.g. with <a class="reference internal" href="../c-api/dict.html#c.PyDict_Copy" title="PyDict_Copy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_Copy()</span></code></a>), or by calling the new <a class="reference internal" href="../c-api/reflection.html#c.PyEval_GetFrameLocals" title="PyEval_GetFrameLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_GetFrameLocals()</span></code></a> API.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_FastToLocals()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_FastToLocalsWithError()</span></code> no longer have any effect. Calling these functions has been redundant since Python 3.11, when <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLocals()</span></code></a> was first introduced.</p></li> <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_LocalsToFast()</span></code> no longer has any effect. Calling this function is redundant now that <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLocals()</span></code></a> returns a write-through proxy for <a class="reference internal" href="../glossary.html#term-optimized-scope"><span class="xref std std-term">optimized scopes</span></a>.</p></li> </ul> </li> </ul> </section> </section> <section id="regression-test-changes"> <h2>Regression Test Changes<a class="headerlink" href="#regression-test-changes" title="Link to this heading">¶</a></h2> <ul class="simple"> <li><p>Python built with <code class="file docutils literal notranslate"><span class="pre">configure</span></code> <a class="reference internal" href="../using/configure.html#cmdoption-with-pydebug"><code class="xref std std-option docutils literal notranslate"><span class="pre">--with-pydebug</span></code></a> now supports a <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">presite=package.module</span></code></a> command-line option. If used, it specifies a module that should be imported early in the lifecycle of the interpreter, before <code class="docutils literal notranslate"><span class="pre">site.py</span></code> is executed. (Contributed by Łukasz Langa in <a class="reference external" href="https://github.com/python/cpython/issues/110769">gh-110769</a>.)</p></li> </ul> </section> <section id="notable-changes-in-3-13-1"> <h2>Notable changes in 3.13.1<a class="headerlink" href="#notable-changes-in-3-13-1" title="Link to this heading">¶</a></h2> <section id="id11"> <h3>sys<a class="headerlink" href="#id11" title="Link to this heading">¶</a></h3> <ul class="simple"> <li><p>The previously undocumented special function <a class="reference internal" href="../library/sys.html#sys.getobjects" title="sys.getobjects"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getobjects()</span></code></a>, which only exists in specialized builds of Python, may now return objects from other interpreters than the one it’s called in.</p></li> </ul> </section> </section> </section> <div class="clearer"></div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="Main"> <div class="sphinxsidebarwrapper"> <div> <h3><a href="../contents.html">Table of Contents</a></h3> <ul> <li><a class="reference internal" href="#">What’s New In Python 3.13</a><ul> <li><a class="reference internal" href="#summary-release-highlights">Summary – Release Highlights</a></li> <li><a class="reference internal" href="#new-features">New Features</a><ul> <li><a class="reference internal" href="#a-better-interactive-interpreter">A better interactive interpreter</a></li> <li><a class="reference internal" href="#improved-error-messages">Improved error messages</a></li> <li><a class="reference internal" href="#free-threaded-cpython">Free-threaded CPython</a></li> <li><a class="reference internal" href="#an-experimental-just-in-time-jit-compiler">An experimental just-in-time (JIT) compiler</a></li> <li><a class="reference internal" href="#defined-mutation-semantics-for-locals">Defined mutation semantics for <code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a></li> <li><a class="reference internal" href="#support-for-mobile-platforms">Support for mobile platforms</a></li> </ul> </li> <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li> <li><a class="reference internal" href="#new-modules">New Modules</a></li> <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul> <li><a class="reference internal" href="#argparse">argparse</a></li> <li><a class="reference internal" href="#array">array</a></li> <li><a class="reference internal" href="#ast">ast</a></li> <li><a class="reference internal" href="#asyncio">asyncio</a></li> <li><a class="reference internal" href="#base64">base64</a></li> <li><a class="reference internal" href="#compileall">compileall</a></li> <li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li> <li><a class="reference internal" href="#configparser">configparser</a></li> <li><a class="reference internal" href="#copy">copy</a></li> <li><a class="reference internal" href="#ctypes">ctypes</a></li> <li><a class="reference internal" href="#dbm">dbm</a></li> <li><a class="reference internal" href="#dis">dis</a></li> <li><a class="reference internal" href="#doctest">doctest</a></li> <li><a class="reference internal" href="#email">email</a></li> <li><a class="reference internal" href="#fractions">fractions</a></li> <li><a class="reference internal" href="#glob">glob</a></li> <li><a class="reference internal" href="#importlib">importlib</a></li> <li><a class="reference internal" href="#io">io</a></li> <li><a class="reference internal" href="#ipaddress">ipaddress</a></li> <li><a class="reference internal" href="#itertools">itertools</a></li> <li><a class="reference internal" href="#marshal">marshal</a></li> <li><a class="reference internal" href="#math">math</a></li> <li><a class="reference internal" href="#mimetypes">mimetypes</a></li> <li><a class="reference internal" href="#mmap">mmap</a></li> <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li> <li><a class="reference internal" href="#os">os</a></li> <li><a class="reference internal" href="#os-path">os.path</a></li> <li><a class="reference internal" href="#pathlib">pathlib</a></li> <li><a class="reference internal" href="#pdb">pdb</a></li> <li><a class="reference internal" href="#queue">queue</a></li> <li><a class="reference internal" href="#random">random</a></li> <li><a class="reference internal" href="#re">re</a></li> <li><a class="reference internal" href="#shutil">shutil</a></li> <li><a class="reference internal" href="#site">site</a></li> <li><a class="reference internal" href="#sqlite3">sqlite3</a></li> <li><a class="reference internal" href="#ssl">ssl</a></li> <li><a class="reference internal" href="#statistics">statistics</a></li> <li><a class="reference internal" href="#subprocess">subprocess</a></li> <li><a class="reference internal" href="#sys">sys</a></li> <li><a class="reference internal" href="#tempfile">tempfile</a></li> <li><a class="reference internal" href="#time">time</a></li> <li><a class="reference internal" href="#tkinter">tkinter</a></li> <li><a class="reference internal" href="#traceback">traceback</a></li> <li><a class="reference internal" href="#types">types</a></li> <li><a class="reference internal" href="#typing">typing</a></li> <li><a class="reference internal" href="#unicodedata">unicodedata</a></li> <li><a class="reference internal" href="#venv">venv</a></li> <li><a class="reference internal" href="#warnings">warnings</a></li> <li><a class="reference internal" href="#xml">xml</a></li> <li><a class="reference internal" href="#zipimport">zipimport</a></li> </ul> </li> <li><a class="reference internal" href="#optimizations">Optimizations</a></li> <li><a class="reference internal" href="#removed-modules-and-apis">Removed Modules And APIs</a><ul> <li><a class="reference internal" href="#pep-594-remove-dead-batteries-from-the-standard-library">PEP 594: Remove “dead batteries” from the standard library</a></li> <li><a class="reference internal" href="#to3">2to3</a></li> <li><a class="reference internal" href="#builtins">builtins</a></li> <li><a class="reference internal" href="#id3">configparser</a></li> <li><a class="reference internal" href="#importlib-metadata">importlib.metadata</a></li> <li><a class="reference internal" href="#locale">locale</a></li> <li><a class="reference internal" href="#opcode">opcode</a></li> <li><a class="reference internal" href="#id4">pathlib</a></li> <li><a class="reference internal" href="#id5">re</a></li> <li><a class="reference internal" href="#tkinter-tix">tkinter.tix</a></li> <li><a class="reference internal" href="#turtle">turtle</a></li> <li><a class="reference internal" href="#id6">typing</a></li> <li><a class="reference internal" href="#unittest">unittest</a></li> <li><a class="reference internal" href="#urllib">urllib</a></li> <li><a class="reference internal" href="#webbrowser">webbrowser</a></li> </ul> </li> <li><a class="reference internal" href="#new-deprecations">New Deprecations</a><ul> <li><a class="reference internal" href="#pending-removal-in-python-3-14">Pending Removal in Python 3.14</a></li> <li><a class="reference internal" href="#pending-removal-in-python-3-15">Pending Removal in Python 3.15</a></li> <li><a class="reference internal" href="#pending-removal-in-python-3-16">Pending removal in Python 3.16</a></li> <li><a class="reference internal" href="#pending-removal-in-future-versions">Pending Removal in Future Versions</a></li> </ul> </li> <li><a class="reference internal" href="#cpython-bytecode-changes">CPython Bytecode Changes</a></li> <li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul> <li><a class="reference internal" href="#id7">New Features</a></li> <li><a class="reference internal" href="#changed-c-apis">Changed C APIs</a></li> <li><a class="reference internal" href="#limited-c-api-changes">Limited C API Changes</a></li> <li><a class="reference internal" href="#removed-c-apis">Removed C APIs</a></li> <li><a class="reference internal" href="#deprecated-c-apis">Deprecated C APIs</a><ul> <li><a class="reference internal" href="#id8">Pending Removal in Python 3.14</a></li> <li><a class="reference internal" href="#id9">Pending Removal in Python 3.15</a></li> <li><a class="reference internal" href="#id10">Pending Removal in Future Versions</a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#build-changes">Build Changes</a></li> <li><a class="reference internal" href="#porting-to-python-3-13">Porting to Python 3.13</a><ul> <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li> <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li> </ul> </li> <li><a class="reference internal" href="#regression-test-changes">Regression Test Changes</a></li> <li><a class="reference internal" href="#notable-changes-in-3-13-1">Notable changes in 3.13.1</a><ul> <li><a class="reference internal" href="#id11">sys</a></li> </ul> </li> </ul> </li> </ul> </div> <div> <h4>Previous topic</h4> <p class="topless"><a href="index.html" title="previous chapter">What’s New in Python</a></p> </div> <div> <h4>Next topic</h4> <p class="topless"><a href="3.12.html" title="next chapter">What’s New In Python 3.12</a></p> </div> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li> <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.13.rst" rel="nofollow">Show Source </a> </li> </ul> </div> </div> <div id="sidebarbutton" title="Collapse sidebar"> <span>«</span> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="Related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="3.12.html" title="What’s New In Python 3.12" >next</a> |</li> <li class="right" > <a href="index.html" title="What’s New in Python" >previous</a> |</li> <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li class="switchers"> <div class="language_switcher_placeholder"></div> <div class="version_switcher_placeholder"></div> </li> <li> </li> <li id="cpython-language-and-version"> <a href="../index.html">3.13.0 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> »</li> <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.13</a></li> <li class="right"> <div class="inline-search" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" /> <input type="submit" value="Go" /> </form> </div> | </li> <li class="right"> <label class="theme-selector-label"> Theme <select class="theme-selector" oninput="activateTheme(this.value)"> <option value="auto" selected>Auto</option> <option value="light">Light</option> <option value="dark">Dark</option> </select> </label> |</li> </ul> </div> <div class="footer"> © <a href="../copyright.html"> Copyright </a> 2001-2024, Python Software Foundation. <br /> This page is licensed under the Python Software Foundation License Version 2. <br /> Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License. <br /> See <a href="/license.html">History and License</a> for more information.<br /> <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> <br /> Last updated on Nov 24, 2024 (17:50 UTC). <a href="/bugs.html">Found a bug</a>? <br /> Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3. </div> <script type="text/javascript" src="../_static/switchers.js"></script> </body> </html>