|
- <!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.12" />
- <meta property="og:type" content="website" />
- <meta property="og:url" content="https://docs.python.org/3/whatsnew/3.12.html" />
- <meta property="og:site_name" content="Python documentation" />
- <meta property="og:description" content="Editor, Adam Turner,. This article explains the new features in Python 3.12, compared to 3.11. Python 3.12 was released on October 2, 2023. For full details, see the changelog. Summary – Release hi..." />
- <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="Editor, Adam Turner,. This article explains the new features in Python 3.12, compared to 3.11. Python 3.12 was released on October 2, 2023. For full details, see the changelog. Summary – Release hi..." />
- <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.12 — Python 3.12.3 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=bb723527" />
- <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=2c828074"></script>
- <script src="../_static/doctools.js?v=888ff710"></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.12.3 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.11" href="3.11.html" />
- <link rel="prev" title="What’s New in Python" href="index.html" />
- <link rel="canonical" href="https://docs.python.org/3/whatsnew/3.12.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>
-
- </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.12</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="#pep-695-type-parameter-syntax">PEP 695: Type Parameter Syntax</a></li>
- <li><a class="reference internal" href="#pep-701-syntactic-formalization-of-f-strings">PEP 701: Syntactic formalization of f-strings</a></li>
- <li><a class="reference internal" href="#pep-684-a-per-interpreter-gil">PEP 684: A Per-Interpreter GIL</a></li>
- <li><a class="reference internal" href="#pep-669-low-impact-monitoring-for-cpython">PEP 669: Low impact monitoring for CPython</a></li>
- <li><a class="reference internal" href="#pep-688-making-the-buffer-protocol-accessible-in-python">PEP 688: Making the buffer protocol accessible in Python</a></li>
- <li><a class="reference internal" href="#pep-709-comprehension-inlining">PEP 709: Comprehension inlining</a></li>
- <li><a class="reference internal" href="#improved-error-messages">Improved Error Messages</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#new-features-related-to-type-hints">New Features Related to Type Hints</a><ul>
- <li><a class="reference internal" href="#pep-692-using-typeddict-for-more-precise-kwargs-typing">PEP 692: Using <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> for more precise <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> typing</a></li>
- <li><a class="reference internal" href="#pep-698-override-decorator-for-static-typing">PEP 698: Override Decorator for Static Typing</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="#array">array</a></li>
- <li><a class="reference internal" href="#asyncio">asyncio</a></li>
- <li><a class="reference internal" href="#calendar">calendar</a></li>
- <li><a class="reference internal" href="#csv">csv</a></li>
- <li><a class="reference internal" href="#dis">dis</a></li>
- <li><a class="reference internal" href="#fractions">fractions</a></li>
- <li><a class="reference internal" href="#importlib-resources">importlib.resources</a></li>
- <li><a class="reference internal" href="#inspect">inspect</a></li>
- <li><a class="reference internal" href="#itertools">itertools</a></li>
- <li><a class="reference internal" href="#math">math</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="#random">random</a></li>
- <li><a class="reference internal" href="#shutil">shutil</a></li>
- <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
- <li><a class="reference internal" href="#statistics">statistics</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="#threading">threading</a></li>
- <li><a class="reference internal" href="#tkinter">tkinter</a></li>
- <li><a class="reference internal" href="#tokenize">tokenize</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="#unittest">unittest</a></li>
- <li><a class="reference internal" href="#uuid">uuid</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
- <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
- <li><a class="reference internal" href="#demos-and-tools">Demos and Tools</a></li>
- <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
- <li><a class="reference internal" href="#pending-removal-in-python-3-13">Pending Removal in Python 3.13</a></li>
- <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-future-versions">Pending Removal in Future Versions</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#removed">Removed</a><ul>
- <li><a class="reference internal" href="#asynchat-and-asyncore">asynchat and asyncore</a></li>
- <li><a class="reference internal" href="#configparser">configparser</a></li>
- <li><a class="reference internal" href="#distutils">distutils</a></li>
- <li><a class="reference internal" href="#ensurepip">ensurepip</a></li>
- <li><a class="reference internal" href="#enum">enum</a></li>
- <li><a class="reference internal" href="#ftplib">ftplib</a></li>
- <li><a class="reference internal" href="#gzip">gzip</a></li>
- <li><a class="reference internal" href="#hashlib">hashlib</a></li>
- <li><a class="reference internal" href="#importlib">importlib</a></li>
- <li><a class="reference internal" href="#imp">imp</a></li>
- <li><a class="reference internal" href="#io">io</a></li>
- <li><a class="reference internal" href="#locale">locale</a></li>
- <li><a class="reference internal" href="#smtpd">smtpd</a></li>
- <li><a class="reference internal" href="#id2">sqlite3</a></li>
- <li><a class="reference internal" href="#ssl">ssl</a></li>
- <li><a class="reference internal" href="#id3">unittest</a></li>
- <li><a class="reference internal" href="#webbrowser">webbrowser</a></li>
- <li><a class="reference internal" href="#xml-etree-elementtree">xml.etree.ElementTree</a></li>
- <li><a class="reference internal" href="#zipimport">zipimport</a></li>
- <li><a class="reference internal" href="#others">Others</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#porting-to-python-3-12">Porting to Python 3.12</a><ul>
- <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#build-changes">Build Changes</a></li>
- <li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
- <li><a class="reference internal" href="#id4">New Features</a></li>
- <li><a class="reference internal" href="#id5">Porting to Python 3.12</a></li>
- <li><a class="reference internal" href="#id6">Deprecated</a><ul>
- <li><a class="reference internal" href="#id7">Pending Removal in Python 3.14</a></li>
- <li><a class="reference internal" href="#id8">Pending Removal in Python 3.15</a></li>
- <li><a class="reference internal" href="#id9">Pending Removal in Future Versions</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#id10">Removed</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.11.html"
- title="next chapter">What’s New In Python 3.11</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.12.rst"
- rel="nofollow">Show Source
- </a>
- </li>
- </ul>
- </div>
- </nav>
- </div>
- </div>
-
-
- <div class="related" role="navigation" aria-label="related navigation">
- <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.11.html" title="What’s New In Python 3.11"
- 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.12.3 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.12</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-12">
- <h1>What’s New In Python 3.12<a class="headerlink" href="#what-s-new-in-python-3-12" title="Link to this heading">¶</a></h1>
- <dl class="field-list simple">
- <dt class="field-odd">Editor<span class="colon">:</span></dt>
- <dd class="field-odd"><p>Adam Turner</p>
- </dd>
- </dl>
- <p>This article explains the new features in Python 3.12, compared to 3.11.
- Python 3.12 was released on October 2, 2023.
- 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-0693/"><strong>PEP 693</strong></a> – Python 3.12 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.12 is the latest stable release of the Python programming language,
- with a mix of changes to the language and the standard library.
- The library changes focus on cleaning up deprecated APIs, usability, and correctness.
- Of note, the <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code> package has been removed from the standard library.
- Filesystem support in <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> and <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> has seen a number of improvements,
- and several modules have better performance.</p>
- <p>The language changes focus on usability,
- as <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-strings</span></a> have had many limitations removed
- and ‘Did you mean …’ suggestions continue to improve.
- The new <a class="reference internal" href="#whatsnew312-pep695"><span class="std std-ref">type parameter syntax</span></a>
- and <a class="reference internal" href="../reference/simple_stmts.html#type"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">type</span></code></a> statement improve ergonomics for using <a class="reference internal" href="../glossary.html#term-generic-type"><span class="xref std std-term">generic types</span></a> and <a class="reference internal" href="../glossary.html#term-type-alias"><span class="xref std std-term">type aliases</span></a> with static type checkers.</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, you should 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>.
- If you want 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.</p>
- <hr class="docutils" />
- <p>New syntax features:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="#whatsnew312-pep695"><span class="std std-ref">PEP 695</span></a>, type parameter syntax and the <a class="reference internal" href="../reference/simple_stmts.html#type"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">type</span></code></a> statement</p></li>
- </ul>
- <p>New grammar features:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="#whatsnew312-pep701"><span class="std std-ref">PEP 701</span></a>, <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-strings</span></a> in the grammar</p></li>
- </ul>
- <p>Interpreter improvements:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="#whatsnew312-pep684"><span class="std std-ref">PEP 684</span></a>, a unique per-interpreter <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">GIL</span></a></p></li>
- <li><p><a class="reference internal" href="#whatsnew312-pep669"><span class="std std-ref">PEP 669</span></a>, low impact monitoring</p></li>
- <li><p><a class="reference internal" href="#improved-error-messages">Improved ‘Did you mean …’ suggestions</a>
- for <a class="reference internal" href="../library/exceptions.html#NameError" title="NameError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NameError</span></code></a>, <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>, and <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> exceptions</p></li>
- </ul>
- <p>Python data model improvements:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="#whatsnew312-pep688"><span class="std std-ref">PEP 688</span></a>, using the <a class="reference internal" href="../c-api/buffer.html#bufferobjects"><span class="std std-ref">buffer protocol</span></a> from Python</p></li>
- </ul>
- <p>Significant improvements in the standard library:</p>
- <ul class="simple">
- <li><p>The <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">pathlib.Path</span></code></a> class now supports subclassing</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 received several improvements for Windows support</p></li>
- <li><p>A <a class="reference internal" href="../library/sqlite3.html#sqlite3-cli"><span class="std std-ref">command-line interface</span></a> has been added to 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> module</p></li>
- <li><p><a class="reference internal" href="../library/functions.html#isinstance" title="isinstance"><code class="xref py py-func docutils literal notranslate"><span class="pre">isinstance()</span></code></a> checks against <a class="reference internal" href="../library/typing.html#typing.runtime_checkable" title="typing.runtime_checkable"><code class="xref py py-func docutils literal notranslate"><span class="pre">runtime-checkable</span> <span class="pre">protocols</span></code></a> enjoy a speed up of between two and 20 times</p></li>
- <li><p>The <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> package has had a number of performance improvements,
- with some benchmarks showing a 75% speed up.</p></li>
- <li><p>A <a class="reference internal" href="../library/uuid.html#uuid-cli"><span class="std std-ref">command-line interface</span></a> has been added to the
- <a class="reference internal" href="../library/uuid.html#module-uuid" title="uuid: UUID objects (universally unique identifiers) according to RFC 4122"><code class="xref py py-mod docutils literal notranslate"><span class="pre">uuid</span></code></a> module</p></li>
- <li><p>Due to the changes in <a class="reference internal" href="#whatsnew312-pep701"><span class="std std-ref">PEP 701</span></a>,
- producing tokens via the <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> module is up to 64% faster.</p></li>
- </ul>
- <p>Security improvements:</p>
- <ul class="simple">
- <li><p>Replace the builtin <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> implementations of
- SHA1, SHA3, SHA2-384, SHA2-512, and MD5 with formally verified code from the
- <a class="reference external" href="https://github.com/hacl-star/hacl-star/">HACL*</a> project.
- These builtin implementations remain as fallbacks that are only used when
- OpenSSL does not provide them.</p></li>
- </ul>
- <p>C API improvements:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="#whatsnew312-pep697"><span class="std std-ref">PEP 697</span></a>, unstable C API tier</p></li>
- <li><p><a class="reference internal" href="#whatsnew312-pep683"><span class="std std-ref">PEP 683</span></a>, immortal objects</p></li>
- </ul>
- <p>CPython implementation improvements:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="#whatsnew312-pep709"><span class="std std-ref">PEP 709</span></a>, comprehension inlining</p></li>
- <li><p><a class="reference internal" href="../howto/perf_profiling.html#perf-profiling"><span class="std std-ref">CPython support</span></a> for the Linux <code class="docutils literal notranslate"><span class="pre">perf</span></code> profiler</p></li>
- <li><p>Implement stack overflow protection on supported platforms</p></li>
- </ul>
- <p>New typing features:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="#whatsnew312-pep692"><span class="std std-ref">PEP 692</span></a>, using <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> to
- annotate <a class="reference internal" href="../glossary.html#term-argument"><span class="xref std std-term">**kwargs</span></a></p></li>
- <li><p><a class="reference internal" href="#whatsnew312-pep698"><span class="std std-ref">PEP 698</span></a>, <a class="reference internal" href="../library/typing.html#typing.override" title="typing.override"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.override()</span></code></a> decorator</p></li>
- </ul>
- <p>Important deprecations, removals or restrictions:</p>
- <ul class="simple">
- <li><p><span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0623/"><strong>PEP 623</strong></a>: Remove <code class="docutils literal notranslate"><span class="pre">wstr</span></code> from Unicode objects in Python’s C API,
- reducing the size of every <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> object by at least 8 bytes.</p></li>
- <li><p><span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0632/"><strong>PEP 632</strong></a>: Remove the <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code> package.
- See <a class="reference external" href="https://peps.python.org/pep-0632/#migration-advice">the migration guide</a>
- for advice replacing the APIs it provided.
- The third-party <a class="reference external" href="https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html">Setuptools</a>
- package continues to provide <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code>,
- if you still require it in Python 3.12 and beyond.</p></li>
- <li><p><a class="reference external" href="https://github.com/python/cpython/issues/95299">gh-95299</a>: Do not pre-install <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> in virtual environments
- created with <a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a>.
- This means that <code class="docutils literal notranslate"><span class="pre">distutils</span></code>, <code class="docutils literal notranslate"><span class="pre">setuptools</span></code>, <code class="docutils literal notranslate"><span class="pre">pkg_resources</span></code>,
- and <code class="docutils literal notranslate"><span class="pre">easy_install</span></code> will no longer available by default; to access these
- run <code class="docutils literal notranslate"><span class="pre">pip</span> <span class="pre">install</span> <span class="pre">setuptools</span></code> in the <a class="reference internal" href="../library/venv.html#venv-explanation"><span class="std std-ref">activated</span></a>
- virtual environment.</p></li>
- <li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">asynchat</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncore</span></code>, and <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> modules have been
- removed, along with several <a class="reference internal" href="../library/unittest.html#unittest.TestCase" title="unittest.TestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">unittest.TestCase</span></code></a>
- <a class="reference internal" href="#unittest-testcase-removed-aliases">method aliases</a>.</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="pep-695-type-parameter-syntax">
- <span id="whatsnew312-pep695"></span><h3>PEP 695: Type Parameter Syntax<a class="headerlink" href="#pep-695-type-parameter-syntax" title="Link to this heading">¶</a></h3>
- <p>Generic classes and functions under <span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> were declared using a verbose syntax
- that left the scope of type parameters unclear and required explicit declarations of
- variance.</p>
- <p><span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0695/"><strong>PEP 695</strong></a> introduces a new, more compact and explicit way to create
- <a class="reference internal" href="../reference/compound_stmts.html#generic-classes"><span class="std std-ref">generic classes</span></a> and <a class="reference internal" href="../reference/compound_stmts.html#generic-functions"><span class="std std-ref">functions</span></a>:</p>
- <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">max</span><span class="p">[</span><span class="n">T</span><span class="p">](</span><span class="n">args</span><span class="p">:</span> <span class="n">Iterable</span><span class="p">[</span><span class="n">T</span><span class="p">])</span> <span class="o">-></span> <span class="n">T</span><span class="p">:</span>
- <span class="o">...</span>
-
- <span class="k">class</span> <span class="nc">list</span><span class="p">[</span><span class="n">T</span><span class="p">]:</span>
- <span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">index</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="o">/</span><span class="p">)</span> <span class="o">-></span> <span class="n">T</span><span class="p">:</span>
- <span class="o">...</span>
-
- <span class="k">def</span> <span class="nf">append</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">element</span><span class="p">:</span> <span class="n">T</span><span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span>
- <span class="o">...</span>
- </pre></div>
- </div>
- <p>In addition, the PEP introduces a new way to declare <a class="reference internal" href="../library/typing.html#type-aliases"><span class="std std-ref">type aliases</span></a>
- using the <a class="reference internal" href="../reference/simple_stmts.html#type"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">type</span></code></a> statement, which creates an instance of
- <a class="reference internal" href="../library/typing.html#typing.TypeAliasType" title="typing.TypeAliasType"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeAliasType</span></code></a>:</p>
- <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">type</span> <span class="n">Point</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">[</span><span class="nb">float</span><span class="p">,</span> <span class="nb">float</span><span class="p">]</span>
- </pre></div>
- </div>
- <p>Type aliases can also be <a class="reference internal" href="../reference/compound_stmts.html#generic-type-aliases"><span class="std std-ref">generic</span></a>:</p>
- <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">type</span> <span class="n">Point</span><span class="p">[</span><span class="n">T</span><span class="p">]</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">[</span><span class="n">T</span><span class="p">,</span> <span class="n">T</span><span class="p">]</span>
- </pre></div>
- </div>
- <p>The new syntax allows declaring <a class="reference internal" href="../library/typing.html#typing.TypeVarTuple" title="typing.TypeVarTuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeVarTuple</span></code></a>
- and <a class="reference internal" href="../library/typing.html#typing.ParamSpec" title="typing.ParamSpec"><code class="xref py py-class docutils literal notranslate"><span class="pre">ParamSpec</span></code></a> parameters, as well as <a class="reference internal" href="../library/typing.html#typing.TypeVar" title="typing.TypeVar"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeVar</span></code></a>
- parameters with bounds or constraints:</p>
- <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">type</span> <span class="n">IntFunc</span><span class="p">[</span><span class="o">**</span><span class="n">P</span><span class="p">]</span> <span class="o">=</span> <span class="n">Callable</span><span class="p">[</span><span class="n">P</span><span class="p">,</span> <span class="nb">int</span><span class="p">]</span> <span class="c1"># ParamSpec</span>
- <span class="nb">type</span> <span class="n">LabeledTuple</span><span class="p">[</span><span class="o">*</span><span class="n">Ts</span><span class="p">]</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">Ts</span><span class="p">]</span> <span class="c1"># TypeVarTuple</span>
- <span class="nb">type</span> <span class="n">HashableSequence</span><span class="p">[</span><span class="n">T</span><span class="p">:</span> <span class="n">Hashable</span><span class="p">]</span> <span class="o">=</span> <span class="n">Sequence</span><span class="p">[</span><span class="n">T</span><span class="p">]</span> <span class="c1"># TypeVar with bound</span>
- <span class="nb">type</span> <span class="n">IntOrStrSequence</span><span class="p">[</span><span class="n">T</span><span class="p">:</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="nb">str</span><span class="p">)]</span> <span class="o">=</span> <span class="n">Sequence</span><span class="p">[</span><span class="n">T</span><span class="p">]</span> <span class="c1"># TypeVar with constraints</span>
- </pre></div>
- </div>
- <p>The value of type aliases and the bound and constraints of type variables
- created through this syntax are evaluated only on demand (see
- <a class="reference internal" href="../reference/executionmodel.html#lazy-evaluation"><span class="std std-ref">lazy evaluation</span></a>). This means type aliases are able to
- refer to other types defined later in the file.</p>
- <p>Type parameters declared through a type parameter list are visible within the
- scope of the declaration and any nested scopes, but not in the outer scope. For
- example, they can be used in the type annotations for the methods of a generic
- class or in the class body. However, they cannot be used in the module scope after
- the class is defined. See <a class="reference internal" href="../reference/compound_stmts.html#type-params"><span class="std std-ref">Type parameter lists</span></a> for a detailed description of the
- runtime semantics of type parameters.</p>
- <p>In order to support these scoping semantics, a new kind of scope is introduced,
- the <a class="reference internal" href="../reference/executionmodel.html#annotation-scopes"><span class="std std-ref">annotation scope</span></a>. Annotation scopes behave for the
- most part like function scopes, but interact differently with enclosing class scopes.
- In Python 3.13, <a class="reference internal" href="../glossary.html#term-annotation"><span class="xref std std-term">annotations</span></a> will also be evaluated in
- annotation scopes.</p>
- <p>See <span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0695/"><strong>PEP 695</strong></a> for more details.</p>
- <p>(PEP written by Eric Traut. Implementation by Jelle Zijlstra, Eric Traut,
- and others in <a class="reference external" href="https://github.com/python/cpython/issues/103764">gh-103764</a>.)</p>
- </section>
- <section id="pep-701-syntactic-formalization-of-f-strings">
- <span id="whatsnew312-pep701"></span><h3>PEP 701: Syntactic formalization of f-strings<a class="headerlink" href="#pep-701-syntactic-formalization-of-f-strings" title="Link to this heading">¶</a></h3>
- <p><span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a> lifts some restrictions on the usage of <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-strings</span></a>.
- Expression components inside f-strings can now be any valid Python expression,
- including strings reusing the same quote as the containing f-string,
- multi-line expressions, comments, backslashes, and unicode escape sequences.
- Let’s cover these in detail:</p>
- <ul>
- <li><p>Quote reuse: in Python 3.11, reusing the same quotes as the enclosing f-string
- raises a <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>, forcing the user to either use other available
- quotes (like using double quotes or triple quotes if the f-string uses single
- quotes). In Python 3.12, you can now do things like this:</p>
- <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">songs</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'Take me back to Eden'</span><span class="p">,</span> <span class="s1">'Alkaline'</span><span class="p">,</span> <span class="s1">'Ascensionism'</span><span class="p">]</span>
- <span class="gp">>>> </span><span class="sa">f</span><span class="s2">"This is the playlist: </span><span class="si">{</span><span class="s2">", "</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">songs</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span>
- <span class="go">'This is the playlist: Take me back to Eden, Alkaline, Ascensionism'</span>
- </pre></div>
- </div>
- <p>Note that before this change there was no explicit limit in how f-strings can
- be nested, but the fact that string quotes cannot be reused inside the
- expression component of f-strings made it impossible to nest f-strings
- arbitrarily. In fact, this is the most nested f-string that could be written:</p>
- <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="sa">f</span><span class="s2">"""</span><span class="si">{</span><span class="sa">f</span><span class="s1">'''</span><span class="si">{</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="mi">1</span><span class="o">+</span><span class="mi">1</span><span class="si">}</span><span class="s2">"</span><span class="si">}</span><span class="s1">'</span><span class="si">}</span><span class="s1">'''</span><span class="si">}</span><span class="s2">"""</span>
- <span class="go">'2'</span>
- </pre></div>
- </div>
- <p>As now f-strings can contain any valid Python expression inside expression
- components, it is now possible to nest f-strings arbitrarily:</p>
- <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="mi">1</span><span class="o">+</span><span class="mi">1</span><span class="si">}</span><span class="s2">"</span><span class="si">}</span><span class="s2">"</span><span class="si">}</span><span class="s2">"</span><span class="si">}</span><span class="s2">"</span><span class="si">}</span><span class="s2">"</span><span class="si">}</span><span class="s2">"</span>
- <span class="go">'2'</span>
- </pre></div>
- </div>
- </li>
- <li><p>Multi-line expressions and comments: In Python 3.11, f-string expressions
- must be defined in a single line, even if the expression within the f-string
- could normally span multiple lines
- (like literal lists being defined over multiple lines),
- making them harder to read. In Python 3.12 you can now define f-strings
- spanning multiple lines, and add inline comments:</p>
- <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span>>>> f"This is the playlist: {", ".join([
- ... 'Take me back to Eden', # My, my, those eyes like fire
- ... 'Alkaline', # Not acid nor alkaline
- ... 'Ascensionism' # Take to the broken skies at last
- ... ])}"
- 'This is the playlist: Take me back to Eden, Alkaline, Ascensionism'
- </pre></div>
- </div>
- </li>
- <li><p>Backslashes and unicode characters: before Python 3.12 f-string expressions
- couldn’t contain any <code class="docutils literal notranslate"><span class="pre">\</span></code> character. This also affected unicode <a class="reference internal" href="../reference/lexical_analysis.html#escape-sequences"><span class="std std-ref">escape
- sequences</span></a> (such as <code class="docutils literal notranslate"><span class="pre">\N{snowman}</span></code>) as these contain
- the <code class="docutils literal notranslate"><span class="pre">\N</span></code> part that previously could not be part of expression components of
- f-strings. Now, you can define expressions like this:</p>
- <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"This is the playlist: </span><span class="si">{</span><span class="s2">"</span><span class="se">\n</span><span class="s2">"</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">songs</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
- <span class="go">This is the playlist: Take me back to Eden</span>
- <span class="go">Alkaline</span>
- <span class="go">Ascensionism</span>
- <span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"This is the playlist: </span><span class="si">{</span><span class="s2">"</span><span class="se">\N{BLACK HEART SUIT}</span><span class="s2">"</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">songs</span><span class="p">)</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
- <span class="go">This is the playlist: Take me back to Eden♥Alkaline♥Ascensionism</span>
- </pre></div>
- </div>
- </li>
- </ul>
- <p>See <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a> for more details.</p>
- <p>As a positive side-effect of how this feature has been implemented (by parsing f-strings
- with <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0617/"><strong>the PEG parser</strong></a>), now error messages for f-strings are more precise
- and include the exact location of the error. For example, in Python 3.11, the following
- f-string raises a <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>:</p>
- <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">my_string</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">x</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="n">y</span><span class="si">}</span><span class="s2">"</span> <span class="o">+</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="mi">1</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="si">}</span><span class="s2">"</span>
- File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>
- <span class="w"> </span><span class="p">(</span><span class="n">x</span> <span class="n">z</span> <span class="n">y</span><span class="p">)</span>
- <span class="w"> </span><span class="pm">^^^</span>
- <span class="gr">SyntaxError</span>: <span class="n">f-string: invalid syntax. Perhaps you forgot a comma?</span>
- </pre></div>
- </div>
- <p>but the error message doesn’t include the exact location of the error within the line and
- also has the expression artificially surrounded by parentheses. In Python 3.12, as f-strings
- are parsed with the PEG parser, error messages can be more precise and show the entire line:</p>
- <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">my_string</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">x</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="n">y</span><span class="si">}</span><span class="s2">"</span> <span class="o">+</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="mi">1</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="si">}</span><span class="s2">"</span>
- File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>
- <span class="w"> </span><span class="n">my_string</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">x</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="n">y</span><span class="si">}</span><span class="s2">"</span> <span class="o">+</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="mi">1</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="si">}</span><span class="s2">"</span>
- <span class="w"> </span><span class="pm">^^^</span>
- <span class="gr">SyntaxError</span>: <span class="n">invalid syntax. Perhaps you forgot a comma?</span>
- </pre></div>
- </div>
- <p>(Contributed by Pablo Galindo, Batuhan Taskaya, Lysandros Nikolaou, Cristián
- Maureira-Fredes and Marta Gómez in <a class="reference external" href="https://github.com/python/cpython/issues/102856">gh-102856</a>. PEP written by Pablo Galindo,
- Batuhan Taskaya, Lysandros Nikolaou and Marta Gómez).</p>
- </section>
- <section id="pep-684-a-per-interpreter-gil">
- <span id="whatsnew312-pep684"></span><h3>PEP 684: A Per-Interpreter GIL<a class="headerlink" href="#pep-684-a-per-interpreter-gil" title="Link to this heading">¶</a></h3>
- <p><span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0684/"><strong>PEP 684</strong></a> introduces a per-interpreter <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">GIL</span></a>,
- so that sub-interpreters may now be created with a unique GIL per interpreter.
- This allows Python programs to take full advantage of multiple CPU
- cores. This is currently only available through the C-API,
- though a Python API is <span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0554/"><strong>anticipated for 3.13</strong></a>.</p>
- <p>Use the new <a class="reference internal" href="../c-api/init.html#c.Py_NewInterpreterFromConfig" title="Py_NewInterpreterFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_NewInterpreterFromConfig()</span></code></a> function to
- create an interpreter with its own GIL:</p>
- <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">PyInterpreterConfig</span><span class="w"> </span><span class="n">config</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span>
- <span class="w"> </span><span class="p">.</span><span class="n">check_multi_interp_extensions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span>
- <span class="w"> </span><span class="p">.</span><span class="n">gil</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyInterpreterConfig_OWN_GIL</span><span class="p">,</span>
- <span class="p">};</span>
- <span class="n">PyThreadState</span><span class="w"> </span><span class="o">*</span><span class="n">tstate</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span>
- <span class="n">PyStatus</span><span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Py_NewInterpreterFromConfig</span><span class="p">(</span><span class="o">&</span><span class="n">tstate</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">config</span><span class="p">);</span>
- <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</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="mi">-1</span><span class="p">;</span>
- <span class="p">}</span>
- <span class="cm">/* The new interpreter is now active in the current thread. */</span>
- </pre></div>
- </div>
- <p>For further examples how to use the C-API for sub-interpreters with a
- per-interpreter GIL, see <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Modules/_xxsubinterpretersmodule.c">Modules/_xxsubinterpretersmodule.c</a>.</p>
- <p>(Contributed by Eric Snow in <a class="reference external" href="https://github.com/python/cpython/issues/104210">gh-104210</a>, etc.)</p>
- </section>
- <section id="pep-669-low-impact-monitoring-for-cpython">
- <span id="whatsnew312-pep669"></span><h3>PEP 669: Low impact monitoring for CPython<a class="headerlink" href="#pep-669-low-impact-monitoring-for-cpython" title="Link to this heading">¶</a></h3>
- <p><span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0669/"><strong>PEP 669</strong></a> defines a new <a class="reference internal" href="../library/sys.monitoring.html#module-sys.monitoring" title="sys.monitoring: Access and control event monitoring"><code class="xref py py-mod docutils literal notranslate"><span class="pre">API</span></code></a> for profilers,
- debuggers, and other tools to monitor events in CPython.
- It covers a wide range of events, including calls,
- returns, lines, exceptions, jumps, and more.
- This means that you only pay for what you use, providing support
- for near-zero overhead debuggers and coverage tools.
- See <a class="reference internal" href="../library/sys.monitoring.html#module-sys.monitoring" title="sys.monitoring: Access and control event monitoring"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys.monitoring</span></code></a> for details.</p>
- <p>(Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/103082">gh-103082</a>.)</p>
- </section>
- <section id="pep-688-making-the-buffer-protocol-accessible-in-python">
- <span id="whatsnew312-pep688"></span><h3>PEP 688: Making the buffer protocol accessible in Python<a class="headerlink" href="#pep-688-making-the-buffer-protocol-accessible-in-python" title="Link to this heading">¶</a></h3>
- <p><span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0688/"><strong>PEP 688</strong></a> introduces a way to use the <a class="reference internal" href="../c-api/buffer.html#bufferobjects"><span class="std std-ref">buffer protocol</span></a>
- from Python code. Classes that implement the <a class="reference internal" href="../reference/datamodel.html#object.__buffer__" title="object.__buffer__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__buffer__()</span></code></a> method
- are now usable as buffer types.</p>
- <p>The new <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> ABC provides a standard
- way to represent buffer objects, for example in type annotations.
- The new <a class="reference internal" href="../library/inspect.html#inspect.BufferFlags" title="inspect.BufferFlags"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.BufferFlags</span></code></a> enum represents the flags that
- can be used to customize buffer creation.
- (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/102500">gh-102500</a>.)</p>
- </section>
- <section id="pep-709-comprehension-inlining">
- <span id="whatsnew312-pep709"></span><h3>PEP 709: Comprehension inlining<a class="headerlink" href="#pep-709-comprehension-inlining" title="Link to this heading">¶</a></h3>
- <p>Dictionary, list, and set comprehensions are now inlined, rather than creating a
- new single-use function object for each execution of the comprehension. This
- speeds up execution of a comprehension by up to two times.
- See <span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0709/"><strong>PEP 709</strong></a> for further details.</p>
- <p>Comprehension iteration variables remain isolated and don’t overwrite a
- variable of the same name in the outer scope, nor are they visible after the
- comprehension. Inlining does result in a few visible behavior changes:</p>
- <ul class="simple">
- <li><p>There is no longer a separate frame for the comprehension in tracebacks,
- and tracing/profiling no longer shows the comprehension as a function call.</p></li>
- <li><p>The <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> module will no longer produce child symbol tables for each
- comprehension; instead, the comprehension’s locals will be included in the
- parent function’s symbol table.</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> inside a comprehension now includes variables
- from outside the comprehension, and no longer includes the synthetic <code class="docutils literal notranslate"><span class="pre">.0</span></code>
- variable for the comprehension “argument”.</p></li>
- <li><p>A comprehension iterating directly over <code class="docutils literal notranslate"><span class="pre">locals()</span></code> (e.g. <code class="docutils literal notranslate"><span class="pre">[k</span> <span class="pre">for</span> <span class="pre">k</span> <span class="pre">in</span>
- <span class="pre">locals()]</span></code>) may see “RuntimeError: dictionary changed size during iteration”
- when run under tracing (e.g. code coverage measurement). This is the same
- behavior already seen in e.g. <code class="docutils literal notranslate"><span class="pre">for</span> <span class="pre">k</span> <span class="pre">in</span> <span class="pre">locals():</span></code>. To avoid the error, first
- create a list of keys to iterate over: <code class="docutils literal notranslate"><span class="pre">keys</span> <span class="pre">=</span> <span class="pre">list(locals());</span> <span class="pre">[k</span> <span class="pre">for</span> <span class="pre">k</span> <span class="pre">in</span>
- <span class="pre">keys]</span></code>.</p></li>
- </ul>
- <p>(Contributed by Carl Meyer and Vladimir Matveev in <span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0709/"><strong>PEP 709</strong></a>.)</p>
- </section>
- <section id="improved-error-messages">
- <h3>Improved Error Messages<a class="headerlink" href="#improved-error-messages" title="Link to this heading">¶</a></h3>
- <ul>
- <li><p>Modules from the standard library are now potentially suggested as part of
- the error messages displayed by the interpreter when a <a class="reference internal" href="../library/exceptions.html#NameError" title="NameError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NameError</span></code></a> is
- raised to the top level. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/98254">gh-98254</a>.)</p>
- <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">sys</span><span class="o">.</span><span class="n">version_info</span>
- <span class="gt">Traceback (most recent call last):</span>
- File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
- <span class="gr">NameError</span>: <span class="n">name 'sys' is not defined. Did you forget to import 'sys'?</span>
- </pre></div>
- </div>
- </li>
- <li><p>Improve the error suggestion for <a class="reference internal" href="../library/exceptions.html#NameError" title="NameError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NameError</span></code></a> exceptions for instances.
- Now if a <a class="reference internal" href="../library/exceptions.html#NameError" title="NameError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NameError</span></code></a> is raised in a method and the instance has an
- attribute that’s exactly equal to the name in the exception, the suggestion
- will include <code class="docutils literal notranslate"><span class="pre">self.<NAME></span></code> instead of the closest match in the method
- scope. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/99139">gh-99139</a>.)</p>
- <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">class</span> <span class="nc">A</span><span class="p">:</span>
- <span class="gp">... </span> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
- <span class="gp">... </span> <span class="bp">self</span><span class="o">.</span><span class="n">blech</span> <span class="o">=</span> <span class="mi">1</span>
- <span class="gp">...</span>
- <span class="gp">... </span> <span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
- <span class="gp">... </span> <span class="n">somethin</span> <span class="o">=</span> <span class="n">blech</span>
- <span class="gp">...</span>
- <span class="gp">>>> </span><span class="n">A</span><span class="p">()</span><span class="o">.</span><span class="n">foo</span><span class="p">()</span>
- <span class="gt">Traceback (most recent call last):</span>
- File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>
- <span class="w"> </span><span class="n">somethin</span> <span class="o">=</span> <span class="n">blech</span>
- <span class="w"> </span><span class="pm">^^^^^</span>
- <span class="gr">NameError</span>: <span class="n">name 'blech' is not defined. Did you mean: 'self.blech'?</span>
- </pre></div>
- </div>
- </li>
- <li><p>Improve the <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> error message when the user types <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">x</span>
- <span class="pre">from</span> <span class="pre">y</span></code> instead of <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">y</span> <span class="pre">import</span> <span class="pre">x</span></code>. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/98931">gh-98931</a>.)</p>
- <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">a.y.z</span> <span class="kn">from</span> <span class="nn">b.y.z</span>
- <span class="gt">Traceback (most recent call last):</span>
- File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>
- <span class="w"> </span><span class="kn">import</span> <span class="nn">a.y.z</span> <span class="kn">from</span> <span class="nn">b.y.z</span>
- <span class="w"> </span><span class="pm">^^^^^^^^^^^^^^^^^^^^^^^</span>
- <span class="gr">SyntaxError</span>: <span class="n">Did you mean to use 'from ... import ...' instead?</span>
- </pre></div>
- </div>
- </li>
- <li><p><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> exceptions raised from failed <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre"><module></span> <span class="pre">import</span>
- <span class="pre"><name></span></code> statements now include suggestions for the value of <code class="docutils literal notranslate"><span class="pre"><name></span></code> based on the
- available names in <code class="docutils literal notranslate"><span class="pre"><module></span></code>. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/91058">gh-91058</a>.)</p>
- <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">chainmap</span>
- <span class="gt">Traceback (most recent call last):</span>
- File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
- <span class="gr">ImportError</span>: <span class="n">cannot import name 'chainmap' from 'collections'. Did you mean: 'ChainMap'?</span>
- </pre></div>
- </div>
- </li>
- </ul>
- </section>
- </section>
- <section id="new-features-related-to-type-hints">
- <h2>New Features Related to Type Hints<a class="headerlink" href="#new-features-related-to-type-hints" title="Link to this heading">¶</a></h2>
- <p>This section covers major changes affecting <span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>type hints</strong></a> and
- 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.</p>
- <section id="pep-692-using-typeddict-for-more-precise-kwargs-typing">
- <span id="whatsnew312-pep692"></span><h3>PEP 692: Using <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> for more precise <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> typing<a class="headerlink" href="#pep-692-using-typeddict-for-more-precise-kwargs-typing" title="Link to this heading">¶</a></h3>
- <p>Typing <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> in a function signature as introduced by <span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> allowed
- for valid annotations only in cases where all of the <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> were of the
- same type.</p>
- <p><span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0692/"><strong>PEP 692</strong></a> specifies a more precise way of typing <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> by relying on
- typed dictionaries:</p>
- <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">TypedDict</span><span class="p">,</span> <span class="n">Unpack</span>
-
- <span class="k">class</span> <span class="nc">Movie</span><span class="p">(</span><span class="n">TypedDict</span><span class="p">):</span>
- <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>
- <span class="n">year</span><span class="p">:</span> <span class="nb">int</span>
-
- <span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Unpack</span><span class="p">[</span><span class="n">Movie</span><span class="p">]):</span> <span class="o">...</span>
- </pre></div>
- </div>
- <p>See <span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0692/"><strong>PEP 692</strong></a> for more details.</p>
- <p>(Contributed by Franek Magiera in <a class="reference external" href="https://github.com/python/cpython/issues/103629">gh-103629</a>.)</p>
- </section>
- <section id="pep-698-override-decorator-for-static-typing">
- <span id="whatsnew312-pep698"></span><h3>PEP 698: Override Decorator for Static Typing<a class="headerlink" href="#pep-698-override-decorator-for-static-typing" title="Link to this heading">¶</a></h3>
- <p>A new decorator <a class="reference internal" href="../library/typing.html#typing.override" title="typing.override"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.override()</span></code></a> has been added to 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 indicates to type checkers that the method is intended to override
- a method in a superclass. This allows type checkers to catch mistakes where
- a method that is intended to override something in a base class
- does not in fact do so.</p>
- <p>Example:</p>
- <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">override</span>
-
- <span class="k">class</span> <span class="nc">Base</span><span class="p">:</span>
- <span class="k">def</span> <span class="nf">get_color</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span>
- <span class="k">return</span> <span class="s2">"blue"</span>
-
- <span class="k">class</span> <span class="nc">GoodChild</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
- <span class="nd">@override</span> <span class="c1"># ok: overrides Base.get_color</span>
- <span class="k">def</span> <span class="nf">get_color</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span>
- <span class="k">return</span> <span class="s2">"yellow"</span>
-
- <span class="k">class</span> <span class="nc">BadChild</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
- <span class="nd">@override</span> <span class="c1"># type checker error: does not override Base.get_color</span>
- <span class="k">def</span> <span class="nf">get_colour</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span>
- <span class="k">return</span> <span class="s2">"red"</span>
- </pre></div>
- </div>
- <p>See <span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0698/"><strong>PEP 698</strong></a> for more details.</p>
- <p>(Contributed by Steven Troxler in <a class="reference external" href="https://github.com/python/cpython/issues/101561">gh-101561</a>.)</p>
- </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 class="simple">
- <li><p>The parser now raises <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> when parsing source code containing
- null bytes. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/96670">gh-96670</a>.)</p></li>
- <li><p>A backslash-character pair that is not a valid escape sequence now generates
- a <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a>, instead of <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>.
- For example, <code class="docutils literal notranslate"><span class="pre">re.compile("\d+\.\d+")</span></code> now emits a <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a>
- (<code class="docutils literal notranslate"><span class="pre">"\d"</span></code> is an invalid escape sequence, use raw strings for regular
- expression: <code class="docutils literal notranslate"><span class="pre">re.compile(r"\d+\.\d+")</span></code>).
- In a future Python version, <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> will eventually be raised,
- instead of <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a>.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/98401">gh-98401</a>.)</p></li>
- <li><p>Octal escapes with value larger than <code class="docutils literal notranslate"><span class="pre">0o377</span></code> (ex: <code class="docutils literal notranslate"><span class="pre">"\477"</span></code>), deprecated
- in Python 3.11, now produce a <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a>, instead of
- <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 a future Python version they will be eventually a <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 Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/98401">gh-98401</a>.)</p></li>
- <li><p>Variables used in the target part of comprehensions that are not stored to
- can now be used in assignment expressions (<code class="docutils literal notranslate"><span class="pre">:=</span></code>).
- For example, in <code class="docutils literal notranslate"><span class="pre">[(b</span> <span class="pre">:=</span> <span class="pre">1)</span> <span class="pre">for</span> <span class="pre">a,</span> <span class="pre">b.prop</span> <span class="pre">in</span> <span class="pre">some_iter]</span></code>, the assignment to
- <code class="docutils literal notranslate"><span class="pre">b</span></code> is now allowed. Note that assigning to variables stored to in the target
- part of comprehensions (like <code class="docutils literal notranslate"><span class="pre">a</span></code>) is still disallowed, as per <span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0572/"><strong>PEP 572</strong></a>.
- (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/100581">gh-100581</a>.)</p></li>
- <li><p>Exceptions raised in a class or type’s <code class="docutils literal notranslate"><span class="pre">__set_name__</span></code> method are no longer
- wrapped by 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>. Context information is added to the
- exception as a <span class="target" id="index-21"></span><a class="pep reference external" href="https://peps.python.org/pep-0678/"><strong>PEP 678</strong></a> note. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/77757">gh-77757</a>.)</p></li>
- <li><p>When a <code class="docutils literal notranslate"><span class="pre">try-except*</span></code> construct handles the entire <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>
- and raises one other exception, that exception is no longer wrapped in 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>. Also changed in version 3.11.4. (Contributed by Irit
- Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/103590">gh-103590</a>.)</p></li>
- <li><p>The Garbage Collector now runs only on the eval breaker mechanism of the
- Python bytecode evaluation loop instead of object allocations. The GC can
- also run when <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_CheckSignals" title="PyErr_CheckSignals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_CheckSignals()</span></code></a> is called so C extensions that
- need to run for a long time without executing any Python code also have a
- chance to execute the GC periodically. (Contributed by Pablo Galindo in
- <a class="reference external" href="https://github.com/python/cpython/issues/97922">gh-97922</a>.)</p></li>
- <li><p>All builtin and extension callables expecting boolean parameters now accept
- arguments of any type instead of just <a class="reference internal" href="../library/functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a> and <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>.
- (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/60203">gh-60203</a>.)</p></li>
- <li><p><a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-class docutils literal notranslate"><span class="pre">memoryview</span></code></a> now supports the half-float type (the “e” format code).
- (Contributed by Donghee Na and Antoine Pitrou in <a class="reference external" href="https://github.com/python/cpython/issues/90751">gh-90751</a>.)</p></li>
- <li><p><a class="reference internal" href="../library/functions.html#slice" title="slice"><code class="xref py py-class docutils literal notranslate"><span class="pre">slice</span></code></a> objects are now hashable, allowing them to be used as dict keys and
- set items. (Contributed by Will Bradshaw, Furkan Onder, and Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/101264">gh-101264</a>.)</p></li>
- <li><p><a class="reference internal" href="../library/functions.html#sum" title="sum"><code class="xref py py-func docutils literal notranslate"><span class="pre">sum()</span></code></a> now uses Neumaier summation to improve accuracy and commutativity
- when summing floats or mixed ints and floats.
- (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/100425">gh-100425</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 raises <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> instead of <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>
- when parsing source code containing null bytes. (Contributed by Pablo Galindo
- in <a class="reference external" href="https://github.com/python/cpython/issues/96670">gh-96670</a>.)</p></li>
- <li><p>The extraction methods in <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/shutil.html#shutil.unpack_archive" title="shutil.unpack_archive"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.unpack_archive()</span></code></a>,
- have a new a <em>filter</em> argument that allows limiting tar features than may be
- surprising or dangerous, such as creating files outside the destination
- directory.
- See <a class="reference internal" href="../library/tarfile.html#tarfile-extraction-filter"><span class="std std-ref">tarfile extraction filters</span></a> for details.
- In Python 3.14, the default will switch to <code class="docutils literal notranslate"><span class="pre">'data'</span></code>.
- (Contributed by Petr Viktorin in <span class="target" id="index-22"></span><a class="pep reference external" href="https://peps.python.org/pep-0706/"><strong>PEP 706</strong></a>.)</p></li>
- <li><p><a class="reference internal" href="../library/types.html#types.MappingProxyType" title="types.MappingProxyType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.MappingProxyType</span></code></a> instances are now hashable if the underlying
- mapping is hashable.
- (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/87995">gh-87995</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> through the new
- environment variable <span class="target" id="index-23"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPERFSUPPORT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPERFSUPPORT</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</span></code></a>,
- as well as the new <a class="reference internal" href="../library/sys.html#sys.activate_stack_trampoline" title="sys.activate_stack_trampoline"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.activate_stack_trampoline()</span></code></a>,
- <a class="reference internal" href="../library/sys.html#sys.deactivate_stack_trampoline" title="sys.deactivate_stack_trampoline"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.deactivate_stack_trampoline()</span></code></a>,
- and <a class="reference internal" href="../library/sys.html#sys.is_stack_trampoline_active" title="sys.is_stack_trampoline_active"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.is_stack_trampoline_active()</span></code></a> functions.
- (Design by Pablo Galindo. Contributed by Pablo Galindo and Christian Heimes
- with contributions from Gregory P. Smith [Google] and Mark Shannon
- in <a class="reference external" href="https://github.com/python/cpython/issues/96123">gh-96123</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>None.</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="array">
- <h3>array<a class="headerlink" href="#array" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>The <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> class now supports subscripting, making it a
- <a class="reference internal" href="../glossary.html#term-generic-type"><span class="xref std std-term">generic type</span></a>. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/98658">gh-98658</a>.)</p></li>
- </ul>
- </section>
- <section id="asyncio">
- <h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>The performance of writing to sockets in <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> has been
- significantly improved. <code class="docutils literal notranslate"><span class="pre">asyncio</span></code> now avoids unnecessary copying when
- writing to sockets and uses <a class="reference internal" href="../library/socket.html#socket.socket.sendmsg" title="socket.socket.sendmsg"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sendmsg()</span></code></a> if the platform
- supports it. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/91166">gh-91166</a>.)</p></li>
- <li><p>Add <a class="reference internal" href="../library/asyncio-task.html#asyncio.eager_task_factory" title="asyncio.eager_task_factory"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.eager_task_factory()</span></code></a> and <a class="reference internal" href="../library/asyncio-task.html#asyncio.create_eager_task_factory" title="asyncio.create_eager_task_factory"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.create_eager_task_factory()</span></code></a>
- functions to allow opting an event loop in to eager task execution,
- making some use-cases 2x to 5x faster.
- (Contributed by Jacob Bower & Itamar Oren in <a class="reference external" href="https://github.com/python/cpython/issues/102853">gh-102853</a>, <a class="reference external" href="https://github.com/python/cpython/issues/104140">gh-104140</a>, and <a class="reference external" href="https://github.com/python/cpython/issues/104138">gh-104138</a>)</p></li>
- <li><p>On Linux, <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> uses <a class="reference internal" href="../library/asyncio-policy.html#asyncio.PidfdChildWatcher" title="asyncio.PidfdChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.PidfdChildWatcher</span></code></a> by default
- if <a class="reference internal" href="../library/os.html#os.pidfd_open" title="os.pidfd_open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pidfd_open()</span></code></a> is available and functional instead of
- <a class="reference internal" href="../library/asyncio-policy.html#asyncio.ThreadedChildWatcher" title="asyncio.ThreadedChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.ThreadedChildWatcher</span></code></a>.
- (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/98024">gh-98024</a>.)</p></li>
- <li><p>The event loop now uses the best available child watcher for each platform
- (<a class="reference internal" href="../library/asyncio-policy.html#asyncio.PidfdChildWatcher" title="asyncio.PidfdChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.PidfdChildWatcher</span></code></a> if supported and
- <a class="reference internal" href="../library/asyncio-policy.html#asyncio.ThreadedChildWatcher" title="asyncio.ThreadedChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.ThreadedChildWatcher</span></code></a> otherwise), so manually
- configuring a child watcher is not recommended.
- (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/94597">gh-94597</a>.)</p></li>
- <li><p>Add <em>loop_factory</em> parameter to <a class="reference internal" href="../library/asyncio-runner.html#asyncio.run" title="asyncio.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.run()</span></code></a> to allow specifying
- a custom event loop factory.
- (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/99388">gh-99388</a>.)</p></li>
- <li><p>Add C implementation of <a class="reference internal" href="../library/asyncio-task.html#asyncio.current_task" title="asyncio.current_task"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.current_task()</span></code></a> for 4x-6x speedup.
- (Contributed by Itamar Oren and Pranav Thulasiram Bhat in <a class="reference external" href="https://github.com/python/cpython/issues/100344">gh-100344</a>.)</p></li>
- <li><p><a class="reference internal" href="../library/asyncio-task.html#asyncio.iscoroutine" title="asyncio.iscoroutine"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.iscoroutine()</span></code></a> now returns <code class="docutils literal notranslate"><span class="pre">False</span></code> for generators as
- <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> does not support legacy generator-based coroutines.
- (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/102748">gh-102748</a>.)</p></li>
- <li><p><a class="reference internal" href="../library/asyncio-task.html#asyncio.wait" title="asyncio.wait"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.wait()</span></code></a> and <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 accepts generators
- yielding tasks.
- (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/78530">gh-78530</a>.)</p></li>
- </ul>
- </section>
- <section id="calendar">
- <h3>calendar<a class="headerlink" href="#calendar" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Add enums <a class="reference internal" href="../library/calendar.html#calendar.Month" title="calendar.Month"><code class="xref py py-data docutils literal notranslate"><span class="pre">calendar.Month</span></code></a> and <a class="reference internal" href="../library/calendar.html#calendar.Day" title="calendar.Day"><code class="xref py py-data docutils literal notranslate"><span class="pre">calendar.Day</span></code></a>
- defining months of the year and days of the week.
- (Contributed by Prince Roshan in <a class="reference external" href="https://github.com/python/cpython/issues/103636">gh-103636</a>.)</p></li>
- </ul>
- </section>
- <section id="csv">
- <h3>csv<a class="headerlink" href="#csv" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Add <a class="reference internal" href="../library/csv.html#csv.QUOTE_NOTNULL" title="csv.QUOTE_NOTNULL"><code class="xref py py-const docutils literal notranslate"><span class="pre">csv.QUOTE_NOTNULL</span></code></a> and <a class="reference internal" href="../library/csv.html#csv.QUOTE_STRINGS" title="csv.QUOTE_STRINGS"><code class="xref py py-const docutils literal notranslate"><span class="pre">csv.QUOTE_STRINGS</span></code></a> flags to
- provide finer grained control of <code class="docutils literal notranslate"><span class="pre">None</span></code> and empty strings by
- <a class="reference internal" href="../library/csv.html#csv.writer" title="csv.writer"><code class="xref py py-class docutils literal notranslate"><span class="pre">csv.writer</span></code></a> objects.</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>Pseudo instruction opcodes (which are used by the compiler but
- do not appear in executable bytecode) are now exposed in the
- <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.
- <a class="reference internal" href="../library/dis.html#opcode-HAVE_ARGUMENT"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">HAVE_ARGUMENT</span></code></a> is still relevant to real opcodes,
- but it is not useful for pseudo instructions. Use the new
- <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">dis.hasarg</span></code></a> collection instead.
- (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/94216">gh-94216</a>.)</p></li>
- <li><p>Add the <a class="reference internal" href="../library/dis.html#dis.hasexc" title="dis.hasexc"><code class="xref py py-data docutils literal notranslate"><span class="pre">dis.hasexc</span></code></a> collection to signify instructions that set
- an exception handler. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/94216">gh-94216</a>.)</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>Objects of type <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">fractions.Fraction</span></code></a> now support float-style
- formatting. (Contributed by Mark Dickinson in <a class="reference external" href="https://github.com/python/cpython/issues/100161">gh-100161</a>.)</p></li>
- </ul>
- </section>
- <section id="importlib-resources">
- <h3>importlib.resources<a class="headerlink" href="#importlib-resources" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.as_file" title="importlib.resources.as_file"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.as_file()</span></code></a> now supports resource directories.
- (Contributed by Jason R. Coombs in <a class="reference external" href="https://github.com/python/cpython/issues/97930">gh-97930</a>.)</p></li>
- <li><p>Rename first parameter of <a class="reference internal" href="../library/importlib.resources.html#importlib.resources.files" title="importlib.resources.files"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.files()</span></code></a> to <em>anchor</em>.
- (Contributed by Jason R. Coombs in <a class="reference external" href="https://github.com/python/cpython/issues/100598">gh-100598</a>.)</p></li>
- </ul>
- </section>
- <section id="inspect">
- <h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Add <a class="reference internal" href="../library/inspect.html#inspect.markcoroutinefunction" title="inspect.markcoroutinefunction"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.markcoroutinefunction()</span></code></a> to mark sync functions that return
- a <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> for use with <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>.
- (Contributed Carlton Gibson in <a class="reference external" href="https://github.com/python/cpython/issues/99247">gh-99247</a>.)</p></li>
- <li><p>Add <a class="reference internal" href="../library/inspect.html#inspect.getasyncgenstate" title="inspect.getasyncgenstate"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getasyncgenstate()</span></code></a> and <a class="reference internal" href="../library/inspect.html#inspect.getasyncgenlocals" title="inspect.getasyncgenlocals"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getasyncgenlocals()</span></code></a>
- for determining the current state of asynchronous generators.
- (Contributed by Thomas Krennwallner in <a class="reference external" href="https://github.com/python/cpython/issues/79940">gh-79940</a>.)</p></li>
- <li><p>The performance of <a class="reference internal" href="../library/inspect.html#inspect.getattr_static" title="inspect.getattr_static"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getattr_static()</span></code></a> has been considerably
- improved. Most calls to the function should be at least 2x faster than they
- were in Python 3.11, and some may be 6x faster or more. (Contributed by Alex
- Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/103193">gh-103193</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>Add <a class="reference internal" href="../library/itertools.html#itertools.batched" title="itertools.batched"><code class="xref py py-class docutils literal notranslate"><span class="pre">itertools.batched()</span></code></a> for collecting into even-sized
- tuples where the last batch may be shorter than the rest.
- (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/98363">gh-98363</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>Add <a class="reference internal" href="../library/math.html#math.sumprod" title="math.sumprod"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.sumprod()</span></code></a> for computing a sum of products.
- (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/100485">gh-100485</a>.)</p></li>
- <li><p>Extend <a class="reference internal" href="../library/math.html#math.nextafter" title="math.nextafter"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.nextafter()</span></code></a> to include a <em>steps</em> argument
- for moving up or down multiple steps at a time.
- (By Matthias Goergens, Mark Dickinson, and Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/94906">gh-94906</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.PIDFD_NONBLOCK" title="os.PIDFD_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">os.PIDFD_NONBLOCK</span></code></a> to open a file descriptor
- for a process with <a class="reference internal" href="../library/os.html#os.pidfd_open" title="os.pidfd_open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pidfd_open()</span></code></a> in non-blocking mode.
- (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/93312">gh-93312</a>.)</p></li>
- <li><p><a class="reference internal" href="../library/os.html#os.DirEntry" title="os.DirEntry"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.DirEntry</span></code></a> now includes an <a class="reference internal" href="../library/os.html#os.DirEntry.is_junction" title="os.DirEntry.is_junction"><code class="xref py py-meth docutils literal notranslate"><span class="pre">os.DirEntry.is_junction()</span></code></a>
- method to check if the entry is a junction.
- (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/99547">gh-99547</a>.)</p></li>
- <li><p>Add <a class="reference internal" href="../library/os.html#os.listdrives" title="os.listdrives"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listdrives()</span></code></a>, <a class="reference internal" href="../library/os.html#os.listvolumes" title="os.listvolumes"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listvolumes()</span></code></a> and <a class="reference internal" href="../library/os.html#os.listmounts" title="os.listmounts"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listmounts()</span></code></a>
- functions on Windows for enumerating drives, volumes and mount points.
- (Contributed by Steve Dower in <a class="reference external" href="https://github.com/python/cpython/issues/102519">gh-102519</a>.)</p></li>
- <li><p><a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> and <a class="reference internal" href="../library/os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.lstat()</span></code></a> are now more accurate on Windows.
- The <code class="docutils literal notranslate"><span class="pre">st_birthtime</span></code> field will now be filled with the creation time
- of the file, and <code class="docutils literal notranslate"><span class="pre">st_ctime</span></code> is deprecated but still contains the
- creation time (but in the future will return the last metadata change,
- for consistency with other platforms). <code class="docutils literal notranslate"><span class="pre">st_dev</span></code> may be up to 64 bits
- and <code class="docutils literal notranslate"><span class="pre">st_ino</span></code> up to 128 bits depending on your file system, and
- <code class="docutils literal notranslate"><span class="pre">st_rdev</span></code> is always set to zero rather than incorrect values.
- Both functions may be significantly faster on newer releases of
- Windows. (Contributed by Steve Dower in <a class="reference external" href="https://github.com/python/cpython/issues/99726">gh-99726</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.isjunction" title="os.path.isjunction"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.isjunction()</span></code></a> to check if a given path is a junction.
- (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/99547">gh-99547</a>.)</p></li>
- <li><p>Add <a class="reference internal" href="../library/os.path.html#os.path.splitroot" title="os.path.splitroot"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.splitroot()</span></code></a> to split a path into a triad
- <code class="docutils literal notranslate"><span class="pre">(drive,</span> <span class="pre">root,</span> <span class="pre">tail)</span></code>. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/101000">gh-101000</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 support for subclassing <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.PurePath</span></code></a> and
- <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">pathlib.Path</span></code></a>, plus their Posix- and Windows-specific variants.
- Subclasses may override the <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.with_segments" title="pathlib.PurePath.with_segments"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.PurePath.with_segments()</span></code></a> method
- to pass information between path instances.</p></li>
- <li><p>Add <a class="reference internal" href="../library/pathlib.html#pathlib.Path.walk" title="pathlib.Path.walk"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.walk()</span></code></a> for walking the directory trees and generating
- all file or directory names within them, similar to <a class="reference internal" href="../library/os.html#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.walk()</span></code></a>.
- (Contributed by Stanislav Zmiev in <a class="reference external" href="https://github.com/python/cpython/issues/90385">gh-90385</a>.)</p></li>
- <li><p>Add <em>walk_up</em> optional parameter to <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">pathlib.PurePath.relative_to()</span></code></a>
- to allow the insertion of <code class="docutils literal notranslate"><span class="pre">..</span></code> entries in the result; this behavior is
- more consistent with <a class="reference internal" href="../library/os.path.html#os.path.relpath" title="os.path.relpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.relpath()</span></code></a>.
- (Contributed by Domenico Ragusa in <a class="reference external" href="https://github.com/python/cpython/issues/84538">gh-84538</a>.)</p></li>
- <li><p>Add <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_junction" title="pathlib.Path.is_junction"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.is_junction()</span></code></a> as a proxy to <a class="reference internal" href="../library/os.path.html#os.path.isjunction" title="os.path.isjunction"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.isjunction()</span></code></a>.
- (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/99547">gh-99547</a>.)</p></li>
- <li><p>Add <em>case_sensitive</em> optional parameter 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">pathlib.Path.glob()</span></code></a>,
- <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">pathlib.Path.rglob()</span></code></a> and <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.match" title="pathlib.PurePath.match"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.PurePath.match()</span></code></a> for matching
- the path’s case sensitivity, allowing for more precise control over the matching process.</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>Add convenience variables to hold values temporarily for debug session
- and provide quick access to values like the current frame or the return
- value.
- (Contributed by Tian Gao in <a class="reference external" href="https://github.com/python/cpython/issues/103693">gh-103693</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 class="reference internal" href="../library/random.html#random.binomialvariate" title="random.binomialvariate"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.binomialvariate()</span></code></a>.
- (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/81620">gh-81620</a>.)</p></li>
- <li><p>Add a default of <code class="docutils literal notranslate"><span class="pre">lambd=1.0</span></code> to <a class="reference internal" href="../library/random.html#random.expovariate" title="random.expovariate"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.expovariate()</span></code></a>.
- (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/100234">gh-100234</a>.)</p></li>
- </ul>
- </section>
- <section id="shutil">
- <h3>shutil<a class="headerlink" href="#shutil" title="Link to this heading">¶</a></h3>
- <ul>
- <li><p><a class="reference internal" href="../library/shutil.html#shutil.make_archive" title="shutil.make_archive"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.make_archive()</span></code></a> now passes the <em>root_dir</em> argument to custom
- archivers which support it.
- In this case it no longer temporarily changes the current working directory
- of the process to <em>root_dir</em> to perform archiving.
- (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/74696">gh-74696</a>.)</p></li>
- <li><p><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">shutil.rmtree()</span></code></a> now accepts a new argument <em>onexc</em> which is an
- error handler like <em>onerror</em> but which expects an exception instance
- rather than a <em>(typ, val, tb)</em> triplet. <em>onerror</em> is deprecated.
- (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102828">gh-102828</a>.)</p></li>
- <li><p><a class="reference internal" href="../library/shutil.html#shutil.which" title="shutil.which"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.which()</span></code></a> now consults the <em>PATHEXT</em> environment variable to
- find matches within <em>PATH</em> on Windows even when the given <em>cmd</em> includes
- a directory component.
- (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/103179">gh-103179</a>.)</p>
- <p><a class="reference internal" href="../library/shutil.html#shutil.which" title="shutil.which"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.which()</span></code></a> will call <code class="docutils literal notranslate"><span class="pre">NeedCurrentDirectoryForExePathW</span></code> when
- querying for executables on Windows to determine if the current working
- directory should be prepended to the search path.
- (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/103179">gh-103179</a>.)</p>
- <p><a class="reference internal" href="../library/shutil.html#shutil.which" title="shutil.which"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.which()</span></code></a> will return a path matching the <em>cmd</em> with a component
- from <code class="docutils literal notranslate"><span class="pre">PATHEXT</span></code> prior to a direct match elsewhere in the search path on
- Windows.
- (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/103179">gh-103179</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>Add a <a class="reference internal" href="../library/sqlite3.html#sqlite3-cli"><span class="std std-ref">command-line interface</span></a>.
- (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/77617">gh-77617</a>.)</p></li>
- <li><p>Add the <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.autocommit" title="sqlite3.Connection.autocommit"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sqlite3.Connection.autocommit</span></code></a> attribute
- to <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">sqlite3.Connection</span></code></a>
- and the <em>autocommit</em> parameter to <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">sqlite3.connect()</span></code></a>
- to control <span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0249/"><strong>PEP 249</strong></a>-compliant
- <a class="reference internal" href="../library/sqlite3.html#sqlite3-transaction-control-autocommit"><span class="std std-ref">transaction handling</span></a>.
- (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/83638">gh-83638</a>.)</p></li>
- <li><p>Add <em>entrypoint</em> keyword-only parameter to
- <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.load_extension" title="sqlite3.Connection.load_extension"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sqlite3.Connection.load_extension()</span></code></a>,
- for overriding the SQLite extension entry point.
- (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/103015">gh-103015</a>.)</p></li>
- <li><p>Add <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.getconfig" title="sqlite3.Connection.getconfig"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sqlite3.Connection.getconfig()</span></code></a> and
- <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.setconfig" title="sqlite3.Connection.setconfig"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sqlite3.Connection.setconfig()</span></code></a> to <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">sqlite3.Connection</span></code></a>
- to make configuration changes to a database connection.
- (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/103489">gh-103489</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>Extend <a class="reference internal" href="../library/statistics.html#statistics.correlation" title="statistics.correlation"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.correlation()</span></code></a> to include as a <code class="docutils literal notranslate"><span class="pre">ranked</span></code> method
- for computing the Spearman correlation of ranked data.
- (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/95861">gh-95861</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.monitoring.html#module-sys.monitoring" title="sys.monitoring: Access and control event monitoring"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys.monitoring</span></code></a> namespace to expose the new <a class="reference internal" href="#whatsnew312-pep669"><span class="std std-ref">PEP 669</span></a> monitoring API.
- (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/103082">gh-103082</a>.)</p></li>
- <li><p>Add <a class="reference internal" href="../library/sys.html#sys.activate_stack_trampoline" title="sys.activate_stack_trampoline"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.activate_stack_trampoline()</span></code></a> and
- <a class="reference internal" href="../library/sys.html#sys.deactivate_stack_trampoline" title="sys.deactivate_stack_trampoline"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.deactivate_stack_trampoline()</span></code></a> for activating and deactivating
- stack profiler trampolines,
- and <a class="reference internal" href="../library/sys.html#sys.is_stack_trampoline_active" title="sys.is_stack_trampoline_active"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.is_stack_trampoline_active()</span></code></a> for querying if stack profiler
- trampolines are active.
- (Contributed by Pablo Galindo and Christian Heimes
- with contributions from Gregory P. Smith [Google] and Mark Shannon
- in <a class="reference external" href="https://github.com/python/cpython/issues/96123">gh-96123</a>.)</p></li>
- <li><p>Add <a class="reference internal" href="../library/sys.html#sys.last_exc" title="sys.last_exc"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_exc</span></code></a> which holds the last unhandled exception that
- was raised (for post-mortem debugging use cases). Deprecate the
- three fields that have the same information in its legacy form:
- <a class="reference internal" href="../library/sys.html#sys.last_type" title="sys.last_type"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_type</span></code></a>, <a class="reference internal" href="../library/sys.html#sys.last_value" title="sys.last_value"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_value</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.last_traceback" title="sys.last_traceback"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_traceback</span></code></a>.
- (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102778">gh-102778</a>.)</p></li>
- <li><p><a class="reference internal" href="../library/sys.html#sys._current_exceptions" title="sys._current_exceptions"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys._current_exceptions()</span></code></a> now returns a mapping from thread-id to an
- exception instance, rather than to a <code class="docutils literal notranslate"><span class="pre">(typ,</span> <span class="pre">exc,</span> <span class="pre">tb)</span></code> tuple.
- (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/103176">gh-103176</a>.)</p></li>
- <li><p><a class="reference internal" href="../library/sys.html#sys.setrecursionlimit" title="sys.setrecursionlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.setrecursionlimit()</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.getrecursionlimit" title="sys.getrecursionlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getrecursionlimit()</span></code></a>.
- The recursion limit now applies only to Python code. Builtin functions do
- not use the recursion limit, but are protected by a different mechanism
- that prevents recursion from causing a virtual machine crash.</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>The <a class="reference internal" href="../library/tempfile.html#tempfile.NamedTemporaryFile" title="tempfile.NamedTemporaryFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">tempfile.NamedTemporaryFile</span></code></a> function has a new optional parameter
- <em>delete_on_close</em> (Contributed by Evgeny Zorin in <a class="reference external" href="https://github.com/python/cpython/issues/58451">gh-58451</a>.)</p></li>
- <li><p><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 always returns an absolute path, even if the
- argument provided to the <em>dir</em> parameter is a relative path.</p></li>
- </ul>
- </section>
- <section id="threading">
- <span id="whatsnew-typing-py312"></span><h3>threading<a class="headerlink" href="#threading" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Add <a class="reference internal" href="../library/threading.html#threading.settrace_all_threads" title="threading.settrace_all_threads"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.settrace_all_threads()</span></code></a> and
- <a class="reference internal" href="../library/threading.html#threading.setprofile_all_threads" title="threading.setprofile_all_threads"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.setprofile_all_threads()</span></code></a> that allow to set tracing and
- profiling functions in all running threads in addition to the calling one.
- (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/93503">gh-93503</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><code class="docutils literal notranslate"><span class="pre">tkinter.Canvas.coords()</span></code> now flattens its arguments.
- It now accepts not only coordinates as separate arguments
- (<code class="docutils literal notranslate"><span class="pre">x1,</span> <span class="pre">y1,</span> <span class="pre">x2,</span> <span class="pre">y2,</span> <span class="pre">...</span></code>) and a sequence of coordinates
- (<code class="docutils literal notranslate"><span class="pre">[x1,</span> <span class="pre">y1,</span> <span class="pre">x2,</span> <span class="pre">y2,</span> <span class="pre">...]</span></code>), but also coordinates grouped in pairs
- (<code class="docutils literal notranslate"><span class="pre">(x1,</span> <span class="pre">y1),</span> <span class="pre">(x2,</span> <span class="pre">y2),</span> <span class="pre">...</span></code> and <code class="docutils literal notranslate"><span class="pre">[(x1,</span> <span class="pre">y1),</span> <span class="pre">(x2,</span> <span class="pre">y2),</span> <span class="pre">...]</span></code>),
- like <code class="docutils literal notranslate"><span class="pre">create_*()</span></code> methods.
- (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/94473">gh-94473</a>.)</p></li>
- </ul>
- </section>
- <section id="tokenize">
- <h3>tokenize<a class="headerlink" href="#tokenize" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>The <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> module includes the changes introduced in <span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a>.
- (Contributed by Marta Gómez Macías and Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/102856">gh-102856</a>.)
- See <a class="reference internal" href="#whatsnew312-porting-to-python312"><span class="std std-ref">Porting to Python 3.12</span></a> for more information on the
- changes to the <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> module.</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>Add <a class="reference internal" href="../library/types.html#types.get_original_bases" title="types.get_original_bases"><code class="xref py py-func docutils literal notranslate"><span class="pre">types.get_original_bases()</span></code></a> to allow for further introspection of
- <a class="reference internal" href="../library/typing.html#user-defined-generics"><span class="std std-ref">User-defined generic types</span></a> when subclassed. (Contributed by
- James Hilton-Balfe and Alex Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/101827">gh-101827</a>.)</p></li>
- </ul>
- </section>
- <section id="typing">
- <h3>typing<a class="headerlink" href="#typing" title="Link to this heading">¶</a></h3>
- <ul>
- <li><p><a class="reference internal" href="../library/functions.html#isinstance" title="isinstance"><code class="xref py py-func docutils literal notranslate"><span class="pre">isinstance()</span></code></a> checks against
- <a class="reference internal" href="../library/typing.html#typing.runtime_checkable" title="typing.runtime_checkable"><code class="xref py py-func docutils literal notranslate"><span class="pre">runtime-checkable</span> <span class="pre">protocols</span></code></a> now use
- <a class="reference internal" href="../library/inspect.html#inspect.getattr_static" title="inspect.getattr_static"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getattr_static()</span></code></a> rather than <a class="reference internal" href="../library/functions.html#hasattr" title="hasattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">hasattr()</span></code></a> to lookup whether
- attributes exist. This means that descriptors and <a class="reference internal" href="../reference/datamodel.html#object.__getattr__" title="object.__getattr__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getattr__()</span></code></a>
- methods are no longer unexpectedly evaluated during <code class="docutils literal notranslate"><span class="pre">isinstance()</span></code> checks
- against runtime-checkable protocols. However, it may also mean that some
- objects which used to be considered instances of a runtime-checkable protocol
- may no longer be considered instances of that protocol on Python 3.12+, and
- vice versa. Most users are unlikely to be affected by this change.
- (Contributed by Alex Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/102433">gh-102433</a>.)</p></li>
- <li><p>The members of a runtime-checkable protocol are now considered “frozen” at
- runtime as soon as the class has been created. Monkey-patching attributes
- onto a runtime-checkable protocol will still work, but will have no impact on
- <a class="reference internal" href="../library/functions.html#isinstance" title="isinstance"><code class="xref py py-func docutils literal notranslate"><span class="pre">isinstance()</span></code></a> checks comparing objects to the protocol. For example:</p>
- <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Protocol</span><span class="p">,</span> <span class="n">runtime_checkable</span>
- <span class="gp">>>> </span><span class="nd">@runtime_checkable</span>
- <span class="gp">... </span><span class="k">class</span> <span class="nc">HasX</span><span class="p">(</span><span class="n">Protocol</span><span class="p">):</span>
- <span class="gp">... </span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>
- <span class="gp">...</span>
- <span class="gp">>>> </span><span class="k">class</span> <span class="nc">Foo</span><span class="p">:</span> <span class="o">...</span>
- <span class="gp">...</span>
- <span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">Foo</span><span class="p">()</span>
- <span class="gp">>>> </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">HasX</span><span class="p">)</span>
- <span class="go">False</span>
- <span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>
- <span class="gp">>>> </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">HasX</span><span class="p">)</span>
- <span class="go">True</span>
- <span class="gp">>>> </span><span class="n">HasX</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="mi">2</span>
- <span class="gp">>>> </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">HasX</span><span class="p">)</span> <span class="c1"># unchanged, even though HasX now also has a "y" attribute</span>
- <span class="go">True</span>
- </pre></div>
- </div>
- <p>This change was made in order to speed up <code class="docutils literal notranslate"><span class="pre">isinstance()</span></code> checks against
- runtime-checkable protocols.</p>
- </li>
- <li><p>The performance profile of <a class="reference internal" href="../library/functions.html#isinstance" title="isinstance"><code class="xref py py-func docutils literal notranslate"><span class="pre">isinstance()</span></code></a> checks against
- <a class="reference internal" href="../library/typing.html#typing.runtime_checkable" title="typing.runtime_checkable"><code class="xref py py-func docutils literal notranslate"><span class="pre">runtime-checkable</span> <span class="pre">protocols</span></code></a> has changed
- significantly. Most <code class="docutils literal notranslate"><span class="pre">isinstance()</span></code> checks against protocols with only a few
- members should be at least 2x faster than in 3.11, and some may be 20x
- faster or more. However, <code class="docutils literal notranslate"><span class="pre">isinstance()</span></code> checks against protocols with fourteen
- or more members may be slower than in Python 3.11. (Contributed by Alex
- Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/74690">gh-74690</a> and <a class="reference external" href="https://github.com/python/cpython/issues/103193">gh-103193</a>.)</p></li>
- <li><p>All <a class="reference internal" href="../library/typing.html#typing.TypedDict" title="typing.TypedDict"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.TypedDict</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.NamedTuple" title="typing.NamedTuple"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.NamedTuple</span></code></a> classes now have the
- <code class="docutils literal notranslate"><span class="pre">__orig_bases__</span></code> attribute. (Contributed by Adrian Garcia Badaracco in
- <a class="reference external" href="https://github.com/python/cpython/issues/103699">gh-103699</a>.)</p></li>
- <li><p>Add <code class="docutils literal notranslate"><span class="pre">frozen_default</span></code> parameter to <a class="reference internal" href="../library/typing.html#typing.dataclass_transform" title="typing.dataclass_transform"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.dataclass_transform()</span></code></a>.
- (Contributed by Erik De Bonte in <a class="reference external" href="https://github.com/python/cpython/issues/99957">gh-99957</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>The Unicode database has been updated to version 15.0.0. (Contributed by
- Benjamin Peterson in <a class="reference external" href="https://github.com/python/cpython/issues/96734">gh-96734</a>).</p></li>
- </ul>
- </section>
- <section id="unittest">
- <h3>unittest<a class="headerlink" href="#unittest" title="Link to this heading">¶</a></h3>
- <p>Add a <code class="docutils literal notranslate"><span class="pre">--durations</span></code> command line option, showing the N slowest test cases:</p>
- <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python3</span> <span class="o">-</span><span class="n">m</span> <span class="n">unittest</span> <span class="o">--</span><span class="n">durations</span><span class="o">=</span><span class="mi">3</span> <span class="n">lib</span><span class="o">.</span><span class="n">tests</span><span class="o">.</span><span class="n">test_threading</span>
- <span class="o">.....</span>
- <span class="n">Slowest</span> <span class="n">test</span> <span class="n">durations</span>
- <span class="o">----------------------------------------------------------------------</span>
- <span class="mf">1.210</span><span class="n">s</span> <span class="n">test_timeout</span> <span class="p">(</span><span class="n">Lib</span><span class="o">.</span><span class="n">test</span><span class="o">.</span><span class="n">test_threading</span><span class="o">.</span><span class="n">BarrierTests</span><span class="p">)</span>
- <span class="mf">1.003</span><span class="n">s</span> <span class="n">test_default_timeout</span> <span class="p">(</span><span class="n">Lib</span><span class="o">.</span><span class="n">test</span><span class="o">.</span><span class="n">test_threading</span><span class="o">.</span><span class="n">BarrierTests</span><span class="p">)</span>
- <span class="mf">0.518</span><span class="n">s</span> <span class="n">test_timeout</span> <span class="p">(</span><span class="n">Lib</span><span class="o">.</span><span class="n">test</span><span class="o">.</span><span class="n">test_threading</span><span class="o">.</span><span class="n">EventTests</span><span class="p">)</span>
-
- <span class="p">(</span><span class="mf">0.000</span> <span class="n">durations</span> <span class="n">hidden</span><span class="o">.</span> <span class="n">Use</span> <span class="o">-</span><span class="n">v</span> <span class="n">to</span> <span class="n">show</span> <span class="n">these</span> <span class="n">durations</span><span class="o">.</span><span class="p">)</span>
- <span class="o">----------------------------------------------------------------------</span>
- <span class="n">Ran</span> <span class="mi">158</span> <span class="n">tests</span> <span class="ow">in</span> <span class="mf">9.869</span><span class="n">s</span>
-
- <span class="n">OK</span> <span class="p">(</span><span class="n">skipped</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
- </pre></div>
- </div>
- <p>(Contributed by Giampaolo Rodola in <a class="reference external" href="https://github.com/python/cpython/issues/48330">gh-48330</a>)</p>
- </section>
- <section id="uuid">
- <h3>uuid<a class="headerlink" href="#uuid" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Add a <a class="reference internal" href="../library/uuid.html#uuid-cli"><span class="std std-ref">command-line interface</span></a>.
- (Contributed by Adam Chhina in <a class="reference external" href="https://github.com/python/cpython/issues/88597">gh-88597</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>Remove <code class="docutils literal notranslate"><span class="pre">wstr</span></code> and <code class="docutils literal notranslate"><span class="pre">wstr_length</span></code> members from Unicode objects.
- It reduces object size by 8 or 16 bytes on 64bit platform. (<span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-0623/"><strong>PEP 623</strong></a>)
- (Contributed by Inada Naoki in <a class="reference external" href="https://github.com/python/cpython/issues/92536">gh-92536</a>.)</p></li>
- <li><p>Add experimental support for using the BOLT binary optimizer in the build
- process, which improves performance by 1-5%.
- (Contributed by Kevin Modzelewski in <a class="reference external" href="https://github.com/python/cpython/issues/90536">gh-90536</a> and tuned by Donghee Na in <a class="reference external" href="https://github.com/python/cpython/issues/101525">gh-101525</a>)</p></li>
- <li><p>Speed up the regular expression substitution (functions <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">re.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">re.subn()</span></code></a> and corresponding <code class="xref py py-class docutils literal notranslate"><span class="pre">re.Pattern</span></code> methods) for
- replacement strings containing group references by 2–3 times.
- (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/91524">gh-91524</a>.)</p></li>
- <li><p>Speed up <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a> creation by deferring expensive string formatting.
- (Contributed by Itamar Oren in <a class="reference external" href="https://github.com/python/cpython/issues/103793">gh-103793</a>.)</p></li>
- <li><p>The <a class="reference internal" href="../library/tokenize.html#tokenize.tokenize" title="tokenize.tokenize"><code class="xref py py-func docutils literal notranslate"><span class="pre">tokenize.tokenize()</span></code></a> and <a class="reference internal" href="../library/tokenize.html#tokenize.generate_tokens" title="tokenize.generate_tokens"><code class="xref py py-func docutils literal notranslate"><span class="pre">tokenize.generate_tokens()</span></code></a> functions are
- up to 64% faster as a side effect of the changes required to cover <span class="target" id="index-27"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a> in
- the <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> module. (Contributed by Marta Gómez Macías and Pablo Galindo
- in <a class="reference external" href="https://github.com/python/cpython/issues/102856">gh-102856</a>.)</p></li>
- <li><p>Speed up <a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a> method calls and attribute loads via the
- new <a class="reference internal" href="../library/dis.html#opcode-LOAD_SUPER_ATTR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_SUPER_ATTR</span></code></a> instruction. (Contributed by Carl Meyer and
- Vladimir Matveev in <a class="reference external" href="https://github.com/python/cpython/issues/103497">gh-103497</a>.)</p></li>
- </ul>
- </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>Remove the <code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_METHOD</span></code> instruction. It has been merged into
- <a class="reference internal" href="../library/dis.html#opcode-LOAD_ATTR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_ATTR</span></code></a>. <a class="reference internal" href="../library/dis.html#opcode-LOAD_ATTR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_ATTR</span></code></a> will now behave like the old
- <code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_METHOD</span></code> instruction if the low bit of its oparg is set.
- (Contributed by Ken Jin in <a class="reference external" href="https://github.com/python/cpython/issues/93429">gh-93429</a>.)</p></li>
- <li><p>Remove the <code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_IF_FALSE_OR_POP</span></code> and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_IF_TRUE_OR_POP</span></code>
- instructions. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102859">gh-102859</a>.)</p></li>
- <li><p>Remove the <code class="xref std std-opcode docutils literal notranslate"><span class="pre">PRECALL</span></code> instruction. (Contributed by Mark Shannon in
- <a class="reference external" href="https://github.com/python/cpython/issues/92925">gh-92925</a>.)</p></li>
- <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-BINARY_SLICE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BINARY_SLICE</span></code></a> and <a class="reference internal" href="../library/dis.html#opcode-STORE_SLICE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">STORE_SLICE</span></code></a> instructions.
- (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/94163">gh-94163</a>.)</p></li>
- <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-CALL_INTRINSIC_1"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_INTRINSIC_1</span></code></a> instructions.
- (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/99005">gh-99005</a>.)</p></li>
- <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-CALL_INTRINSIC_2"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_INTRINSIC_2</span></code></a> instruction.
- (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/101799">gh-101799</a>.)</p></li>
- <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-CLEANUP_THROW"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CLEANUP_THROW</span></code></a> instruction.
- (Contributed by Brandt Bucher in <a class="reference external" href="https://github.com/python/cpython/issues/90997">gh-90997</a>.)</p></li>
- <li><p>Add the <code class="xref std std-opcode docutils literal notranslate"><span class="pre">END_SEND</span></code> instruction.
- (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/103082">gh-103082</a>.)</p></li>
- <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-LOAD_FAST_AND_CLEAR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_FAST_AND_CLEAR</span></code></a> instruction as part of the
- implementation of <span class="target" id="index-28"></span><a class="pep reference external" href="https://peps.python.org/pep-0709/"><strong>PEP 709</strong></a>. (Contributed by Carl Meyer in <a class="reference external" href="https://github.com/python/cpython/issues/101441">gh-101441</a>.)</p></li>
- <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-LOAD_FAST_CHECK"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_FAST_CHECK</span></code></a> instruction.
- (Contributed by Dennis Sweeney in <a class="reference external" href="https://github.com/python/cpython/issues/93143">gh-93143</a>.)</p></li>
- <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-LOAD_FROM_DICT_OR_DEREF"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_FROM_DICT_OR_DEREF</span></code></a>, <a class="reference internal" href="../library/dis.html#opcode-LOAD_FROM_DICT_OR_GLOBALS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_FROM_DICT_OR_GLOBALS</span></code></a>,
- and <a class="reference internal" href="../library/dis.html#opcode-LOAD_LOCALS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_LOCALS</span></code></a> opcodes as part of the implementation of <span class="target" id="index-29"></span><a class="pep reference external" href="https://peps.python.org/pep-0695/"><strong>PEP 695</strong></a>.
- Remove the <code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_CLASSDEREF</span></code> opcode, which can be replaced with
- <a class="reference internal" href="../library/dis.html#opcode-LOAD_LOCALS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_LOCALS</span></code></a> plus <a class="reference internal" href="../library/dis.html#opcode-LOAD_FROM_DICT_OR_DEREF"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_FROM_DICT_OR_DEREF</span></code></a>. (Contributed
- by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/103764">gh-103764</a>.)</p></li>
- <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-LOAD_SUPER_ATTR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_SUPER_ATTR</span></code></a> instruction. (Contributed by Carl Meyer and
- Vladimir Matveev in <a class="reference external" href="https://github.com/python/cpython/issues/103497">gh-103497</a>.)</p></li>
- <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-RETURN_CONST"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">RETURN_CONST</span></code></a> instruction. (Contributed by Wenyang Wang in <a class="reference external" href="https://github.com/python/cpython/issues/101632">gh-101632</a>.)</p></li>
- </ul>
- </section>
- <section id="demos-and-tools">
- <h2>Demos and Tools<a class="headerlink" href="#demos-and-tools" title="Link to this heading">¶</a></h2>
- <ul class="simple">
- <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">Tools/demo/</span></code> directory which contained old demo scripts. A copy
- can be found in the <a class="reference external" href="https://github.com/gvanrossum/old-demos">old-demos project</a>.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/97681">gh-97681</a>.)</p></li>
- <li><p>Remove outdated example scripts of the <code class="docutils literal notranslate"><span class="pre">Tools/scripts/</span></code> directory.
- A copy can be found in the <a class="reference external" href="https://github.com/gvanrossum/old-demos">old-demos project</a>.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/97669">gh-97669</a>.)</p></li>
- </ul>
- </section>
- <section id="deprecated">
- <h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading">¶</a></h2>
- <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 <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> 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">asyncio.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">asyncio.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">asyncio.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">asyncio.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/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="../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">collections.abc.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">collections.abc.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/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>: <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>’s <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> and
- <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> are deprecated and will be
- removed in a future version. Instead, use timezone-aware objects to represent
- datetimes in UTC: respectively, call <a class="reference internal" href="../library/datetime.html#datetime.datetime.now" title="datetime.datetime.now"><code class="xref py py-meth docutils literal notranslate"><span class="pre">now()</span></code></a> and
- <a class="reference internal" href="../library/datetime.html#datetime.datetime.fromtimestamp" title="datetime.datetime.fromtimestamp"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fromtimestamp()</span></code></a> with the <em>tz</em> parameter set to
- <a class="reference internal" href="../library/datetime.html#datetime.UTC" title="datetime.UTC"><code class="xref py py-const docutils literal notranslate"><span class="pre">datetime.UTC</span></code></a>.
- (Contributed by Paul Ganssle in <a class="reference external" href="https://github.com/python/cpython/issues/103857">gh-103857</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>: Deprecate 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 the following classes, scheduled for removal in
- Python 3.14:</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>: Deprecate the support for copy, deepcopy, and pickle operations,
- which is undocumented, inefficient, historically buggy, and inconsistent.
- 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>: In Python 3.14, the default <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>
- 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/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">pkgutil.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">pkgutil.get_loader()</span></code></a>
- are deprecated and will be removed in Python 3.14;
- 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>: The module has two undocumented <code class="docutils literal notranslate"><span class="pre">master_open()</span></code> and <code class="docutils literal notranslate"><span class="pre">slave_open()</span></code>
- functions that have been deprecated since Python 2 but only gained 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. Remove them in 3.14.
- (Contributed by Soumendra Ganguly and Gregory P. Smith in <a class="reference external" href="https://github.com/python/cpython/issues/85984">gh-85984</a>.)</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>:</p>
- <ul class="simple">
- <li><p>The <code class="docutils literal notranslate"><span class="pre">st_ctime</span></code> fields return by <a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> and <a class="reference internal" href="../library/os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.lstat()</span></code></a> on
- Windows are deprecated. In a future release, they will contain the last
- metadata change time, consistent with other platforms. For now, they still
- contain the creation time, which is also available in the new <code class="docutils literal notranslate"><span class="pre">st_birthtime</span></code>
- field. (Contributed by Steve Dower in <a class="reference external" href="https://github.com/python/cpython/issues/99726">gh-99726</a>.)</p></li>
- <li><p>On POSIX platforms, <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> can now raise 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> when it can detect being called from a
- multithreaded process. There has always been a fundamental incompatibility
- with the POSIX platform when doing so. Even if such code <em>appeared</em> to work.
- We added the warning to to raise awareness as issues encounted by code doing
- this are becoming more frequent. See the <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> documentation for
- more details along with <a class="reference external" href="https://discuss.python.org/t/33555">this discussion on fork being incompatible with threads</a> for <em>why</em> we’re now surfacing this
- longstanding platform compatibility problem to developers.</p></li>
- </ul>
- <p>When this warning appears due to usage of <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> or
- <a class="reference internal" href="../library/concurrent.futures.html#module-concurrent.futures" title="concurrent.futures: Execute computations concurrently using threads or processes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.futures</span></code></a> the fix is to use a different
- <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> start method such as <code class="docutils literal notranslate"><span class="pre">"spawn"</span></code> or <code class="docutils literal notranslate"><span class="pre">"forkserver"</span></code>.</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>: The <em>onerror</em> argument of <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">shutil.rmtree()</span></code></a> is deprecated;
- use <em>onexc</em> instead. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102828">gh-102828</a>.)</p></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-default-converters"><span class="std std-ref">default adapters and converters</span></a> are now deprecated.
- Instead, use the <a class="reference internal" href="../library/sqlite3.html#sqlite3-adapter-converter-recipes"><span class="std std-ref">Adapter and converter recipes</span></a>
- and tailor them to your needs.
- (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/90016">gh-90016</a>.)</p></li>
- <li><p>In <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>, <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> is now emitted
- when <a class="reference internal" href="../library/sqlite3.html#sqlite3-placeholders"><span class="std std-ref">named placeholders</span></a> are used together with
- parameters supplied as a <a class="reference internal" href="../glossary.html#term-sequence"><span class="xref std std-term">sequence</span></a> instead of 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>.
- Starting from Python 3.14, using named placeholders with parameters supplied
- as a sequence will raise a <a class="reference internal" href="../library/sqlite3.html#sqlite3.ProgrammingError" title="sqlite3.ProgrammingError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ProgrammingError</span></code></a>.
- (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/101698">gh-101698</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>: The <a class="reference internal" href="../library/sys.html#sys.last_type" title="sys.last_type"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_type</span></code></a>, <a class="reference internal" href="../library/sys.html#sys.last_value" title="sys.last_value"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_value</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.last_traceback" title="sys.last_traceback"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_traceback</span></code></a>
- fields are deprecated. Use <a class="reference internal" href="../library/sys.html#sys.last_exc" title="sys.last_exc"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_exc</span></code></a> instead.
- (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102778">gh-102778</a>.)</p></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>: Extracting tar archives without specifying <em>filter</em> is deprecated until
- Python 3.14, when <code class="docutils literal notranslate"><span class="pre">'data'</span></code> filter will become the default.
- See <a class="reference internal" href="../library/tarfile.html#tarfile-extraction-filter"><span class="std std-ref">Extraction filters</span></a> for details.</p></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 class="simple">
- <li><p><a class="reference internal" href="../library/typing.html#typing.Hashable" title="typing.Hashable"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Hashable</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.Sized" title="typing.Sized"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Sized</span></code></a>, aliases for
- <a class="reference internal" href="../library/collections.abc.html#collections.abc.Hashable" title="collections.abc.Hashable"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Hashable</span></code></a> and <a class="reference internal" href="../library/collections.abc.html#collections.abc.Sized" title="collections.abc.Sized"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Sized</span></code></a> respectively, are
- deprecated. (<a class="reference external" href="https://github.com/python/cpython/issues/94309">gh-94309</a>.)</p></li>
- <li><p><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">typing.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.
- (Contributed by Alex Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/91896">gh-91896</a>.)</p></li>
- </ul>
- </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>: The module now emits <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>
- when 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">xml.etree.ElementTree.Element</span></code></a>.
- Before, the Python implementation emitted <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>, and the C
- implementation emitted nothing.
- (Contributed by Jacob Walls in <a class="reference external" href="https://github.com/python/cpython/issues/83122">gh-83122</a>.)</p></li>
- <li><p>The 3-arg signatures (type, value, traceback) of <a class="reference internal" href="../reference/datamodel.html#coroutine.throw" title="coroutine.throw"><code class="xref py py-meth docutils literal notranslate"><span class="pre">coroutine</span> <span class="pre">throw()</span></code></a>, <a class="reference internal" href="../reference/expressions.html#generator.throw" title="generator.throw"><code class="xref py py-meth docutils literal notranslate"><span class="pre">generator</span> <span class="pre">throw()</span></code></a> and
- <a class="reference internal" href="../reference/expressions.html#agen.athrow" title="agen.athrow"><code class="xref py py-meth docutils literal notranslate"><span class="pre">async</span> <span class="pre">generator</span> <span class="pre">throw()</span></code></a> are deprecated and
- may be removed in a future version of Python. Use the single-arg versions
- of these functions instead. (Contributed by Ofey Chan in <a class="reference external" href="https://github.com/python/cpython/issues/89874">gh-89874</a>.)</p></li>
- <li><p><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> is now raised when <code class="docutils literal notranslate"><span class="pre">__package__</span></code> on a
- module differs from <code class="docutils literal notranslate"><span class="pre">__spec__.parent</span></code> (previously it was
- <a class="reference internal" href="../library/exceptions.html#ImportWarning" title="ImportWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportWarning</span></code></a>).
- (Contributed by Brett Cannon in <a class="reference external" href="https://github.com/python/cpython/issues/65961">gh-65961</a>.)</p></li>
- <li><p>Setting <code class="docutils literal notranslate"><span class="pre">__package__</span></code> or <code class="docutils literal notranslate"><span class="pre">__cached__</span></code> on a module is deprecated,
- and will cease to be set or taken into consideration by the import system in Python 3.14.
- (Contributed by Brett Cannon in <a class="reference external" href="https://github.com/python/cpython/issues/65961">gh-65961</a>.)</p></li>
- <li><p>The bitwise inversion operator (<code class="docutils literal notranslate"><span class="pre">~</span></code>) on bool is deprecated. It will throw an
- error in Python 3.14. Use <code class="docutils literal notranslate"><span class="pre">not</span></code> for logical negation of bools instead.
- In the rare case that you really need the bitwise inversion of the underlying
- <code class="docutils literal notranslate"><span class="pre">int</span></code>, convert to int explicitly: <code class="docutils literal notranslate"><span class="pre">~int(x)</span></code>. (Contributed by Tim Hoffmann
- in <a class="reference external" href="https://github.com/python/cpython/issues/103487">gh-103487</a>.)</p></li>
- <li><p>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> on code objects was deprecated in
- Python 3.10 via <span class="target" id="index-30"></span><a class="pep reference external" href="https://peps.python.org/pep-0626/"><strong>PEP 626</strong></a>,
- 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,
- therefore it will be removed in 3.14.
- (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/101866">gh-101866</a>.)</p></li>
- </ul>
- <section id="pending-removal-in-python-3-13">
- <h3>Pending Removal in Python 3.13<a class="headerlink" href="#pending-removal-in-python-3-13" title="Link to this heading">¶</a></h3>
- <p>The following modules and APIs have been deprecated in earlier Python releases,
- and will be removed in Python 3.13.</p>
- <p>Modules (see <span class="target" id="index-31"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a>):</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="../library/aifc.html#module-aifc" title="aifc: Read and write audio files in AIFF or AIFC format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">aifc</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/audioop.html#module-audioop" title="audioop: Manipulate raw audio data. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/cgi.html#module-cgi" title="cgi: Helpers for running Python scripts via the Common Gateway Interface. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cgi</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/cgitb.html#module-cgitb" title="cgitb: Configurable traceback handler for CGI scripts. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cgitb</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/chunk.html#module-chunk" title="chunk: Module to read IFF chunks. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">chunk</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/crypt.html#module-crypt" title="crypt: The crypt() function used to check Unix passwords. (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">crypt</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/imghdr.html#module-imghdr" title="imghdr: Determine the type of image contained in a file or byte stream. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imghdr</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/mailcap.html#module-mailcap" title="mailcap: Mailcap file handling. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mailcap</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/msilib.html#module-msilib" title="msilib: Creation of Microsoft Installer files, and CAB files. (deprecated) (Windows)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">msilib</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/nis.html#module-nis" title="nis: Interface to Sun's NIS (Yellow Pages) library. (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">nis</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/nntplib.html#module-nntplib" title="nntplib: NNTP protocol client (requires sockets). (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">nntplib</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/ossaudiodev.html#module-ossaudiodev" title="ossaudiodev: Access to OSS-compatible audio devices. (deprecated) (Linux, FreeBSD)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/pipes.html#module-pipes" title="pipes: A Python interface to Unix shell pipelines. (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/sndhdr.html#module-sndhdr" title="sndhdr: Determine type of a sound file. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sndhdr</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/spwd.html#module-spwd" title="spwd: The shadow password database (getspnam() and friends). (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">spwd</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/sunau.html#module-sunau" title="sunau: Provide an interface to the Sun AU sound format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/telnetlib.html#module-telnetlib" title="telnetlib: Telnet client class. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">telnetlib</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/uu.html#module-uu" title="uu: Encode and decode files in uuencode format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">uu</span></code></a></p></li>
- <li><p><a class="reference internal" href="../library/xdrlib.html#module-xdrlib" title="xdrlib: Encoders and decoders for the External Data Representation (XDR). (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xdrlib</span></code></a></p></li>
- </ul>
- <p>Other modules:</p>
- <ul class="simple">
- <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">lib2to3</span></code>, and the <strong class="program">2to3</strong> program (<a class="reference external" href="https://github.com/python/cpython/issues/84540">gh-84540</a>)</p></li>
- </ul>
- <p>APIs:</p>
- <ul>
- <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.LegacyInterpolation</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/90765">gh-90765</a>)</p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">locale.resetlocale()</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/90817">gh-90817</a>)</p></li>
- <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">turtle.RawTurtle.settiltangle()</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/50096">gh-50096</a>)</p></li>
- <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.findTestCases()</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/50096">gh-50096</a>)</p></li>
- <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.getTestCaseNames()</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/50096">gh-50096</a>)</p></li>
- <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.makeSuite()</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/50096">gh-50096</a>)</p></li>
- <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestProgram.usageExit()</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/67048">gh-67048</a>)</p></li>
- <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">webbrowser.MacOSX</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/86421">gh-86421</a>)</p></li>
- <li><p><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> descriptor chaining (<a class="reference external" href="https://github.com/python/cpython/issues/89519">gh-89519</a>)</p></li>
- <li><p><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> deprecated methods:</p>
- <ul class="simple">
- <li><p><code class="docutils literal notranslate"><span class="pre">contents()</span></code></p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">is_resource()</span></code></p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">open_binary()</span></code></p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">open_text()</span></code></p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">path()</span></code></p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">read_binary()</span></code></p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">read_text()</span></code></p></li>
- </ul>
- <p>Use <a class="reference internal" href="../library/importlib.resources.html#importlib.resources.files" title="importlib.resources.files"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.files()</span></code></a> instead. Refer to <a class="reference external" href="https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy">importlib-resources: Migrating from Legacy</a> (<a class="reference external" href="https://github.com/python/cpython/issues/106531">gh-106531</a>)</p>
- </li>
- </ul>
- </section>
- <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>
- <p>The following APIs have been deprecated
- and will be removed in Python 3.14.</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>: 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></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>:</p>
- <ul>
- <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>
- </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-class docutils literal notranslate"><span class="pre">asyncio.MultiLoopChildWatcher</span></code></p></li>
- <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.FastChildWatcher</span></code></p></li>
- <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.AbstractChildWatcher</span></code></p></li>
- <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.SafeChildWatcher</span></code></p></li>
- <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.set_child_watcher()</span></code></p></li>
- <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.get_child_watcher()</span></code>,</p></li>
- <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.AbstractEventLoopPolicy.set_child_watcher()</span></code></p></li>
- <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.AbstractEventLoopPolicy.get_child_watcher()</span></code></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>: <code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.ByteString</span></code>.</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>: 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>.</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>:</p>
- <ul>
- <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>
- </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>: Support for copy, deepcopy, and pickle operations.</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>:</p>
- <ul>
- <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.find_loader()</span></code></p></li>
- <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.get_loader()</span></code>.</p></li>
- </ul>
- </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>
- <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">pty.master_open()</span></code></p></li>
- <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">pty.slave_open()</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>: The <em>onerror</em> argument of <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">shutil.rmtree()</span></code></a></p></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>: <code class="xref py py-class docutils literal notranslate"><span class="pre">typing.ByteString</span></code></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">xml.etree.ElementTree.Element</span></code></a>.</p></li>
- <li><p>The <code class="docutils literal notranslate"><span class="pre">__package__</span></code> and <code class="docutils literal notranslate"><span class="pre">__cached__</span></code> attributes on module objects.</p></li>
- <li><p>The <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> attribute of code objects.</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>
- <p>The following APIs have been deprecated
- and will be removed in Python 3.15.</p>
- <p>APIs:</p>
- <ul class="simple">
- <li><p><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">locale.getdefaultlocale()</span></code></a> (<a class="reference external" href="https://github.com/python/cpython/issues/90817">gh-90817</a>)</p></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 were deprecated in earlier Python versions 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="../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/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>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>
- </ul>
- </section>
- </section>
- <section id="removed">
- <h2>Removed<a class="headerlink" href="#removed" title="Link to this heading">¶</a></h2>
- <section id="asynchat-and-asyncore">
- <h3>asynchat and asyncore<a class="headerlink" href="#asynchat-and-asyncore" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>These two modules have been removed
- according to the schedule in <span class="target" id="index-32"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a>,
- having been deprecated in Python 3.6.
- Use <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> instead.
- (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/96580">gh-96580</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>Several names deprecated in the <a class="reference internal" href="../library/configparser.html#module-configparser" title="configparser: Configuration file parser."><code class="xref py py-mod docutils literal notranslate"><span class="pre">configparser</span></code></a> way back in 3.2 have
- been removed per <a class="reference external" href="https://github.com/python/cpython/issues/89336">gh-89336</a>:</p>
- <ul>
- <li><p><a class="reference internal" href="../library/configparser.html#configparser.ParsingError" title="configparser.ParsingError"><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.ParsingError</span></code></a> no longer has a <code class="docutils literal notranslate"><span class="pre">filename</span></code> attribute
- or argument. Use the <code class="docutils literal notranslate"><span class="pre">source</span></code> attribute and argument instead.</p></li>
- <li><p><a class="reference internal" href="../library/configparser.html#module-configparser" title="configparser: Configuration file parser."><code class="xref py py-mod docutils literal notranslate"><span class="pre">configparser</span></code></a> no longer has a <code class="docutils literal notranslate"><span class="pre">SafeConfigParser</span></code> class. Use the
- shorter <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> name instead.</p></li>
- <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.ConfigParser</span></code></a> no longer has a <code class="docutils literal notranslate"><span class="pre">readfp</span></code> method.
- Use <a class="reference internal" href="../library/configparser.html#configparser.ConfigParser.read_file" title="configparser.ConfigParser.read_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">read_file()</span></code></a> instead.</p></li>
- </ul>
- </li>
- </ul>
- </section>
- <section id="distutils">
- <h3>distutils<a class="headerlink" href="#distutils" 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">distutils</span></code> package. It was deprecated in Python 3.10 by
- <span class="target" id="index-33"></span><a class="pep reference external" href="https://peps.python.org/pep-0632/"><strong>PEP 632</strong></a> “Deprecate distutils module”. For projects still using
- <code class="docutils literal notranslate"><span class="pre">distutils</span></code> and cannot be updated to something else, the <code class="docutils literal notranslate"><span class="pre">setuptools</span></code>
- project can be installed: it still provides <code class="docutils literal notranslate"><span class="pre">distutils</span></code>.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/92584">gh-92584</a>.)</p></li>
- </ul>
- </section>
- <section id="ensurepip">
- <h3>ensurepip<a class="headerlink" href="#ensurepip" title="Link to this heading">¶</a></h3>
- <ul>
- <li><p>Remove the bundled setuptools wheel from <a class="reference internal" href="../library/ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the "pip" installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a>,
- and stop installing setuptools in environments created by <a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a>.</p>
- <p><code class="docutils literal notranslate"><span class="pre">pip</span> <span class="pre">(>=</span> <span class="pre">22.1)</span></code> does not require setuptools to be installed in the
- environment. <code class="docutils literal notranslate"><span class="pre">setuptools</span></code>-based (and <code class="docutils literal notranslate"><span class="pre">distutils</span></code>-based) packages
- can still be used with <code class="docutils literal notranslate"><span class="pre">pip</span> <span class="pre">install</span></code>, since pip will provide
- <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> in the build environment it uses for building a
- package.</p>
- <p><code class="docutils literal notranslate"><span class="pre">easy_install</span></code>, <code class="docutils literal notranslate"><span class="pre">pkg_resources</span></code>, <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> and <code class="docutils literal notranslate"><span class="pre">distutils</span></code>
- are no longer provided by default in environments created with
- <code class="docutils literal notranslate"><span class="pre">venv</span></code> or bootstrapped with <code class="docutils literal notranslate"><span class="pre">ensurepip</span></code>, since they are part of
- the <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> package. For projects relying on these at runtime,
- the <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> project should be declared as a dependency and
- installed separately (typically, using pip).</p>
- <p>(Contributed by Pradyun Gedam in <a class="reference external" href="https://github.com/python/cpython/issues/95299">gh-95299</a>.)</p>
- </li>
- </ul>
- </section>
- <section id="enum">
- <h3>enum<a class="headerlink" href="#enum" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Remove <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>’s <code class="docutils literal notranslate"><span class="pre">EnumMeta.__getattr__</span></code>, which is no longer needed for
- enum attribute access.
- (Contributed by Ethan Furman in <a class="reference external" href="https://github.com/python/cpython/issues/95083">gh-95083</a>.)</p></li>
- </ul>
- </section>
- <section id="ftplib">
- <h3>ftplib<a class="headerlink" href="#ftplib" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Remove <a class="reference internal" href="../library/ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a>’s <code class="docutils literal notranslate"><span class="pre">FTP_TLS.ssl_version</span></code> class attribute: use the
- <em>context</em> parameter instead.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94172">gh-94172</a>.)</p></li>
- </ul>
- </section>
- <section id="gzip">
- <h3>gzip<a class="headerlink" href="#gzip" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">filename</span></code> attribute of <a class="reference internal" href="../library/gzip.html#module-gzip" title="gzip: Interfaces for gzip compression and decompression using file objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gzip</span></code></a>’s <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>,
- deprecated since Python 2.6, use the <a class="reference internal" href="../library/gzip.html#gzip.GzipFile.name" title="gzip.GzipFile.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> attribute
- instead. In write mode, the <code class="docutils literal notranslate"><span class="pre">filename</span></code> attribute added <code class="docutils literal notranslate"><span class="pre">'.gz'</span></code> file
- extension if it was not present.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94196">gh-94196</a>.)</p></li>
- </ul>
- </section>
- <section id="hashlib">
- <h3>hashlib<a class="headerlink" href="#hashlib" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Remove the pure Python implementation of <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>’s
- <a class="reference internal" href="../library/hashlib.html#hashlib.pbkdf2_hmac" title="hashlib.pbkdf2_hmac"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.pbkdf2_hmac()</span></code></a>, deprecated in Python 3.10. Python 3.10 and
- newer requires OpenSSL 1.1.1 (<span class="target" id="index-34"></span><a class="pep reference external" href="https://peps.python.org/pep-0644/"><strong>PEP 644</strong></a>): this OpenSSL version provides
- a C implementation of <a class="reference internal" href="../library/hashlib.html#hashlib.pbkdf2_hmac" title="hashlib.pbkdf2_hmac"><code class="xref py py-func docutils literal notranslate"><span class="pre">pbkdf2_hmac()</span></code></a> which is faster.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94199">gh-94199</a>.)</p></li>
- </ul>
- </section>
- <section id="importlib">
- <h3>importlib<a class="headerlink" href="#importlib" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Many previously deprecated cleanups in <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> have now been
- completed:</p>
- <ul>
- <li><p>References to, and support for <code class="xref py py-meth docutils literal notranslate"><span class="pre">module_repr()</span></code> has been removed.
- (Contributed by Barry Warsaw in <a class="reference external" href="https://github.com/python/cpython/issues/97850">gh-97850</a>.)</p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">importlib.util.set_package</span></code>, <code class="docutils literal notranslate"><span class="pre">importlib.util.set_loader</span></code> and
- <code class="docutils literal notranslate"><span class="pre">importlib.util.module_for_loader</span></code> have all been removed. (Contributed by
- Brett Cannon and Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/65961">gh-65961</a> and <a class="reference external" href="https://github.com/python/cpython/issues/97850">gh-97850</a>.)</p></li>
- <li><p>Support for <code class="docutils literal notranslate"><span class="pre">find_loader()</span></code> and <code class="docutils literal notranslate"><span class="pre">find_module()</span></code> APIs have been
- removed. (Contributed by Barry Warsaw in <a class="reference external" href="https://github.com/python/cpython/issues/98040">gh-98040</a>.)</p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">importlib.abc.Finder</span></code>, <code class="docutils literal notranslate"><span class="pre">pkgutil.ImpImporter</span></code>, and <code class="docutils literal notranslate"><span class="pre">pkgutil.ImpLoader</span></code>
- have been removed. (Contributed by Barry Warsaw in <a class="reference external" href="https://github.com/python/cpython/issues/98040">gh-98040</a>.)</p></li>
- </ul>
- </li>
- </ul>
- </section>
- <section id="imp">
- <h3>imp<a class="headerlink" href="#imp" title="Link to this heading">¶</a></h3>
- <ul>
- <li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> module has been removed. (Contributed by Barry Warsaw in
- <a class="reference external" href="https://github.com/python/cpython/issues/98040">gh-98040</a>.)</p>
- <p>To migrate, consult the following correspondence table:</p>
- <blockquote>
- <div><table class="docutils align-default">
- <thead>
- <tr class="row-odd"><th class="head"><p>imp</p></th>
- <th class="head"><p>importlib</p></th>
- </tr>
- </thead>
- <tbody>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imp.NullImporter</span></code></p></td>
- <td><p>Insert <code class="docutils literal notranslate"><span class="pre">None</span></code> into <code class="docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></p></td>
- </tr>
- <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">imp.cache_from_source()</span></code></p></td>
- <td><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">importlib.util.cache_from_source()</span></code></a></p></td>
- </tr>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imp.find_module()</span></code></p></td>
- <td><p><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></p></td>
- </tr>
- <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">imp.get_magic()</span></code></p></td>
- <td><p><a class="reference internal" href="../library/importlib.html#importlib.util.MAGIC_NUMBER" title="importlib.util.MAGIC_NUMBER"><code class="xref py py-attr docutils literal notranslate"><span class="pre">importlib.util.MAGIC_NUMBER</span></code></a></p></td>
- </tr>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imp.get_suffixes()</span></code></p></td>
- <td><p><a class="reference internal" href="../library/importlib.html#importlib.machinery.SOURCE_SUFFIXES" title="importlib.machinery.SOURCE_SUFFIXES"><code class="xref py py-attr docutils literal notranslate"><span class="pre">importlib.machinery.SOURCE_SUFFIXES</span></code></a>, <a class="reference internal" href="../library/importlib.html#importlib.machinery.EXTENSION_SUFFIXES" title="importlib.machinery.EXTENSION_SUFFIXES"><code class="xref py py-attr docutils literal notranslate"><span class="pre">importlib.machinery.EXTENSION_SUFFIXES</span></code></a>, and <a class="reference internal" href="../library/importlib.html#importlib.machinery.BYTECODE_SUFFIXES" title="importlib.machinery.BYTECODE_SUFFIXES"><code class="xref py py-attr docutils literal notranslate"><span class="pre">importlib.machinery.BYTECODE_SUFFIXES</span></code></a></p></td>
- </tr>
- <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">imp.get_tag()</span></code></p></td>
- <td><p><a class="reference internal" href="../library/sys.html#sys.implementation" title="sys.implementation"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.implementation.cache_tag</span></code></a></p></td>
- </tr>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imp.load_module()</span></code></p></td>
- <td><p><a class="reference internal" href="../library/importlib.html#importlib.import_module" title="importlib.import_module"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.import_module()</span></code></a></p></td>
- </tr>
- <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">imp.new_module(name)</span></code></p></td>
- <td><p><code class="docutils literal notranslate"><span class="pre">types.ModuleType(name)</span></code></p></td>
- </tr>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imp.reload()</span></code></p></td>
- <td><p><a class="reference internal" href="../library/importlib.html#importlib.reload" title="importlib.reload"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.reload()</span></code></a></p></td>
- </tr>
- <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">imp.source_from_cache()</span></code></p></td>
- <td><p><a class="reference internal" href="../library/importlib.html#importlib.util.source_from_cache" title="importlib.util.source_from_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.source_from_cache()</span></code></a></p></td>
- </tr>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imp.load_source()</span></code></p></td>
- <td><p><em>See below</em></p></td>
- </tr>
- </tbody>
- </table>
- </div></blockquote>
- <p>Replace <code class="docutils literal notranslate"><span class="pre">imp.load_source()</span></code> with:</p>
- <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">importlib.util</span>
- <span class="kn">import</span> <span class="nn">importlib.machinery</span>
-
- <span class="k">def</span> <span class="nf">load_source</span><span class="p">(</span><span class="n">modname</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
- <span class="n">loader</span> <span class="o">=</span> <span class="n">importlib</span><span class="o">.</span><span class="n">machinery</span><span class="o">.</span><span class="n">SourceFileLoader</span><span class="p">(</span><span class="n">modname</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
- <span class="n">spec</span> <span class="o">=</span> <span class="n">importlib</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="n">spec_from_file_location</span><span class="p">(</span><span class="n">modname</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">loader</span><span class="o">=</span><span class="n">loader</span><span class="p">)</span>
- <span class="n">module</span> <span class="o">=</span> <span class="n">importlib</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="n">module_from_spec</span><span class="p">(</span><span class="n">spec</span><span class="p">)</span>
- <span class="c1"># The module is always executed and not cached in sys.modules.</span>
- <span class="c1"># Uncomment the following line to cache the module.</span>
- <span class="c1"># sys.modules[module.__name__] = module</span>
- <span class="n">loader</span><span class="o">.</span><span class="n">exec_module</span><span class="p">(</span><span class="n">module</span><span class="p">)</span>
- <span class="k">return</span> <span class="n">module</span>
- </pre></div>
- </div>
- </li>
- <li><p>Remove <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> functions and attributes with no replacements:</p>
- <ul class="simple">
- <li><p>Undocumented functions:</p>
- <ul>
- <li><p><code class="docutils literal notranslate"><span class="pre">imp.init_builtin()</span></code></p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">imp.load_compiled()</span></code></p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">imp.load_dynamic()</span></code></p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">imp.load_package()</span></code></p></li>
- </ul>
- </li>
- <li><p><code class="docutils literal notranslate"><span class="pre">imp.lock_held()</span></code>, <code class="docutils literal notranslate"><span class="pre">imp.acquire_lock()</span></code>, <code class="docutils literal notranslate"><span class="pre">imp.release_lock()</span></code>:
- the locking scheme has changed in Python 3.3 to per-module locks.</p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">imp.find_module()</span></code> constants: <code class="docutils literal notranslate"><span class="pre">SEARCH_ERROR</span></code>, <code class="docutils literal notranslate"><span class="pre">PY_SOURCE</span></code>,
- <code class="docutils literal notranslate"><span class="pre">PY_COMPILED</span></code>, <code class="docutils literal notranslate"><span class="pre">C_EXTENSION</span></code>, <code class="docutils literal notranslate"><span class="pre">PY_RESOURCE</span></code>, <code class="docutils literal notranslate"><span class="pre">PKG_DIRECTORY</span></code>,
- <code class="docutils literal notranslate"><span class="pre">C_BUILTIN</span></code>, <code class="docutils literal notranslate"><span class="pre">PY_FROZEN</span></code>, <code class="docutils literal notranslate"><span class="pre">PY_CODERESOURCE</span></code>, <code class="docutils literal notranslate"><span class="pre">IMP_HOOK</span></code>.</p></li>
- </ul>
- </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>Remove <a class="reference internal" href="../library/io.html#module-io" title="io: Core tools for working with streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code></a>’s <code class="docutils literal notranslate"><span class="pre">io.OpenWrapper</span></code> and <code class="docutils literal notranslate"><span class="pre">_pyio.OpenWrapper</span></code>, deprecated in Python
- 3.10: just use <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> instead. The <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> (<a class="reference internal" href="../library/io.html#io.open" title="io.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">io.open()</span></code></a>)
- function is a built-in function. Since Python 3.10, <code class="xref py py-func docutils literal notranslate"><span class="pre">_pyio.open()</span></code> is
- also a static method.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94169">gh-94169</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 <a class="reference internal" href="../library/locale.html#module-locale" title="locale: Internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">locale</span></code></a>’s <code class="xref py py-func docutils literal notranslate"><span class="pre">locale.format()</span></code> function, deprecated in Python 3.7:
- use <a class="reference internal" href="../library/locale.html#locale.format_string" title="locale.format_string"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.format_string()</span></code></a> instead.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94226">gh-94226</a>.)</p></li>
- </ul>
- </section>
- <section id="smtpd">
- <h3>smtpd<a class="headerlink" href="#smtpd" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>The <code class="docutils literal notranslate"><span class="pre">smtpd</span></code> module has been removed according to the schedule in <span class="target" id="index-35"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a>,
- having been deprecated in Python 3.4.7 and 3.5.4.
- Use <a class="reference external" href="https://pypi.org/project/aiosmtpd/">aiosmtpd</a> PyPI module or any other
- <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>-based server instead.
- (Contributed by Oleg Iarygin in <a class="reference external" href="https://github.com/python/cpython/issues/93243">gh-93243</a>.)</p></li>
- </ul>
- </section>
- <section id="id2">
- <h3>sqlite3<a class="headerlink" href="#id2" title="Link to this heading">¶</a></h3>
- <ul>
- <li><p>The following undocumented <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> features, deprecated in Python
- 3.10, are now removed:</p>
- <ul class="simple">
- <li><p><code class="docutils literal notranslate"><span class="pre">sqlite3.enable_shared_cache()</span></code></p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">sqlite3.OptimizedUnicode</span></code></p></li>
- </ul>
- <p>If a shared cache must be used, open the database in URI mode using the
- <code class="docutils literal notranslate"><span class="pre">cache=shared</span></code> query parameter.</p>
- <p>The <code class="docutils literal notranslate"><span class="pre">sqlite3.OptimizedUnicode</span></code> text factory has been an alias for
- <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> since Python 3.3. Code that previously set the text factory to
- <code class="docutils literal notranslate"><span class="pre">OptimizedUnicode</span></code> can either use <code class="docutils literal notranslate"><span class="pre">str</span></code> explicitly, or rely on the
- default value which is also <code class="docutils literal notranslate"><span class="pre">str</span></code>.</p>
- <p>(Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/92548">gh-92548</a>.)</p>
- </li>
- </ul>
- </section>
- <section id="ssl">
- <h3>ssl<a class="headerlink" href="#ssl" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Remove <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>’s <code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.RAND_pseudo_bytes()</span></code> function, deprecated in Python 3.6:
- use <a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.urandom()</span></code></a> or <a class="reference internal" href="../library/ssl.html#ssl.RAND_bytes" title="ssl.RAND_bytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.RAND_bytes()</span></code></a> instead.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94199">gh-94199</a>.)</p></li>
- <li><p>Remove the <code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.match_hostname()</span></code> function.
- It was deprecated in Python 3.7. OpenSSL performs
- hostname matching since Python 3.7, Python no longer uses the
- <code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.match_hostname()</span></code> function.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94199">gh-94199</a>.)</p></li>
- <li><p>Remove the <code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.wrap_socket()</span></code> function, deprecated in Python 3.7:
- instead, create a <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> object and call its
- <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.wrap_socket" title="ssl.SSLContext.wrap_socket"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext.wrap_socket</span></code></a> method. Any package that still uses
- <code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.wrap_socket()</span></code> is broken and insecure. The function neither sends a
- SNI TLS extension nor validates server hostname. Code is subject to <a class="reference external" href="https://cwe.mitre.org/data/definitions/295.html">CWE-295</a>: Improper Certificate
- Validation.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94199">gh-94199</a>.)</p></li>
- </ul>
- </section>
- <section id="id3">
- <h3>unittest<a class="headerlink" href="#id3" title="Link to this heading">¶</a></h3>
- <ul>
- <li><p>Remove many long-deprecated <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> features:</p>
- <ul id="unittest-testcase-removed-aliases">
- <li><p>A number of <a class="reference internal" href="../library/unittest.html#unittest.TestCase" title="unittest.TestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestCase</span></code></a> method aliases:</p>
- <table class="docutils align-default">
- <thead>
- <tr class="row-odd"><th class="head"><p>Deprecated alias</p></th>
- <th class="head"><p>Method Name</p></th>
- <th class="head"><p>Deprecated in</p></th>
- </tr>
- </thead>
- <tbody>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">failUnless</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertTrue" title="unittest.TestCase.assertTrue"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertTrue()</span></code></a></p></td>
- <td><p>3.1</p></td>
- </tr>
- <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">failIf</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertFalse" title="unittest.TestCase.assertFalse"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertFalse()</span></code></a></p></td>
- <td><p>3.1</p></td>
- </tr>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">failUnlessEqual</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertEqual" title="unittest.TestCase.assertEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertEqual()</span></code></a></p></td>
- <td><p>3.1</p></td>
- </tr>
- <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">failIfEqual</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertNotEqual" title="unittest.TestCase.assertNotEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertNotEqual()</span></code></a></p></td>
- <td><p>3.1</p></td>
- </tr>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">failUnlessAlmostEqual</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertAlmostEqual" title="unittest.TestCase.assertAlmostEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertAlmostEqual()</span></code></a></p></td>
- <td><p>3.1</p></td>
- </tr>
- <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">failIfAlmostEqual</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertNotAlmostEqual" title="unittest.TestCase.assertNotAlmostEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertNotAlmostEqual()</span></code></a></p></td>
- <td><p>3.1</p></td>
- </tr>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">failUnlessRaises</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertRaises" title="unittest.TestCase.assertRaises"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertRaises()</span></code></a></p></td>
- <td><p>3.1</p></td>
- </tr>
- <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">assert_</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertTrue" title="unittest.TestCase.assertTrue"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertTrue()</span></code></a></p></td>
- <td><p>3.2</p></td>
- </tr>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">assertEquals</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertEqual" title="unittest.TestCase.assertEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertEqual()</span></code></a></p></td>
- <td><p>3.2</p></td>
- </tr>
- <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">assertNotEquals</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertNotEqual" title="unittest.TestCase.assertNotEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertNotEqual()</span></code></a></p></td>
- <td><p>3.2</p></td>
- </tr>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">assertAlmostEquals</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertAlmostEqual" title="unittest.TestCase.assertAlmostEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertAlmostEqual()</span></code></a></p></td>
- <td><p>3.2</p></td>
- </tr>
- <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">assertNotAlmostEquals</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertNotAlmostEqual" title="unittest.TestCase.assertNotAlmostEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertNotAlmostEqual()</span></code></a></p></td>
- <td><p>3.2</p></td>
- </tr>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">assertRegexpMatches</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertRegex" title="unittest.TestCase.assertRegex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertRegex()</span></code></a></p></td>
- <td><p>3.2</p></td>
- </tr>
- <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">assertRaisesRegexp</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertRaisesRegex" title="unittest.TestCase.assertRaisesRegex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertRaisesRegex()</span></code></a></p></td>
- <td><p>3.2</p></td>
- </tr>
- <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">assertNotRegexpMatches</span></code></p></td>
- <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertNotRegex" title="unittest.TestCase.assertNotRegex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertNotRegex()</span></code></a></p></td>
- <td><p>3.5</p></td>
- </tr>
- </tbody>
- </table>
- <p>You can use <a class="reference external" href="https://github.com/isidentical/teyit">https://github.com/isidentical/teyit</a> to automatically modernise
- your unit tests.</p>
- </li>
- <li><p>Undocumented and broken <a class="reference internal" href="../library/unittest.html#unittest.TestCase" title="unittest.TestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestCase</span></code></a> method
- <code class="docutils literal notranslate"><span class="pre">assertDictContainsSubset</span></code> (deprecated in Python 3.2).</p></li>
- <li><p>Undocumented <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">TestLoader.loadTestsFromModule</span></code></a> parameter <em>use_load_tests</em>
- (deprecated and ignored since Python 3.2).</p></li>
- <li><p>An alias of the <a class="reference internal" href="../library/unittest.html#unittest.TextTestResult" title="unittest.TextTestResult"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextTestResult</span></code></a> class:
- <code class="docutils literal notranslate"><span class="pre">_TextTestResult</span></code> (deprecated in Python 3.2).</p></li>
- </ul>
- <p>(Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/89325">gh-89325</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 support for obsolete browsers from <a class="reference internal" href="../library/webbrowser.html#module-webbrowser" title="webbrowser: Easy-to-use controller for web browsers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code></a>.
- The removed browsers include: Grail, Mosaic, Netscape, Galeon, Skipstone,
- Iceape, Firebird, and Firefox versions 35 and below (<a class="reference external" href="https://github.com/python/cpython/issues/102871">gh-102871</a>).</p></li>
- </ul>
- </section>
- <section id="xml-etree-elementtree">
- <h3>xml.etree.ElementTree<a class="headerlink" href="#xml-etree-elementtree" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">ElementTree.Element.copy()</span></code> method of the
- pure Python implementation, deprecated in Python 3.10, use the
- <a class="reference internal" href="../library/copy.html#copy.copy" title="copy.copy"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy.copy()</span></code></a> function instead. The C implementation of <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>
- has no <code class="docutils literal notranslate"><span class="pre">copy()</span></code> method, only a <code class="docutils literal notranslate"><span class="pre">__copy__()</span></code> method.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94383">gh-94383</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>Remove <a class="reference internal" href="../library/zipimport.html#module-zipimport" title="zipimport: Support for importing Python modules from ZIP archives."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipimport</span></code></a>’s <code class="docutils literal notranslate"><span class="pre">find_loader()</span></code> and <code class="docutils literal notranslate"><span class="pre">find_module()</span></code> methods,
- deprecated in Python 3.10: use the <code class="docutils literal notranslate"><span class="pre">find_spec()</span></code> method instead. See
- <span class="target" id="index-36"></span><a class="pep reference external" href="https://peps.python.org/pep-0451/"><strong>PEP 451</strong></a> for the rationale.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94379">gh-94379</a>.)</p></li>
- </ul>
- </section>
- <section id="others">
- <h3>Others<a class="headerlink" href="#others" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">suspicious</span></code> rule from the documentation <code class="file docutils literal notranslate"><span class="pre">Makefile</span></code> and
- <code class="file docutils literal notranslate"><span class="pre">Doc/tools/rstlint.py</span></code>, both in favor of <a class="reference external" href="https://github.com/sphinx-contrib/sphinx-lint">sphinx-lint</a>.
- (Contributed by Julien Palard in <a class="reference external" href="https://github.com/python/cpython/issues/98179">gh-98179</a>.)</p></li>
- <li><p>Remove the <em>keyfile</em> and <em>certfile</em> parameters from the
- <a class="reference internal" href="../library/ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a>, <a class="reference internal" href="../library/imaplib.html#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a>, <a class="reference internal" href="../library/poplib.html#module-poplib" title="poplib: POP3 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code></a> and <a class="reference internal" href="../library/smtplib.html#module-smtplib" title="smtplib: SMTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtplib</span></code></a> modules,
- and the <em>key_file</em>, <em>cert_file</em> and <em>check_hostname</em> parameters from the
- <a class="reference internal" href="../library/http.client.html#module-http.client" title="http.client: HTTP and HTTPS protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.client</span></code></a> module,
- all deprecated since Python 3.6. Use the <em>context</em> parameter
- (<em>ssl_context</em> in <a class="reference internal" href="../library/imaplib.html#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a>) instead.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94172">gh-94172</a>.)</p></li>
- <li><p>Remove <code class="docutils literal notranslate"><span class="pre">Jython</span></code> compatibility hacks from several stdlib modules and tests.
- (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/99482">gh-99482</a>.)</p></li>
- <li><p>Remove <code class="docutils literal notranslate"><span class="pre">_use_broken_old_ctypes_structure_semantics_</span></code> flag
- from <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> module.
- (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/99285">gh-99285</a>.)</p></li>
- </ul>
- </section>
- </section>
- <section id="porting-to-python-3-12">
- <span id="whatsnew312-porting-to-python312"></span><h2>Porting to Python 3.12<a class="headerlink" href="#porting-to-python-3-12" 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>
- <li><p>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>Remove <code class="docutils literal notranslate"><span class="pre">randrange()</span></code> functionality deprecated since Python 3.10. Formerly,
- <code class="docutils literal notranslate"><span class="pre">randrange(10.0)</span></code> losslessly converted to <code class="docutils literal notranslate"><span class="pre">randrange(10)</span></code>. Now, it raises a
- <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>. Also, the exception raised for non-integer values such as
- <code class="docutils literal notranslate"><span class="pre">randrange(10.5)</span></code> or <code class="docutils literal notranslate"><span class="pre">randrange('10')</span></code> has been changed from <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> to
- <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>. This also prevents bugs where <code class="docutils literal notranslate"><span class="pre">randrange(1e25)</span></code> would silently
- select from a larger range than <code class="docutils literal notranslate"><span class="pre">randrange(10**25)</span></code>.
- (Originally suggested by Serhiy Storchaka <a class="reference external" href="https://github.com/python/cpython/issues/86388">gh-86388</a>.)</p></li>
- <li><p><a class="reference internal" href="../library/argparse.html#argparse.ArgumentParser" title="argparse.ArgumentParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">argparse.ArgumentParser</span></code></a> changed encoding and error handler
- for reading arguments from file (e.g. <code class="docutils literal notranslate"><span class="pre">fromfile_prefix_chars</span></code> option)
- from default text encoding (e.g. <a class="reference internal" href="../library/locale.html#locale.getpreferredencoding" title="locale.getpreferredencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getpreferredencoding(False)</span></code></a>)
- to <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>.
- Argument files should be encoded in UTF-8 instead of ANSI Codepage on Windows.</p></li>
- <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">asyncore</span></code>-based <code class="docutils literal notranslate"><span class="pre">smtpd</span></code> module deprecated in Python 3.4.7
- and 3.5.4. A recommended replacement is the
- <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>-based <a class="reference external" href="https://pypi.org/project/aiosmtpd/">aiosmtpd</a> PyPI module.</p></li>
- <li><p><a class="reference internal" href="../library/shlex.html#shlex.split" title="shlex.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">shlex.split()</span></code></a>: Passing <code class="docutils literal notranslate"><span class="pre">None</span></code> for <em>s</em> argument now raises an
- exception, rather than reading <a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a>. The feature was deprecated
- in Python 3.9.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94352">gh-94352</a>.)</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 no longer accepts bytes-like paths, like
- <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-class docutils literal notranslate"><span class="pre">memoryview</span></code></a> types: only the exact
- <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> type is accepted for bytes strings.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/98393">gh-98393</a>.)</p></li>
- <li><p><a class="reference internal" href="../library/syslog.html#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog.openlog()</span></code></a> and <a class="reference internal" href="../library/syslog.html#syslog.closelog" title="syslog.closelog"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog.closelog()</span></code></a> now fail if used in subinterpreters.
- <a class="reference internal" href="../library/syslog.html#syslog.syslog" title="syslog.syslog"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog.syslog()</span></code></a> may still be used in subinterpreters,
- but now only if <a class="reference internal" href="../library/syslog.html#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog.openlog()</span></code></a> has already been called in the main interpreter.
- These new restrictions do not apply to the main interpreter,
- so only a very small set of users might be affected.
- This change helps with interpreter isolation. Furthermore, <a class="reference internal" href="../library/syslog.html#module-syslog" title="syslog: An interface to the Unix syslog library routines. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">syslog</span></code></a> is a wrapper
- around process-global resources, which are best managed from the main interpreter.
- (Contributed by Donghee Na in <a class="reference external" href="https://github.com/python/cpython/issues/99127">gh-99127</a>.)</p></li>
- <li><p>The undocumented locking behavior of <a class="reference internal" href="../library/functools.html#functools.cached_property" title="functools.cached_property"><code class="xref py py-func docutils literal notranslate"><span class="pre">cached_property()</span></code></a>
- is removed, because it locked across all instances of the class, leading to high
- lock contention. This means that a cached property getter function could now run
- more than once for a single instance, if two threads race. For most simple
- cached properties (e.g. those that are idempotent and simply calculate a value
- based on other attributes of the instance) this will be fine. If
- synchronization is needed, implement locking within the cached property getter
- function or around multi-threaded access points.</p></li>
- <li><p><a class="reference internal" href="../library/sys.html#sys._current_exceptions" title="sys._current_exceptions"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys._current_exceptions()</span></code></a> now returns a mapping from thread-id to an
- exception instance, rather than to a <code class="docutils literal notranslate"><span class="pre">(typ,</span> <span class="pre">exc,</span> <span class="pre">tb)</span></code> tuple.
- (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/103176">gh-103176</a>.)</p></li>
- <li><p>When extracting tar files using <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> or
- <a class="reference internal" href="../library/shutil.html#shutil.unpack_archive" title="shutil.unpack_archive"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.unpack_archive()</span></code></a>, pass the <em>filter</em> argument to limit features
- that may be surprising or dangerous.
- See <a class="reference internal" href="../library/tarfile.html#tarfile-extraction-filter"><span class="std std-ref">Extraction filters</span></a> for details.</p></li>
- <li><p>The output of the <a class="reference internal" href="../library/tokenize.html#tokenize.tokenize" title="tokenize.tokenize"><code class="xref py py-func docutils literal notranslate"><span class="pre">tokenize.tokenize()</span></code></a> and <a class="reference internal" href="../library/tokenize.html#tokenize.generate_tokens" title="tokenize.generate_tokens"><code class="xref py py-func docutils literal notranslate"><span class="pre">tokenize.generate_tokens()</span></code></a>
- functions is now changed due to the changes introduced in <span class="target" id="index-37"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a>. This
- means that <code class="docutils literal notranslate"><span class="pre">STRING</span></code> tokens are not emitted any more for f-strings and the
- tokens described in <span class="target" id="index-38"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a> are now produced instead: <code class="docutils literal notranslate"><span class="pre">FSTRING_START</span></code>,
- <code class="docutils literal notranslate"><span class="pre">FSTRING_MIDDLE</span></code> and <code class="docutils literal notranslate"><span class="pre">FSTRING_END</span></code> are now emitted for f-string “string”
- parts in addition to the appropriate tokens for the tokenization in the
- expression components. For example for the f-string <code class="docutils literal notranslate"><span class="pre">f"start</span> <span class="pre">{1+1}</span> <span class="pre">end"</span></code>
- the old version of the tokenizer emitted:</p>
- <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">18</span><span class="p">:</span> <span class="n">STRING</span> <span class="s1">'f"start {1+1} end"'</span>
- </pre></div>
- </div>
- <p>while the new version emits:</p>
- <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">:</span> <span class="n">FSTRING_START</span> <span class="s1">'f"'</span>
- <span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">8</span><span class="p">:</span> <span class="n">FSTRING_MIDDLE</span> <span class="s1">'start '</span>
- <span class="mi">1</span><span class="p">,</span><span class="mi">8</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">9</span><span class="p">:</span> <span class="n">OP</span> <span class="s1">'{'</span>
- <span class="mi">1</span><span class="p">,</span><span class="mi">9</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">10</span><span class="p">:</span> <span class="n">NUMBER</span> <span class="s1">'1'</span>
- <span class="mi">1</span><span class="p">,</span><span class="mi">10</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">11</span><span class="p">:</span> <span class="n">OP</span> <span class="s1">'+'</span>
- <span class="mi">1</span><span class="p">,</span><span class="mi">11</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">12</span><span class="p">:</span> <span class="n">NUMBER</span> <span class="s1">'1'</span>
- <span class="mi">1</span><span class="p">,</span><span class="mi">12</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">13</span><span class="p">:</span> <span class="n">OP</span> <span class="s1">'}'</span>
- <span class="mi">1</span><span class="p">,</span><span class="mi">13</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">17</span><span class="p">:</span> <span class="n">FSTRING_MIDDLE</span> <span class="s1">' end'</span>
- <span class="mi">1</span><span class="p">,</span><span class="mi">17</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">18</span><span class="p">:</span> <span class="n">FSTRING_END</span> <span class="s1">'"'</span>
- </pre></div>
- </div>
- <p>Additionally, there may be some minor behavioral changes as a consequence of the
- changes required to support <span class="target" id="index-39"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a>. Some of these changes include:</p>
- <ul class="simple">
- <li><p>The <code class="docutils literal notranslate"><span class="pre">type</span></code> attribute of the tokens emitted when tokenizing some invalid Python
- characters such as <code class="docutils literal notranslate"><span class="pre">!</span></code> has changed from <code class="docutils literal notranslate"><span class="pre">ERRORTOKEN</span></code> to <code class="docutils literal notranslate"><span class="pre">OP</span></code>.</p></li>
- <li><p>Incomplete single-line strings now also raise <a class="reference internal" href="../library/tokenize.html#tokenize.TokenError" title="tokenize.TokenError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">tokenize.TokenError</span></code></a> as incomplete
- multiline strings do.</p></li>
- <li><p>Some incomplete or invalid Python code now raises <a class="reference internal" href="../library/tokenize.html#tokenize.TokenError" title="tokenize.TokenError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">tokenize.TokenError</span></code></a> instead of
- returning arbitrary <code class="docutils literal notranslate"><span class="pre">ERRORTOKEN</span></code> tokens when tokenizing it.</p></li>
- <li><p>Mixing tabs and spaces as indentation in the same file is not supported anymore and will
- raise a <a class="reference internal" href="../library/exceptions.html#TabError" title="TabError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TabError</span></code></a>.</p></li>
- </ul>
- </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="docutils literal notranslate"><span class="pre">_is_main_interpreter</span></code> attribute. It is a function with no
- arguments that 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="docutils literal notranslate"><span class="pre">_thread</span></code> module
- should provide <code class="docutils literal notranslate"><span class="pre">_is_main_interpreter()</span></code>.
- (See <a class="reference external" href="https://github.com/python/cpython/issues/112826">gh-112826</a>.)</p>
- </li>
- </ul>
- </section>
- </section>
- <section id="build-changes">
- <h2>Build Changes<a class="headerlink" href="#build-changes" title="Link to this heading">¶</a></h2>
- <ul>
- <li><p>Python no longer uses <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> to build shared C extension modules.
- Build parameters like headers and libraries are detected in <code class="docutils literal notranslate"><span class="pre">configure</span></code>
- script. Extensions are built by <code class="file docutils literal notranslate"><span class="pre">Makefile</span></code>. Most extensions use
- <code class="docutils literal notranslate"><span class="pre">pkg-config</span></code> and fall back to manual detection.
- (Contributed by Christian Heimes in <a class="reference external" href="https://github.com/python/cpython/issues/93939">gh-93939</a>.)</p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">va_start()</span></code> with two parameters, like <code class="docutils literal notranslate"><span class="pre">va_start(args,</span> <span class="pre">format),</span></code>
- is now required to build Python.
- <code class="docutils literal notranslate"><span class="pre">va_start()</span></code> is no longer called with a single parameter.
- (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/93207">gh-93207</a>.)</p></li>
- <li><p>CPython now uses the ThinLTO option as the default link time optimization policy
- if the Clang compiler accepts the flag.
- (Contributed by Donghee Na in <a class="reference external" href="https://github.com/python/cpython/issues/89536">gh-89536</a>.)</p></li>
- <li><p>Add <code class="docutils literal notranslate"><span class="pre">COMPILEALL_OPTS</span></code> variable in <code class="file docutils literal notranslate"><span class="pre">Makefile</span></code> to override <a class="reference internal" href="../library/compileall.html#module-compileall" title="compileall: Tools for byte-compiling all Python source files in a directory tree."><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code></a>
- options (default: <code class="docutils literal notranslate"><span class="pre">-j0</span></code>) in <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">install</span></code>. Also merged the 3
- <code class="docutils literal notranslate"><span class="pre">compileall</span></code> commands into a single command to build .pyc files for all
- optimization levels (0, 1, 2) at once.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/99289">gh-99289</a>.)</p></li>
- <li><p>Add platform triplets for 64-bit LoongArch:</p>
- <ul class="simple">
- <li><p>loongarch64-linux-gnusf</p></li>
- <li><p>loongarch64-linux-gnuf32</p></li>
- <li><p>loongarch64-linux-gnu</p></li>
- </ul>
- <p>(Contributed by Zhang Na in <a class="reference external" href="https://github.com/python/cpython/issues/90656">gh-90656</a>.)</p>
- </li>
- <li><p><code class="docutils literal notranslate"><span class="pre">PYTHON_FOR_REGEN</span></code> now require Python 3.10 or newer.</p></li>
- <li><p>Autoconf 2.71 and aclocal 1.16.4 is now required to regenerate
- <code class="file docutils literal notranslate"><span class="pre">!configure</span></code>.
- (Contributed by Christian Heimes in <a class="reference external" href="https://github.com/python/cpython/issues/89886">gh-89886</a>.)</p></li>
- <li><p>Windows builds and macOS installers from python.org now use OpenSSL 3.0.</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="id4">
- <h3>New Features<a class="headerlink" href="#id4" title="Link to this heading">¶</a></h3>
- <ul id="whatsnew312-pep697">
- <li><p><span class="target" id="index-40"></span><a class="pep reference external" href="https://peps.python.org/pep-0697/"><strong>PEP 697</strong></a>: Introduce the <a class="reference internal" href="../c-api/stable.html#unstable-c-api"><span class="std std-ref">Unstable C API tier</span></a>,
- intended for low-level tools like debuggers and JIT compilers.
- This API may change in each minor release of CPython without deprecation
- warnings.
- Its contents are marked by the <code class="docutils literal notranslate"><span class="pre">PyUnstable_</span></code> prefix in names.</p>
- <p>Code object constructors:</p>
- <ul class="simple">
- <li><p><code class="docutils literal notranslate"><span class="pre">PyUnstable_Code_New()</span></code> (renamed from <code class="docutils literal notranslate"><span class="pre">PyCode_New</span></code>)</p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">PyUnstable_Code_NewWithPosOnlyArgs()</span></code> (renamed from <code class="docutils literal notranslate"><span class="pre">PyCode_NewWithPosOnlyArgs</span></code>)</p></li>
- </ul>
- <p>Extra storage for code objects (<span class="target" id="index-41"></span><a class="pep reference external" href="https://peps.python.org/pep-0523/"><strong>PEP 523</strong></a>):</p>
- <ul class="simple">
- <li><p><code class="docutils literal notranslate"><span class="pre">PyUnstable_Eval_RequestCodeExtraIndex()</span></code> (renamed from <code class="docutils literal notranslate"><span class="pre">_PyEval_RequestCodeExtraIndex</span></code>)</p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">PyUnstable_Code_GetExtra()</span></code> (renamed from <code class="docutils literal notranslate"><span class="pre">_PyCode_GetExtra</span></code>)</p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">PyUnstable_Code_SetExtra()</span></code> (renamed from <code class="docutils literal notranslate"><span class="pre">_PyCode_SetExtra</span></code>)</p></li>
- </ul>
- <p>The original names will continue to be available until the respective
- API changes.</p>
- <p>(Contributed by Petr Viktorin in <a class="reference external" href="https://github.com/python/cpython/issues/101101">gh-101101</a>.)</p>
- </li>
- <li><p><span class="target" id="index-42"></span><a class="pep reference external" href="https://peps.python.org/pep-0697/"><strong>PEP 697</strong></a>: Add an API for extending types whose instance memory layout is
- opaque:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="../c-api/type.html#c.PyType_Spec.basicsize" title="PyType_Spec.basicsize"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyType_Spec.basicsize</span></code></a> can be zero or negative to specify
- inheriting or extending the base class size.</p></li>
- <li><p><a class="reference internal" href="../c-api/object.html#c.PyObject_GetTypeData" title="PyObject_GetTypeData"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetTypeData()</span></code></a> and <a class="reference internal" href="../c-api/object.html#c.PyType_GetTypeDataSize" title="PyType_GetTypeDataSize"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetTypeDataSize()</span></code></a>
- added to allow access to subclass-specific instance data.</p></li>
- <li><p><a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_ITEMS_AT_END" title="Py_TPFLAGS_ITEMS_AT_END"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_ITEMS_AT_END</span></code></a> and <a class="reference internal" href="../c-api/object.html#c.PyObject_GetItemData" title="PyObject_GetItemData"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetItemData()</span></code></a>
- added to allow safely extending certain variable-sized types, including
- <a class="reference internal" href="../c-api/type.html#c.PyType_Type" title="PyType_Type"><code class="xref c c-var docutils literal notranslate"><span class="pre">PyType_Type</span></code></a>.</p></li>
- <li><p><a class="reference internal" href="../c-api/structures.html#c.Py_RELATIVE_OFFSET" title="Py_RELATIVE_OFFSET"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_RELATIVE_OFFSET</span></code></a> added to allow defining
- <a class="reference internal" href="../c-api/structures.html#c.PyMemberDef" title="PyMemberDef"><code class="xref c c-type docutils literal notranslate"><span class="pre">members</span></code></a> in terms of a subclass-specific struct.</p></li>
- </ul>
- <p>(Contributed by Petr Viktorin in <a class="reference external" href="https://github.com/python/cpython/issues/103509">gh-103509</a>.)</p>
- </li>
- <li><p>Add the new <a class="reference internal" href="../c-api/stable.html#limited-c-api"><span class="std std-ref">limited C API</span></a> function <a class="reference internal" href="../c-api/type.html#c.PyType_FromMetaclass" title="PyType_FromMetaclass"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromMetaclass()</span></code></a>,
- which generalizes the existing <a class="reference internal" href="../c-api/type.html#c.PyType_FromModuleAndSpec" title="PyType_FromModuleAndSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromModuleAndSpec()</span></code></a> using
- an additional metaclass argument.
- (Contributed by Wenzel Jakob in <a class="reference external" href="https://github.com/python/cpython/issues/93012">gh-93012</a>.)</p></li>
- <li><p>API for creating objects that can be called using
- <a class="reference internal" href="../c-api/call.html#vectorcall"><span class="std std-ref">the vectorcall protocol</span></a> was added to the
- <a class="reference internal" href="../c-api/stable.html#stable"><span class="std std-ref">Limited API</span></a>:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_HAVE_VECTORCALL" title="Py_TPFLAGS_HAVE_VECTORCALL"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_HAVE_VECTORCALL</span></code></a></p></li>
- <li><p><a class="reference internal" href="../c-api/call.html#c.PyVectorcall_NARGS" title="PyVectorcall_NARGS"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyVectorcall_NARGS()</span></code></a></p></li>
- <li><p><a class="reference internal" href="../c-api/call.html#c.PyVectorcall_Call" title="PyVectorcall_Call"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyVectorcall_Call()</span></code></a></p></li>
- <li><p><a class="reference internal" href="../c-api/call.html#c.vectorcallfunc" title="vectorcallfunc"><code class="xref c c-type docutils literal notranslate"><span class="pre">vectorcallfunc</span></code></a></p></li>
- </ul>
- <p>The <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_HAVE_VECTORCALL" title="Py_TPFLAGS_HAVE_VECTORCALL"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_HAVE_VECTORCALL</span></code></a> flag is now removed from a class
- when the class’s <a class="reference internal" href="../reference/datamodel.html#object.__call__" title="object.__call__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__call__()</span></code></a> method is reassigned.
- This makes vectorcall safe to use with mutable types (i.e. heap types
- without the immutable flag, <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_IMMUTABLETYPE" title="Py_TPFLAGS_IMMUTABLETYPE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_IMMUTABLETYPE</span></code></a>).
- Mutable types that do not override <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_call" title="PyTypeObject.tp_call"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_call</span></code></a> now
- inherit the <code class="docutils literal notranslate"><span class="pre">Py_TPFLAGS_HAVE_VECTORCALL</span></code> flag.
- (Contributed by Petr Viktorin in <a class="reference external" href="https://github.com/python/cpython/issues/93274">gh-93274</a>.)</p>
- <p>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> and <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_MANAGED_WEAKREF" title="Py_TPFLAGS_MANAGED_WEAKREF"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_MANAGED_WEAKREF</span></code></a>
- flags have been added. This allows extensions classes to support object
- <code class="docutils literal notranslate"><span class="pre">__dict__</span></code> and weakrefs with less bookkeeping,
- using less memory and with faster access.</p>
- </li>
- <li><p>API for performing calls using
- <a class="reference internal" href="../c-api/call.html#vectorcall"><span class="std std-ref">the vectorcall protocol</span></a> was added to the
- <a class="reference internal" href="../c-api/stable.html#stable"><span class="std std-ref">Limited API</span></a>:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="../c-api/call.html#c.PyObject_Vectorcall" title="PyObject_Vectorcall"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Vectorcall()</span></code></a></p></li>
- <li><p><a class="reference internal" href="../c-api/call.html#c.PyObject_VectorcallMethod" title="PyObject_VectorcallMethod"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_VectorcallMethod()</span></code></a></p></li>
- <li><p><a class="reference internal" href="../c-api/call.html#c.PY_VECTORCALL_ARGUMENTS_OFFSET" title="PY_VECTORCALL_ARGUMENTS_OFFSET"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PY_VECTORCALL_ARGUMENTS_OFFSET</span></code></a></p></li>
- </ul>
- <p>This means that both the incoming and outgoing ends of the vector call
- protocol are now available in the <a class="reference internal" href="../c-api/stable.html#stable"><span class="std std-ref">Limited API</span></a>. (Contributed
- by Wenzel Jakob in <a class="reference external" href="https://github.com/python/cpython/issues/98586">gh-98586</a>.)</p>
- </li>
- <li><p>Add two new public functions,
- <a class="reference internal" href="../c-api/init.html#c.PyEval_SetProfileAllThreads" title="PyEval_SetProfileAllThreads"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_SetProfileAllThreads()</span></code></a> and
- <a class="reference internal" href="../c-api/init.html#c.PyEval_SetTraceAllThreads" title="PyEval_SetTraceAllThreads"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_SetTraceAllThreads()</span></code></a>, that allow to set tracing and profiling
- functions in all running threads in addition to the calling one. (Contributed
- by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/93503">gh-93503</a>.)</p></li>
- <li><p>Add new function <a class="reference internal" href="../c-api/function.html#c.PyFunction_SetVectorcall" title="PyFunction_SetVectorcall"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFunction_SetVectorcall()</span></code></a> to the C API
- which sets the vectorcall field of a given <a class="reference internal" href="../c-api/function.html#c.PyFunctionObject" title="PyFunctionObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyFunctionObject</span></code></a>.
- (Contributed by Andrew Frost in <a class="reference external" href="https://github.com/python/cpython/issues/92257">gh-92257</a>.)</p></li>
- <li><p>The C API now permits registering callbacks via <a class="reference internal" href="../c-api/dict.html#c.PyDict_AddWatcher" title="PyDict_AddWatcher"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_AddWatcher()</span></code></a>,
- <a class="reference internal" href="../c-api/dict.html#c.PyDict_Watch" title="PyDict_Watch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_Watch()</span></code></a> and related APIs to be called whenever a dictionary
- is modified. This is intended for use by optimizing interpreters, JIT
- compilers, or debuggers.
- (Contributed by Carl Meyer in <a class="reference external" href="https://github.com/python/cpython/issues/91052">gh-91052</a>.)</p></li>
- <li><p>Add <a class="reference internal" href="../c-api/type.html#c.PyType_AddWatcher" title="PyType_AddWatcher"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_AddWatcher()</span></code></a> and <a class="reference internal" href="../c-api/type.html#c.PyType_Watch" title="PyType_Watch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_Watch()</span></code></a> API to register
- callbacks to receive notification on changes to a type.
- (Contributed by Carl Meyer in <a class="reference external" href="https://github.com/python/cpython/issues/91051">gh-91051</a>.)</p></li>
- <li><p>Add <a class="reference internal" href="../c-api/code.html#c.PyCode_AddWatcher" title="PyCode_AddWatcher"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_AddWatcher()</span></code></a> and <a class="reference internal" href="../c-api/code.html#c.PyCode_ClearWatcher" title="PyCode_ClearWatcher"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_ClearWatcher()</span></code></a>
- APIs to register callbacks to receive notification on creation and
- destruction of code objects.
- (Contributed by Itamar Oren in <a class="reference external" href="https://github.com/python/cpython/issues/91054">gh-91054</a>.)</p></li>
- <li><p>Add <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetVar" title="PyFrame_GetVar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetVar()</span></code></a> and <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetVarString" title="PyFrame_GetVarString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetVarString()</span></code></a> functions to
- get a frame variable by its name.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/91248">gh-91248</a>.)</p></li>
- <li><p>Add <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> and <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>
- for saving and restoring the current exception.
- These functions return and accept a single exception object,
- rather than the triple arguments of the now-deprecated
- <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> and <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>.
- This is less error prone and a bit more efficient.
- (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/101578">gh-101578</a>.)</p></li>
- <li><p>Add <code class="docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions1</span></code>, which takes an exception instance,
- to replace the legacy-API <code class="docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions</span></code>, which is now
- deprecated. (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/101578">gh-101578</a>.)</p></li>
- <li><p>Add <a class="reference internal" href="../c-api/exceptions.html#c.PyException_GetArgs" title="PyException_GetArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyException_GetArgs()</span></code></a> and <a class="reference internal" href="../c-api/exceptions.html#c.PyException_SetArgs" title="PyException_SetArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyException_SetArgs()</span></code></a>
- as convenience functions for retrieving and modifying
- the <a class="reference internal" href="../library/exceptions.html#BaseException.args" title="BaseException.args"><code class="xref py py-attr docutils literal notranslate"><span class="pre">args</span></code></a> passed to the exception’s constructor.
- (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/101578">gh-101578</a>.)</p></li>
- <li><p>Add <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>, which takes an exception instance,
- to replace the legacy-api <code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Display()</span></code>. (Contributed by
- Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102755">gh-102755</a>).</p></li>
- </ul>
- <ul id="whatsnew312-pep683">
- <li><p><span class="target" id="index-43"></span><a class="pep reference external" href="https://peps.python.org/pep-0683/"><strong>PEP 683</strong></a>: Introduce <em>Immortal Objects</em>, which allows objects
- to bypass reference counts, and related changes to the C-API:</p>
- <ul class="simple">
- <li><dl class="simple">
- <dt><code class="docutils literal notranslate"><span class="pre">_Py_IMMORTAL_REFCNT</span></code>: The reference count that defines an object</dt><dd><p>as immortal.</p>
- </dd>
- </dl>
- </li>
- <li><p><code class="docutils literal notranslate"><span class="pre">_Py_IsImmortal</span></code> Checks if an object has the immortal reference count.</p></li>
- <li><dl class="simple">
- <dt><code class="docutils literal notranslate"><span class="pre">PyObject_HEAD_INIT</span></code> This will now initialize reference count to</dt><dd><p><code class="docutils literal notranslate"><span class="pre">_Py_IMMORTAL_REFCNT</span></code> when used with <code class="docutils literal notranslate"><span class="pre">Py_BUILD_CORE</span></code>.</p>
- </dd>
- </dl>
- </li>
- <li><dl class="simple">
- <dt><code class="docutils literal notranslate"><span class="pre">SSTATE_INTERNED_IMMORTAL</span></code> An identifier for interned unicode objects</dt><dd><p>that are immortal.</p>
- </dd>
- </dl>
- </li>
- <li><dl class="simple">
- <dt><code class="docutils literal notranslate"><span class="pre">SSTATE_INTERNED_IMMORTAL_STATIC</span></code> An identifier for interned unicode</dt><dd><p>objects that are immortal and static</p>
- </dd>
- </dl>
- </li>
- <li><dl class="simple">
- <dt><code class="docutils literal notranslate"><span class="pre">sys.getunicodeinternedsize</span></code> This returns the total number of unicode</dt><dd><p>objects that have been interned. This is now needed for <code class="file docutils literal notranslate"><span class="pre">refleak.py</span></code> to
- correctly track reference counts and allocated blocks</p>
- </dd>
- </dl>
- </li>
- </ul>
- <p>(Contributed by Eddie Elizondo in <a class="reference external" href="https://github.com/python/cpython/issues/84436">gh-84436</a>.)</p>
- </li>
- <li><p><span class="target" id="index-44"></span><a class="pep reference external" href="https://peps.python.org/pep-0684/"><strong>PEP 684</strong></a>: Add the new <a class="reference internal" href="../c-api/init.html#c.Py_NewInterpreterFromConfig" title="Py_NewInterpreterFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_NewInterpreterFromConfig()</span></code></a>
- function and <a class="reference internal" href="../c-api/init.html#c.PyInterpreterConfig" title="PyInterpreterConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyInterpreterConfig</span></code></a>, which may be used
- to create sub-interpreters with their own GILs.
- (See <a class="reference internal" href="#whatsnew312-pep684"><span class="std std-ref">PEP 684: A Per-Interpreter GIL</span></a> for more info.)
- (Contributed by Eric Snow in <a class="reference external" href="https://github.com/python/cpython/issues/104110">gh-104110</a>.)</p></li>
- <li><p>In the limited C API version 3.12, <a class="reference internal" href="../c-api/refcounting.html#c.Py_INCREF" title="Py_INCREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_INCREF()</span></code></a> and
- <a class="reference internal" href="../c-api/refcounting.html#c.Py_DECREF" title="Py_DECREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DECREF()</span></code></a> functions are now implemented as opaque function calls to
- hide implementation details.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105387">gh-105387</a>.)</p></li>
- </ul>
- </section>
- <section id="id5">
- <h3>Porting to Python 3.12<a class="headerlink" href="#id5" title="Link to this heading">¶</a></h3>
- <ul>
- <li><p>Legacy Unicode APIs based on <code class="docutils literal notranslate"><span class="pre">Py_UNICODE*</span></code> representation has been removed.
- Please migrate to APIs based on UTF-8 or <code class="docutils literal notranslate"><span class="pre">wchar_t*</span></code>.</p></li>
- <li><p>Argument parsing functions like <a class="reference internal" href="../c-api/arg.html#c.PyArg_ParseTuple" title="PyArg_ParseTuple"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTuple()</span></code></a> doesn’t support
- <code class="docutils literal notranslate"><span class="pre">Py_UNICODE*</span></code> based format (e.g. <code class="docutils literal notranslate"><span class="pre">u</span></code>, <code class="docutils literal notranslate"><span class="pre">Z</span></code>) anymore. Please migrate
- to other formats for Unicode like <code class="docutils literal notranslate"><span class="pre">s</span></code>, <code class="docutils literal notranslate"><span class="pre">z</span></code>, <code class="docutils literal notranslate"><span class="pre">es</span></code>, and <code class="docutils literal notranslate"><span class="pre">U</span></code>.</p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">tp_weaklist</span></code> for all static builtin types is always <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.
- This is an internal-only field on <code class="docutils literal notranslate"><span class="pre">PyTypeObject</span></code>
- but we’re pointing out the change in case someone happens to be
- accessing the field directly anyway. To avoid breakage, consider
- using the existing public C-API instead, or, if necessary, the
- (internal-only) <code class="docutils literal notranslate"><span class="pre">_PyObject_GET_WEAKREFS_LISTPTR()</span></code> macro.</p></li>
- <li><p>This internal-only <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_subclasses" title="PyTypeObject.tp_subclasses"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_subclasses</span></code></a> may now not be
- a valid object pointer. Its type was changed to <span class="c-expr sig sig-inline c"><span class="kt">void</span><span class="p">*</span></span> to
- reflect this. We mention this in case someone happens to be accessing the
- internal-only field directly.</p>
- <p>To get a list of subclasses, call the Python method
- <a class="reference internal" href="../library/stdtypes.html#class.__subclasses__" title="class.__subclasses__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__subclasses__()</span></code></a> (using <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>,
- for example).</p>
- </li>
- <li><p>Add support of more formatting options (left aligning, octals, uppercase
- hexadecimals, <code class="xref c c-type docutils literal notranslate"><span class="pre">intmax_t</span></code>, <code class="xref c c-type docutils literal notranslate"><span class="pre">ptrdiff_t</span></code>, <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code> C
- strings, variable width and precision) in <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> and
- <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormatV" title="PyUnicode_FromFormatV"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormatV()</span></code></a>.
- (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/98836">gh-98836</a>.)</p></li>
- <li><p>An unrecognized format character in <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> and
- <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormatV" title="PyUnicode_FromFormatV"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormatV()</span></code></a> now sets a <a class="reference internal" href="../library/exceptions.html#SystemError" title="SystemError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemError</span></code></a>.
- In previous versions it caused all the rest of the format string to be
- copied as-is to the result string, and any extra arguments discarded.
- (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/95781">gh-95781</a>.)</p></li>
- <li><p>Fix wrong sign placement in <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> and
- <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormatV" title="PyUnicode_FromFormatV"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormatV()</span></code></a>.
- (Contributed by Philip Georgi in <a class="reference external" href="https://github.com/python/cpython/issues/95504">gh-95504</a>.)</p></li>
- <li><p>Extension classes wanting to add a <code class="docutils literal notranslate"><span class="pre">__dict__</span></code> or weak reference slot
- should use <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> and
- <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_MANAGED_WEAKREF" title="Py_TPFLAGS_MANAGED_WEAKREF"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_MANAGED_WEAKREF</span></code></a> instead of <code class="docutils literal notranslate"><span class="pre">tp_dictoffset</span></code> and
- <code class="docutils literal notranslate"><span class="pre">tp_weaklistoffset</span></code>, respectively.
- The use of <code class="docutils literal notranslate"><span class="pre">tp_dictoffset</span></code> and <code class="docutils literal notranslate"><span class="pre">tp_weaklistoffset</span></code> is still
- supported, but does not fully support multiple inheritance
- (<a class="reference external" href="https://github.com/python/cpython/issues/95589">gh-95589</a>), and performance may be worse.
- Classes declaring <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> should call
- <code class="xref c c-func docutils literal notranslate"><span class="pre">_PyObject_VisitManagedDict()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">_PyObject_ClearManagedDict()</span></code>
- to traverse and clear their instance’s dictionaries.
- To clear weakrefs, call <a class="reference internal" href="../c-api/weakref.html#c.PyObject_ClearWeakRefs" title="PyObject_ClearWeakRefs"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_ClearWeakRefs()</span></code></a>, as before.</p></li>
- <li><p>The <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FSDecoder" title="PyUnicode_FSDecoder"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FSDecoder()</span></code></a> function no longer accepts bytes-like
- paths, like <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-class docutils literal notranslate"><span class="pre">memoryview</span></code></a> types: only the exact
- <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> type is accepted for bytes strings.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/98393">gh-98393</a>.)</p></li>
- <li><p>The <a class="reference internal" href="../c-api/refcounting.html#c.Py_CLEAR" title="Py_CLEAR"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_CLEAR</span></code></a>, <a class="reference internal" href="../c-api/refcounting.html#c.Py_SETREF" title="Py_SETREF"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_SETREF</span></code></a> and <a class="reference internal" href="../c-api/refcounting.html#c.Py_XSETREF" title="Py_XSETREF"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_XSETREF</span></code></a>
- macros now only evaluate their arguments once. If an argument has side
- effects, these side effects are no longer duplicated.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/98724">gh-98724</a>.)</p></li>
- <li><p>The interpreter’s error indicator is now always normalized. This means
- that <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetObject" title="PyErr_SetObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetObject()</span></code></a>, <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetString" title="PyErr_SetString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetString()</span></code></a> and the other
- functions that set the error indicator now normalize the exception
- before storing it. (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/101578">gh-101578</a>.)</p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">_Py_RefTotal</span></code> is no longer authoritative and only kept around
- for ABI compatibility. Note that it is an internal global and only
- available on debug builds. If you happen to be using it then you’ll
- need to start using <code class="docutils literal notranslate"><span class="pre">_Py_GetGlobalRefTotal()</span></code>.</p></li>
- <li><p>The following functions now select an appropriate metaclass for the newly
- created type:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="../c-api/type.html#c.PyType_FromSpec" title="PyType_FromSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromSpec()</span></code></a></p></li>
- <li><p><a class="reference internal" href="../c-api/type.html#c.PyType_FromSpecWithBases" title="PyType_FromSpecWithBases"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromSpecWithBases()</span></code></a></p></li>
- <li><p><a class="reference internal" href="../c-api/type.html#c.PyType_FromModuleAndSpec" title="PyType_FromModuleAndSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromModuleAndSpec()</span></code></a></p></li>
- </ul>
- <p>Creating classes whose metaclass overrides <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_new" title="PyTypeObject.tp_new"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_new</span></code></a>
- is deprecated, and in Python 3.14+ it will be disallowed.
- Note that these functions ignore <code class="docutils literal notranslate"><span class="pre">tp_new</span></code> of the metaclass, possibly
- allowing incomplete initialization.</p>
- <p>Note that <a class="reference internal" href="../c-api/type.html#c.PyType_FromMetaclass" title="PyType_FromMetaclass"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromMetaclass()</span></code></a> (added in Python 3.12)
- already disallows creating classes whose metaclass overrides <code class="docutils literal notranslate"><span class="pre">tp_new</span></code>
- (<a class="reference internal" href="../reference/datamodel.html#object.__new__" title="object.__new__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__new__()</span></code></a> in Python).</p>
- <p>Since <code class="docutils literal notranslate"><span class="pre">tp_new</span></code> overrides almost everything <code class="docutils literal notranslate"><span class="pre">PyType_From*</span></code> functions do,
- the two are incompatible with each other.
- The existing behavior – ignoring the metaclass for several steps
- of type creation – is unsafe in general, since (meta)classes assume that
- <code class="docutils literal notranslate"><span class="pre">tp_new</span></code> was called.
- There is no simple general workaround. One of the following may work for you:</p>
- <ul class="simple">
- <li><p>If you control the metaclass, avoid using <code class="docutils literal notranslate"><span class="pre">tp_new</span></code> in it:</p>
- <ul>
- <li><p>If initialization can be skipped, it can be done in
- <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_init" title="PyTypeObject.tp_init"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_init</span></code></a> instead.</p></li>
- <li><p>If the metaclass doesn’t need to be instantiated from Python,
- set its <code class="docutils literal notranslate"><span class="pre">tp_new</span></code> to <code class="docutils literal notranslate"><span class="pre">NULL</span></code> using
- the <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_DISALLOW_INSTANTIATION" title="Py_TPFLAGS_DISALLOW_INSTANTIATION"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_DISALLOW_INSTANTIATION</span></code></a> flag.
- This makes it acceptable for <code class="docutils literal notranslate"><span class="pre">PyType_From*</span></code> functions.</p></li>
- </ul>
- </li>
- <li><p>Avoid <code class="docutils literal notranslate"><span class="pre">PyType_From*</span></code> functions: if you don’t need C-specific features
- (slots or setting the instance size), create types by <a class="reference internal" href="../c-api/call.html#call"><span class="std std-ref">calling</span></a>
- the metaclass.</p></li>
- <li><p>If you <em>know</em> the <code class="docutils literal notranslate"><span class="pre">tp_new</span></code> can be skipped safely, filter the deprecation
- warning out using <a class="reference internal" href="../library/warnings.html#warnings.catch_warnings" title="warnings.catch_warnings"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.catch_warnings()</span></code></a> from Python.</p></li>
- </ul>
- </li>
- <li><p><a class="reference internal" href="../c-api/veryhigh.html#c.PyOS_InputHook" title="PyOS_InputHook"><code class="xref c c-var docutils literal notranslate"><span class="pre">PyOS_InputHook</span></code></a> and <a class="reference internal" href="../c-api/veryhigh.html#c.PyOS_ReadlineFunctionPointer" title="PyOS_ReadlineFunctionPointer"><code class="xref c c-var docutils literal notranslate"><span class="pre">PyOS_ReadlineFunctionPointer</span></code></a> are no
- longer called in <a class="reference internal" href="../c-api/init.html#sub-interpreter-support"><span class="std std-ref">subinterpreters</span></a>. This is
- because clients generally rely on process-wide global state (since these
- callbacks have no way of recovering extension module state).</p>
- <p>This also avoids situations where extensions may find themselves running in a
- subinterpreter that they don’t support (or haven’t yet been loaded in). See
- <a class="reference external" href="https://github.com/python/cpython/issues/104668">gh-104668</a> for more info.</p>
- </li>
- <li><p><a class="reference internal" href="../c-api/long.html#c.PyLongObject" title="PyLongObject"><code class="xref c c-struct docutils literal notranslate"><span class="pre">PyLongObject</span></code></a> has had its internals changed for better performance.
- Although the internals of <a class="reference internal" href="../c-api/long.html#c.PyLongObject" title="PyLongObject"><code class="xref c c-struct docutils literal notranslate"><span class="pre">PyLongObject</span></code></a> are private, they are used
- by some extension modules.
- The internal fields should no longer be accessed directly, instead the API
- functions beginning <code class="docutils literal notranslate"><span class="pre">PyLong_...</span></code> should be used instead.
- Two new <em>unstable</em> API functions are provided for efficient access to the
- value of <a class="reference internal" href="../c-api/long.html#c.PyLongObject" title="PyLongObject"><code class="xref c c-struct docutils literal notranslate"><span class="pre">PyLongObject</span></code></a>s which fit into a single machine word:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="../c-api/long.html#c.PyUnstable_Long_IsCompact" title="PyUnstable_Long_IsCompact"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnstable_Long_IsCompact()</span></code></a></p></li>
- <li><p><a class="reference internal" href="../c-api/long.html#c.PyUnstable_Long_CompactValue" title="PyUnstable_Long_CompactValue"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnstable_Long_CompactValue()</span></code></a></p></li>
- </ul>
- </li>
- <li><p>Custom allocators, set via <a class="reference internal" href="../c-api/memory.html#c.PyMem_SetAllocator" title="PyMem_SetAllocator"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_SetAllocator()</span></code></a>, are now
- required to be thread-safe, regardless of memory domain. Allocators
- that don’t have their own state, including “hooks”, are not affected.
- If your custom allocator is not already thread-safe and you need
- guidance then please create a new GitHub issue
- and CC <code class="docutils literal notranslate"><span class="pre">@ericsnowcurrently</span></code>.</p></li>
- </ul>
- </section>
- <section id="id6">
- <h3>Deprecated<a class="headerlink" href="#id6" title="Link to this heading">¶</a></h3>
- <ul>
- <li><p>In accordance with <span class="target" id="index-45"></span><a class="pep reference external" href="https://peps.python.org/pep-0699/"><strong>PEP 699</strong></a>, 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>
- is deprecated for extension modules. Accessing this field will generate a compiler
- warning at compile time. This field will be removed in Python 3.14.
- (Contributed by Ramvikrams and Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/101193">gh-101193</a>. PEP by Ken Jin.)</p></li>
- <li><p>Deprecate global configuration variable:</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></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></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></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></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></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></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></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></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></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></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></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></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></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></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></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></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></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></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></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></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> (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_config.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.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/77782">gh-77782</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 is deprecated and will be disabled in Python 3.14. (<a class="reference external" href="https://github.com/python/cpython/issues/95388">gh-95388</a>)</p></li>
- <li><p>The <code class="file docutils literal notranslate"><span class="pre">structmember.h</span></code> header is deprecated, though it continues to be
- available and there are no plans to remove it.</p>
- <p>Its contents are now available just by including <code class="file docutils literal notranslate"><span class="pre">Python.h</span></code>,
- with a <code class="docutils literal notranslate"><span class="pre">Py</span></code> prefix added if it was missing:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="../c-api/structures.html#c.PyMemberDef" title="PyMemberDef"><code class="xref c c-struct docutils literal notranslate"><span class="pre">PyMemberDef</span></code></a>, <a class="reference internal" href="../c-api/structures.html#c.PyMember_GetOne" title="PyMember_GetOne"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMember_GetOne()</span></code></a> and
- <a class="reference internal" href="../c-api/structures.html#c.PyMember_SetOne" title="PyMember_SetOne"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMember_SetOne()</span></code></a></p></li>
- <li><p>Type macros like <a class="reference internal" href="../c-api/structures.html#c.Py_T_INT" title="Py_T_INT"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_T_INT</span></code></a>, <a class="reference internal" href="../c-api/structures.html#c.Py_T_DOUBLE" title="Py_T_DOUBLE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_T_DOUBLE</span></code></a>, etc.
- (previously <code class="docutils literal notranslate"><span class="pre">T_INT</span></code>, <code class="docutils literal notranslate"><span class="pre">T_DOUBLE</span></code>, etc.)</p></li>
- <li><p>The flags <a class="reference internal" href="../c-api/structures.html#c.Py_READONLY" title="Py_READONLY"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_READONLY</span></code></a> (previously <code class="docutils literal notranslate"><span class="pre">READONLY</span></code>) and
- <a class="reference internal" href="../c-api/structures.html#c.Py_AUDIT_READ" title="Py_AUDIT_READ"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_AUDIT_READ</span></code></a> (previously all uppercase)</p></li>
- </ul>
- <p>Several items are not exposed from <code class="file docutils literal notranslate"><span class="pre">Python.h</span></code>:</p>
- <ul class="simple">
- <li><p><a class="reference internal" href="../c-api/structures.html#c.T_OBJECT" title="T_OBJECT"><code class="xref c c-macro docutils literal notranslate"><span class="pre">T_OBJECT</span></code></a> (use <a class="reference internal" href="../c-api/structures.html#c.Py_T_OBJECT_EX" title="Py_T_OBJECT_EX"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_T_OBJECT_EX</span></code></a>)</p></li>
- <li><p><a class="reference internal" href="../c-api/structures.html#c.T_NONE" title="T_NONE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">T_NONE</span></code></a> (previously undocumented, and pretty quirky)</p></li>
- <li><p>The macro <code class="docutils literal notranslate"><span class="pre">WRITE_RESTRICTED</span></code> which does nothing.</p></li>
- <li><p>The macros <code class="docutils literal notranslate"><span class="pre">RESTRICTED</span></code> and <code class="docutils literal notranslate"><span class="pre">READ_RESTRICTED</span></code>, equivalents of
- <a class="reference internal" href="../c-api/structures.html#c.Py_AUDIT_READ" title="Py_AUDIT_READ"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_AUDIT_READ</span></code></a>.</p></li>
- <li><p>In some configurations, <code class="docutils literal notranslate"><span class="pre"><stddef.h></span></code> is not included from <code class="file docutils literal notranslate"><span class="pre">Python.h</span></code>.
- It should be included manually when using <code class="docutils literal notranslate"><span class="pre">offsetof()</span></code>.</p></li>
- </ul>
- <p>The deprecated header continues to provide its original
- contents under the original names.
- Your old code can stay unchanged, unless the extra include and non-namespaced
- macros bother you greatly.</p>
- <p>(Contributed in <a class="reference external" href="https://github.com/python/cpython/issues/47146">gh-47146</a> by Petr Viktorin, based on
- earlier work by Alexander Belopolsky and Matthias Braun.)</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> and <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> are deprecated.
- 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> and
- <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.
- (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/101578">gh-101578</a>.)</p></li>
- <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Display()</span></code> is deprecated. 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. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102755">gh-102755</a>).</p></li>
- <li><p><code class="docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions</span></code> is deprecated. Use <code class="docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions1</span></code>
- instead. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102192">gh-102192</a>.)</p></li>
- <li><p>Using <a class="reference internal" href="../c-api/type.html#c.PyType_FromSpec" title="PyType_FromSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromSpec()</span></code></a>, <a class="reference internal" href="../c-api/type.html#c.PyType_FromSpecWithBases" title="PyType_FromSpecWithBases"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromSpecWithBases()</span></code></a>
- or <a class="reference internal" href="../c-api/type.html#c.PyType_FromModuleAndSpec" title="PyType_FromModuleAndSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromModuleAndSpec()</span></code></a> to create a class whose metaclass
- overrides <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_new" title="PyTypeObject.tp_new"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_new</span></code></a> is deprecated.
- Call the metaclass instead.</p></li>
- </ul>
- <section id="id7">
- <h4>Pending Removal in Python 3.14<a class="headerlink" href="#id7" 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-46"></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>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></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></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></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></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></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></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></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></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></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></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></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></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></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></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></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></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></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></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></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></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> (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_config.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>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>
- </ul>
- </section>
- <section id="id8">
- <h4>Pending Removal in Python 3.15<a class="headerlink" href="#id8" title="Link to this heading">¶</a></h4>
- <ul class="simple">
- <li><p><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></p></li>
- <li><p><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE_WIDE</span></code> type: use <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code></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: use <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code></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></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></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></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></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></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></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-47"></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</p></li>
- </ul>
- </li>
- </ul>
- </section>
- <section id="id9">
- <h4>Pending Removal in Future Versions<a class="headerlink" href="#id9" 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></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></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></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></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></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></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></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></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></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></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></p></li>
- <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions()</span></code>: use <code class="docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions1</span></code></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></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></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></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></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></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 id="id10">
- <h3>Removed<a class="headerlink" href="#id10" title="Link to this heading">¶</a></h3>
- <ul class="simple">
- <li><p>Remove the <code class="file docutils literal notranslate"><span class="pre">token.h</span></code> header file. There was never any public tokenizer C
- API. The <code class="file docutils literal notranslate"><span class="pre">token.h</span></code> header file was only designed to be used by Python
- internals.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/92651">gh-92651</a>.)</p></li>
- <li><p>Legacy Unicode APIs have been removed. See <span class="target" id="index-48"></span><a class="pep reference external" href="https://peps.python.org/pep-0623/"><strong>PEP 623</strong></a> for detail.</p>
- <ul>
- <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_WCHAR_KIND</span></code></p></li>
- <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AS_UNICODE()</span></code></p></li>
- <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicode()</span></code></p></li>
- <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicodeAndSize()</span></code></p></li>
- <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AS_DATA()</span></code></p></li>
- <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromUnicode()</span></code></p></li>
- <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GET_SIZE()</span></code></p></li>
- <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetSize()</span></code></p></li>
- <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GET_DATA_SIZE()</span></code></p></li>
- </ul>
- </li>
- <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">PyUnicode_InternImmortal()</span></code> function macro.
- (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/85858">gh-85858</a>.)</p></li>
- </ul>
- </section>
- </section>
- </section>
-
-
- <div class="clearer"></div>
- </div>
- </div>
- </div>
- <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
- <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.12</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="#pep-695-type-parameter-syntax">PEP 695: Type Parameter Syntax</a></li>
- <li><a class="reference internal" href="#pep-701-syntactic-formalization-of-f-strings">PEP 701: Syntactic formalization of f-strings</a></li>
- <li><a class="reference internal" href="#pep-684-a-per-interpreter-gil">PEP 684: A Per-Interpreter GIL</a></li>
- <li><a class="reference internal" href="#pep-669-low-impact-monitoring-for-cpython">PEP 669: Low impact monitoring for CPython</a></li>
- <li><a class="reference internal" href="#pep-688-making-the-buffer-protocol-accessible-in-python">PEP 688: Making the buffer protocol accessible in Python</a></li>
- <li><a class="reference internal" href="#pep-709-comprehension-inlining">PEP 709: Comprehension inlining</a></li>
- <li><a class="reference internal" href="#improved-error-messages">Improved Error Messages</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#new-features-related-to-type-hints">New Features Related to Type Hints</a><ul>
- <li><a class="reference internal" href="#pep-692-using-typeddict-for-more-precise-kwargs-typing">PEP 692: Using <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> for more precise <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> typing</a></li>
- <li><a class="reference internal" href="#pep-698-override-decorator-for-static-typing">PEP 698: Override Decorator for Static Typing</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="#array">array</a></li>
- <li><a class="reference internal" href="#asyncio">asyncio</a></li>
- <li><a class="reference internal" href="#calendar">calendar</a></li>
- <li><a class="reference internal" href="#csv">csv</a></li>
- <li><a class="reference internal" href="#dis">dis</a></li>
- <li><a class="reference internal" href="#fractions">fractions</a></li>
- <li><a class="reference internal" href="#importlib-resources">importlib.resources</a></li>
- <li><a class="reference internal" href="#inspect">inspect</a></li>
- <li><a class="reference internal" href="#itertools">itertools</a></li>
- <li><a class="reference internal" href="#math">math</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="#random">random</a></li>
- <li><a class="reference internal" href="#shutil">shutil</a></li>
- <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
- <li><a class="reference internal" href="#statistics">statistics</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="#threading">threading</a></li>
- <li><a class="reference internal" href="#tkinter">tkinter</a></li>
- <li><a class="reference internal" href="#tokenize">tokenize</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="#unittest">unittest</a></li>
- <li><a class="reference internal" href="#uuid">uuid</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
- <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
- <li><a class="reference internal" href="#demos-and-tools">Demos and Tools</a></li>
- <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
- <li><a class="reference internal" href="#pending-removal-in-python-3-13">Pending Removal in Python 3.13</a></li>
- <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-future-versions">Pending Removal in Future Versions</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#removed">Removed</a><ul>
- <li><a class="reference internal" href="#asynchat-and-asyncore">asynchat and asyncore</a></li>
- <li><a class="reference internal" href="#configparser">configparser</a></li>
- <li><a class="reference internal" href="#distutils">distutils</a></li>
- <li><a class="reference internal" href="#ensurepip">ensurepip</a></li>
- <li><a class="reference internal" href="#enum">enum</a></li>
- <li><a class="reference internal" href="#ftplib">ftplib</a></li>
- <li><a class="reference internal" href="#gzip">gzip</a></li>
- <li><a class="reference internal" href="#hashlib">hashlib</a></li>
- <li><a class="reference internal" href="#importlib">importlib</a></li>
- <li><a class="reference internal" href="#imp">imp</a></li>
- <li><a class="reference internal" href="#io">io</a></li>
- <li><a class="reference internal" href="#locale">locale</a></li>
- <li><a class="reference internal" href="#smtpd">smtpd</a></li>
- <li><a class="reference internal" href="#id2">sqlite3</a></li>
- <li><a class="reference internal" href="#ssl">ssl</a></li>
- <li><a class="reference internal" href="#id3">unittest</a></li>
- <li><a class="reference internal" href="#webbrowser">webbrowser</a></li>
- <li><a class="reference internal" href="#xml-etree-elementtree">xml.etree.ElementTree</a></li>
- <li><a class="reference internal" href="#zipimport">zipimport</a></li>
- <li><a class="reference internal" href="#others">Others</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#porting-to-python-3-12">Porting to Python 3.12</a><ul>
- <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#build-changes">Build Changes</a></li>
- <li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
- <li><a class="reference internal" href="#id4">New Features</a></li>
- <li><a class="reference internal" href="#id5">Porting to Python 3.12</a></li>
- <li><a class="reference internal" href="#id6">Deprecated</a><ul>
- <li><a class="reference internal" href="#id7">Pending Removal in Python 3.14</a></li>
- <li><a class="reference internal" href="#id8">Pending Removal in Python 3.15</a></li>
- <li><a class="reference internal" href="#id9">Pending Removal in Future Versions</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#id10">Removed</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.11.html"
- title="next chapter">What’s New In Python 3.11</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.12.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 navigation">
- <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.11.html" title="What’s New In Python 3.11"
- >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.12.3 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.12</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 Apr 09, 2024 (13:47 UTC).
-
- <a href="/bugs.html">Found a bug</a>?
-
- <br />
-
- Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
- </div>
-
- </body>
- </html>
|