2990 lines
339 KiB
HTML
2990 lines
339 KiB
HTML
<!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.11" />
|
||
<meta property="og:type" content="website" />
|
||
<meta property="og:url" content="https://docs.python.org/3/whatsnew/3.11.html" />
|
||
<meta property="og:site_name" content="Python documentation" />
|
||
<meta property="og:description" content="Editor, Pablo Galindo Salgado,. This article explains the new features in Python 3.11, compared to 3.10. Python 3.11 was released on October 24, 2022. For full details, see the changelog. Summary –..." />
|
||
<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, Pablo Galindo Salgado,. This article explains the new features in Python 3.11, compared to 3.10. Python 3.11 was released on October 24, 2022. For full details, see the changelog. Summary –..." />
|
||
<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.11 — Python 3.13.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=b86133f3" />
|
||
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
|
||
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
|
||
|
||
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
|
||
<script src="../_static/doctools.js?v=9bcbadda"></script>
|
||
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||
|
||
<script src="../_static/sidebar.js"></script>
|
||
|
||
<link rel="search" type="application/opensearchdescription+xml"
|
||
title="Search within Python 3.13.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.10" href="3.10.html" />
|
||
<link rel="prev" title="What’s New In Python 3.12" href="3.12.html" />
|
||
|
||
<link rel="canonical" href="https://docs.python.org/3/whatsnew/3.11.html">
|
||
|
||
|
||
|
||
|
||
|
||
<style>
|
||
@media only screen {
|
||
table.full-width-table {
|
||
width: 100%;
|
||
}
|
||
}
|
||
</style>
|
||
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
|
||
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
|
||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||
<script type="text/javascript" src="../_static/menu.js"></script>
|
||
<script type="text/javascript" src="../_static/search-focus.js"></script>
|
||
<script type="text/javascript" src="../_static/themetoggle.js"></script>
|
||
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
|
||
<meta name="readthedocs-addons-api-version" content="1">
|
||
|
||
</head>
|
||
<body>
|
||
<div class="mobile-nav">
|
||
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
|
||
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
|
||
<nav class="nav-content" role="navigation">
|
||
<label for="menuToggler" class="toggler__label">
|
||
<span></span>
|
||
</label>
|
||
<span class="nav-items-wrapper">
|
||
<a href="https://www.python.org/" class="nav-logo">
|
||
<img src="../_static/py.svg" alt="Python logo"/>
|
||
</a>
|
||
<span class="version_switcher_placeholder"></span>
|
||
<form role="search" class="search" action="../search.html" method="get">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
|
||
<path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
|
||
</svg>
|
||
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
|
||
<input type="submit" value="Go"/>
|
||
</form>
|
||
</span>
|
||
</nav>
|
||
<div class="menu-wrapper">
|
||
<nav class="menu" role="navigation" aria-label="main navigation">
|
||
<div class="language_switcher_placeholder"></div>
|
||
|
||
<label class="theme-selector-label">
|
||
Theme
|
||
<select class="theme-selector" oninput="activateTheme(this.value)">
|
||
<option value="auto" selected>Auto</option>
|
||
<option value="light">Light</option>
|
||
<option value="dark">Dark</option>
|
||
</select>
|
||
</label>
|
||
<div>
|
||
<h3><a href="../contents.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">What’s New In Python 3.11</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-657-fine-grained-error-locations-in-tracebacks">PEP 657: Fine-grained error locations in tracebacks</a></li>
|
||
<li><a class="reference internal" href="#pep-654-exception-groups-and-except">PEP 654: Exception Groups and <code class="docutils literal notranslate"><span class="pre">except*</span></code></a></li>
|
||
<li><a class="reference internal" href="#pep-678-exceptions-can-be-enriched-with-notes">PEP 678: Exceptions can be enriched with notes</a></li>
|
||
<li><a class="reference internal" href="#windows-py-exe-launcher-improvements">Windows <code class="docutils literal notranslate"><span class="pre">py.exe</span></code> launcher improvements</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-646-variadic-generics">PEP 646: Variadic generics</a></li>
|
||
<li><a class="reference internal" href="#pep-655-marking-individual-typeddict-items-as-required-or-not-required">PEP 655: Marking individual <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> items as required or not-required</a></li>
|
||
<li><a class="reference internal" href="#pep-673-self-type">PEP 673: <code class="docutils literal notranslate"><span class="pre">Self</span></code> type</a></li>
|
||
<li><a class="reference internal" href="#pep-675-arbitrary-literal-string-type">PEP 675: Arbitrary literal string type</a></li>
|
||
<li><a class="reference internal" href="#pep-681-data-class-transforms">PEP 681: Data class transforms</a></li>
|
||
<li><a class="reference internal" href="#pep-563-may-not-be-the-future">PEP 563 may not be the future</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
|
||
<li><a class="reference internal" href="#other-cpython-implementation-changes">Other CPython Implementation 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="#asyncio">asyncio</a></li>
|
||
<li><a class="reference internal" href="#contextlib">contextlib</a></li>
|
||
<li><a class="reference internal" href="#dataclasses">dataclasses</a></li>
|
||
<li><a class="reference internal" href="#datetime">datetime</a></li>
|
||
<li><a class="reference internal" href="#enum">enum</a></li>
|
||
<li><a class="reference internal" href="#fcntl">fcntl</a></li>
|
||
<li><a class="reference internal" href="#fractions">fractions</a></li>
|
||
<li><a class="reference internal" href="#functools">functools</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="#whatsnew311-idle">IDLE and idlelib</a></li>
|
||
<li><a class="reference internal" href="#inspect">inspect</a></li>
|
||
<li><a class="reference internal" href="#locale">locale</a></li>
|
||
<li><a class="reference internal" href="#logging">logging</a></li>
|
||
<li><a class="reference internal" href="#math">math</a></li>
|
||
<li><a class="reference internal" href="#operator">operator</a></li>
|
||
<li><a class="reference internal" href="#os">os</a></li>
|
||
<li><a class="reference internal" href="#pathlib">pathlib</a></li>
|
||
<li><a class="reference internal" href="#re">re</a></li>
|
||
<li><a class="reference internal" href="#shutil">shutil</a></li>
|
||
<li><a class="reference internal" href="#socket">socket</a></li>
|
||
<li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
|
||
<li><a class="reference internal" href="#string">string</a></li>
|
||
<li><a class="reference internal" href="#sys">sys</a></li>
|
||
<li><a class="reference internal" href="#sysconfig">sysconfig</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="#time">time</a></li>
|
||
<li><a class="reference internal" href="#tkinter">tkinter</a></li>
|
||
<li><a class="reference internal" href="#traceback">traceback</a></li>
|
||
<li><a class="reference internal" href="#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="#venv">venv</a></li>
|
||
<li><a class="reference internal" href="#warnings">warnings</a></li>
|
||
<li><a class="reference internal" href="#zipfile">zipfile</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#optimizations">Optimizations</a></li>
|
||
<li><a class="reference internal" href="#faster-cpython">Faster CPython</a><ul>
|
||
<li><a class="reference internal" href="#faster-startup">Faster Startup</a><ul>
|
||
<li><a class="reference internal" href="#frozen-imports-static-code-objects">Frozen imports / Static code objects</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#faster-runtime">Faster Runtime</a><ul>
|
||
<li><a class="reference internal" href="#cheaper-lazy-python-frames">Cheaper, lazy Python frames</a></li>
|
||
<li><a class="reference internal" href="#inlined-python-function-calls">Inlined Python function calls</a></li>
|
||
<li><a class="reference internal" href="#pep-659-specializing-adaptive-interpreter">PEP 659: Specializing Adaptive Interpreter</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#misc">Misc</a></li>
|
||
<li><a class="reference internal" href="#faq">FAQ</a><ul>
|
||
<li><a class="reference internal" href="#how-should-i-write-my-code-to-utilize-these-speedups">How should I write my code to utilize these speedups?</a></li>
|
||
<li><a class="reference internal" href="#will-cpython-3-11-use-more-memory">Will CPython 3.11 use more memory?</a></li>
|
||
<li><a class="reference internal" href="#i-don-t-see-any-speedups-in-my-workload-why">I don’t see any speedups in my workload. Why?</a></li>
|
||
<li><a class="reference internal" href="#is-there-a-jit-compiler">Is there a JIT compiler?</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#about">About</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a><ul>
|
||
<li><a class="reference internal" href="#new-opcodes">New opcodes</a></li>
|
||
<li><a class="reference internal" href="#replaced-opcodes">Replaced opcodes</a></li>
|
||
<li><a class="reference internal" href="#changed-removed-opcodes">Changed/removed opcodes</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
|
||
<li><a class="reference internal" href="#language-builtins">Language/Builtins</a></li>
|
||
<li><a class="reference internal" href="#modules">Modules</a></li>
|
||
<li><a class="reference internal" href="#standard-library">Standard Library</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#pending-removal-in-python-3-12">Pending Removal in Python 3.12</a></li>
|
||
<li><a class="reference internal" href="#removed">Removed</a></li>
|
||
<li><a class="reference internal" href="#porting-to-python-3-11">Porting to Python 3.11</a></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="#whatsnew311-c-api-new-features">New Features</a></li>
|
||
<li><a class="reference internal" href="#whatsnew311-c-api-porting">Porting to Python 3.11</a></li>
|
||
<li><a class="reference internal" href="#whatsnew311-c-api-deprecated">Deprecated</a></li>
|
||
<li><a class="reference internal" href="#whatsnew311-c-api-pending-removal">Pending Removal in Python 3.12</a></li>
|
||
<li><a class="reference internal" href="#whatsnew311-c-api-removed">Removed</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#notable-changes-in-3-11-4">Notable changes in 3.11.4</a><ul>
|
||
<li><a class="reference internal" href="#tarfile">tarfile</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#notable-changes-in-3-11-5">Notable changes in 3.11.5</a><ul>
|
||
<li><a class="reference internal" href="#openssl">OpenSSL</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
</div>
|
||
<div>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="3.12.html"
|
||
title="previous chapter">What’s New In Python 3.12</a></p>
|
||
</div>
|
||
<div>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="3.10.html"
|
||
title="next chapter">What’s New In Python 3.10</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.11.rst"
|
||
rel="nofollow">Show Source
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</nav>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<div class="related" role="navigation" aria-label="Related">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
accesskey="I">index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.10.html" title="What’s New In Python 3.10"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.12.html" title="What’s New In Python 3.12"
|
||
accesskey="P">previous</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.13.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.11</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-11">
|
||
<h1>What’s New In Python 3.11<a class="headerlink" href="#what-s-new-in-python-3-11" 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>Pablo Galindo Salgado</p>
|
||
</dd>
|
||
</dl>
|
||
<p>This article explains the new features in Python 3.11, compared to 3.10.
|
||
Python 3.11 was released on October 24, 2022.
|
||
For full details, see the <a class="reference internal" href="changelog.html#changelog"><span class="std std-ref">changelog</span></a>.</p>
|
||
<section id="summary-release-highlights">
|
||
<span id="whatsnew311-summary"></span><h2>Summary – Release highlights<a class="headerlink" href="#summary-release-highlights" title="Link to this heading">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p>Python 3.11 is between 10-60% faster than Python 3.10.
|
||
On average, we measured a 1.25x speedup on the standard benchmark suite.
|
||
See <a class="reference internal" href="#whatsnew311-faster-cpython"><span class="std std-ref">Faster CPython</span></a> for details.</p></li>
|
||
</ul>
|
||
<p>New syntax features:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#whatsnew311-pep654"><span class="std std-ref">PEP 654: Exception Groups and except*</span></a></p></li>
|
||
</ul>
|
||
<p>New built-in features:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#whatsnew311-pep678"><span class="std std-ref">PEP 678: Exceptions can be enriched with notes</span></a></p></li>
|
||
</ul>
|
||
<p>New standard library modules:</p>
|
||
<ul class="simple">
|
||
<li><p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0680/"><strong>PEP 680</strong></a>: <a class="reference internal" href="../library/tomllib.html#module-tomllib" title="tomllib: Parse TOML files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tomllib</span></code></a> —
|
||
Support for parsing <a class="reference external" href="https://toml.io/">TOML</a> in the Standard Library</p></li>
|
||
</ul>
|
||
<p>Interpreter improvements:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#whatsnew311-pep657"><span class="std std-ref">PEP 657: Fine-grained error locations in tracebacks</span></a></p></li>
|
||
<li><p>New <a class="reference internal" href="../using/cmdline.html#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a> command line option and <span class="target" id="index-1"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSAFEPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSAFEPATH</span></code></a> environment
|
||
variable to <a class="reference internal" href="#whatsnew311-pythonsafepath"><span class="std std-ref">disable automatically prepending potentially unsafe paths</span></a> to <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>
|
||
</ul>
|
||
<p>New typing features:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#whatsnew311-pep646"><span class="std std-ref">PEP 646: Variadic generics</span></a></p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew311-pep655"><span class="std std-ref">PEP 655: Marking individual TypedDict items as required or not-required</span></a></p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew311-pep673"><span class="std std-ref">PEP 673: Self type</span></a></p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew311-pep675"><span class="std std-ref">PEP 675: Arbitrary literal string type</span></a></p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew311-pep681"><span class="std std-ref">PEP 681: Data class transforms</span></a></p></li>
|
||
</ul>
|
||
<p>Important deprecations, removals and restrictions:</p>
|
||
<ul class="simple">
|
||
<li><p><span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a>:
|
||
<a class="reference internal" href="#whatsnew311-pep594"><span class="std std-ref">Many legacy standard library modules have been deprecated</span></a> and will be removed in Python 3.13</p></li>
|
||
<li><p><span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0624/"><strong>PEP 624</strong></a>:
|
||
<a class="reference internal" href="#whatsnew311-pep624"><span class="std std-ref">Py_UNICODE encoder APIs have been removed</span></a></p></li>
|
||
<li><p><span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0670/"><strong>PEP 670</strong></a>:
|
||
<a class="reference internal" href="#whatsnew311-pep670"><span class="std std-ref">Macros converted to static inline functions</span></a></p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="new-features">
|
||
<span id="whatsnew311-features"></span><h2>New Features<a class="headerlink" href="#new-features" title="Link to this heading">¶</a></h2>
|
||
<section id="pep-657-fine-grained-error-locations-in-tracebacks">
|
||
<span id="whatsnew311-pep657"></span><h3>PEP 657: Fine-grained error locations in tracebacks<a class="headerlink" href="#pep-657-fine-grained-error-locations-in-tracebacks" title="Link to this heading">¶</a></h3>
|
||
<p>When printing tracebacks, the interpreter will now point to the exact expression
|
||
that caused the error, instead of just the line. For example:</p>
|
||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
|
||
<span class="n">File</span> <span class="s2">"distance.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">11</span><span class="p">,</span> <span class="ow">in</span> <span class="o"><</span><span class="n">module</span><span class="o">></span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">manhattan_distance</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">))</span>
|
||
<span class="o">^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
|
||
<span class="n">File</span> <span class="s2">"distance.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">6</span><span class="p">,</span> <span class="ow">in</span> <span class="n">manhattan_distance</span>
|
||
<span class="k">return</span> <span class="nb">abs</span><span class="p">(</span><span class="n">point_1</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">point_2</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="nb">abs</span><span class="p">(</span><span class="n">point_1</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">point_2</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
|
||
<span class="o">^^^^^^^^^</span>
|
||
<span class="ne">AttributeError</span><span class="p">:</span> <span class="s1">'NoneType'</span> <span class="nb">object</span> <span class="n">has</span> <span class="n">no</span> <span class="n">attribute</span> <span class="s1">'x'</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Previous versions of the interpreter would point to just the line, making it
|
||
ambiguous which object was <code class="docutils literal notranslate"><span class="pre">None</span></code>. These enhanced errors can also be helpful
|
||
when dealing with deeply nested <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> objects and multiple function calls:</p>
|
||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
|
||
<span class="n">File</span> <span class="s2">"query.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">37</span><span class="p">,</span> <span class="ow">in</span> <span class="o"><</span><span class="n">module</span><span class="o">></span>
|
||
<span class="n">magic_arithmetic</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">)</span>
|
||
<span class="n">File</span> <span class="s2">"query.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">18</span><span class="p">,</span> <span class="ow">in</span> <span class="n">magic_arithmetic</span>
|
||
<span class="k">return</span> <span class="n">add_counts</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">/</span> <span class="mi">25</span>
|
||
<span class="o">^^^^^^^^^^^^^</span>
|
||
<span class="n">File</span> <span class="s2">"query.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">24</span><span class="p">,</span> <span class="ow">in</span> <span class="n">add_counts</span>
|
||
<span class="k">return</span> <span class="mi">25</span> <span class="o">+</span> <span class="n">query_user</span><span class="p">(</span><span class="n">user1</span><span class="p">)</span> <span class="o">+</span> <span class="n">query_user</span><span class="p">(</span><span class="n">user2</span><span class="p">)</span>
|
||
<span class="o">^^^^^^^^^^^^^^^^^</span>
|
||
<span class="n">File</span> <span class="s2">"query.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">32</span><span class="p">,</span> <span class="ow">in</span> <span class="n">query_user</span>
|
||
<span class="k">return</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">query_count</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">response</span><span class="p">[</span><span class="s1">'a'</span><span class="p">][</span><span class="s1">'b'</span><span class="p">][</span><span class="s1">'c'</span><span class="p">][</span><span class="s1">'user'</span><span class="p">],</span> <span class="n">retry</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||
<span class="o">~~~~~~~~~~~~~~~~~~^^^^^</span>
|
||
<span class="ne">TypeError</span><span class="p">:</span> <span class="s1">'NoneType'</span> <span class="nb">object</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">subscriptable</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>As well as complex arithmetic expressions:</p>
|
||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
|
||
<span class="n">File</span> <span class="s2">"calculation.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">54</span><span class="p">,</span> <span class="ow">in</span> <span class="o"><</span><span class="n">module</span><span class="o">></span>
|
||
<span class="n">result</span> <span class="o">=</span> <span class="p">(</span><span class="n">x</span> <span class="o">/</span> <span class="n">y</span> <span class="o">/</span> <span class="n">z</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">a</span> <span class="o">/</span> <span class="n">b</span> <span class="o">/</span> <span class="n">c</span><span class="p">)</span>
|
||
<span class="o">~~~~~~^~~</span>
|
||
<span class="ne">ZeroDivisionError</span><span class="p">:</span> <span class="n">division</span> <span class="n">by</span> <span class="n">zero</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Additionally, the information used by the enhanced traceback feature
|
||
is made available via a general API, that can be used to correlate
|
||
<a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a> <a class="reference internal" href="../library/dis.html#bytecodes"><span class="std std-ref">instructions</span></a> with source code location.
|
||
This information can be retrieved using:</p>
|
||
<ul class="simple">
|
||
<li><p>The <a class="reference internal" href="../reference/datamodel.html#codeobject.co_positions" title="codeobject.co_positions"><code class="xref py py-meth docutils literal notranslate"><span class="pre">codeobject.co_positions()</span></code></a> method in Python.</p></li>
|
||
<li><p>The <a class="reference internal" href="../c-api/code.html#c.PyCode_Addr2Location" title="PyCode_Addr2Location"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_Addr2Location()</span></code></a> function in the C API.</p></li>
|
||
</ul>
|
||
<p>See <span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0657/"><strong>PEP 657</strong></a> for more details. (Contributed by Pablo Galindo, Batuhan Taskaya
|
||
and Ammar Askar in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43950">bpo-43950</a>.)</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>This feature requires storing column positions in <a class="reference internal" href="../c-api/code.html#codeobjects"><span class="std std-ref">Code Objects</span></a>,
|
||
which may result in a small increase in interpreter memory usage
|
||
and disk usage for compiled Python files.
|
||
To avoid storing the extra information
|
||
and deactivate printing the extra traceback information,
|
||
use the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">no_debug_ranges</span></code></a> command line option
|
||
or the <span class="target" id="index-6"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONNODEBUGRANGES"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONNODEBUGRANGES</span></code></a> environment variable.</p>
|
||
</div>
|
||
</section>
|
||
<section id="pep-654-exception-groups-and-except">
|
||
<span id="whatsnew311-pep654"></span><h3>PEP 654: Exception Groups and <code class="docutils literal notranslate"><span class="pre">except*</span></code><a class="headerlink" href="#pep-654-exception-groups-and-except" title="Link to this heading">¶</a></h3>
|
||
<p><span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0654/"><strong>PEP 654</strong></a> introduces language features that enable a program
|
||
to raise and handle multiple unrelated exceptions simultaneously.
|
||
The builtin types <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 <a class="reference internal" href="../library/exceptions.html#BaseExceptionGroup" title="BaseExceptionGroup"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseExceptionGroup</span></code></a>
|
||
make it possible to group exceptions and raise them together,
|
||
and the new <a class="reference internal" href="../reference/compound_stmts.html#except-star"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except*</span></code></a> syntax generalizes
|
||
<a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> to match subgroups of exception groups.</p>
|
||
<p>See <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0654/"><strong>PEP 654</strong></a> for more details.</p>
|
||
<p>(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45292">bpo-45292</a>. PEP written by
|
||
Irit Katriel, Yury Selivanov and Guido van Rossum.)</p>
|
||
</section>
|
||
<section id="pep-678-exceptions-can-be-enriched-with-notes">
|
||
<span id="whatsnew311-pep678"></span><h3>PEP 678: Exceptions can be enriched with notes<a class="headerlink" href="#pep-678-exceptions-can-be-enriched-with-notes" title="Link to this heading">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/exceptions.html#BaseException.add_note" title="BaseException.add_note"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_note()</span></code></a> method is added to <a class="reference internal" href="../library/exceptions.html#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a>.
|
||
It can be used to enrich exceptions with context information
|
||
that is not available at the time when the exception is raised.
|
||
The added notes appear in the default traceback.</p>
|
||
<p>See <span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0678/"><strong>PEP 678</strong></a> for more details.</p>
|
||
<p>(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45607">bpo-45607</a>.
|
||
PEP written by Zac Hatfield-Dodds.)</p>
|
||
</section>
|
||
<section id="windows-py-exe-launcher-improvements">
|
||
<span id="whatsnew311-windows-launcher"></span><h3>Windows <code class="docutils literal notranslate"><span class="pre">py.exe</span></code> launcher improvements<a class="headerlink" href="#windows-py-exe-launcher-improvements" title="Link to this heading">¶</a></h3>
|
||
<p>The copy of the <a class="reference internal" href="../using/windows.html#launcher"><span class="std std-ref">Python Launcher for Windows</span></a> included with Python 3.11 has been significantly
|
||
updated. It now supports company/tag syntax as defined in <span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0514/"><strong>PEP 514</strong></a> using the
|
||
<code class="samp docutils literal notranslate"><span class="pre">-V:</span><em><span class="pre"><company></span></em><span class="pre">/</span><em><span class="pre"><tag></span></em></code> argument instead of the limited <code class="samp docutils literal notranslate"><span class="pre">-</span><em><span class="pre"><major></span></em><span class="pre">.</span><em><span class="pre"><minor></span></em></code>.
|
||
This allows launching distributions other than <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>,
|
||
the one hosted on <a class="reference external" href="https://www.python.org">python.org</a>.</p>
|
||
<p>When using <code class="docutils literal notranslate"><span class="pre">-V:</span></code> selectors, either company or tag can be omitted, but all
|
||
installs will be searched. For example, <code class="docutils literal notranslate"><span class="pre">-V:OtherPython/</span></code> will select the
|
||
“best” tag registered for <code class="docutils literal notranslate"><span class="pre">OtherPython</span></code>, while <code class="docutils literal notranslate"><span class="pre">-V:3.11</span></code> or <code class="docutils literal notranslate"><span class="pre">-V:/3.11</span></code>
|
||
will select the “best” distribution with tag <code class="docutils literal notranslate"><span class="pre">3.11</span></code>.</p>
|
||
<p>When using the legacy <code class="samp docutils literal notranslate"><span class="pre">-</span><em><span class="pre"><major></span></em></code>, <code class="samp docutils literal notranslate"><span class="pre">-</span><em><span class="pre"><major></span></em><span class="pre">.</span><em><span class="pre"><minor></span></em></code>,
|
||
<code class="samp docutils literal notranslate"><span class="pre">-</span><em><span class="pre"><major></span></em><span class="pre">-</span><em><span class="pre"><bitness></span></em></code> or <code class="samp docutils literal notranslate"><span class="pre">-</span><em><span class="pre"><major></span></em><span class="pre">.</span><em><span class="pre"><minor></span></em><span class="pre">-</span><em><span class="pre"><bitness></span></em></code> arguments,
|
||
all existing behaviour should be preserved from past versions,
|
||
and only releases from <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code> will be selected.
|
||
However, the <code class="docutils literal notranslate"><span class="pre">-64</span></code> suffix now implies “not 32-bit” (not necessarily x86-64),
|
||
as there are multiple supported 64-bit platforms.
|
||
32-bit runtimes are detected by checking the runtime’s tag for a <code class="docutils literal notranslate"><span class="pre">-32</span></code> suffix.
|
||
All releases of Python since 3.5 have included this in their 32-bit builds.</p>
|
||
</section>
|
||
</section>
|
||
<section id="new-features-related-to-type-hints">
|
||
<span id="whatsnew311-typing-features"></span><span id="new-feat-related-type-hints-311"></span><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-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> type hints 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-646-variadic-generics">
|
||
<span id="whatsnew311-pep646"></span><h3>PEP 646: Variadic generics<a class="headerlink" href="#pep-646-variadic-generics" 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-0484/"><strong>PEP 484</strong></a> previously introduced <a class="reference internal" href="../library/typing.html#typing.TypeVar" title="typing.TypeVar"><code class="xref py py-data docutils literal notranslate"><span class="pre">TypeVar</span></code></a>, enabling creation
|
||
of generics parameterised with a single type. <span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0646/"><strong>PEP 646</strong></a> adds
|
||
<a class="reference internal" href="../library/typing.html#typing.TypeVarTuple" title="typing.TypeVarTuple"><code class="xref py py-data docutils literal notranslate"><span class="pre">TypeVarTuple</span></code></a>, enabling parameterisation
|
||
with an <em>arbitrary</em> number of types. In other words,
|
||
a <a class="reference internal" href="../library/typing.html#typing.TypeVarTuple" title="typing.TypeVarTuple"><code class="xref py py-data docutils literal notranslate"><span class="pre">TypeVarTuple</span></code></a> is a <em>variadic</em> type variable,
|
||
enabling <em>variadic</em> generics.</p>
|
||
<p>This enables a wide variety of use cases.
|
||
In particular, it allows the type of array-like structures
|
||
in numerical computing libraries such as NumPy and TensorFlow to be
|
||
parameterised with the array <em>shape</em>. Static type checkers will now
|
||
be able to catch shape-related bugs in code that uses these libraries.</p>
|
||
<p>See <span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0646/"><strong>PEP 646</strong></a> for more details.</p>
|
||
<p>(Contributed by Matthew Rahtz in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43224">bpo-43224</a>, with contributions by
|
||
Serhiy Storchaka and Jelle Zijlstra. PEP written by Mark Mendoza, Matthew
|
||
Rahtz, Pradeep Kumar Srinivasan, and Vincent Siles.)</p>
|
||
</section>
|
||
<section id="pep-655-marking-individual-typeddict-items-as-required-or-not-required">
|
||
<span id="whatsnew311-pep655"></span><h3>PEP 655: Marking individual <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> items as required or not-required<a class="headerlink" href="#pep-655-marking-individual-typeddict-items-as-required-or-not-required" title="Link to this heading">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/typing.html#typing.Required" title="typing.Required"><code class="xref py py-data docutils literal notranslate"><span class="pre">Required</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.NotRequired" title="typing.NotRequired"><code class="xref py py-data docutils literal notranslate"><span class="pre">NotRequired</span></code></a> provide a
|
||
straightforward way to mark whether individual items in a
|
||
<a class="reference internal" href="../library/typing.html#typing.TypedDict" title="typing.TypedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypedDict</span></code></a> must be present. Previously, this was only possible
|
||
using inheritance.</p>
|
||
<p>All fields are still required by default,
|
||
unless the <em>total</em> parameter is set to <code class="docutils literal notranslate"><span class="pre">False</span></code>,
|
||
in which case all fields are still not-required by default.
|
||
For example, the following specifies a <code class="xref py py-class docutils literal notranslate"><span class="pre">TypedDict</span></code>
|
||
with one required and one not-required key:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span><span class="w"> </span><span class="nc">Movie</span><span class="p">(</span><span class="n">TypedDict</span><span class="p">):</span>
|
||
<span class="n">title</span><span class="p">:</span> <span class="nb">str</span>
|
||
<span class="n">year</span><span class="p">:</span> <span class="n">NotRequired</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span>
|
||
|
||
<span class="n">m1</span><span class="p">:</span> <span class="n">Movie</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"title"</span><span class="p">:</span> <span class="s2">"Black Panther"</span><span class="p">,</span> <span class="s2">"year"</span><span class="p">:</span> <span class="mi">2018</span><span class="p">}</span> <span class="c1"># OK</span>
|
||
<span class="n">m2</span><span class="p">:</span> <span class="n">Movie</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"title"</span><span class="p">:</span> <span class="s2">"Star Wars"</span><span class="p">}</span> <span class="c1"># OK (year is not required)</span>
|
||
<span class="n">m3</span><span class="p">:</span> <span class="n">Movie</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"year"</span><span class="p">:</span> <span class="mi">2022</span><span class="p">}</span> <span class="c1"># ERROR (missing required field title)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The following definition is equivalent:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span><span class="w"> </span><span class="nc">Movie</span><span class="p">(</span><span class="n">TypedDict</span><span class="p">,</span> <span class="n">total</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
|
||
<span class="n">title</span><span class="p">:</span> <span class="n">Required</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span>
|
||
<span class="n">year</span><span class="p">:</span> <span class="nb">int</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>See <span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0655/"><strong>PEP 655</strong></a> for more details.</p>
|
||
<p>(Contributed by David Foster and Jelle Zijlstra in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47087">bpo-47087</a>. PEP
|
||
written by David Foster.)</p>
|
||
</section>
|
||
<section id="pep-673-self-type">
|
||
<span id="whatsnew311-pep673"></span><h3>PEP 673: <code class="docutils literal notranslate"><span class="pre">Self</span></code> type<a class="headerlink" href="#pep-673-self-type" title="Link to this heading">¶</a></h3>
|
||
<p>The new <a class="reference internal" href="../library/typing.html#typing.Self" title="typing.Self"><code class="xref py py-data docutils literal notranslate"><span class="pre">Self</span></code></a> annotation provides a simple and intuitive
|
||
way to annotate methods that return an instance of their class. This
|
||
behaves the same as the <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>-based approach
|
||
<span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/#annotating-instance-and-class-methods"><strong>specified in PEP 484</strong></a>,
|
||
but is more concise and easier to follow.</p>
|
||
<p>Common use cases include alternative constructors provided as
|
||
<a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">classmethod</span></code></a>s,
|
||
and <a class="reference internal" href="../reference/datamodel.html#object.__enter__" title="object.__enter__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__enter__()</span></code></a> methods that return <code class="docutils literal notranslate"><span class="pre">self</span></code>:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span><span class="w"> </span><span class="nc">MyLock</span><span class="p">:</span>
|
||
<span class="k">def</span><span class="w"> </span><span class="fm">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">Self</span><span class="p">:</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">lock</span><span class="p">()</span>
|
||
<span class="k">return</span> <span class="bp">self</span>
|
||
|
||
<span class="o">...</span>
|
||
|
||
<span class="k">class</span><span class="w"> </span><span class="nc">MyInt</span><span class="p">:</span>
|
||
<span class="nd">@classmethod</span>
|
||
<span class="k">def</span><span class="w"> </span><span class="nf">fromhex</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">s</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">Self</span><span class="p">:</span>
|
||
<span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="mi">16</span><span class="p">))</span>
|
||
|
||
<span class="o">...</span>
|
||
</pre></div>
|
||
</div>
|
||
<p><a class="reference internal" href="../library/typing.html#typing.Self" title="typing.Self"><code class="xref py py-data docutils literal notranslate"><span class="pre">Self</span></code></a> can also be used to annotate method parameters
|
||
or attributes of the same type as their enclosing class.</p>
|
||
<p>See <span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0673/"><strong>PEP 673</strong></a> for more details.</p>
|
||
<p>(Contributed by James Hilton-Balfe in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46534">bpo-46534</a>. PEP written by
|
||
Pradeep Kumar Srinivasan and James Hilton-Balfe.)</p>
|
||
</section>
|
||
<section id="pep-675-arbitrary-literal-string-type">
|
||
<span id="whatsnew311-pep675"></span><h3>PEP 675: Arbitrary literal string type<a class="headerlink" href="#pep-675-arbitrary-literal-string-type" title="Link to this heading">¶</a></h3>
|
||
<p>The new <a class="reference internal" href="../library/typing.html#typing.LiteralString" title="typing.LiteralString"><code class="xref py py-data docutils literal notranslate"><span class="pre">LiteralString</span></code></a> annotation may be used to indicate
|
||
that a function parameter can be of any literal string type. This allows
|
||
a function to accept arbitrary literal string types, as well as strings
|
||
created from other literal strings. Type checkers can then
|
||
enforce that sensitive functions, such as those that execute SQL
|
||
statements or shell commands, are called only with static arguments,
|
||
providing protection against injection attacks.</p>
|
||
<p>For example, a SQL query function could be annotated as follows:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">run_query</span><span class="p">(</span><span class="n">sql</span><span class="p">:</span> <span class="n">LiteralString</span><span class="p">)</span> <span class="o">-></span> <span class="o">...</span>
|
||
<span class="o">...</span>
|
||
|
||
<span class="k">def</span><span class="w"> </span><span class="nf">caller</span><span class="p">(</span>
|
||
<span class="n">arbitrary_string</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
|
||
<span class="n">query_string</span><span class="p">:</span> <span class="n">LiteralString</span><span class="p">,</span>
|
||
<span class="n">table_name</span><span class="p">:</span> <span class="n">LiteralString</span><span class="p">,</span>
|
||
<span class="p">)</span> <span class="o">-></span> <span class="kc">None</span><span class="p">:</span>
|
||
<span class="n">run_query</span><span class="p">(</span><span class="s2">"SELECT * FROM students"</span><span class="p">)</span> <span class="c1"># ok</span>
|
||
<span class="n">run_query</span><span class="p">(</span><span class="n">query_string</span><span class="p">)</span> <span class="c1"># ok</span>
|
||
<span class="n">run_query</span><span class="p">(</span><span class="s2">"SELECT * FROM "</span> <span class="o">+</span> <span class="n">table_name</span><span class="p">)</span> <span class="c1"># ok</span>
|
||
<span class="n">run_query</span><span class="p">(</span><span class="n">arbitrary_string</span><span class="p">)</span> <span class="c1"># type checker error</span>
|
||
<span class="n">run_query</span><span class="p">(</span> <span class="c1"># type checker error</span>
|
||
<span class="sa">f</span><span class="s2">"SELECT * FROM students WHERE name = </span><span class="si">{</span><span class="n">arbitrary_string</span><span class="si">}</span><span class="s2">"</span>
|
||
<span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>See <span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0675/"><strong>PEP 675</strong></a> for more details.</p>
|
||
<p>(Contributed by Jelle Zijlstra in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47088">bpo-47088</a>. PEP written by Pradeep
|
||
Kumar Srinivasan and Graham Bleaney.)</p>
|
||
</section>
|
||
<section id="pep-681-data-class-transforms">
|
||
<span id="whatsnew311-pep681"></span><h3>PEP 681: Data class transforms<a class="headerlink" href="#pep-681-data-class-transforms" title="Link to this heading">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/typing.html#typing.dataclass_transform" title="typing.dataclass_transform"><code class="xref py py-data docutils literal notranslate"><span class="pre">dataclass_transform</span></code></a> may be used to
|
||
decorate a class, metaclass, or a function that is itself a decorator.
|
||
The presence of <code class="docutils literal notranslate"><span class="pre">@dataclass_transform()</span></code> tells a static type checker that the
|
||
decorated object performs runtime “magic” that transforms a class,
|
||
giving it <a class="reference internal" href="../library/dataclasses.html#dataclasses.dataclass" title="dataclasses.dataclass"><code class="xref py py-func docutils literal notranslate"><span class="pre">dataclass</span></code></a>-like behaviors.</p>
|
||
<p>For example:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># The create_model decorator is defined by a library.</span>
|
||
<span class="nd">@typing</span><span class="o">.</span><span class="n">dataclass_transform</span><span class="p">()</span>
|
||
<span class="k">def</span><span class="w"> </span><span class="nf">create_model</span><span class="p">(</span><span class="bp">cls</span><span class="p">:</span> <span class="n">Type</span><span class="p">[</span><span class="n">T</span><span class="p">])</span> <span class="o">-></span> <span class="n">Type</span><span class="p">[</span><span class="n">T</span><span class="p">]:</span>
|
||
<span class="bp">cls</span><span class="o">.</span><span class="fm">__init__</span> <span class="o">=</span> <span class="o">...</span>
|
||
<span class="bp">cls</span><span class="o">.</span><span class="fm">__eq__</span> <span class="o">=</span> <span class="o">...</span>
|
||
<span class="bp">cls</span><span class="o">.</span><span class="fm">__ne__</span> <span class="o">=</span> <span class="o">...</span>
|
||
<span class="k">return</span> <span class="bp">cls</span>
|
||
|
||
<span class="c1"># The create_model decorator can now be used to create new model classes:</span>
|
||
<span class="nd">@create_model</span>
|
||
<span class="k">class</span><span class="w"> </span><span class="nc">CustomerModel</span><span class="p">:</span>
|
||
<span class="nb">id</span><span class="p">:</span> <span class="nb">int</span>
|
||
<span class="n">name</span><span class="p">:</span> <span class="nb">str</span>
|
||
|
||
<span class="n">c</span> <span class="o">=</span> <span class="n">CustomerModel</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="mi">327</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">"Eric Idle"</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>See <span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0681/"><strong>PEP 681</strong></a> for more details.</p>
|
||
<p>(Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/91860">gh-91860</a>. PEP written by
|
||
Erik De Bonte and Eric Traut.)</p>
|
||
</section>
|
||
<section id="pep-563-may-not-be-the-future">
|
||
<span id="whatsnew311-pep563-deferred"></span><h3>PEP 563 may not be the future<a class="headerlink" href="#pep-563-may-not-be-the-future" title="Link to this heading">¶</a></h3>
|
||
<p><span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0563/"><strong>PEP 563</strong></a> Postponed Evaluation of Annotations
|
||
(the <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">annotations</span></code> <a class="reference internal" href="../reference/simple_stmts.html#future"><span class="std std-ref">future statement</span></a>)
|
||
that was originally planned for release in Python 3.10
|
||
has been put on hold indefinitely.
|
||
See <a class="reference external" href="https://mail.python.org/archives/list/python-dev@python.org/message/VIZEBX5EYMSYIJNDBF6DMUMZOCWHARSO/">this message from the Steering Council</a>
|
||
for more information.</p>
|
||
</section>
|
||
</section>
|
||
<section id="other-language-changes">
|
||
<span id="whatsnew311-other-lang-changes"></span><h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p>Starred unpacking expressions can now be used in <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> statements.
|
||
(See <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46725">bpo-46725</a> for more details.)</p></li>
|
||
<li><p>Asynchronous <a class="reference internal" href="../reference/expressions.html#comprehensions"><span class="std std-ref">comprehensions</span></a> are now allowed
|
||
inside comprehensions in <a class="reference internal" href="../reference/compound_stmts.html#async-def"><span class="std std-ref">asynchronous functions</span></a>.
|
||
Outer comprehensions implicitly become asynchronous in this case.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33346">bpo-33346</a>.)</p></li>
|
||
<li><p>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> is now raised instead of an <a class="reference internal" href="../library/exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a> in
|
||
<a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statements and <a class="reference internal" href="../library/contextlib.html#contextlib.ExitStack.enter_context" title="contextlib.ExitStack.enter_context"><code class="xref py py-meth docutils literal notranslate"><span class="pre">contextlib.ExitStack.enter_context()</span></code></a>
|
||
for objects that do not support the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> protocol,
|
||
and in <a class="reference internal" href="../reference/compound_stmts.html#async-with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">with</span></code></a> statements and
|
||
<a class="reference internal" href="../library/contextlib.html#contextlib.AsyncExitStack.enter_async_context" title="contextlib.AsyncExitStack.enter_async_context"><code class="xref py py-meth docutils literal notranslate"><span class="pre">contextlib.AsyncExitStack.enter_async_context()</span></code></a>
|
||
for objects not supporting the <a class="reference internal" href="../glossary.html#term-asynchronous-context-manager"><span class="xref std std-term">asynchronous context manager</span></a> protocol.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=12022">bpo-12022</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44471">bpo-44471</a>.)</p></li>
|
||
<li><p>Added <a class="reference internal" href="../library/pickle.html#object.__getstate__" title="object.__getstate__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__getstate__()</span></code></a>, which provides the default
|
||
implementation of the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__getstate__()</span></code> method. <a class="reference internal" href="../library/copy.html#module-copy" title="copy: Shallow and deep copy operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">copy</span></code></a>ing
|
||
and <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a>ing instances of subclasses of builtin types
|
||
<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>, <a class="reference internal" href="../library/stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#frozenset" title="frozenset"><code class="xref py py-class docutils literal notranslate"><span class="pre">frozenset</span></code></a>,
|
||
<a class="reference internal" href="../library/collections.html#collections.OrderedDict" title="collections.OrderedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.OrderedDict</span></code></a>, <a class="reference internal" href="../library/collections.html#collections.deque" title="collections.deque"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.deque</span></code></a>,
|
||
<a class="reference internal" href="../library/weakref.html#weakref.WeakSet" title="weakref.WeakSet"><code class="xref py py-class docutils literal notranslate"><span class="pre">weakref.WeakSet</span></code></a>, and <a class="reference internal" href="../library/datetime.html#datetime.tzinfo" title="datetime.tzinfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.tzinfo</span></code></a> now copies and
|
||
pickles instance attributes implemented as <a class="reference internal" href="../glossary.html#term-__slots__"><span class="xref std std-term">slots</span></a>.
|
||
This change has an unintended side effect: It trips up a small minority
|
||
of existing Python projects not expecting <a class="reference internal" href="../library/pickle.html#object.__getstate__" title="object.__getstate__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__getstate__()</span></code></a> to
|
||
exist. See the later comments on <a class="reference external" href="https://github.com/python/cpython/issues/70766">gh-70766</a> for discussions of what
|
||
workarounds such code may need.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26579">bpo-26579</a>.)</p></li>
|
||
</ul>
|
||
<ul class="simple" id="whatsnew311-pythonsafepath">
|
||
<li><p>Added a <a class="reference internal" href="../using/cmdline.html#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a> command line option
|
||
and a <span class="target" id="index-21"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSAFEPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSAFEPATH</span></code></a> environment variable,
|
||
which disable the automatic prepending to <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>
|
||
of the script’s directory when running a script,
|
||
or the current directory when using <a class="reference internal" href="../using/cmdline.html#cmdoption-c"><code class="xref std std-option docutils literal notranslate"><span class="pre">-c</span></code></a> and <a class="reference internal" href="../using/cmdline.html#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a>.
|
||
This ensures only stdlib and installed modules
|
||
are picked up by <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a>,
|
||
and avoids unintentionally or maliciously shadowing modules
|
||
with those in a local (and typically user-writable) directory.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/57684">gh-57684</a>.)</p></li>
|
||
<li><p>A <code class="docutils literal notranslate"><span class="pre">"z"</span></code> option was added to the <a class="reference internal" href="../library/string.html#formatspec"><span class="std std-ref">Format Specification Mini-Language</span></a> that
|
||
coerces negative to positive zero after rounding to the format precision.
|
||
See <span class="target" id="index-22"></span><a class="pep reference external" href="https://peps.python.org/pep-0682/"><strong>PEP 682</strong></a> for more details.
|
||
(Contributed by John Belmonte in <a class="reference external" href="https://github.com/python/cpython/issues/90153">gh-90153</a>.)</p></li>
|
||
<li><p>Bytes are no longer accepted on <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>. Support broke sometime
|
||
between Python 3.2 and 3.6, with no one noticing until after Python 3.10.0
|
||
was released. In addition, bringing back support would be problematic due to
|
||
interactions between <a class="reference internal" href="../using/cmdline.html#cmdoption-b"><code class="xref std std-option docutils literal notranslate"><span class="pre">-b</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a> when
|
||
there is a mixture of <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> and <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> keys.
|
||
(Contributed by Thomas Grainger in <a class="reference external" href="https://github.com/python/cpython/issues/91181">gh-91181</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="other-cpython-implementation-changes">
|
||
<span id="whatsnew311-other-implementation-changes"></span><h2>Other CPython Implementation Changes<a class="headerlink" href="#other-cpython-implementation-changes" title="Link to this heading">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p>The special methods <a class="reference internal" href="../reference/datamodel.html#object.__complex__" title="object.__complex__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__complex__()</span></code></a> for <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a>
|
||
and <a class="reference internal" href="../reference/datamodel.html#object.__bytes__" title="object.__bytes__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__bytes__()</span></code></a> for <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> are implemented to support
|
||
the <a class="reference internal" href="../library/typing.html#typing.SupportsComplex" title="typing.SupportsComplex"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.SupportsComplex</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.SupportsBytes" title="typing.SupportsBytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.SupportsBytes</span></code></a> protocols.
|
||
(Contributed by Mark Dickinson and Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24234">bpo-24234</a>.)</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">siphash13</span></code> is added as a new internal hashing algorithm.
|
||
It has similar security properties as <code class="docutils literal notranslate"><span class="pre">siphash24</span></code>,
|
||
but it is slightly faster for long inputs.
|
||
<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>, <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>, and some other types
|
||
now use it as the default algorithm for <a class="reference internal" href="../library/functions.html#hash" title="hash"><code class="xref py py-func docutils literal notranslate"><span class="pre">hash()</span></code></a>.
|
||
<span class="target" id="index-23"></span><a class="pep reference external" href="https://peps.python.org/pep-0552/"><strong>PEP 552</strong></a> <a class="reference internal" href="../reference/import.html#pyc-invalidation"><span class="std std-ref">hash-based .pyc files</span></a>
|
||
now use <code class="docutils literal notranslate"><span class="pre">siphash13</span></code> too.
|
||
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=29410">bpo-29410</a>.)</p></li>
|
||
<li><p>When an active exception is re-raised by a <a class="reference internal" href="../reference/simple_stmts.html#raise"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">raise</span></code></a> statement with no parameters,
|
||
the traceback attached to this exception is now always <code class="docutils literal notranslate"><span class="pre">sys.exc_info()[1].__traceback__</span></code>.
|
||
This means that changes made to the traceback in the current <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> clause are
|
||
reflected in the re-raised exception.
|
||
(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45711">bpo-45711</a>.)</p></li>
|
||
<li><p>The interpreter state’s representation of handled exceptions
|
||
(aka <code class="docutils literal notranslate"><span class="pre">exc_info</span></code> or <code class="docutils literal notranslate"><span class="pre">_PyErr_StackItem</span></code>)
|
||
now only has the <code class="docutils literal notranslate"><span class="pre">exc_value</span></code> field; <code class="docutils literal notranslate"><span class="pre">exc_type</span></code> and <code class="docutils literal notranslate"><span class="pre">exc_traceback</span></code>
|
||
have been removed, as they can be derived from <code class="docutils literal notranslate"><span class="pre">exc_value</span></code>.
|
||
(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45711">bpo-45711</a>.)</p></li>
|
||
<li><p>A new <a class="reference internal" href="../using/windows.html#install-quiet-option"><span class="std std-ref">command line option</span></a>, <code class="docutils literal notranslate"><span class="pre">AppendPath</span></code>,
|
||
has been added for the Windows installer.
|
||
It behaves similarly to <code class="docutils literal notranslate"><span class="pre">PrependPath</span></code>,
|
||
but appends the install and scripts directories instead of prepending them.
|
||
(Contributed by Bastian Neuburger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44934">bpo-44934</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths_set" title="PyConfig.module_search_paths_set"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths_set</span></code></a> field must now be set to <code class="docutils literal notranslate"><span class="pre">1</span></code> for
|
||
initialization to use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths" title="PyConfig.module_search_paths"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths</span></code></a> to initialize
|
||
<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>. Otherwise, initialization will recalculate the path and replace
|
||
any values added to <code class="docutils literal notranslate"><span class="pre">module_search_paths</span></code>.</p></li>
|
||
<li><p>The output of the <a class="reference internal" href="../using/cmdline.html#cmdoption-help"><code class="xref std std-option docutils literal notranslate"><span class="pre">--help</span></code></a> option now fits in 50 lines/80 columns.
|
||
Information about <a class="reference internal" href="../using/cmdline.html#using-on-envvars"><span class="std std-ref">Python environment variables</span></a>
|
||
and <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> options is now available using the respective
|
||
<a class="reference internal" href="../using/cmdline.html#cmdoption-help-env"><code class="xref std std-option docutils literal notranslate"><span class="pre">--help-env</span></code></a> and <a class="reference internal" href="../using/cmdline.html#cmdoption-help-xoptions"><code class="xref std std-option docutils literal notranslate"><span class="pre">--help-xoptions</span></code></a> flags,
|
||
and with the new <a class="reference internal" href="../using/cmdline.html#cmdoption-help-all"><code class="xref std std-option docutils literal notranslate"><span class="pre">--help-all</span></code></a>.
|
||
(Contributed by Éric Araujo in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46142">bpo-46142</a>.)</p></li>
|
||
<li><p>Converting between <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> and <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> in bases other than 2
|
||
(binary), 4, 8 (octal), 16 (hexadecimal), or 32 such as base 10 (decimal)
|
||
now raises a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> if the number of digits in string form is
|
||
above a limit to avoid potential denial of service attacks due to the
|
||
algorithmic complexity. This is a mitigation for <span class="target" id="index-24"></span><a class="cve reference external" href="https://www.cve.org/CVERecord?id=CVE-2020-10735"><strong>CVE 2020-10735</strong></a>.
|
||
This limit can be configured or disabled by environment variable, command
|
||
line flag, or <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> APIs. See the <a class="reference internal" href="../library/stdtypes.html#int-max-str-digits"><span class="std std-ref">integer string conversion
|
||
length limitation</span></a> documentation. The default limit
|
||
is 4300 digits in string form.</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="new-modules">
|
||
<span id="whatsnew311-new-modules"></span><h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/tomllib.html#module-tomllib" title="tomllib: Parse TOML files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tomllib</span></code></a>: For parsing <a class="reference external" href="https://toml.io/">TOML</a>.
|
||
See <span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-0680/"><strong>PEP 680</strong></a> for more details.
|
||
(Contributed by Taneli Hukkinen in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=40059">bpo-40059</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/wsgiref.html#module-wsgiref.types" title="wsgiref.types: WSGI types for static type checking"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.types</span></code></a>:
|
||
<span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>WSGI</strong></a>-specific types for static type checking.
|
||
(Contributed by Sebastian Rittau in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=42012">bpo-42012</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="improved-modules">
|
||
<span id="whatsnew311-improved-modules"></span><h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading">¶</a></h2>
|
||
<section id="asyncio">
|
||
<span id="whatsnew311-asyncio"></span><h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Added the <a class="reference internal" href="../library/asyncio-task.html#asyncio.TaskGroup" title="asyncio.TaskGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">TaskGroup</span></code></a> class,
|
||
an <a class="reference internal" href="../reference/datamodel.html#async-context-managers"><span class="std std-ref">asynchronous context manager</span></a>
|
||
holding a group of tasks that will wait for all of them upon exit.
|
||
For new code this is recommended over using
|
||
<a class="reference internal" href="../library/asyncio-task.html#asyncio.create_task" title="asyncio.create_task"><code class="xref py py-func docutils literal notranslate"><span class="pre">create_task()</span></code></a> and <a class="reference internal" href="../library/asyncio-task.html#asyncio.gather" title="asyncio.gather"><code class="xref py py-func docutils literal notranslate"><span class="pre">gather()</span></code></a> directly.
|
||
(Contributed by Yury Selivanov and others in <a class="reference external" href="https://github.com/python/cpython/issues/90908">gh-90908</a>.)</p></li>
|
||
<li><p>Added <a class="reference internal" href="../library/asyncio-task.html#asyncio.timeout" title="asyncio.timeout"><code class="xref py py-func docutils literal notranslate"><span class="pre">timeout()</span></code></a>, an asynchronous context manager for
|
||
setting a timeout on asynchronous operations. For new code this is
|
||
recommended over using <a class="reference internal" href="../library/asyncio-task.html#asyncio.wait_for" title="asyncio.wait_for"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait_for()</span></code></a> directly.
|
||
(Contributed by Andrew Svetlov in <a class="reference external" href="https://github.com/python/cpython/issues/90927">gh-90927</a>.)</p></li>
|
||
<li><p>Added the <a class="reference internal" href="../library/asyncio-runner.html#asyncio.Runner" title="asyncio.Runner"><code class="xref py py-class docutils literal notranslate"><span class="pre">Runner</span></code></a> class, which exposes the machinery
|
||
used by <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">run()</span></code></a>.
|
||
(Contributed by Andrew Svetlov in <a class="reference external" href="https://github.com/python/cpython/issues/91218">gh-91218</a>.)</p></li>
|
||
<li><p>Added the <a class="reference internal" href="../library/asyncio-sync.html#asyncio.Barrier" title="asyncio.Barrier"><code class="xref py py-class docutils literal notranslate"><span class="pre">Barrier</span></code></a> class to the synchronization
|
||
primitives in the asyncio library, and the related
|
||
<a class="reference internal" href="../library/asyncio-sync.html#asyncio.BrokenBarrierError" title="asyncio.BrokenBarrierError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BrokenBarrierError</span></code></a> exception.
|
||
(Contributed by Yves Duprat and Andrew Svetlov in <a class="reference external" href="https://github.com/python/cpython/issues/87518">gh-87518</a>.)</p></li>
|
||
<li><p>Added keyword argument <em>all_errors</em> to <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_connection" title="asyncio.loop.create_connection"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.create_connection()</span></code></a>
|
||
so that multiple connection errors can be raised as 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>.</p></li>
|
||
<li><p>Added the <a class="reference internal" href="../library/asyncio-stream.html#asyncio.StreamWriter.start_tls" title="asyncio.StreamWriter.start_tls"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.StreamWriter.start_tls()</span></code></a> method for
|
||
upgrading existing stream-based connections to TLS.
|
||
(Contributed by Ian Good in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34975">bpo-34975</a>.)</p></li>
|
||
<li><p>Added raw datagram socket functions to the event loop:
|
||
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_sendto" title="asyncio.loop.sock_sendto"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sock_sendto()</span></code></a>,
|
||
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_recvfrom" title="asyncio.loop.sock_recvfrom"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sock_recvfrom()</span></code></a> and
|
||
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_recvfrom_into" title="asyncio.loop.sock_recvfrom_into"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sock_recvfrom_into()</span></code></a>.
|
||
These have implementations in <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.SelectorEventLoop" title="asyncio.SelectorEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">SelectorEventLoop</span></code></a> and
|
||
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.ProactorEventLoop" title="asyncio.ProactorEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProactorEventLoop</span></code></a>.
|
||
(Contributed by Alex Grönholm in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46805">bpo-46805</a>.)</p></li>
|
||
<li><p>Added <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.cancelling" title="asyncio.Task.cancelling"><code class="xref py py-meth docutils literal notranslate"><span class="pre">cancelling()</span></code></a> and
|
||
<a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.uncancel" title="asyncio.Task.uncancel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">uncancel()</span></code></a> methods to <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">Task</span></code></a>.
|
||
These are primarily intended for internal use,
|
||
notably by <a class="reference internal" href="../library/asyncio-task.html#asyncio.TaskGroup" title="asyncio.TaskGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">TaskGroup</span></code></a>.</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="contextlib">
|
||
<span id="whatsnew311-contextlib"></span><h3>contextlib<a class="headerlink" href="#contextlib" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Added non parallel-safe <a class="reference internal" href="../library/contextlib.html#contextlib.chdir" title="contextlib.chdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">chdir()</span></code></a> context manager to change
|
||
the current working directory and then restore it on exit. Simple wrapper
|
||
around <a class="reference internal" href="../library/os.html#os.chdir" title="os.chdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">chdir()</span></code></a>. (Contributed by Filipe Laíns in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25625">bpo-25625</a>)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="dataclasses">
|
||
<span id="whatsnew311-dataclasses"></span><h3>dataclasses<a class="headerlink" href="#dataclasses" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Change field default mutability check, allowing only defaults which are
|
||
<a class="reference internal" href="../glossary.html#term-hashable"><span class="xref std std-term">hashable</span></a> instead of any object which is not an instance of
|
||
<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>, <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> or <a class="reference internal" href="../library/stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>. (Contributed by Eric V. Smith in
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44674">bpo-44674</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="datetime">
|
||
<span id="whatsnew311-datetime"></span><h3>datetime<a class="headerlink" href="#datetime" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Add <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>, a convenience alias for
|
||
<a class="reference internal" href="../library/datetime.html#datetime.timezone.utc" title="datetime.timezone.utc"><code class="xref py py-attr docutils literal notranslate"><span class="pre">datetime.timezone.utc</span></code></a>. (Contributed by Kabir Kwatra in <a class="reference external" href="https://github.com/python/cpython/issues/91973">gh-91973</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/datetime.html#datetime.date.fromisoformat" title="datetime.date.fromisoformat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.date.fromisoformat()</span></code></a>, <a class="reference internal" href="../library/datetime.html#datetime.time.fromisoformat" title="datetime.time.fromisoformat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.time.fromisoformat()</span></code></a> and
|
||
<a class="reference internal" href="../library/datetime.html#datetime.datetime.fromisoformat" title="datetime.datetime.fromisoformat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.fromisoformat()</span></code></a> can now be used to parse most ISO 8601
|
||
formats (barring only those that support fractional hours and minutes).
|
||
(Contributed by Paul Ganssle in <a class="reference external" href="https://github.com/python/cpython/issues/80010">gh-80010</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="enum">
|
||
<span id="whatsnew311-enum"></span><h3>enum<a class="headerlink" href="#enum" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Renamed <code class="xref py py-class docutils literal notranslate"><span class="pre">EnumMeta</span></code> to <a class="reference internal" href="../library/enum.html#enum.EnumType" title="enum.EnumType"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnumType</span></code></a>
|
||
(<code class="xref py py-class docutils literal notranslate"><span class="pre">EnumMeta</span></code> kept as an alias).</p></li>
|
||
<li><p>Added <a class="reference internal" href="../library/enum.html#enum.StrEnum" title="enum.StrEnum"><code class="xref py py-class docutils literal notranslate"><span class="pre">StrEnum</span></code></a>,
|
||
with members that can be used as (and must be) strings.</p></li>
|
||
<li><p>Added <a class="reference internal" href="../library/enum.html#enum.ReprEnum" title="enum.ReprEnum"><code class="xref py py-class docutils literal notranslate"><span class="pre">ReprEnum</span></code></a>,
|
||
which only modifies the <a class="reference internal" href="../reference/datamodel.html#object.__repr__" title="object.__repr__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__repr__()</span></code></a> of members
|
||
while returning their literal values (rather than names)
|
||
for <a class="reference internal" href="../reference/datamodel.html#object.__str__" title="object.__str__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__str__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__format__" title="object.__format__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__format__()</span></code></a>
|
||
(used by <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a>, <a class="reference internal" href="../library/functions.html#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a> and <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-string</span></a>s).</p></li>
|
||
<li><p>Changed <a class="reference internal" href="../library/enum.html#enum.Enum.__format__" title="enum.Enum.__format__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Enum.__format__()</span></code></a> (the default for
|
||
<a class="reference internal" href="../library/functions.html#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#str.format" title="str.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.format()</span></code></a> and <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-string</span></a>s) to always produce
|
||
the same result as <a class="reference internal" href="../library/enum.html#enum.Enum.__str__" title="enum.Enum.__str__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Enum.__str__()</span></code></a>: for enums inheriting from
|
||
<a class="reference internal" href="../library/enum.html#enum.ReprEnum" title="enum.ReprEnum"><code class="xref py py-class docutils literal notranslate"><span class="pre">ReprEnum</span></code></a> it will be the member’s value; for all other enums
|
||
it will be the enum and member name (e.g. <code class="docutils literal notranslate"><span class="pre">Color.RED</span></code>).</p></li>
|
||
<li><p>Added a new <em>boundary</em> class parameter to <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a> enums
|
||
and the <a class="reference internal" href="../library/enum.html#enum.FlagBoundary" title="enum.FlagBoundary"><code class="xref py py-class docutils literal notranslate"><span class="pre">FlagBoundary</span></code></a> enum with its options,
|
||
to control how to handle out-of-range flag values.</p></li>
|
||
<li><p>Added the <a class="reference internal" href="../library/enum.html#enum.verify" title="enum.verify"><code class="xref py py-func docutils literal notranslate"><span class="pre">verify()</span></code></a> enum decorator
|
||
and the <a class="reference internal" href="../library/enum.html#enum.EnumCheck" title="enum.EnumCheck"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnumCheck</span></code></a> enum with its options,
|
||
to check enum classes against several specific constraints.</p></li>
|
||
<li><p>Added the <a class="reference internal" href="../library/enum.html#enum.member" title="enum.member"><code class="xref py py-func docutils literal notranslate"><span class="pre">member()</span></code></a> and <a class="reference internal" href="../library/enum.html#enum.nonmember" title="enum.nonmember"><code class="xref py py-func docutils literal notranslate"><span class="pre">nonmember()</span></code></a> decorators,
|
||
to ensure the decorated object is/is not converted to an enum member.</p></li>
|
||
<li><p>Added the <a class="reference internal" href="../library/enum.html#enum.property" title="enum.property"><code class="xref py py-func docutils literal notranslate"><span class="pre">property()</span></code></a> decorator,
|
||
which works like <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-func docutils literal notranslate"><span class="pre">property()</span></code></a> except for enums.
|
||
Use this instead of <a class="reference internal" href="../library/types.html#types.DynamicClassAttribute" title="types.DynamicClassAttribute"><code class="xref py py-func docutils literal notranslate"><span class="pre">types.DynamicClassAttribute()</span></code></a>.</p></li>
|
||
<li><p>Added the <a class="reference internal" href="../library/enum.html#enum.global_enum" title="enum.global_enum"><code class="xref py py-func docutils literal notranslate"><span class="pre">global_enum()</span></code></a> enum decorator,
|
||
which adjusts <a class="reference internal" href="../reference/datamodel.html#object.__repr__" title="object.__repr__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__repr__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__str__" title="object.__str__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__str__()</span></code></a>
|
||
to show values as members of their module rather than the enum class.
|
||
For example, <code class="docutils literal notranslate"><span class="pre">'re.ASCII'</span></code> for the <a class="reference internal" href="../library/re.html#re.ASCII" title="re.ASCII"><code class="xref py py-const docutils literal notranslate"><span class="pre">ASCII</span></code></a> member
|
||
of <a class="reference internal" href="../library/re.html#re.RegexFlag" title="re.RegexFlag"><code class="xref py py-class docutils literal notranslate"><span class="pre">re.RegexFlag</span></code></a> rather than <code class="docutils literal notranslate"><span class="pre">'RegexFlag.ASCII'</span></code>.</p></li>
|
||
<li><p>Enhanced <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a> to support
|
||
<a class="reference internal" href="../library/functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a>, iteration and <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#not-in"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">not</span> <span class="pre">in</span></code></a> on its members.
|
||
For example, the following now works:
|
||
<code class="docutils literal notranslate"><span class="pre">len(AFlag(3))</span> <span class="pre">==</span> <span class="pre">2</span> <span class="pre">and</span> <span class="pre">list(AFlag(3))</span> <span class="pre">==</span> <span class="pre">(AFlag.ONE,</span> <span class="pre">AFlag.TWO)</span></code></p></li>
|
||
<li><p>Changed <a class="reference internal" href="../library/enum.html#enum.Enum" title="enum.Enum"><code class="xref py py-class docutils literal notranslate"><span class="pre">Enum</span></code></a> and <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a>
|
||
so that members are now defined
|
||
before <a class="reference internal" href="../reference/datamodel.html#object.__init_subclass__" title="object.__init_subclass__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__init_subclass__()</span></code></a> is called;
|
||
<a class="reference internal" href="../library/functions.html#dir" title="dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">dir()</span></code></a> now includes methods, etc., from mixed-in data types.</p></li>
|
||
<li><p>Changed <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a>
|
||
to only consider primary values (power of two) canonical
|
||
while composite values (<code class="docutils literal notranslate"><span class="pre">3</span></code>, <code class="docutils literal notranslate"><span class="pre">6</span></code>, <code class="docutils literal notranslate"><span class="pre">10</span></code>, etc.) are considered aliases;
|
||
inverted flags are coerced to their positive equivalent.</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="fcntl">
|
||
<span id="whatsnew311-fcntl"></span><h3>fcntl<a class="headerlink" href="#fcntl" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>On FreeBSD, the <code class="xref py py-data docutils literal notranslate"><span class="pre">F_DUP2FD</span></code> and <code class="xref py py-data docutils literal notranslate"><span class="pre">F_DUP2FD_CLOEXEC</span></code> flags respectively
|
||
are supported, the former equals to <code class="docutils literal notranslate"><span class="pre">dup2</span></code> usage while the latter set
|
||
the <code class="docutils literal notranslate"><span class="pre">FD_CLOEXEC</span></code> flag in addition.</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="fractions">
|
||
<span id="whatsnew311-fractions"></span><h3>fractions<a class="headerlink" href="#fractions" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Support <span class="target" id="index-27"></span><a class="pep reference external" href="https://peps.python.org/pep-0515/"><strong>PEP 515</strong></a>-style initialization of <a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> from
|
||
string. (Contributed by Sergey B Kirpichev in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44258">bpo-44258</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> now implements an <code class="docutils literal notranslate"><span class="pre">__int__</span></code> method, so
|
||
that an <code class="docutils literal notranslate"><span class="pre">isinstance(some_fraction,</span> <span class="pre">typing.SupportsInt)</span></code> check passes.
|
||
(Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44547">bpo-44547</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="functools">
|
||
<span id="whatsnew311-functools"></span><h3>functools<a class="headerlink" href="#functools" title="Link to this heading">¶</a></h3>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="../library/functools.html#functools.singledispatch" title="functools.singledispatch"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.singledispatch()</span></code></a> now supports <a class="reference internal" href="../library/types.html#types.UnionType" title="types.UnionType"><code class="xref py py-data docutils literal notranslate"><span class="pre">types.UnionType</span></code></a>
|
||
and <a class="reference internal" href="../library/typing.html#typing.Union" title="typing.Union"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.Union</span></code></a> as annotations to the dispatch argument.:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span><span class="w"> </span><span class="nn">functools</span><span class="w"> </span><span class="kn">import</span> <span class="n">singledispatch</span>
|
||
<span class="gp">>>> </span><span class="nd">@singledispatch</span>
|
||
<span class="gp">... </span><span class="k">def</span><span class="w"> </span><span class="nf">fun</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">"Let me just say,"</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s2">" "</span><span class="p">)</span>
|
||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="nd">@fun</span><span class="o">.</span><span class="n">register</span>
|
||
<span class="gp">... </span><span class="k">def</span><span class="w"> </span><span class="nf">_</span><span class="p">(</span><span class="n">arg</span><span class="p">:</span> <span class="nb">int</span> <span class="o">|</span> <span class="nb">float</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">"Strength in numbers, eh?"</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s2">" "</span><span class="p">)</span>
|
||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="kn">from</span><span class="w"> </span><span class="nn">typing</span><span class="w"> </span><span class="kn">import</span> <span class="n">Union</span>
|
||
<span class="gp">>>> </span><span class="nd">@fun</span><span class="o">.</span><span class="n">register</span>
|
||
<span class="gp">... </span><span class="k">def</span><span class="w"> </span><span class="nf">_</span><span class="p">(</span><span class="n">arg</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">list</span><span class="p">,</span> <span class="nb">set</span><span class="p">],</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">"Enumerate this:"</span><span class="p">)</span>
|
||
<span class="gp">... </span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">elem</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">arg</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">elem</span><span class="p">)</span>
|
||
<span class="gp">...</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Yurii Karabas in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46014">bpo-46014</a>.)</p>
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
<section id="gzip">
|
||
<span id="whatsnew311-gzip"></span><h3>gzip<a class="headerlink" href="#gzip" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>The <a class="reference internal" href="../library/gzip.html#gzip.compress" title="gzip.compress"><code class="xref py py-func docutils literal notranslate"><span class="pre">gzip.compress()</span></code></a> function is now faster when used with the
|
||
<strong>mtime=0</strong> argument as it delegates the compression entirely to a single
|
||
<a class="reference internal" href="../library/zlib.html#zlib.compress" title="zlib.compress"><code class="xref py py-func docutils literal notranslate"><span class="pre">zlib.compress()</span></code></a> operation. There is one side effect of this change: The
|
||
gzip file header contains an “OS” byte in its header. That was traditionally
|
||
always set to a value of 255 representing “unknown” by the <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>
|
||
module. Now, when using <a class="reference internal" href="../library/gzip.html#gzip.compress" title="gzip.compress"><code class="xref py py-func docutils literal notranslate"><span class="pre">compress()</span></code></a> with <strong>mtime=0</strong>, it may be
|
||
set to a different value by the underlying zlib C library Python was linked
|
||
against.
|
||
(See <a class="reference external" href="https://github.com/python/cpython/issues/112346">gh-112346</a> for details on the side effect.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="hashlib">
|
||
<span id="whatsnew311-hashlib"></span><h3>hashlib<a class="headerlink" href="#hashlib" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/hashlib.html#hashlib.blake2b" title="hashlib.blake2b"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.blake2b()</span></code></a> and <a class="reference internal" href="../library/hashlib.html#hashlib.blake2s" title="hashlib.blake2s"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.blake2s()</span></code></a> now prefer <a class="reference external" href="https://www.blake2.net/">libb2</a>
|
||
over Python’s vendored copy.
|
||
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47095">bpo-47095</a>.)</p></li>
|
||
<li><p>The internal <code class="docutils literal notranslate"><span class="pre">_sha3</span></code> module with SHA3 and SHAKE algorithms now uses
|
||
<em>tiny_sha3</em> instead of the <em>Keccak Code Package</em> to reduce code and binary
|
||
size. The <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> module prefers optimized SHA3 and SHAKE
|
||
implementations from OpenSSL. The change affects only installations without
|
||
OpenSSL support.
|
||
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47098">bpo-47098</a>.)</p></li>
|
||
<li><p>Add <a class="reference internal" href="../library/hashlib.html#hashlib.file_digest" title="hashlib.file_digest"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.file_digest()</span></code></a>, a helper function for efficient hashing
|
||
of files or file-like objects.
|
||
(Contributed by Christian Heimes in <a class="reference external" href="https://github.com/python/cpython/issues/89313">gh-89313</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="whatsnew311-idle">
|
||
<span id="idle-and-idlelib"></span><h3>IDLE and idlelib<a class="headerlink" href="#whatsnew311-idle" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Apply syntax highlighting to <code class="docutils literal notranslate"><span class="pre">.pyi</span></code> files. (Contributed by Alex
|
||
Waygood and Terry Jan Reedy in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45447">bpo-45447</a>.)</p></li>
|
||
<li><p>Include prompts when saving Shell with inputs and outputs.
|
||
(Contributed by Terry Jan Reedy in <a class="reference external" href="https://github.com/python/cpython/issues/95191">gh-95191</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="inspect">
|
||
<span id="whatsnew311-inspect"></span><h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading">¶</a></h3>
|
||
<ul>
|
||
<li><p>Add <a class="reference internal" href="../library/inspect.html#inspect.getmembers_static" title="inspect.getmembers_static"><code class="xref py py-func docutils literal notranslate"><span class="pre">getmembers_static()</span></code></a> to return all members without
|
||
triggering dynamic lookup via the descriptor protocol. (Contributed by
|
||
Weipeng Hong in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=30533">bpo-30533</a>.)</p></li>
|
||
<li><p>Add <a class="reference internal" href="../library/inspect.html#inspect.ismethodwrapper" title="inspect.ismethodwrapper"><code class="xref py py-func docutils literal notranslate"><span class="pre">ismethodwrapper()</span></code></a>
|
||
for checking if the type of an object is a <a class="reference internal" href="../library/types.html#types.MethodWrapperType" title="types.MethodWrapperType"><code class="xref py py-class docutils literal notranslate"><span class="pre">MethodWrapperType</span></code></a>.
|
||
(Contributed by Hakan Çelik in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=29418">bpo-29418</a>.)</p></li>
|
||
<li><p>Change the frame-related functions in the <a class="reference internal" href="../library/inspect.html#module-inspect" title="inspect: Extract information and source code from live objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">inspect</span></code></a> module to return new
|
||
<a class="reference internal" href="../library/inspect.html#inspect.FrameInfo" title="inspect.FrameInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">FrameInfo</span></code></a> and <a class="reference internal" href="../library/inspect.html#inspect.Traceback" title="inspect.Traceback"><code class="xref py py-class docutils literal notranslate"><span class="pre">Traceback</span></code></a> class instances
|
||
(backwards compatible with the previous <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named tuple</span></a>-like interfaces)
|
||
that includes the extended <span class="target" id="index-28"></span><a class="pep reference external" href="https://peps.python.org/pep-0657/"><strong>PEP 657</strong></a> position information (end
|
||
line number, column and end column). The affected functions are:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/inspect.html#inspect.getframeinfo" title="inspect.getframeinfo"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getframeinfo()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/inspect.html#inspect.getouterframes" title="inspect.getouterframes"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getouterframes()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/inspect.html#inspect.getinnerframes" title="inspect.getinnerframes"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getinnerframes()</span></code></a>,</p></li>
|
||
<li><p><a class="reference internal" href="../library/inspect.html#inspect.stack" title="inspect.stack"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.stack()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/inspect.html#inspect.trace" title="inspect.trace"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.trace()</span></code></a></p></li>
|
||
</ul>
|
||
<p>(Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/88116">gh-88116</a>.)</p>
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
<section id="locale">
|
||
<span id="whatsnew311-locale"></span><h3>locale<a class="headerlink" href="#locale" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Add <a class="reference internal" href="../library/locale.html#locale.getencoding" title="locale.getencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getencoding()</span></code></a> to get the current locale encoding. It is similar to
|
||
<code class="docutils literal notranslate"><span class="pre">locale.getpreferredencoding(False)</span></code> but ignores the
|
||
<a class="reference internal" href="../library/os.html#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a>.</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="logging">
|
||
<span id="whatsnew311-logging"></span><h3>logging<a class="headerlink" href="#logging" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Added <a class="reference internal" href="../library/logging.html#logging.getLevelNamesMapping" title="logging.getLevelNamesMapping"><code class="xref py py-func docutils literal notranslate"><span class="pre">getLevelNamesMapping()</span></code></a>
|
||
to return a mapping from logging level names (e.g. <code class="docutils literal notranslate"><span class="pre">'CRITICAL'</span></code>)
|
||
to the values of their corresponding <a class="reference internal" href="../library/logging.html#levels"><span class="std std-ref">Logging Levels</span></a> (e.g. <code class="docutils literal notranslate"><span class="pre">50</span></code>, by default).
|
||
(Contributed by Andrei Kulakovin in <a class="reference external" href="https://github.com/python/cpython/issues/88024">gh-88024</a>.)</p></li>
|
||
<li><p>Added a <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SysLogHandler.createSocket" title="logging.handlers.SysLogHandler.createSocket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">createSocket()</span></code></a> method
|
||
to <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SysLogHandler" title="logging.handlers.SysLogHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SysLogHandler</span></code></a>, to match
|
||
<a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SocketHandler.createSocket" title="logging.handlers.SocketHandler.createSocket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SocketHandler.createSocket()</span></code></a>.
|
||
It is called automatically during handler initialization
|
||
and when emitting an event, if there is no active socket.
|
||
(Contributed by Kirill Pinchuk in <a class="reference external" href="https://github.com/python/cpython/issues/88457">gh-88457</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="math">
|
||
<span id="whatsnew311-math"></span><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.exp2" title="math.exp2"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.exp2()</span></code></a>: return 2 raised to the power of x.
|
||
(Contributed by Gideon Mitchell in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45917">bpo-45917</a>.)</p></li>
|
||
<li><p>Add <a class="reference internal" href="../library/math.html#math.cbrt" title="math.cbrt"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.cbrt()</span></code></a>: return the cube root of x.
|
||
(Contributed by Ajith Ramachandran in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44357">bpo-44357</a>.)</p></li>
|
||
<li><p>The behaviour of two <a class="reference internal" href="../library/math.html#math.pow" title="math.pow"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.pow()</span></code></a> corner cases was changed, for
|
||
consistency with the IEEE 754 specification. The operations
|
||
<code class="docutils literal notranslate"><span class="pre">math.pow(0.0,</span> <span class="pre">-math.inf)</span></code> and <code class="docutils literal notranslate"><span class="pre">math.pow(-0.0,</span> <span class="pre">-math.inf)</span></code> now return
|
||
<code class="docutils literal notranslate"><span class="pre">inf</span></code>. Previously they raised <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>. (Contributed by Mark
|
||
Dickinson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44339">bpo-44339</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/math.html#math.nan" title="math.nan"><code class="xref py py-data docutils literal notranslate"><span class="pre">math.nan</span></code></a> value is now always available.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46917">bpo-46917</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="operator">
|
||
<span id="whatsnew311-operator"></span><h3>operator<a class="headerlink" href="#operator" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>A new function <code class="docutils literal notranslate"><span class="pre">operator.call</span></code> has been added, such that
|
||
<code class="docutils literal notranslate"><span class="pre">operator.call(obj,</span> <span class="pre">*args,</span> <span class="pre">**kwargs)</span> <span class="pre">==</span> <span class="pre">obj(*args,</span> <span class="pre">**kwargs)</span></code>.
|
||
(Contributed by Antony Lee in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44019">bpo-44019</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="os">
|
||
<span id="whatsnew311-os"></span><h3>os<a class="headerlink" href="#os" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>On Windows, <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> now uses <code class="docutils literal notranslate"><span class="pre">BCryptGenRandom()</span></code>,
|
||
instead of <code class="docutils literal notranslate"><span class="pre">CryptGenRandom()</span></code> which is deprecated.
|
||
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44611">bpo-44611</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="pathlib">
|
||
<span id="whatsnew311-pathlib"></span><h3>pathlib<a class="headerlink" href="#pathlib" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/pathlib.html#pathlib.Path.glob" title="pathlib.Path.glob"><code class="xref py py-meth docutils literal notranslate"><span class="pre">glob()</span></code></a> and <a class="reference internal" href="../library/pathlib.html#pathlib.Path.rglob" title="pathlib.Path.rglob"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rglob()</span></code></a> return only
|
||
directories if <em>pattern</em> ends with a pathname components separator:
|
||
<a class="reference internal" href="../library/os.html#os.sep" title="os.sep"><code class="xref py py-data docutils literal notranslate"><span class="pre">sep</span></code></a> or <a class="reference internal" href="../library/os.html#os.altsep" title="os.altsep"><code class="xref py py-data docutils literal notranslate"><span class="pre">altsep</span></code></a>.
|
||
(Contributed by Eisuke Kawasima in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=22276">bpo-22276</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33392">bpo-33392</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="re">
|
||
<span id="whatsnew311-re"></span><h3>re<a class="headerlink" href="#re" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Atomic grouping (<code class="docutils literal notranslate"><span class="pre">(?>...)</span></code>) and possessive quantifiers (<code class="docutils literal notranslate"><span class="pre">*+</span></code>, <code class="docutils literal notranslate"><span class="pre">++</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">?+</span></code>, <code class="docutils literal notranslate"><span class="pre">{m,n}+</span></code>) are now supported in regular expressions.
|
||
(Contributed by Jeffrey C. Jacobs and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=433030">bpo-433030</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="shutil">
|
||
<span id="whatsnew311-shutil"></span><h3>shutil<a class="headerlink" href="#shutil" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Add optional parameter <em>dir_fd</em> in <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>.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46245">bpo-46245</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="socket">
|
||
<span id="whatsnew311-socket"></span><h3>socket<a class="headerlink" href="#socket" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Add CAN Socket support for NetBSD.
|
||
(Contributed by Thomas Klausner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=30512">bpo-30512</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/socket.html#socket.create_connection" title="socket.create_connection"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_connection()</span></code></a> has an option to raise, in case of
|
||
failure to connect, 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> containing all errors
|
||
instead of only raising the last error.
|
||
(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=29980">bpo-29980</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="sqlite3">
|
||
<span id="whatsnew311-sqlite3"></span><h3>sqlite3<a class="headerlink" href="#sqlite3" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>You can now disable the authorizer by passing <a class="reference internal" href="../library/constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> to
|
||
<a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.set_authorizer" title="sqlite3.Connection.set_authorizer"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_authorizer()</span></code></a>.
|
||
(Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44491">bpo-44491</a>.)</p></li>
|
||
<li><p>Collation name <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.create_collation" title="sqlite3.Connection.create_collation"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_collation()</span></code></a> can now
|
||
contain any Unicode character. Collation names with invalid characters
|
||
now raise <a class="reference internal" href="../library/exceptions.html#UnicodeEncodeError" title="UnicodeEncodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeEncodeError</span></code></a> instead of <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">sqlite3.ProgrammingError</span></code></a>.
|
||
(Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44688">bpo-44688</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> exceptions now include the SQLite extended error code as
|
||
<a class="reference internal" href="../library/sqlite3.html#sqlite3.Error.sqlite_errorcode" title="sqlite3.Error.sqlite_errorcode"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sqlite_errorcode</span></code></a> and the SQLite error name as
|
||
<a class="reference internal" href="../library/sqlite3.html#sqlite3.Error.sqlite_errorname" title="sqlite3.Error.sqlite_errorname"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sqlite_errorname</span></code></a>.
|
||
(Contributed by Aviv Palivoda, Daniel Shahaf, and Erlend E. Aasland in
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=16379">bpo-16379</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24139">bpo-24139</a>.)</p></li>
|
||
<li><p>Add <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.setlimit" title="sqlite3.Connection.setlimit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setlimit()</span></code></a> and
|
||
<a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.getlimit" title="sqlite3.Connection.getlimit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getlimit()</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> for
|
||
setting and getting SQLite limits by connection basis.
|
||
(Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45243">bpo-45243</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> now sets <a class="reference internal" href="../library/sqlite3.html#sqlite3.threadsafety" title="sqlite3.threadsafety"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sqlite3.threadsafety</span></code></a> based on the default
|
||
threading mode the underlying SQLite library has been compiled with.
|
||
(Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45613">bpo-45613</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> C callbacks now use unraisable exceptions if callback
|
||
tracebacks are enabled. Users can now register an
|
||
<a class="reference internal" href="../library/sys.html#sys.unraisablehook" title="sys.unraisablehook"><code class="xref py py-func docutils literal notranslate"><span class="pre">unraisable</span> <span class="pre">hook</span> <span class="pre">handler</span></code></a> to improve their debug
|
||
experience.
|
||
(Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45828">bpo-45828</a>.)</p></li>
|
||
<li><p>Fetch across rollback no longer raises <a class="reference internal" href="../library/sqlite3.html#sqlite3.InterfaceError" title="sqlite3.InterfaceError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterfaceError</span></code></a>.
|
||
Instead we leave it to the SQLite library to handle these cases.
|
||
(Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44092">bpo-44092</a>.)</p></li>
|
||
<li><p>Add <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.serialize" title="sqlite3.Connection.serialize"><code class="xref py py-meth docutils literal notranslate"><span class="pre">serialize()</span></code></a> and
|
||
<a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.deserialize" title="sqlite3.Connection.deserialize"><code class="xref py py-meth docutils literal notranslate"><span class="pre">deserialize()</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> for
|
||
serializing and deserializing databases.
|
||
(Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=41930">bpo-41930</a>.)</p></li>
|
||
<li><p>Add <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.create_window_function" title="sqlite3.Connection.create_window_function"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_window_function()</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> for creating aggregate window functions.
|
||
(Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34916">bpo-34916</a>.)</p></li>
|
||
<li><p>Add <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.blobopen" title="sqlite3.Connection.blobopen"><code class="xref py py-meth docutils literal notranslate"><span class="pre">blobopen()</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>.
|
||
<a class="reference internal" href="../library/sqlite3.html#sqlite3.Blob" title="sqlite3.Blob"><code class="xref py py-class docutils literal notranslate"><span class="pre">sqlite3.Blob</span></code></a> allows incremental I/O operations on blobs.
|
||
(Contributed by Aviv Palivoda and Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24905">bpo-24905</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="string">
|
||
<span id="whatsnew311-string"></span><h3>string<a class="headerlink" href="#string" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Add <a class="reference internal" href="../library/string.html#string.Template.get_identifiers" title="string.Template.get_identifiers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_identifiers()</span></code></a>
|
||
and <a class="reference internal" href="../library/string.html#string.Template.is_valid" title="string.Template.is_valid"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_valid()</span></code></a> to <a class="reference internal" href="../library/string.html#string.Template" title="string.Template"><code class="xref py py-class docutils literal notranslate"><span class="pre">string.Template</span></code></a>,
|
||
which respectively return all valid placeholders,
|
||
and whether any invalid placeholders are present.
|
||
(Contributed by Ben Kehoe in <a class="reference external" href="https://github.com/python/cpython/issues/90465">gh-90465</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="sys">
|
||
<span id="whatsnew311-sys"></span><h3>sys<a class="headerlink" href="#sys" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a> now derives the <code class="docutils literal notranslate"><span class="pre">type</span></code> and <code class="docutils literal notranslate"><span class="pre">traceback</span></code> fields
|
||
from the <code class="docutils literal notranslate"><span class="pre">value</span></code> (the exception instance), so when an exception is
|
||
modified while it is being handled, the changes are reflected in
|
||
the results of subsequent calls to <code class="xref py py-func docutils literal notranslate"><span class="pre">exc_info()</span></code>.
|
||
(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45711">bpo-45711</a>.)</p></li>
|
||
<li><p>Add <a class="reference internal" href="../library/sys.html#sys.exception" title="sys.exception"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exception()</span></code></a> which returns the active exception instance
|
||
(equivalent to <code class="docutils literal notranslate"><span class="pre">sys.exc_info()[1]</span></code>).
|
||
(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46328">bpo-46328</a>.)</p></li>
|
||
<li><p>Add the <a class="reference internal" href="../library/sys.html#sys.flags" title="sys.flags"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.flags.safe_path</span></code></a> flag.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/57684">gh-57684</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="sysconfig">
|
||
<span id="whatsnew311-sysconfig"></span><h3>sysconfig<a class="headerlink" href="#sysconfig" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Three new <a class="reference internal" href="../library/sysconfig.html#installation-paths"><span class="std std-ref">installation schemes</span></a>
|
||
(<em>posix_venv</em>, <em>nt_venv</em> and <em>venv</em>) were added and are used when Python
|
||
creates new virtual environments or when it is running from a virtual
|
||
environment.
|
||
The first two schemes (<em>posix_venv</em> and <em>nt_venv</em>) are OS-specific
|
||
for non-Windows and Windows, the <em>venv</em> is essentially an alias to one of
|
||
them according to the OS Python runs on.
|
||
This is useful for downstream distributors who modify
|
||
<a class="reference internal" href="../library/sysconfig.html#sysconfig.get_preferred_scheme" title="sysconfig.get_preferred_scheme"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconfig.get_preferred_scheme()</span></code></a>.
|
||
Third party code that creates new virtual environments should use the new
|
||
<em>venv</em> installation scheme to determine the paths, as does <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>.
|
||
(Contributed by Miro Hrončok in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45413">bpo-45413</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="tempfile">
|
||
<span id="whatsnew311-tempfile"></span><h3>tempfile<a class="headerlink" href="#tempfile" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/tempfile.html#tempfile.SpooledTemporaryFile" title="tempfile.SpooledTemporaryFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpooledTemporaryFile</span></code></a> objects now fully implement the methods
|
||
of <a class="reference internal" href="../library/io.html#io.BufferedIOBase" title="io.BufferedIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.BufferedIOBase</span></code></a> or <a class="reference internal" href="../library/io.html#io.TextIOBase" title="io.TextIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.TextIOBase</span></code></a>
|
||
(depending on file mode).
|
||
This lets them work correctly with APIs that expect file-like objects,
|
||
such as compression modules.
|
||
(Contributed by Carey Metcalfe in <a class="reference external" href="https://github.com/python/cpython/issues/70363">gh-70363</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="threading">
|
||
<span id="whatsnew311-threading"></span><h3>threading<a class="headerlink" href="#threading" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>On Unix, if the <code class="docutils literal notranslate"><span class="pre">sem_clockwait()</span></code> function is available in the C library
|
||
(glibc 2.30 and newer), the <a class="reference internal" href="../library/threading.html#threading.Lock.acquire" title="threading.Lock.acquire"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Lock.acquire()</span></code></a> method now uses
|
||
the monotonic clock (<a class="reference internal" href="../library/time.html#time.CLOCK_MONOTONIC" title="time.CLOCK_MONOTONIC"><code class="xref py py-const docutils literal notranslate"><span class="pre">time.CLOCK_MONOTONIC</span></code></a>) for the timeout, rather
|
||
than using the system clock (<a class="reference internal" href="../library/time.html#time.CLOCK_REALTIME" title="time.CLOCK_REALTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">time.CLOCK_REALTIME</span></code></a>), to not be affected
|
||
by system clock changes.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=41710">bpo-41710</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="time">
|
||
<span id="whatsnew311-time"></span><h3>time<a class="headerlink" href="#time" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>On Unix, <a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.sleep()</span></code></a> now uses the <code class="docutils literal notranslate"><span class="pre">clock_nanosleep()</span></code> or
|
||
<code class="docutils literal notranslate"><span class="pre">nanosleep()</span></code> function, if available, which has a resolution of 1 nanosecond
|
||
(10<sup>-9</sup> seconds), rather than using <code class="docutils literal notranslate"><span class="pre">select()</span></code> which has a resolution
|
||
of 1 microsecond (10<sup>-6</sup> seconds).
|
||
(Contributed by Benjamin Szőke and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=21302">bpo-21302</a>.)</p></li>
|
||
<li><p>On Windows 8.1 and newer, <a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.sleep()</span></code></a> now uses a waitable timer based
|
||
on <a class="reference external" href="https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/high-resolution-timers">high-resolution timers</a>
|
||
which has a resolution of 100 nanoseconds (10<sup>-7</sup> seconds). Previously,
|
||
it had a resolution of 1 millisecond (10<sup>-3</sup> seconds).
|
||
(Contributed by Benjamin Szőke, Donghee Na, Eryk Sun and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=21302">bpo-21302</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45429">bpo-45429</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="tkinter">
|
||
<span id="whatsnew311-tkinter"></span><h3>tkinter<a class="headerlink" href="#tkinter" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Added method <code class="docutils literal notranslate"><span class="pre">info_patchlevel()</span></code> which returns the exact version of
|
||
the Tcl library as a named tuple similar to <a class="reference internal" href="../library/sys.html#sys.version_info" title="sys.version_info"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.version_info</span></code></a>.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/91827">gh-91827</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="traceback">
|
||
<span id="whatsnew311-traceback"></span><h3>traceback<a class="headerlink" href="#traceback" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Add <a class="reference internal" href="../library/traceback.html#traceback.StackSummary.format_frame_summary" title="traceback.StackSummary.format_frame_summary"><code class="xref py py-func docutils literal notranslate"><span class="pre">traceback.StackSummary.format_frame_summary()</span></code></a> to allow users
|
||
to override which frames appear in the traceback, and how they are
|
||
formatted.
|
||
(Contributed by Ammar Askar in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44569">bpo-44569</a>.)</p></li>
|
||
<li><p>Add <a class="reference internal" href="../library/traceback.html#traceback.TracebackException.print" title="traceback.TracebackException.print"><code class="xref py py-func docutils literal notranslate"><span class="pre">traceback.TracebackException.print()</span></code></a>, which prints the
|
||
formatted <a class="reference internal" href="../library/traceback.html#traceback.TracebackException" title="traceback.TracebackException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TracebackException</span></code></a> instance to a file.
|
||
(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33809">bpo-33809</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="typing">
|
||
<span id="whatsnew311-typing"></span><h3>typing<a class="headerlink" href="#typing" title="Link to this heading">¶</a></h3>
|
||
<p>For major changes, see <a class="reference internal" href="#new-feat-related-type-hints-311"><span class="std std-ref">New Features Related to Type Hints</span></a>.</p>
|
||
<ul class="simple">
|
||
<li><p>Add <a class="reference internal" href="../library/typing.html#typing.assert_never" title="typing.assert_never"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.assert_never()</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.Never" title="typing.Never"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Never</span></code></a>.
|
||
<a class="reference internal" href="../library/typing.html#typing.assert_never" title="typing.assert_never"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.assert_never()</span></code></a> is useful for asking a type checker to confirm
|
||
that a line of code is not reachable. At runtime, it raises an
|
||
<a class="reference internal" href="../library/exceptions.html#AssertionError" title="AssertionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AssertionError</span></code></a>.
|
||
(Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/90633">gh-90633</a>.)</p></li>
|
||
<li><p>Add <a class="reference internal" href="../library/typing.html#typing.reveal_type" title="typing.reveal_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.reveal_type()</span></code></a>. This is useful for asking a type checker
|
||
what type it has inferred for a given expression. At runtime it prints
|
||
the type of the received value.
|
||
(Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/90572">gh-90572</a>.)</p></li>
|
||
<li><p>Add <a class="reference internal" href="../library/typing.html#typing.assert_type" title="typing.assert_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.assert_type()</span></code></a>. This is useful for asking a type checker
|
||
to confirm that the type it has inferred for a given expression matches
|
||
the given type. At runtime it simply returns the received value.
|
||
(Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/90638">gh-90638</a>.)</p></li>
|
||
<li><p><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> types can now be generic. (Contributed by
|
||
Samodya Abeysiriwardane in <a class="reference external" href="https://github.com/python/cpython/issues/89026">gh-89026</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/typing.html#typing.NamedTuple" title="typing.NamedTuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">NamedTuple</span></code></a> types can now be generic.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43923">bpo-43923</a>.)</p></li>
|
||
<li><p>Allow subclassing of <a class="reference internal" href="../library/typing.html#typing.Any" title="typing.Any"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Any</span></code></a>. This is useful for avoiding
|
||
type checker errors related to highly dynamic class, such as mocks.
|
||
(Contributed by Shantanu Jain in <a class="reference external" href="https://github.com/python/cpython/issues/91154">gh-91154</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/typing.html#typing.final" title="typing.final"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.final()</span></code></a> decorator now sets the <code class="docutils literal notranslate"><span class="pre">__final__</span></code> attributed on
|
||
the decorated object.
|
||
(Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/90500">gh-90500</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/typing.html#typing.get_overloads" title="typing.get_overloads"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_overloads()</span></code></a> function can be used for introspecting
|
||
the overloads of a function. <a class="reference internal" href="../library/typing.html#typing.clear_overloads" title="typing.clear_overloads"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.clear_overloads()</span></code></a> can be used
|
||
to clear all registered overloads of a function.
|
||
(Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/89263">gh-89263</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../reference/datamodel.html#object.__init__" title="object.__init__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code></a> method of <a class="reference internal" href="../library/typing.html#typing.Protocol" title="typing.Protocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">Protocol</span></code></a> subclasses
|
||
is now preserved. (Contributed by Adrian Garcia Badarasco in <a class="reference external" href="https://github.com/python/cpython/issues/88970">gh-88970</a>.)</p></li>
|
||
<li><p>The representation of empty tuple types (<code class="docutils literal notranslate"><span class="pre">Tuple[()]</span></code>) is simplified.
|
||
This affects introspection, e.g. <code class="docutils literal notranslate"><span class="pre">get_args(Tuple[()])</span></code> now evaluates
|
||
to <code class="docutils literal notranslate"><span class="pre">()</span></code> instead of <code class="docutils literal notranslate"><span class="pre">((),)</span></code>.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/91137">gh-91137</a>.)</p></li>
|
||
<li><p>Loosen runtime requirements for type annotations by removing the callable
|
||
check in the private <code class="docutils literal notranslate"><span class="pre">typing._type_check</span></code> function. (Contributed by
|
||
Gregory Beauregard in <a class="reference external" href="https://github.com/python/cpython/issues/90802">gh-90802</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/typing.html#typing.get_type_hints" title="typing.get_type_hints"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_type_hints()</span></code></a> now supports evaluating strings as forward
|
||
references in <a class="reference internal" href="../library/stdtypes.html#types-genericalias"><span class="std std-ref">PEP 585 generic aliases</span></a>.
|
||
(Contributed by Niklas Rosenstein in <a class="reference external" href="https://github.com/python/cpython/issues/85542">gh-85542</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/typing.html#typing.get_type_hints" title="typing.get_type_hints"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_type_hints()</span></code></a> no longer adds <a class="reference internal" href="../library/typing.html#typing.Optional" title="typing.Optional"><code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code></a>
|
||
to parameters with <code class="docutils literal notranslate"><span class="pre">None</span></code> as a default. (Contributed by Nikita Sobolev
|
||
in <a class="reference external" href="https://github.com/python/cpython/issues/90353">gh-90353</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/typing.html#typing.get_type_hints" title="typing.get_type_hints"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_type_hints()</span></code></a> now supports evaluating bare stringified
|
||
<a class="reference internal" href="../library/typing.html#typing.ClassVar" title="typing.ClassVar"><code class="xref py py-data docutils literal notranslate"><span class="pre">ClassVar</span></code></a> annotations. (Contributed by Gregory Beauregard
|
||
in <a class="reference external" href="https://github.com/python/cpython/issues/90711">gh-90711</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/typing.html#typing.no_type_check" title="typing.no_type_check"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.no_type_check()</span></code></a> no longer modifies external classes and functions.
|
||
It also now correctly marks classmethods as not to be type checked. (Contributed
|
||
by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/90729">gh-90729</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="unicodedata">
|
||
<span id="whatsnew311-unicodedata"></span><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 14.0.0.
|
||
(Contributed by Benjamin Peterson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45190">bpo-45190</a>).</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="unittest">
|
||
<span id="whatsnew311-unittest"></span><h3>unittest<a class="headerlink" href="#unittest" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Added methods <a class="reference internal" href="../library/unittest.html#unittest.TestCase.enterContext" title="unittest.TestCase.enterContext"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enterContext()</span></code></a> and
|
||
<a class="reference internal" href="../library/unittest.html#unittest.TestCase.enterClassContext" title="unittest.TestCase.enterClassContext"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enterClassContext()</span></code></a> of class
|
||
<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
|
||
<a class="reference internal" href="../library/unittest.html#unittest.IsolatedAsyncioTestCase.enterAsyncContext" title="unittest.IsolatedAsyncioTestCase.enterAsyncContext"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enterAsyncContext()</span></code></a> of
|
||
class <a class="reference internal" href="../library/unittest.html#unittest.IsolatedAsyncioTestCase" title="unittest.IsolatedAsyncioTestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">IsolatedAsyncioTestCase</span></code></a> and function
|
||
<a class="reference internal" href="../library/unittest.html#unittest.enterModuleContext" title="unittest.enterModuleContext"><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.enterModuleContext()</span></code></a>.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45046">bpo-45046</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="venv">
|
||
<span id="whatsnew311-venv"></span><h3>venv<a class="headerlink" href="#venv" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>When new Python virtual environments are created, the <em>venv</em>
|
||
<a class="reference internal" href="../library/sysconfig.html#installation-paths"><span class="std std-ref">sysconfig installation scheme</span></a> is used
|
||
to determine the paths inside the environment.
|
||
When Python runs in a virtual environment, the same installation scheme
|
||
is the default.
|
||
That means that downstream distributors can change the default sysconfig install
|
||
scheme without changing behavior of virtual environments.
|
||
Third party code that also creates new virtual environments should do the same.
|
||
(Contributed by Miro Hrončok in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45413">bpo-45413</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="warnings">
|
||
<span id="whatsnew311-warnings"></span><h3>warnings<a class="headerlink" href="#warnings" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p><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> now accepts arguments for <a class="reference internal" href="../library/warnings.html#warnings.simplefilter" title="warnings.simplefilter"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.simplefilter()</span></code></a>,
|
||
providing a more concise way to locally ignore warnings or convert them to errors.
|
||
(Contributed by Zac Hatfield-Dodds in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47074">bpo-47074</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="zipfile">
|
||
<span id="whatsnew311-zipfile"></span><h3>zipfile<a class="headerlink" href="#zipfile" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Added support for specifying member name encoding for reading metadata
|
||
in a <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile" title="zipfile.ZipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">ZipFile</span></code></a>’s directory and file headers.
|
||
(Contributed by Stephen J. Turnbull and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28080">bpo-28080</a>.)</p></li>
|
||
<li><p>Added <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile.mkdir" title="zipfile.ZipFile.mkdir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ZipFile.mkdir()</span></code></a>
|
||
for creating new directories inside ZIP archives.
|
||
(Contributed by Sam Ezeh in <a class="reference external" href="https://github.com/python/cpython/issues/49083">gh-49083</a>.)</p></li>
|
||
<li><p>Added <a class="reference internal" href="../library/zipfile.html#zipfile.Path.stem" title="zipfile.Path.stem"><code class="xref py py-attr docutils literal notranslate"><span class="pre">stem</span></code></a>, <a class="reference internal" href="../library/zipfile.html#zipfile.Path.suffix" title="zipfile.Path.suffix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">suffix</span></code></a>
|
||
and <a class="reference internal" href="../library/zipfile.html#zipfile.Path.suffixes" title="zipfile.Path.suffixes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">suffixes</span></code></a> to <a class="reference internal" href="../library/zipfile.html#zipfile.Path" title="zipfile.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">zipfile.Path</span></code></a>.
|
||
(Contributed by Miguel Brito in <a class="reference external" href="https://github.com/python/cpython/issues/88261">gh-88261</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
</section>
|
||
<section id="optimizations">
|
||
<span id="whatsnew311-optimizations"></span><h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading">¶</a></h2>
|
||
<p>This section covers specific optimizations independent of the
|
||
<a class="reference internal" href="#whatsnew311-faster-cpython"><span class="std std-ref">Faster CPython</span></a> project, which is covered in its own section.</p>
|
||
<ul class="simple">
|
||
<li><p>The compiler now optimizes simple
|
||
<a class="reference internal" href="../library/stdtypes.html#old-string-formatting"><span class="std std-ref">printf-style % formatting</span></a> on string literals
|
||
containing only the format codes <code class="docutils literal notranslate"><span class="pre">%s</span></code>, <code class="docutils literal notranslate"><span class="pre">%r</span></code> and <code class="docutils literal notranslate"><span class="pre">%a</span></code> and makes it as
|
||
fast as a corresponding <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-string</span></a> expression.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28307">bpo-28307</a>.)</p></li>
|
||
<li><p>Integer division (<code class="docutils literal notranslate"><span class="pre">//</span></code>) is better tuned for optimization by compilers.
|
||
It is now around 20% faster on x86-64 when dividing an <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>
|
||
by a value smaller than <code class="docutils literal notranslate"><span class="pre">2**30</span></code>.
|
||
(Contributed by Gregory P. Smith and Tim Peters in <a class="reference external" href="https://github.com/python/cpython/issues/90564">gh-90564</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> is now nearly 30% faster for integers smaller than <code class="docutils literal notranslate"><span class="pre">2**30</span></code>.
|
||
(Contributed by Stefan Behnel in <a class="reference external" href="https://github.com/python/cpython/issues/68264">gh-68264</a>.)</p></li>
|
||
<li><p>Resizing lists is streamlined for the common case,
|
||
speeding up <code class="xref py py-meth docutils literal notranslate"><span class="pre">list.append()</span></code> by ≈15%
|
||
and simple <a class="reference internal" href="../glossary.html#term-list-comprehension"><span class="xref std std-term">list comprehension</span></a>s by up to 20-30%
|
||
(Contributed by Dennis Sweeney in <a class="reference external" href="https://github.com/python/cpython/issues/91165">gh-91165</a>.)</p></li>
|
||
<li><p>Dictionaries don’t store hash values when all keys are Unicode objects,
|
||
decreasing <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> size.
|
||
For example, <code class="docutils literal notranslate"><span class="pre">sys.getsizeof(dict.fromkeys("abcdefg"))</span></code>
|
||
is reduced from 352 bytes to 272 bytes (23% smaller) on 64-bit platforms.
|
||
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46845">bpo-46845</a>.)</p></li>
|
||
<li><p>Using <a class="reference internal" href="../library/asyncio-protocol.html#asyncio.DatagramProtocol" title="asyncio.DatagramProtocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.DatagramProtocol</span></code></a> is now orders of magnitude faster
|
||
when transferring large files over UDP,
|
||
with speeds over 100 times higher for a ≈60 MiB file.
|
||
(Contributed by msoxzw in <a class="reference external" href="https://github.com/python/cpython/issues/91487">gh-91487</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/math.html#module-math" title="math: Mathematical functions (sin() etc.)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">math</span></code></a> functions <a class="reference internal" href="../library/math.html#math.comb" title="math.comb"><code class="xref py py-func docutils literal notranslate"><span class="pre">comb()</span></code></a> and <a class="reference internal" href="../library/math.html#math.perm" title="math.perm"><code class="xref py py-func docutils literal notranslate"><span class="pre">perm()</span></code></a> are now
|
||
≈10 times faster for large arguments (with a larger speedup for larger <em>k</em>).
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37295">bpo-37295</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/statistics.html#module-statistics" title="statistics: Mathematical statistics functions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">statistics</span></code></a> functions <a class="reference internal" href="../library/statistics.html#statistics.mean" title="statistics.mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">mean()</span></code></a>,
|
||
<a class="reference internal" href="../library/statistics.html#statistics.variance" title="statistics.variance"><code class="xref py py-func docutils literal notranslate"><span class="pre">variance()</span></code></a> and <a class="reference internal" href="../library/statistics.html#statistics.stdev" title="statistics.stdev"><code class="xref py py-func docutils literal notranslate"><span class="pre">stdev()</span></code></a> now consume
|
||
iterators in one pass rather than converting them to a <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> first.
|
||
This is twice as fast and can save substantial memory.
|
||
(Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/90415">gh-90415</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/unicodedata.html#unicodedata.normalize" title="unicodedata.normalize"><code class="xref py py-func docutils literal notranslate"><span class="pre">unicodedata.normalize()</span></code></a>
|
||
now normalizes pure-ASCII strings in constant time.
|
||
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44987">bpo-44987</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="faster-cpython">
|
||
<span id="whatsnew311-faster-cpython"></span><h2>Faster CPython<a class="headerlink" href="#faster-cpython" title="Link to this heading">¶</a></h2>
|
||
<p>CPython 3.11 is an average of
|
||
<a class="reference external" href="https://github.com/faster-cpython/ideas#published-results">25% faster</a>
|
||
than CPython 3.10 as measured with the
|
||
<a class="reference external" href="https://github.com/python/pyperformance">pyperformance</a> benchmark suite,
|
||
when compiled with GCC on Ubuntu Linux.
|
||
Depending on your workload, the overall speedup could be 10-60%.</p>
|
||
<p>This project focuses on two major areas in Python:
|
||
<a class="reference internal" href="#whatsnew311-faster-startup"><span class="std std-ref">Faster Startup</span></a> and <a class="reference internal" href="#whatsnew311-faster-runtime"><span class="std std-ref">Faster Runtime</span></a>.
|
||
Optimizations not covered by this project are listed separately under
|
||
<a class="reference internal" href="#whatsnew311-optimizations"><span class="std std-ref">Optimizations</span></a>.</p>
|
||
<section id="faster-startup">
|
||
<span id="whatsnew311-faster-startup"></span><h3>Faster Startup<a class="headerlink" href="#faster-startup" title="Link to this heading">¶</a></h3>
|
||
<section id="frozen-imports-static-code-objects">
|
||
<span id="whatsnew311-faster-imports"></span><h4>Frozen imports / Static code objects<a class="headerlink" href="#frozen-imports-static-code-objects" title="Link to this heading">¶</a></h4>
|
||
<p>Python caches <a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a> in the <a class="reference internal" href="../tutorial/modules.html#tut-pycache"><span class="std std-ref">__pycache__</span></a>
|
||
directory to speed up module loading.</p>
|
||
<p>Previously in 3.10, Python module execution looked like this:</p>
|
||
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
|
||
</pre></div>
|
||
</div>
|
||
<p>In Python 3.11, the core modules essential for Python startup are “frozen”.
|
||
This means that their <a class="reference internal" href="../c-api/code.html#codeobjects"><span class="std std-ref">Code Objects</span></a> (and bytecode)
|
||
are statically allocated by the interpreter.
|
||
This reduces the steps in module execution process to:</p>
|
||
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>Statically allocated code object -> Evaluate
|
||
</pre></div>
|
||
</div>
|
||
<p>Interpreter startup is now 10-15% faster in Python 3.11. This has a big
|
||
impact for short-running programs using Python.</p>
|
||
<p>(Contributed by Eric Snow, Guido van Rossum and Kumar Aditya in many issues.)</p>
|
||
</section>
|
||
</section>
|
||
<section id="faster-runtime">
|
||
<span id="whatsnew311-faster-runtime"></span><h3>Faster Runtime<a class="headerlink" href="#faster-runtime" title="Link to this heading">¶</a></h3>
|
||
<section id="cheaper-lazy-python-frames">
|
||
<span id="whatsnew311-lazy-python-frames"></span><h4>Cheaper, lazy Python frames<a class="headerlink" href="#cheaper-lazy-python-frames" title="Link to this heading">¶</a></h4>
|
||
<p>Python frames, holding execution information,
|
||
are created whenever Python calls a Python function.
|
||
The following are new frame optimizations:</p>
|
||
<ul class="simple">
|
||
<li><p>Streamlined the frame creation process.</p></li>
|
||
<li><p>Avoided memory allocation by generously re-using frame space on the C stack.</p></li>
|
||
<li><p>Streamlined the internal frame struct to contain only essential information.
|
||
Frames previously held extra debugging and memory management information.</p></li>
|
||
</ul>
|
||
<p>Old-style <a class="reference internal" href="../reference/datamodel.html#frame-objects"><span class="std std-ref">frame objects</span></a>
|
||
are now created only when requested by debuggers
|
||
or by Python introspection functions such as <a class="reference internal" href="../library/sys.html#sys._getframe" title="sys._getframe"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys._getframe()</span></code></a> and
|
||
<a class="reference internal" href="../library/inspect.html#inspect.currentframe" title="inspect.currentframe"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.currentframe()</span></code></a>. For most user code, no frame objects are
|
||
created at all. As a result, nearly all Python functions calls have sped
|
||
up significantly. We measured a 3-7% speedup in pyperformance.</p>
|
||
<p>(Contributed by Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44590">bpo-44590</a>.)</p>
|
||
</section>
|
||
<section id="inlined-python-function-calls">
|
||
<span id="whatsnew311-inline-calls"></span><span id="inline-calls"></span><h4>Inlined Python function calls<a class="headerlink" href="#inlined-python-function-calls" title="Link to this heading">¶</a></h4>
|
||
<p>During a Python function call, Python will call an evaluating C function to
|
||
interpret that function’s code. This effectively limits pure Python recursion to
|
||
what’s safe for the C stack.</p>
|
||
<p>In 3.11, when CPython detects Python code calling another Python function,
|
||
it sets up a new frame, and “jumps” to the new code inside the new frame. This
|
||
avoids calling the C interpreting function altogether.</p>
|
||
<p>Most Python function calls now consume no C stack space, speeding them up.
|
||
In simple recursive functions like fibonacci or
|
||
factorial, we observed a 1.7x speedup. This also means recursive functions
|
||
can recurse significantly deeper
|
||
(if the user increases the recursion limit with <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>).
|
||
We measured a 1-3% improvement in pyperformance.</p>
|
||
<p>(Contributed by Pablo Galindo and Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45256">bpo-45256</a>.)</p>
|
||
</section>
|
||
<section id="pep-659-specializing-adaptive-interpreter">
|
||
<span id="whatsnew311-pep659"></span><h4>PEP 659: Specializing Adaptive Interpreter<a class="headerlink" href="#pep-659-specializing-adaptive-interpreter" title="Link to this heading">¶</a></h4>
|
||
<p><span class="target" id="index-29"></span><a class="pep reference external" href="https://peps.python.org/pep-0659/"><strong>PEP 659</strong></a> is one of the key parts of the Faster CPython project. The general
|
||
idea is that while Python is a dynamic language, most code has regions where
|
||
objects and types rarely change. This concept is known as <em>type stability</em>.</p>
|
||
<p>At runtime, Python will try to look for common patterns and type stability
|
||
in the executing code. Python will then replace the current operation with a
|
||
more specialized one. This specialized operation uses fast paths available only
|
||
to those use cases/types, which generally outperform their generic
|
||
counterparts. This also brings in another concept called <em>inline caching</em>, where
|
||
Python caches the results of expensive operations directly in the
|
||
<a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a>.</p>
|
||
<p>The specializer will also combine certain common instruction pairs into one
|
||
superinstruction, reducing the overhead during execution.</p>
|
||
<p>Python will only specialize
|
||
when it sees code that is “hot” (executed multiple times). This prevents Python
|
||
from wasting time on run-once code. Python can also de-specialize when code is
|
||
too dynamic or when the use changes. Specialization is attempted periodically,
|
||
and specialization attempts are not too expensive,
|
||
allowing specialization to adapt to new circumstances.</p>
|
||
<p>(PEP written by Mark Shannon, with ideas inspired by Stefan Brunthaler.
|
||
See <span class="target" id="index-30"></span><a class="pep reference external" href="https://peps.python.org/pep-0659/"><strong>PEP 659</strong></a> for more information. Implementation by Mark Shannon and Brandt
|
||
Bucher, with additional help from Irit Katriel and Dennis Sweeney.)</p>
|
||
<table class="docutils align-default">
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>Operation</p></th>
|
||
<th class="head"><p>Form</p></th>
|
||
<th class="head"><p>Specialization</p></th>
|
||
<th class="head"><p>Operation speedup
|
||
(up to)</p></th>
|
||
<th class="head"><p>Contributor(s)</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>Binary
|
||
operations</p></td>
|
||
<td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">+</span> <span class="pre">x</span></code></p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">-</span> <span class="pre">x</span></code></p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">*</span> <span class="pre">x</span></code></p>
|
||
</td>
|
||
<td><p>Binary add, multiply and subtract for common types
|
||
such as <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>, <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> and <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>
|
||
take custom fast paths for their underlying types.</p></td>
|
||
<td><p>10%</p></td>
|
||
<td><p>Mark Shannon,
|
||
Donghee Na,
|
||
Brandt Bucher,
|
||
Dennis Sweeney</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>Subscript</p></td>
|
||
<td><p><code class="docutils literal notranslate"><span class="pre">a[i]</span></code></p></td>
|
||
<td><p>Subscripting container types such as <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>,
|
||
<a class="reference internal" href="../library/stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a> and <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> directly index
|
||
the underlying data structures.</p>
|
||
<p>Subscripting custom <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a>
|
||
is also inlined similar to <a class="reference internal" href="#inline-calls"><span class="std std-ref">Inlined Python function calls</span></a>.</p>
|
||
</td>
|
||
<td><p>10-25%</p></td>
|
||
<td><p>Irit Katriel,
|
||
Mark Shannon</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>Store
|
||
subscript</p></td>
|
||
<td><p><code class="docutils literal notranslate"><span class="pre">a[i]</span> <span class="pre">=</span> <span class="pre">z</span></code></p></td>
|
||
<td><p>Similar to subscripting specialization above.</p></td>
|
||
<td><p>10-25%</p></td>
|
||
<td><p>Dennis Sweeney</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>Calls</p></td>
|
||
<td><p><code class="docutils literal notranslate"><span class="pre">f(arg)</span></code></p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">C(arg)</span></code></p>
|
||
</td>
|
||
<td><p>Calls to common builtin (C) functions and types such
|
||
as <a class="reference internal" href="../library/functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a> and <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> directly call their
|
||
underlying C version. This avoids going through the
|
||
internal calling convention.</p></td>
|
||
<td><p>20%</p></td>
|
||
<td><p>Mark Shannon,
|
||
Ken Jin</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>Load
|
||
global
|
||
variable</p></td>
|
||
<td><p><code class="docutils literal notranslate"><span class="pre">print</span></code></p>
|
||
<p><code class="docutils literal notranslate"><span class="pre">len</span></code></p>
|
||
</td>
|
||
<td><p>The object’s index in the globals/builtins namespace
|
||
is cached. Loading globals and builtins require
|
||
zero namespace lookups.</p></td>
|
||
<td><p><a class="footnote-reference brackets" href="#load-global" id="id2" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p></td>
|
||
<td><p>Mark Shannon</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>Load
|
||
attribute</p></td>
|
||
<td><p><code class="docutils literal notranslate"><span class="pre">o.attr</span></code></p></td>
|
||
<td><p>Similar to loading global variables. The attribute’s
|
||
index inside the class/object’s namespace is cached.
|
||
In most cases, attribute loading will require zero
|
||
namespace lookups.</p></td>
|
||
<td><p><a class="footnote-reference brackets" href="#load-attr" id="id3" role="doc-noteref"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></a></p></td>
|
||
<td><p>Mark Shannon</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>Load
|
||
methods for
|
||
call</p></td>
|
||
<td><p><code class="docutils literal notranslate"><span class="pre">o.meth()</span></code></p></td>
|
||
<td><p>The actual address of the method is cached. Method
|
||
loading now has no namespace lookups – even for
|
||
classes with long inheritance chains.</p></td>
|
||
<td><p>10-20%</p></td>
|
||
<td><p>Ken Jin,
|
||
Mark Shannon</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>Store
|
||
attribute</p></td>
|
||
<td><p><code class="docutils literal notranslate"><span class="pre">o.attr</span> <span class="pre">=</span> <span class="pre">z</span></code></p></td>
|
||
<td><p>Similar to load attribute optimization.</p></td>
|
||
<td><p>2%
|
||
in pyperformance</p></td>
|
||
<td><p>Mark Shannon</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>Unpack
|
||
Sequence</p></td>
|
||
<td><p><code class="docutils literal notranslate"><span class="pre">*seq</span></code></p></td>
|
||
<td><p>Specialized for common containers such as
|
||
<a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a>.
|
||
Avoids internal calling convention.</p></td>
|
||
<td><p>8%</p></td>
|
||
<td><p>Brandt Bucher</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<aside class="footnote-list brackets">
|
||
<aside class="footnote brackets" id="load-global" role="doc-footnote">
|
||
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id2">1</a><span class="fn-bracket">]</span></span>
|
||
<p>A similar optimization already existed since Python 3.8.
|
||
3.11 specializes for more forms and reduces some overhead.</p>
|
||
</aside>
|
||
<aside class="footnote brackets" id="load-attr" role="doc-footnote">
|
||
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id3">2</a><span class="fn-bracket">]</span></span>
|
||
<p>A similar optimization already existed since Python 3.10.
|
||
3.11 specializes for more forms. Furthermore, all attribute loads should
|
||
be sped up by <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45947">bpo-45947</a>.</p>
|
||
</aside>
|
||
</aside>
|
||
</section>
|
||
</section>
|
||
<section id="misc">
|
||
<span id="whatsnew311-faster-cpython-misc"></span><h3>Misc<a class="headerlink" href="#misc" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Objects now require less memory due to lazily created object namespaces.
|
||
Their namespace dictionaries now also share keys more freely.
|
||
(Contributed Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45340">bpo-45340</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=40116">bpo-40116</a>.)</p></li>
|
||
<li><p>“Zero-cost” exceptions are implemented, eliminating the cost
|
||
of <a class="reference internal" href="../reference/compound_stmts.html#try"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">try</span></code></a> statements when no exception is raised.
|
||
(Contributed by Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=40222">bpo-40222</a>.)</p></li>
|
||
<li><p>A more concise representation of exceptions in the interpreter reduced the
|
||
time required for catching an exception by about 10%.
|
||
(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45711">bpo-45711</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a>’s regular expression matching engine has been partially refactored,
|
||
and now uses computed gotos (or “threaded code”) on supported platforms. As a
|
||
result, Python 3.11 executes the <a class="reference external" href="https://pyperformance.readthedocs.io/benchmarks.html#regex-dna">pyperformance regular expression benchmarks</a> up to 10%
|
||
faster than Python 3.10.
|
||
(Contributed by Brandt Bucher in <a class="reference external" href="https://github.com/python/cpython/issues/91404">gh-91404</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="faq">
|
||
<span id="whatsnew311-faster-cpython-faq"></span><h3>FAQ<a class="headerlink" href="#faq" title="Link to this heading">¶</a></h3>
|
||
<section id="how-should-i-write-my-code-to-utilize-these-speedups">
|
||
<span id="faster-cpython-faq-my-code"></span><h4>How should I write my code to utilize these speedups?<a class="headerlink" href="#how-should-i-write-my-code-to-utilize-these-speedups" title="Link to this heading">¶</a></h4>
|
||
<p>Write Pythonic code that follows common best practices;
|
||
you don’t have to change your code.
|
||
The Faster CPython project optimizes for common code patterns we observe.</p>
|
||
</section>
|
||
<section id="will-cpython-3-11-use-more-memory">
|
||
<span id="faster-cpython-faq-memory"></span><h4>Will CPython 3.11 use more memory?<a class="headerlink" href="#will-cpython-3-11-use-more-memory" title="Link to this heading">¶</a></h4>
|
||
<p>Maybe not; we don’t expect memory use to exceed 20% higher than 3.10.
|
||
This is offset by memory optimizations for frame objects and object
|
||
dictionaries as mentioned above.</p>
|
||
</section>
|
||
<section id="i-don-t-see-any-speedups-in-my-workload-why">
|
||
<span id="faster-cpython-ymmv"></span><h4>I don’t see any speedups in my workload. Why?<a class="headerlink" href="#i-don-t-see-any-speedups-in-my-workload-why" title="Link to this heading">¶</a></h4>
|
||
<p>Certain code won’t have noticeable benefits. If your code spends most of
|
||
its time on I/O operations, or already does most of its
|
||
computation in a C extension library like NumPy, there won’t be significant
|
||
speedups. This project currently benefits pure-Python workloads the most.</p>
|
||
<p>Furthermore, the pyperformance figures are a geometric mean. Even within the
|
||
pyperformance benchmarks, certain benchmarks have slowed down slightly, while
|
||
others have sped up by nearly 2x!</p>
|
||
</section>
|
||
<section id="is-there-a-jit-compiler">
|
||
<span id="faster-cpython-jit"></span><h4>Is there a JIT compiler?<a class="headerlink" href="#is-there-a-jit-compiler" title="Link to this heading">¶</a></h4>
|
||
<p>No. We’re still exploring other optimizations.</p>
|
||
</section>
|
||
</section>
|
||
<section id="about">
|
||
<span id="whatsnew311-faster-cpython-about"></span><h3>About<a class="headerlink" href="#about" title="Link to this heading">¶</a></h3>
|
||
<p>Faster CPython explores optimizations for <a class="reference internal" href="../glossary.html#term-CPython"><span class="xref std std-term">CPython</span></a>. The main team is
|
||
funded by Microsoft to work on this full-time. Pablo Galindo Salgado is also
|
||
funded by Bloomberg LP to work on the project part-time. Finally, many
|
||
contributors are volunteers from the community.</p>
|
||
</section>
|
||
</section>
|
||
<section id="cpython-bytecode-changes">
|
||
<span id="whatsnew311-bytecode-changes"></span><h2>CPython bytecode changes<a class="headerlink" href="#cpython-bytecode-changes" title="Link to this heading">¶</a></h2>
|
||
<p>The bytecode now contains inline cache entries,
|
||
which take the form of the newly-added <a class="reference internal" href="../library/dis.html#opcode-CACHE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CACHE</span></code></a> instructions.
|
||
Many opcodes expect to be followed by an exact number of caches,
|
||
and instruct the interpreter to skip over them at runtime.
|
||
Populated caches can look like arbitrary instructions,
|
||
so great care should be taken when reading or modifying
|
||
raw, adaptive bytecode containing quickened data.</p>
|
||
<section id="new-opcodes">
|
||
<span id="whatsnew311-added-opcodes"></span><h3>New opcodes<a class="headerlink" href="#new-opcodes" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p><code class="xref std std-opcode docutils literal notranslate"><span class="pre">ASYNC_GEN_WRAP</span></code>, <a class="reference internal" href="../library/dis.html#opcode-RETURN_GENERATOR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">RETURN_GENERATOR</span></code></a> and <a class="reference internal" href="../library/dis.html#opcode-SEND"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">SEND</span></code></a>,
|
||
used in generators and co-routines.</p></li>
|
||
<li><p><a class="reference internal" href="../library/dis.html#opcode-COPY_FREE_VARS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">COPY_FREE_VARS</span></code></a>,
|
||
which avoids needing special caller-side code for closures.</p></li>
|
||
<li><p><a class="reference internal" href="../library/dis.html#opcode-JUMP_BACKWARD_NO_INTERRUPT"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_BACKWARD_NO_INTERRUPT</span></code></a>,
|
||
for use in certain loops where handling interrupts is undesirable.</p></li>
|
||
<li><p><a class="reference internal" href="../library/dis.html#opcode-MAKE_CELL"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">MAKE_CELL</span></code></a>, to create <a class="reference internal" href="../c-api/cell.html#cell-objects"><span class="std std-ref">Cell Objects</span></a>.</p></li>
|
||
<li><p><a class="reference internal" href="../library/dis.html#opcode-CHECK_EG_MATCH"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CHECK_EG_MATCH</span></code></a> and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">PREP_RERAISE_STAR</span></code>,
|
||
to handle the <a class="reference internal" href="#whatsnew311-pep654"><span class="std std-ref">new exception groups and except*</span></a>
|
||
added in <span class="target" id="index-31"></span><a class="pep reference external" href="https://peps.python.org/pep-0654/"><strong>PEP 654</strong></a>.</p></li>
|
||
<li><p><a class="reference internal" href="../library/dis.html#opcode-PUSH_EXC_INFO"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">PUSH_EXC_INFO</span></code></a>, for use in exception handlers.</p></li>
|
||
<li><p><a class="reference internal" href="../library/dis.html#opcode-RESUME"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">RESUME</span></code></a>, a no-op,
|
||
for internal tracing, debugging and optimization checks.</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="replaced-opcodes">
|
||
<span id="whatsnew311-replaced-opcodes"></span><h3>Replaced opcodes<a class="headerlink" href="#replaced-opcodes" title="Link to this heading">¶</a></h3>
|
||
<table class="docutils align-default">
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>Replaced Opcode(s)</p></th>
|
||
<th class="head"><p>New Opcode(s)</p></th>
|
||
<th class="head"><p>Notes</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><div class="line-block">
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BINARY_*</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">INPLACE_*</span></code></div>
|
||
</div>
|
||
</td>
|
||
<td><p><a class="reference internal" href="../library/dis.html#opcode-BINARY_OP"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BINARY_OP</span></code></a></p></td>
|
||
<td><p>Replaced all numeric binary/in-place
|
||
opcodes with a single opcode</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><div class="line-block">
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FUNCTION</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FUNCTION_KW</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_METHOD</span></code></div>
|
||
</div>
|
||
</td>
|
||
<td><div class="line-block">
|
||
<div class="line"><a class="reference internal" href="../library/dis.html#opcode-CALL"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL</span></code></a></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">KW_NAMES</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">PRECALL</span></code></div>
|
||
<div class="line"><a class="reference internal" href="../library/dis.html#opcode-PUSH_NULL"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">PUSH_NULL</span></code></a></div>
|
||
</div>
|
||
</td>
|
||
<td><p>Decouples argument shifting for methods
|
||
from handling of keyword arguments;
|
||
allows better specialization of calls</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><div class="line-block">
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">DUP_TOP</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">DUP_TOP_TWO</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">ROT_TWO</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">ROT_THREE</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">ROT_FOUR</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">ROT_N</span></code></div>
|
||
</div>
|
||
</td>
|
||
<td><div class="line-block">
|
||
<div class="line"><a class="reference internal" href="../library/dis.html#opcode-COPY"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">COPY</span></code></a></div>
|
||
<div class="line"><a class="reference internal" href="../library/dis.html#opcode-SWAP"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">SWAP</span></code></a></div>
|
||
</div>
|
||
</td>
|
||
<td><p>Stack manipulation instructions</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><div class="line-block">
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_IF_NOT_EXC_MATCH</span></code></div>
|
||
</div>
|
||
</td>
|
||
<td><div class="line-block">
|
||
<div class="line"><a class="reference internal" href="../library/dis.html#opcode-CHECK_EXC_MATCH"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CHECK_EXC_MATCH</span></code></a></div>
|
||
</div>
|
||
</td>
|
||
<td><p>Now performs check but doesn’t jump</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><div class="line-block">
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_ABSOLUTE</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_JUMP_IF_FALSE</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_JUMP_IF_TRUE</span></code></div>
|
||
</div>
|
||
</td>
|
||
<td><div class="line-block">
|
||
<div class="line"><a class="reference internal" href="../library/dis.html#opcode-JUMP_BACKWARD"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_BACKWARD</span></code></a></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_JUMP_BACKWARD_IF_*</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_JUMP_FORWARD_IF_*</span></code></div>
|
||
</div>
|
||
</td>
|
||
<td><p>See <a class="footnote-reference brackets" href="#bytecode-jump" id="id4" role="doc-noteref"><span class="fn-bracket">[</span>3<span class="fn-bracket">]</span></a>;
|
||
<code class="docutils literal notranslate"><span class="pre">TRUE</span></code>, <code class="docutils literal notranslate"><span class="pre">FALSE</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">NONE</span></code> and <code class="docutils literal notranslate"><span class="pre">NOT_NONE</span></code> variants
|
||
for each direction</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><div class="line-block">
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">SETUP_WITH</span></code></div>
|
||
<div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">SETUP_ASYNC_WITH</span></code></div>
|
||
</div>
|
||
</td>
|
||
<td><p><a class="reference internal" href="../library/dis.html#opcode-BEFORE_WITH"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BEFORE_WITH</span></code></a></p></td>
|
||
<td><p><a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> block setup</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<aside class="footnote-list brackets">
|
||
<aside class="footnote brackets" id="bytecode-jump" role="doc-footnote">
|
||
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id4">3</a><span class="fn-bracket">]</span></span>
|
||
<p>All jump opcodes are now relative, including the
|
||
existing <code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_IF_TRUE_OR_POP</span></code> and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_IF_FALSE_OR_POP</span></code>.
|
||
The argument is now an offset from the current instruction
|
||
rather than an absolute location.</p>
|
||
</aside>
|
||
</aside>
|
||
</section>
|
||
<section id="changed-removed-opcodes">
|
||
<span id="whatsnew311-changed-removed-opcodes"></span><span id="whatsnew311-removed-opcodes"></span><span id="whatsnew311-changed-opcodes"></span><h3>Changed/removed opcodes<a class="headerlink" href="#changed-removed-opcodes" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Changed <a class="reference internal" href="../library/dis.html#opcode-MATCH_CLASS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">MATCH_CLASS</span></code></a> and <a class="reference internal" href="../library/dis.html#opcode-MATCH_KEYS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">MATCH_KEYS</span></code></a>
|
||
to no longer push an additional boolean value to indicate success/failure.
|
||
Instead, <code class="docutils literal notranslate"><span class="pre">None</span></code> is pushed on failure
|
||
in place of the tuple of extracted values.</p></li>
|
||
<li><p>Changed opcodes that work with exceptions to reflect them
|
||
now being represented as one item on the stack instead of three
|
||
(see <a class="reference external" href="https://github.com/python/cpython/issues/89874">gh-89874</a>).</p></li>
|
||
<li><p>Removed <code class="xref std std-opcode docutils literal notranslate"><span class="pre">COPY_DICT_WITHOUT_KEYS</span></code>, <code class="xref std std-opcode docutils literal notranslate"><span class="pre">GEN_START</span></code>,
|
||
<code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_BLOCK</span></code>, <code class="xref std std-opcode docutils literal notranslate"><span class="pre">SETUP_FINALLY</span></code> and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">YIELD_FROM</span></code>.</p></li>
|
||
</ul>
|
||
</section>
|
||
</section>
|
||
<section id="deprecated">
|
||
<span id="whatsnew311-python-api-deprecated"></span><span id="whatsnew311-deprecated"></span><h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading">¶</a></h2>
|
||
<p>This section lists Python APIs that have been deprecated in Python 3.11.</p>
|
||
<p>Deprecated C APIs are <a class="reference internal" href="#whatsnew311-c-api-deprecated"><span class="std std-ref">listed separately</span></a>.</p>
|
||
<section id="language-builtins">
|
||
<span id="whatsnew311-deprecated-builtins"></span><span id="whatsnew311-deprecated-language"></span><h3>Language/Builtins<a class="headerlink" href="#language-builtins" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Chaining <a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">classmethod</span></code></a> descriptors (introduced in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=19072">bpo-19072</a>)
|
||
is now deprecated. It can no longer be used to wrap other descriptors
|
||
such as <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-class docutils literal notranslate"><span class="pre">property</span></code></a>. The core design of this feature was flawed
|
||
and caused a number of downstream problems. To “pass-through” a
|
||
<a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">classmethod</span></code></a>, consider using the <code class="xref py py-attr docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute
|
||
that was added in Python 3.10.
|
||
(Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/89519">gh-89519</a>.)</p></li>
|
||
<li><p>Octal escapes in string and bytes literals with values larger than <code class="docutils literal notranslate"><span class="pre">0o377</span></code>
|
||
(255 in decimal) now produce 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>.
|
||
In a future Python version, they will raise 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> and
|
||
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 Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/81548">gh-81548</a>.)</p></li>
|
||
<li><p>The delegation of <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-func docutils literal notranslate"><span class="pre">int()</span></code></a> to <a class="reference internal" href="../reference/datamodel.html#object.__trunc__" title="object.__trunc__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__trunc__()</span></code></a> is now deprecated.
|
||
Calling <code class="docutils literal notranslate"><span class="pre">int(a)</span></code> when <code class="docutils literal notranslate"><span class="pre">type(a)</span></code> implements <code class="xref py py-meth docutils literal notranslate"><span class="pre">__trunc__()</span></code> but not
|
||
<a class="reference internal" href="../reference/datamodel.html#object.__int__" title="object.__int__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__int__()</span></code></a> or <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> now raises
|
||
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>.
|
||
(Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44977">bpo-44977</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="modules">
|
||
<span id="whatsnew311-deprecated-modules"></span><h3>Modules<a class="headerlink" href="#modules" title="Link to this heading">¶</a></h3>
|
||
<ul id="whatsnew311-pep594">
|
||
<li><p><span class="target" id="index-32"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a> led to the deprecations of the following modules
|
||
slated for removal in Python 3.13:</p>
|
||
<table class="docutils align-default">
|
||
<tbody>
|
||
<tr class="row-odd"><td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">aifc</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">chunk</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">msilib</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">telnetlib</span></code></p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">crypt</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">nis</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">sndhdr</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">uu</span></code></p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">cgi</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">imghdr</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">nntplib</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">spwd</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">xdrlib</span></code></p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">cgitb</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">mailcap</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code></p></td>
|
||
<td><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code></p></td>
|
||
<td></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<p>(Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47061">bpo-47061</a> and Victor Stinner in
|
||
<a class="reference external" href="https://github.com/python/cpython/issues/68966">gh-68966</a>.)</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">smtpd</span></code> modules have been
|
||
deprecated since at least Python 3.6. Their documentation and deprecation
|
||
warnings have now been updated to note they will be removed in Python 3.12.
|
||
(Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47022">bpo-47022</a>.)</p></li>
|
||
<li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">lib2to3</span></code> package and <code class="docutils literal notranslate"><span class="pre">2to3</span></code> tool
|
||
are now deprecated and may not be able to parse Python 3.10 or newer.
|
||
See <span class="target" id="index-33"></span><a class="pep reference external" href="https://peps.python.org/pep-0617/"><strong>PEP 617</strong></a>, introducing the new PEG parser, for details.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=40360">bpo-40360</a>.)</p></li>
|
||
<li><p>Undocumented modules <code class="xref py py-mod docutils literal notranslate"><span class="pre">sre_compile</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">sre_constants</span></code>
|
||
and <code class="xref py py-mod docutils literal notranslate"><span class="pre">sre_parse</span></code> are now deprecated.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47152">bpo-47152</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="standard-library">
|
||
<span id="whatsnew311-deprecated-stdlib"></span><h3>Standard Library<a class="headerlink" href="#standard-library" title="Link to this heading">¶</a></h3>
|
||
<ul>
|
||
<li><p>The following have been deprecated in <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> since Python 3.2.
|
||
Their deprecation warnings have now been updated to note they will be removed
|
||
in Python 3.12:</p>
|
||
<ul class="simple">
|
||
<li><p>the <code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.SafeConfigParser</span></code> class</p></li>
|
||
<li><p>the <code class="xref py py-attr docutils literal notranslate"><span class="pre">configparser.ParsingError.filename</span></code> property</p></li>
|
||
<li><p>the <code class="xref py py-meth docutils literal notranslate"><span class="pre">configparser.RawConfigParser.readfp()</span></code> method</p></li>
|
||
</ul>
|
||
<p>(Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45173">bpo-45173</a>.)</p>
|
||
</li>
|
||
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.LegacyInterpolation</span></code> has been deprecated in the docstring
|
||
since Python 3.2, and is not listed 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> documentation.
|
||
It 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> and will be removed
|
||
in Python 3.13. Use <a class="reference internal" href="../library/configparser.html#configparser.BasicInterpolation" title="configparser.BasicInterpolation"><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.BasicInterpolation</span></code></a> or
|
||
<a class="reference internal" href="../library/configparser.html#configparser.ExtendedInterpolation" title="configparser.ExtendedInterpolation"><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.ExtendedInterpolation</span></code></a> instead.
|
||
(Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46607">bpo-46607</a>.)</p></li>
|
||
<li><p>The older set of <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> functions were deprecated
|
||
in favor of the replacements added in Python 3.9
|
||
and will be removed in a future Python version,
|
||
due to not supporting resources located within package subdirectories:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.contents()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.is_resource()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.open_binary()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.open_text()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.read_binary()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.read_text()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.path()</span></code></p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p>The <a class="reference internal" href="../library/locale.html#locale.getdefaultlocale" title="locale.getdefaultlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getdefaultlocale()</span></code></a> function is deprecated and will be
|
||
removed in Python 3.15. Use <a class="reference internal" href="../library/locale.html#locale.setlocale" title="locale.setlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.setlocale()</span></code></a>,
|
||
<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> and
|
||
<a class="reference internal" href="../library/locale.html#locale.getlocale" title="locale.getlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getlocale()</span></code></a> functions instead.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/90817">gh-90817</a>.)</p></li>
|
||
<li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">locale.resetlocale()</span></code> function is deprecated and will be
|
||
removed in Python 3.13. Use <code class="docutils literal notranslate"><span class="pre">locale.setlocale(locale.LC_ALL,</span> <span class="pre">"")</span></code> instead.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/90817">gh-90817</a>.)</p></li>
|
||
<li><p>Stricter rules will now be applied for numerical group references
|
||
and group names in <a class="reference internal" href="../library/re.html#re-syntax"><span class="std std-ref">regular expressions</span></a>.
|
||
Only sequences of ASCII digits will now be accepted as a numerical reference,
|
||
and the group name in <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> patterns and replacement strings
|
||
can only contain ASCII letters, digits and underscores.
|
||
For now, a deprecation warning is raised for syntax violating these rules.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/91760">gh-91760</a>.)</p></li>
|
||
<li><p>In the <a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a> module, the <code class="xref py py-func docutils literal notranslate"><span class="pre">re.template()</span></code> function
|
||
and the corresponding <code class="xref py py-const docutils literal notranslate"><span class="pre">re.TEMPLATE</span></code> and <code class="xref py py-const docutils literal notranslate"><span class="pre">re.T</span></code> flags
|
||
are deprecated, as they were undocumented and lacked an obvious purpose.
|
||
They will be removed in Python 3.13.
|
||
(Contributed by Serhiy Storchaka and Miro Hrončok in <a class="reference external" href="https://github.com/python/cpython/issues/92728">gh-92728</a>.)</p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">turtle.settiltangle()</span></code> has been deprecated since Python 3.1;
|
||
it now emits a deprecation warning and will be removed in Python 3.13. Use
|
||
<a class="reference internal" href="../library/turtle.html#turtle.tiltangle" title="turtle.tiltangle"><code class="xref py py-func docutils literal notranslate"><span class="pre">turtle.tiltangle()</span></code></a> instead (it was earlier incorrectly marked
|
||
as deprecated, and its docstring is now corrected).
|
||
(Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45837">bpo-45837</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>, which exists solely to provide compatibility support
|
||
between Python 2 and Python 3 code, is now deprecated. Its removal is
|
||
currently unplanned, but users are encouraged to use <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> instead
|
||
wherever possible.
|
||
(Contributed by Alex Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/92332">gh-92332</a>.)</p></li>
|
||
<li><p>The keyword argument syntax for constructing <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> types
|
||
is now deprecated. Support will be removed in Python 3.13. (Contributed by
|
||
Jingchen Ye in <a class="reference external" href="https://github.com/python/cpython/issues/90224">gh-90224</a>.)</p></li>
|
||
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">webbrowser.MacOSX</span></code> is deprecated and will be removed in Python 3.13.
|
||
It is untested, undocumented, and not used by <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> itself.
|
||
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=42255">bpo-42255</a>.)</p></li>
|
||
<li><p>The behavior of returning a value from a <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> and
|
||
<a class="reference internal" href="../library/unittest.html#unittest.IsolatedAsyncioTestCase" title="unittest.IsolatedAsyncioTestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">IsolatedAsyncioTestCase</span></code></a> test methods (other than the
|
||
default <code class="docutils literal notranslate"><span class="pre">None</span></code> value) is now deprecated.</p></li>
|
||
<li><p>Deprecated the following not-formally-documented <a class="reference internal" href="../library/unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code></a> functions,
|
||
scheduled for removal in Python 3.13:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.findTestCases()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.makeSuite()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.getTestCaseNames()</span></code></p></li>
|
||
</ul>
|
||
<p>Use <a class="reference internal" href="../library/unittest.html#unittest.TestLoader" title="unittest.TestLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestLoader</span></code></a> methods instead:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/unittest.html#unittest.TestLoader.loadTestsFromModule" title="unittest.TestLoader.loadTestsFromModule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestLoader.loadTestsFromModule()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/unittest.html#unittest.TestLoader.loadTestsFromTestCase" title="unittest.TestLoader.loadTestsFromTestCase"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestLoader.loadTestsFromTestCase()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/unittest.html#unittest.TestLoader.getTestCaseNames" title="unittest.TestLoader.getTestCaseNames"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestLoader.getTestCaseNames()</span></code></a></p></li>
|
||
</ul>
|
||
<p>(Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=5846">bpo-5846</a>.)</p>
|
||
</li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestProgram.usageExit()</span></code> is marked deprecated, to be removed
|
||
in 3.13.
|
||
(Contributed by Carlos Damázio in <a class="reference external" href="https://github.com/python/cpython/issues/67048">gh-67048</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
</section>
|
||
<section id="pending-removal-in-python-3-12">
|
||
<span id="whatsnew311-python-api-pending-removal"></span><span id="whatsnew311-pending-removal"></span><h2>Pending Removal in Python 3.12<a class="headerlink" href="#pending-removal-in-python-3-12" title="Link to this heading">¶</a></h2>
|
||
<p>The following Python APIs have been deprecated in earlier Python releases,
|
||
and will be removed in Python 3.12.</p>
|
||
<p>C APIs pending removal are
|
||
<a class="reference internal" href="#whatsnew311-c-api-pending-removal"><span class="std std-ref">listed separately</span></a>.</p>
|
||
<ul>
|
||
<li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">asynchat</span></code> module</p></li>
|
||
<li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncore</span></code> module</p></li>
|
||
<li><p>The <a class="reference internal" href="3.10.html#distutils-deprecated"><span class="std std-ref">entire distutils package</span></a></p></li>
|
||
<li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> module</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/typing.html#typing.IO" title="typing.IO"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.io</span></code></a> namespace</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/typing.html#typing.Pattern" title="typing.Pattern"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.re</span></code></a> namespace</p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.log()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.find_loader()</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.module_repr()</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder.find_module()</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_loader()</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_module()</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.BuiltinImporter.find_module()</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.BuiltinLoader.module_repr()</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.FileFinder.find_loader()</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.FileFinder.find_module()</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.FrozenImporter.find_module()</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.FrozenLoader.module_repr()</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.PathFinder.find_module()</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.WindowsRegistryFinder.find_module()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.module_for_loader()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.set_loader_wrapper()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.set_package_wrapper()</span></code></p></li>
|
||
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">pkgutil.ImpImporter</span></code></p></li>
|
||
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">pkgutil.ImpLoader</span></code></p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.link_to()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">sqlite3.enable_shared_cache()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">sqlite3.OptimizedUnicode()</span></code></p></li>
|
||
<li><p><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONTHREADDEBUG</span></code> environment variable</p></li>
|
||
<li><p>The following deprecated aliases in <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>:</p>
|
||
<blockquote>
|
||
<div><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>
|
||
</div></blockquote>
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
<section id="removed">
|
||
<span id="whatsnew311-python-api-removed"></span><span id="whatsnew311-removed"></span><h2>Removed<a class="headerlink" href="#removed" title="Link to this heading">¶</a></h2>
|
||
<p>This section lists Python APIs that have been removed in Python 3.11.</p>
|
||
<p>Removed C APIs are <a class="reference internal" href="#whatsnew311-c-api-removed"><span class="std std-ref">listed separately</span></a>.</p>
|
||
<ul>
|
||
<li><p>Removed the <code class="xref py py-func docutils literal notranslate"><span class="pre">@asyncio.coroutine()</span></code> <a class="reference internal" href="../glossary.html#term-decorator"><span class="xref std std-term">decorator</span></a>
|
||
enabling legacy generator-based coroutines to be compatible with
|
||
<a class="reference internal" href="../reference/compound_stmts.html#async"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span></code></a> / <a class="reference internal" href="../reference/expressions.html#await"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">await</span></code></a> code.
|
||
The function has been deprecated since Python 3.8 and the removal was
|
||
initially scheduled for Python 3.10. Use <a class="reference internal" href="../reference/compound_stmts.html#async-def"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">def</span></code></a> instead.
|
||
(Contributed by Illia Volochii in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43216">bpo-43216</a>.)</p></li>
|
||
<li><p>Removed <code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.coroutines.CoroWrapper</span></code> used for wrapping legacy
|
||
generator-based coroutine objects in the debug mode.
|
||
(Contributed by Illia Volochii in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43216">bpo-43216</a>.)</p></li>
|
||
<li><p>Due to significant security concerns, the <em>reuse_address</em> parameter of
|
||
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_datagram_endpoint" title="asyncio.loop.create_datagram_endpoint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.create_datagram_endpoint()</span></code></a>, disabled in Python 3.9, is
|
||
now entirely removed. This is because of the behavior of the socket option
|
||
<code class="docutils literal notranslate"><span class="pre">SO_REUSEADDR</span></code> in UDP.
|
||
(Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45129">bpo-45129</a>.)</p></li>
|
||
<li><p>Removed the <code class="xref py py-mod docutils literal notranslate"><span class="pre">binhex</span></code> module, deprecated in Python 3.9.
|
||
Also removed the related, similarly-deprecated <a class="reference internal" href="../library/binascii.html#module-binascii" title="binascii: Tools for converting between binary and various ASCII-encoded binary representations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">binascii</span></code></a> functions:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">binascii.a2b_hqx()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">binascii.b2a_hqx()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">binascii.rlecode_hqx()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">binascii.rldecode_hqx()</span></code></p></li>
|
||
</ul>
|
||
<p>The <a class="reference internal" href="../library/binascii.html#binascii.crc_hqx" title="binascii.crc_hqx"><code class="xref py py-func docutils literal notranslate"><span class="pre">binascii.crc_hqx()</span></code></a> function remains available.</p>
|
||
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45085">bpo-45085</a>.)</p>
|
||
</li>
|
||
<li><p>Removed the <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code> <code class="docutils literal notranslate"><span class="pre">bdist_msi</span></code> command deprecated in Python 3.9.
|
||
Use <code class="docutils literal notranslate"><span class="pre">bdist_wheel</span></code> (wheel packages) instead.
|
||
(Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45124">bpo-45124</a>.)</p></li>
|
||
<li><p>Removed the <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a> methods of
|
||
<a class="reference internal" href="../library/xml.dom.pulldom.html#xml.dom.pulldom.DOMEventStream" title="xml.dom.pulldom.DOMEventStream"><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.dom.pulldom.DOMEventStream</span></code></a>, <a class="reference internal" href="../library/wsgiref.html#wsgiref.util.FileWrapper" title="wsgiref.util.FileWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">wsgiref.util.FileWrapper</span></code></a>
|
||
and <a class="reference internal" href="../library/fileinput.html#fileinput.FileInput" title="fileinput.FileInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">fileinput.FileInput</span></code></a>, deprecated since Python 3.9.
|
||
(Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45132">bpo-45132</a>.)</p></li>
|
||
<li><p>Removed the deprecated <a class="reference internal" href="../library/gettext.html#module-gettext" title="gettext: Multilingual internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gettext</span></code></a> functions
|
||
<code class="xref py py-func docutils literal notranslate"><span class="pre">lgettext()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">ldgettext()</span></code>,
|
||
<code class="xref py py-func docutils literal notranslate"><span class="pre">lngettext()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">ldngettext()</span></code>.
|
||
Also removed the <code class="xref py py-func docutils literal notranslate"><span class="pre">bind_textdomain_codeset()</span></code> function,
|
||
the <code class="xref py py-meth docutils literal notranslate"><span class="pre">NullTranslations.output_charset()</span></code> and
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">NullTranslations.set_output_charset()</span></code> methods,
|
||
and the <em>codeset</em> parameter of <code class="xref py py-func docutils literal notranslate"><span class="pre">translation()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">install()</span></code>,
|
||
since they are only used for the <code class="xref py py-func docutils literal notranslate"><span class="pre">l*gettext()</span></code> functions.
|
||
(Contributed by Donghee Na and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44235">bpo-44235</a>.)</p></li>
|
||
<li><p>Removed from the <a class="reference internal" href="../library/inspect.html#module-inspect" title="inspect: Extract information and source code from live objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">inspect</span></code></a> module:</p>
|
||
<ul class="simple">
|
||
<li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">getargspec()</span></code> function, deprecated since Python 3.0;
|
||
use <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.signature()</span></code></a> or <a class="reference internal" href="../library/inspect.html#inspect.getfullargspec" title="inspect.getfullargspec"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getfullargspec()</span></code></a> instead.</p></li>
|
||
<li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">formatargspec()</span></code> function, deprecated since Python 3.5;
|
||
use the <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.signature()</span></code></a> function
|
||
or the <a class="reference internal" href="../library/inspect.html#inspect.Signature" title="inspect.Signature"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.Signature</span></code></a> object directly.</p></li>
|
||
<li><p>The undocumented <code class="xref py py-meth docutils literal notranslate"><span class="pre">Signature.from_builtin()</span></code>
|
||
and <code class="xref py py-meth docutils literal notranslate"><span class="pre">Signature.from_function()</span></code> methods, deprecated since Python 3.5;
|
||
use the <a class="reference internal" href="../library/inspect.html#inspect.Signature.from_callable" title="inspect.Signature.from_callable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Signature.from_callable()</span></code></a>
|
||
method instead.</p></li>
|
||
</ul>
|
||
<p>(Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45320">bpo-45320</a>.)</p>
|
||
</li>
|
||
<li><p>Removed the <a class="reference internal" href="../reference/datamodel.html#object.__class_getitem__" title="object.__class_getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__class_getitem__()</span></code></a> method
|
||
from <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>,
|
||
because it was not used and added by mistake in previous versions.
|
||
(Contributed by Nikita Sobolev in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46483">bpo-46483</a>.)</p></li>
|
||
<li><p>Removed the <code class="xref py py-class docutils literal notranslate"><span class="pre">MailmanProxy</span></code> class in the <code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code> module,
|
||
as it is unusable without the external <code class="xref py py-mod docutils literal notranslate"><span class="pre">mailman</span></code> package.
|
||
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35800">bpo-35800</a>.)</p></li>
|
||
<li><p>Removed the deprecated <code class="xref py py-meth docutils literal notranslate"><span class="pre">split()</span></code> method of <code class="xref py py-class docutils literal notranslate"><span class="pre">_tkinter.TkappType</span></code>.
|
||
(Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=38371">bpo-38371</a>.)</p></li>
|
||
<li><p>Removed namespace package support from <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> discovery.
|
||
It was introduced in Python 3.4 but has been broken since Python 3.7.
|
||
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23882">bpo-23882</a>.)</p></li>
|
||
<li><p>Removed the undocumented private <code class="xref py py-meth docutils literal notranslate"><span class="pre">float.__set_format__()</span></code> method,
|
||
previously known as <code class="xref py py-meth docutils literal notranslate"><span class="pre">float.__setformat__()</span></code> in Python 3.7.
|
||
Its docstring said: “You probably don’t want to use this function.
|
||
It exists mainly to be used in Python’s test suite.”
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46852">bpo-46852</a>.)</p></li>
|
||
<li><p>The <code class="xref std std-option docutils literal notranslate"><span class="pre">--experimental-isolated-subinterpreters</span></code> configure flag
|
||
(and corresponding <code class="xref c c-macro docutils literal notranslate"><span class="pre">EXPERIMENTAL_ISOLATED_SUBINTERPRETERS</span></code> macro)
|
||
have been removed.</p></li>
|
||
<li><p><a class="extlink-pypi reference external" href="https://pypi.org/project/Pynche/">Pynche</a>
|
||
— The Pythonically Natural Color and Hue Editor — has been moved out
|
||
of <code class="docutils literal notranslate"><span class="pre">Tools/scripts</span></code> and is <a class="reference external" href="https://gitlab.com/warsaw/pynche/-/tree/main">being developed independently</a> from the Python source tree.</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="porting-to-python-3-11">
|
||
<span id="whatsnew311-python-api-porting"></span><span id="whatsnew311-porting"></span><h2>Porting to Python 3.11<a class="headerlink" href="#porting-to-python-3-11" title="Link to this heading">¶</a></h2>
|
||
<p>This section lists previously described changes and other bugfixes
|
||
in the Python API that may require changes to your Python code.</p>
|
||
<p>Porting notes for the C API are
|
||
<a class="reference internal" href="#whatsnew311-c-api-porting"><span class="std std-ref">listed separately</span></a>.</p>
|
||
<ul class="simple">
|
||
<li><p><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>, <a class="reference internal" href="../library/codecs.html#codecs.open" title="codecs.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">codecs.open()</span></code></a> and
|
||
<a class="reference internal" href="../library/fileinput.html#fileinput.FileInput" title="fileinput.FileInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">fileinput.FileInput</span></code></a> no longer accept <code class="docutils literal notranslate"><span class="pre">'U'</span></code> (“universal newline”)
|
||
in the file mode. In Python 3, “universal newline” mode is used by default
|
||
whenever a file is opened in text mode,
|
||
and the <code class="docutils literal notranslate"><span class="pre">'U'</span></code> flag has been deprecated since Python 3.3.
|
||
The <a class="reference internal" href="../library/functions.html#open-newline-parameter"><span class="std std-ref">newline parameter</span></a>
|
||
to these functions controls how universal newlines work.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37330">bpo-37330</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/ast.html#ast.AST" title="ast.AST"><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.AST</span></code></a> node positions are now validated when provided to
|
||
<a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> and other related functions. If invalid positions are detected,
|
||
a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> will be raised. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/93351">gh-93351</a>)</p></li>
|
||
<li><p>Prohibited passing non-<a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.ThreadPoolExecutor</span></code></a>
|
||
executors to <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.set_default_executor" title="asyncio.loop.set_default_executor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.set_default_executor()</span></code></a>
|
||
following a deprecation in Python 3.8.
|
||
(Contributed by Illia Volochii in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43234">bpo-43234</a>.)</p></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>: The <a class="reference internal" href="../library/calendar.html#calendar.LocaleTextCalendar" title="calendar.LocaleTextCalendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">calendar.LocaleTextCalendar</span></code></a> and
|
||
<a class="reference internal" href="../library/calendar.html#calendar.LocaleHTMLCalendar" title="calendar.LocaleHTMLCalendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">calendar.LocaleHTMLCalendar</span></code></a> classes now use
|
||
<a class="reference internal" href="../library/locale.html#locale.getlocale" title="locale.getlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getlocale()</span></code></a>, instead of using <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>,
|
||
if no locale is specified.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46659">bpo-46659</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/pdb.html#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a> module now reads the <code class="file docutils literal notranslate"><span class="pre">.pdbrc</span></code> configuration file with
|
||
the <code class="docutils literal notranslate"><span class="pre">'UTF-8'</span></code> encoding.
|
||
(Contributed by Srinivas Reddy Thatiparthy (శ్రీనివాస్ రెడ్డి తాటిపర్తి) in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=41137">bpo-41137</a>.)</p></li>
|
||
<li><p>The <em>population</em> parameter of <a class="reference internal" href="../library/random.html#random.sample" title="random.sample"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.sample()</span></code></a> must be a sequence,
|
||
and automatic conversion of <a class="reference internal" href="../library/stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>s to <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>s
|
||
is no longer supported. Also, if the sample size
|
||
is larger than the population size, a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised.
|
||
(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=40465">bpo-40465</a>.)</p></li>
|
||
<li><p>The <em>random</em> optional parameter of <a class="reference internal" href="../library/random.html#random.shuffle" title="random.shuffle"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.shuffle()</span></code></a> was removed.
|
||
It was previously an arbitrary random function to use for the shuffle;
|
||
now, <a class="reference internal" href="../library/random.html#random.random" title="random.random"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.random()</span></code></a> (its previous default) will always be used.</p></li>
|
||
<li><p>In <a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a> <a class="reference internal" href="../library/re.html#re-syntax"><span class="std std-ref">Regular Expression Syntax</span></a>, global inline flags (e.g. <code class="docutils literal notranslate"><span class="pre">(?i)</span></code>)
|
||
can now only be used at the start of regular expressions.
|
||
Using them elsewhere has been deprecated since Python 3.6.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=47066">bpo-47066</a>.)</p></li>
|
||
<li><p>In the <a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a> module, several long-standing bugs where fixed that,
|
||
in rare cases, could cause capture groups to get the wrong result.
|
||
Therefore, this could change the captured output in these cases.
|
||
(Contributed by Ma Lin in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35859">bpo-35859</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="build-changes">
|
||
<span id="whatsnew311-build-changes"></span><h2>Build Changes<a class="headerlink" href="#build-changes" title="Link to this heading">¶</a></h2>
|
||
<ul>
|
||
<li><p>CPython now has <span class="target" id="index-34"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/"><strong>PEP 11</strong></a> <span class="target" id="index-35"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/#tier-3"><strong>Tier 3 support</strong></a> for
|
||
cross compiling to the <a class="reference external" href="https://webassembly.org/">WebAssembly</a> platforms
|
||
<a class="reference external" href="https://emscripten.org/">Emscripten</a>
|
||
(<code class="docutils literal notranslate"><span class="pre">wasm32-unknown-emscripten</span></code>, i.e. Python in the browser)
|
||
and <a class="reference external" href="https://wasi.dev/">WebAssembly System Interface (WASI)</a>
|
||
(<code class="docutils literal notranslate"><span class="pre">wasm32-unknown-wasi</span></code>).
|
||
The effort is inspired by previous work like <a class="reference external" href="https://pyodide.org/">Pyodide</a>.
|
||
These platforms provide a limited subset of POSIX APIs; Python standard
|
||
libraries features and modules related to networking, processes, threading,
|
||
signals, mmap, and users/groups are not available or don’t work.
|
||
(Emscripten contributed by Christian Heimes and Ethan Smith in <a class="reference external" href="https://github.com/python/cpython/issues/84461">gh-84461</a>
|
||
and WASI contributed by Christian Heimes in <a class="reference external" href="https://github.com/python/cpython/issues/90473">gh-90473</a>;
|
||
platforms promoted in <a class="reference external" href="https://github.com/python/cpython/issues/95085">gh-95085</a>)</p></li>
|
||
<li><p>Building CPython now requires:</p>
|
||
<ul class="simple">
|
||
<li><p>A <a class="reference external" href="https://en.cppreference.com/w/c/11">C11</a> compiler and standard library.
|
||
<a class="reference external" href="https://en.wikipedia.org/wiki/C11_(C_standard_revision)#Optional_features">Optional C11 features</a>
|
||
are not required.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46656">bpo-46656</a>,
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45440">bpo-45440</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46640">bpo-46640</a>.)</p></li>
|
||
<li><p>Support for <a class="reference external" href="https://en.wikipedia.org/wiki/IEEE_754">IEEE 754</a>
|
||
floating-point numbers.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46917">bpo-46917</a>.)</p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p>The <code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_NO_NAN</span></code> macro has been removed.
|
||
Since CPython now requires IEEE 754 floats, NaN values are always available.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46656">bpo-46656</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> package now requires <a class="reference external" href="https://www.tcl.tk">Tcl/Tk</a>
|
||
version 8.5.12 or newer.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46996">bpo-46996</a>.)</p></li>
|
||
<li><p>Build dependencies, compiler flags, and linker flags for most stdlib
|
||
extension modules are now detected by <strong class="program">configure</strong>. libffi, libnsl,
|
||
libsqlite3, zlib, bzip2, liblzma, libcrypt, Tcl/Tk, and uuid flags
|
||
are detected by <a class="reference external" href="https://www.freedesktop.org/wiki/Software/pkg-config/">pkg-config</a> (when available).
|
||
<a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> now requires a pkg-config command
|
||
to detect development settings for <a class="reference external" href="https://www.tcl.tk">Tcl/Tk</a> headers and libraries.
|
||
(Contributed by Christian Heimes and Erlend Egeberg Aasland in
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45847">bpo-45847</a>, <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45747">bpo-45747</a>, and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45763">bpo-45763</a>.)</p></li>
|
||
<li><p>libpython is no longer linked against libcrypt.
|
||
(Contributed by Mike Gilbert in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45433">bpo-45433</a>.)</p></li>
|
||
<li><p>CPython can now be built with the
|
||
<a class="reference external" href="https://clang.llvm.org/docs/ThinLTO.html">ThinLTO</a> option
|
||
via passing <code class="docutils literal notranslate"><span class="pre">thin</span></code> to <a class="reference internal" href="../using/configure.html#cmdoption-with-lto"><code class="xref std std-option docutils literal notranslate"><span class="pre">--with-lto</span></code></a>, i.e. <code class="docutils literal notranslate"><span class="pre">--with-lto=thin</span></code>.
|
||
(Contributed by Donghee Na and Brett Holman in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44340">bpo-44340</a>.)</p></li>
|
||
<li><p>Freelists for object structs can now be disabled. A new <strong class="program">configure</strong>
|
||
option <a class="reference internal" href="../using/configure.html#cmdoption-without-freelists"><code class="xref std std-option docutils literal notranslate"><span class="pre">--without-freelists</span></code></a> can be used to disable all freelists
|
||
except empty tuple singleton.
|
||
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45522">bpo-45522</a>.)</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">Modules/Setup</span></code> and <code class="docutils literal notranslate"><span class="pre">Modules/makesetup</span></code> have been improved and tied up.
|
||
Extension modules can now be built through <code class="docutils literal notranslate"><span class="pre">makesetup</span></code>. All except some
|
||
test modules can be linked statically into a main binary or library.
|
||
(Contributed by Brett Cannon and Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45548">bpo-45548</a>,
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45570">bpo-45570</a>, <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45571">bpo-45571</a>, and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43974">bpo-43974</a>.)</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>Use the environment variables <code class="xref std std-envvar docutils literal notranslate"><span class="pre">TCLTK_CFLAGS</span></code> and
|
||
<code class="xref std std-envvar docutils literal notranslate"><span class="pre">TCLTK_LIBS</span></code> to manually specify the location of Tcl/Tk headers
|
||
and libraries. The <strong class="program">configure</strong> options
|
||
<code class="xref std std-option docutils literal notranslate"><span class="pre">--with-tcltk-includes</span></code> and <code class="xref std std-option docutils literal notranslate"><span class="pre">--with-tcltk-libs</span></code>
|
||
have been removed.</p>
|
||
<p>On RHEL 7 and CentOS 7 the development packages do not provide <code class="docutils literal notranslate"><span class="pre">tcl.pc</span></code>
|
||
and <code class="docutils literal notranslate"><span class="pre">tk.pc</span></code>; use <code class="docutils literal notranslate"><span class="pre">TCLTK_LIBS="-ltk8.5</span> <span class="pre">-ltkstub8.5</span> <span class="pre">-ltcl8.5"</span></code>.
|
||
The directory <code class="docutils literal notranslate"><span class="pre">Misc/rhel7</span></code> contains <code class="docutils literal notranslate"><span class="pre">.pc</span></code> files and instructions
|
||
on how to build Python with RHEL 7’s and CentOS 7’s Tcl/Tk and OpenSSL.</p>
|
||
</div>
|
||
</li>
|
||
<li><p>CPython will now use 30-bit digits by default for the Python <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>
|
||
implementation. Previously, the default was to use 30-bit digits on platforms
|
||
with <code class="docutils literal notranslate"><span class="pre">SIZEOF_VOID_P</span> <span class="pre">>=</span> <span class="pre">8</span></code>, and 15-bit digits otherwise. It’s still possible
|
||
to explicitly request use of 15-bit digits via either the
|
||
<a class="reference internal" href="../using/configure.html#cmdoption-enable-big-digits"><code class="xref std std-option docutils literal notranslate"><span class="pre">--enable-big-digits</span></code></a> option to the configure script
|
||
or (for Windows) the <code class="docutils literal notranslate"><span class="pre">PYLONG_BITS_IN_DIGIT</span></code> variable in <code class="docutils literal notranslate"><span class="pre">PC/pyconfig.h</span></code>,
|
||
but this option may be removed at some point in the future.
|
||
(Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45569">bpo-45569</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="c-api-changes">
|
||
<span id="whatsnew311-c-api"></span><h2>C API Changes<a class="headerlink" href="#c-api-changes" title="Link to this heading">¶</a></h2>
|
||
<section id="whatsnew311-c-api-new-features">
|
||
<span id="id5"></span><h3>New Features<a class="headerlink" href="#whatsnew311-c-api-new-features" title="Link to this heading">¶</a></h3>
|
||
<ul>
|
||
<li><p>Add a new <a class="reference internal" href="../c-api/type.html#c.PyType_GetName" title="PyType_GetName"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetName()</span></code></a> function to get type’s short name.
|
||
(Contributed by Hai Shi in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=42035">bpo-42035</a>.)</p></li>
|
||
<li><p>Add a new <a class="reference internal" href="../c-api/type.html#c.PyType_GetQualName" title="PyType_GetQualName"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetQualName()</span></code></a> function to get type’s qualified name.
|
||
(Contributed by Hai Shi in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=42035">bpo-42035</a>.)</p></li>
|
||
<li><p>Add new <a class="reference internal" href="../c-api/init.html#c.PyThreadState_EnterTracing" title="PyThreadState_EnterTracing"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_EnterTracing()</span></code></a> and
|
||
<a class="reference internal" href="../c-api/init.html#c.PyThreadState_LeaveTracing" title="PyThreadState_LeaveTracing"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_LeaveTracing()</span></code></a> functions to the limited C API to
|
||
suspend and resume tracing and profiling.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43760">bpo-43760</a>.)</p></li>
|
||
<li><p>Added the <a class="reference internal" href="../c-api/apiabiversion.html#c.Py_Version" title="Py_Version"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_Version</span></code></a> constant which bears the same value as
|
||
<a class="reference internal" href="../c-api/apiabiversion.html#c.PY_VERSION_HEX" title="PY_VERSION_HEX"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PY_VERSION_HEX</span></code></a>.
|
||
(Contributed by Gabriele N. Tornetta in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43931">bpo-43931</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/buffer.html#c.Py_buffer" title="Py_buffer"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_buffer</span></code></a> and APIs are now part of the limited API and the stable
|
||
ABI:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../c-api/buffer.html#c.PyObject_CheckBuffer" title="PyObject_CheckBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CheckBuffer()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/buffer.html#c.PyObject_GetBuffer" title="PyObject_GetBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetBuffer()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_GetPointer" title="PyBuffer_GetPointer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_GetPointer()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_SizeFromFormat" title="PyBuffer_SizeFromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_SizeFromFormat()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_ToContiguous" title="PyBuffer_ToContiguous"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_ToContiguous()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_FromContiguous" title="PyBuffer_FromContiguous"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_FromContiguous()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/buffer.html#c.PyObject_CopyData" title="PyObject_CopyData"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CopyData()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_IsContiguous" title="PyBuffer_IsContiguous"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_IsContiguous()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_FillContiguousStrides" title="PyBuffer_FillContiguousStrides"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_FillContiguousStrides()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_FillInfo" title="PyBuffer_FillInfo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_FillInfo()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_Release" title="PyBuffer_Release"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_Release()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/memoryview.html#c.PyMemoryView_FromBuffer" title="PyMemoryView_FromBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMemoryView_FromBuffer()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/typeobj.html#c.PyBufferProcs.bf_getbuffer" title="PyBufferProcs.bf_getbuffer"><code class="xref c c-member docutils literal notranslate"><span class="pre">bf_getbuffer</span></code></a> and
|
||
<a class="reference internal" href="../c-api/typeobj.html#c.PyBufferProcs.bf_releasebuffer" title="PyBufferProcs.bf_releasebuffer"><code class="xref c c-member docutils literal notranslate"><span class="pre">bf_releasebuffer</span></code></a> type slots</p></li>
|
||
</ul>
|
||
<p>(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45459">bpo-45459</a>.)</p>
|
||
</li>
|
||
<li><p>Added the <a class="reference internal" href="../c-api/type.html#c.PyType_GetModuleByDef" title="PyType_GetModuleByDef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetModuleByDef()</span></code></a> function, used to get the module
|
||
in which a method was defined, in cases where this information is not
|
||
available directly (via <a class="reference internal" href="../c-api/structures.html#c.PyCMethod" title="PyCMethod"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyCMethod</span></code></a>).
|
||
(Contributed by Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46613">bpo-46613</a>.)</p></li>
|
||
<li><p>Add new functions to pack and unpack C double (serialize and deserialize):
|
||
<a class="reference internal" href="../c-api/float.html#c.PyFloat_Pack2" title="PyFloat_Pack2"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_Pack2()</span></code></a>, <a class="reference internal" href="../c-api/float.html#c.PyFloat_Pack4" title="PyFloat_Pack4"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_Pack4()</span></code></a>, <a class="reference internal" href="../c-api/float.html#c.PyFloat_Pack8" title="PyFloat_Pack8"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_Pack8()</span></code></a>,
|
||
<a class="reference internal" href="../c-api/float.html#c.PyFloat_Unpack2" title="PyFloat_Unpack2"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_Unpack2()</span></code></a>, <a class="reference internal" href="../c-api/float.html#c.PyFloat_Unpack4" title="PyFloat_Unpack4"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_Unpack4()</span></code></a> and
|
||
<a class="reference internal" href="../c-api/float.html#c.PyFloat_Unpack8" title="PyFloat_Unpack8"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_Unpack8()</span></code></a>.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46906">bpo-46906</a>.)</p></li>
|
||
<li><p>Add new functions to get frame object attributes:
|
||
<a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBuiltins" title="PyFrame_GetBuiltins"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBuiltins()</span></code></a>, <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetGenerator" title="PyFrame_GetGenerator"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetGenerator()</span></code></a>,
|
||
<a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetGlobals" title="PyFrame_GetGlobals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetGlobals()</span></code></a>, <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLasti" title="PyFrame_GetLasti"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLasti()</span></code></a>.</p></li>
|
||
<li><p>Added two new functions to get and set the active exception instance:
|
||
<a class="reference internal" href="../c-api/exceptions.html#c.PyErr_GetHandledException" title="PyErr_GetHandledException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetHandledException()</span></code></a> and <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetHandledException" title="PyErr_SetHandledException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetHandledException()</span></code></a>.
|
||
These are alternatives to <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetExcInfo" title="PyErr_SetExcInfo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetExcInfo()</span></code></a> and
|
||
<a class="reference internal" href="../c-api/exceptions.html#c.PyErr_GetExcInfo" title="PyErr_GetExcInfo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetExcInfo()</span></code></a> which work with the legacy 3-tuple
|
||
representation of exceptions.
|
||
(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46343">bpo-46343</a>.)</p></li>
|
||
<li><p>Added the <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.safe_path" title="PyConfig.safe_path"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.safe_path</span></code></a> member.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/57684">gh-57684</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="whatsnew311-c-api-porting">
|
||
<span id="id6"></span><h3>Porting to Python 3.11<a class="headerlink" href="#whatsnew311-c-api-porting" title="Link to this heading">¶</a></h3>
|
||
<ul id="whatsnew311-pep670">
|
||
<li><p>Some macros have been converted to static inline functions to avoid
|
||
<a class="reference external" href="https://gcc.gnu.org/onlinedocs/cpp/Macro-Pitfalls.html">macro pitfalls</a>.
|
||
The change should be mostly transparent to users,
|
||
as the replacement functions will cast their arguments to the expected types
|
||
to avoid compiler warnings due to static type checks.
|
||
However, when the limited C API is set to >=3.11,
|
||
these casts are not done,
|
||
and callers will need to cast arguments to their expected types.
|
||
See <span class="target" id="index-36"></span><a class="pep reference external" href="https://peps.python.org/pep-0670/"><strong>PEP 670</strong></a> for more details.
|
||
(Contributed by Victor Stinner and Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/89653">gh-89653</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetExcInfo" title="PyErr_SetExcInfo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetExcInfo()</span></code></a> no longer uses the <code class="docutils literal notranslate"><span class="pre">type</span></code> and <code class="docutils literal notranslate"><span class="pre">traceback</span></code>
|
||
arguments, the interpreter now derives those values from the exception
|
||
instance (the <code class="docutils literal notranslate"><span class="pre">value</span></code> argument). The function still steals references
|
||
of all three arguments.
|
||
(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45711">bpo-45711</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_GetExcInfo" title="PyErr_GetExcInfo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetExcInfo()</span></code></a> now derives the <code class="docutils literal notranslate"><span class="pre">type</span></code> and <code class="docutils literal notranslate"><span class="pre">traceback</span></code>
|
||
fields of the result from the exception instance (the <code class="docutils literal notranslate"><span class="pre">value</span></code> field).
|
||
(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45711">bpo-45711</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/import.html#c._frozen" title="_frozen"><code class="xref c c-struct docutils literal notranslate"><span class="pre">_frozen</span></code></a> has a new <code class="docutils literal notranslate"><span class="pre">is_package</span></code> field to indicate whether
|
||
or not the frozen module is a package. Previously, a negative value
|
||
in the <code class="docutils literal notranslate"><span class="pre">size</span></code> field was the indicator. Now only non-negative values
|
||
be used for <code class="docutils literal notranslate"><span class="pre">size</span></code>.
|
||
(Contributed by Kumar Aditya in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46608">bpo-46608</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init.html#c._PyFrameEvalFunction" title="_PyFrameEvalFunction"><code class="xref c c-func docutils literal notranslate"><span class="pre">_PyFrameEvalFunction()</span></code></a> now takes <code class="docutils literal notranslate"><span class="pre">_PyInterpreterFrame*</span></code>
|
||
as its second parameter, instead of <code class="docutils literal notranslate"><span class="pre">PyFrameObject*</span></code>.
|
||
See <span class="target" id="index-37"></span><a class="pep reference external" href="https://peps.python.org/pep-0523/"><strong>PEP 523</strong></a> for more details of how to use this function pointer type.</p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_New()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_NewWithPosOnlyArgs()</span></code> now take
|
||
an additional <code class="docutils literal notranslate"><span class="pre">exception_table</span></code> argument.
|
||
Using these functions should be avoided, if at all possible.
|
||
To get a custom code object: create a code object using the compiler,
|
||
then get a modified version with the <code class="docutils literal notranslate"><span class="pre">replace</span></code> method.</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/code.html#c.PyCodeObject" title="PyCodeObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyCodeObject</span></code></a> no longer has the <code class="docutils literal notranslate"><span class="pre">co_code</span></code>, <code class="docutils literal notranslate"><span class="pre">co_varnames</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">co_cellvars</span></code> and <code class="docutils literal notranslate"><span class="pre">co_freevars</span></code> fields. Instead, use
|
||
<a class="reference internal" href="../c-api/code.html#c.PyCode_GetCode" title="PyCode_GetCode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_GetCode()</span></code></a>, <a class="reference internal" href="../c-api/code.html#c.PyCode_GetVarnames" title="PyCode_GetVarnames"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_GetVarnames()</span></code></a>,
|
||
<a class="reference internal" href="../c-api/code.html#c.PyCode_GetCellvars" title="PyCode_GetCellvars"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_GetCellvars()</span></code></a> and <a class="reference internal" href="../c-api/code.html#c.PyCode_GetFreevars" title="PyCode_GetFreevars"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_GetFreevars()</span></code></a> respectively
|
||
to access them via the C API.
|
||
(Contributed by Brandt Bucher in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46841">bpo-46841</a> and Ken Jin in <a class="reference external" href="https://github.com/python/cpython/issues/92154">gh-92154</a>
|
||
and <a class="reference external" href="https://github.com/python/cpython/issues/94936">gh-94936</a>.)</p></li>
|
||
<li><p>The old trashcan macros (<code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_SAFE_BEGIN</span></code>/<code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_SAFE_END</span></code>)
|
||
are now deprecated. They should be replaced by the new macros
|
||
<code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_BEGIN</span></code> and <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_END</span></code>.</p>
|
||
<p>A tp_dealloc function that has the old macros, such as:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">static</span> <span class="n">void</span>
|
||
<span class="n">mytype_dealloc</span><span class="p">(</span><span class="n">mytype</span> <span class="o">*</span><span class="n">p</span><span class="p">)</span>
|
||
<span class="p">{</span>
|
||
<span class="n">PyObject_GC_UnTrack</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
|
||
<span class="n">Py_TRASHCAN_SAFE_BEGIN</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
|
||
<span class="o">...</span>
|
||
<span class="n">Py_TRASHCAN_SAFE_END</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>should migrate to the new macros as follows:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">static</span> <span class="n">void</span>
|
||
<span class="n">mytype_dealloc</span><span class="p">(</span><span class="n">mytype</span> <span class="o">*</span><span class="n">p</span><span class="p">)</span>
|
||
<span class="p">{</span>
|
||
<span class="n">PyObject_GC_UnTrack</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
|
||
<span class="n">Py_TRASHCAN_BEGIN</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">mytype_dealloc</span><span class="p">)</span>
|
||
<span class="o">...</span>
|
||
<span class="n">Py_TRASHCAN_END</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Note that <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_BEGIN</span></code> has a second argument which
|
||
should be the deallocation function it is in.</p>
|
||
<p>To support older Python versions in the same codebase, you
|
||
can define the following macros and use them throughout
|
||
the code (credit: these were copied from the <code class="docutils literal notranslate"><span class="pre">mypy</span></code> codebase):</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX >= 0x03080000</span>
|
||
<span class="c1"># define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_BEGIN(op, dealloc)</span>
|
||
<span class="c1"># define CPy_TRASHCAN_END(op) Py_TRASHCAN_END</span>
|
||
<span class="c1">#else</span>
|
||
<span class="c1"># define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_SAFE_BEGIN(op)</span>
|
||
<span class="c1"># define CPy_TRASHCAN_END(op) Py_TRASHCAN_SAFE_END(op)</span>
|
||
<span class="c1">#endif</span>
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>The <a class="reference internal" href="../c-api/type.html#c.PyType_Ready" title="PyType_Ready"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_Ready()</span></code></a> function now raises an error if a type is defined
|
||
with the <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_HAVE_GC" title="Py_TPFLAGS_HAVE_GC"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_HAVE_GC</span></code></a> flag set but has no traverse function
|
||
(<a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_traverse" title="PyTypeObject.tp_traverse"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_traverse</span></code></a>).
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44263">bpo-44263</a>.)</p></li>
|
||
<li><p>Heap types with the <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> flag can now inherit
|
||
the <span class="target" id="index-38"></span><a class="pep reference external" href="https://peps.python.org/pep-0590/"><strong>PEP 590</strong></a> vectorcall protocol. Previously, this was only possible for
|
||
<a class="reference internal" href="../c-api/typeobj.html#static-types"><span class="std std-ref">static types</span></a>.
|
||
(Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43908">bpo-43908</a>)</p></li>
|
||
<li><p>Since <a class="reference internal" href="../c-api/structures.html#c.Py_TYPE" title="Py_TYPE"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_TYPE()</span></code></a> is changed to a inline static function,
|
||
<code class="docutils literal notranslate"><span class="pre">Py_TYPE(obj)</span> <span class="pre">=</span> <span class="pre">new_type</span></code> must be replaced with
|
||
<code class="docutils literal notranslate"><span class="pre">Py_SET_TYPE(obj,</span> <span class="pre">new_type)</span></code>: see the <a class="reference internal" href="../c-api/structures.html#c.Py_SET_TYPE" title="Py_SET_TYPE"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SET_TYPE()</span></code></a> function
|
||
(available since Python 3.9). For backward compatibility, this macro can be
|
||
used:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)</span>
|
||
<span class="n">static</span> <span class="n">inline</span> <span class="n">void</span> <span class="n">_Py_SET_TYPE</span><span class="p">(</span><span class="n">PyObject</span> <span class="o">*</span><span class="n">ob</span><span class="p">,</span> <span class="n">PyTypeObject</span> <span class="o">*</span><span class="nb">type</span><span class="p">)</span>
|
||
<span class="p">{</span> <span class="n">ob</span><span class="o">-></span><span class="n">ob_type</span> <span class="o">=</span> <span class="nb">type</span><span class="p">;</span> <span class="p">}</span>
|
||
<span class="c1">#define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type)</span>
|
||
<span class="c1">#endif</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=39573">bpo-39573</a>.)</p>
|
||
</li>
|
||
<li><p>Since <a class="reference internal" href="../c-api/structures.html#c.Py_SIZE" title="Py_SIZE"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SIZE()</span></code></a> is changed to a inline static function,
|
||
<code class="docutils literal notranslate"><span class="pre">Py_SIZE(obj)</span> <span class="pre">=</span> <span class="pre">new_size</span></code> must be replaced with
|
||
<code class="docutils literal notranslate"><span class="pre">Py_SET_SIZE(obj,</span> <span class="pre">new_size)</span></code>: see the <a class="reference internal" href="../c-api/structures.html#c.Py_SET_SIZE" title="Py_SET_SIZE"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SET_SIZE()</span></code></a> function
|
||
(available since Python 3.9). For backward compatibility, this macro can be
|
||
used:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_SIZE)</span>
|
||
<span class="n">static</span> <span class="n">inline</span> <span class="n">void</span> <span class="n">_Py_SET_SIZE</span><span class="p">(</span><span class="n">PyVarObject</span> <span class="o">*</span><span class="n">ob</span><span class="p">,</span> <span class="n">Py_ssize_t</span> <span class="n">size</span><span class="p">)</span>
|
||
<span class="p">{</span> <span class="n">ob</span><span class="o">-></span><span class="n">ob_size</span> <span class="o">=</span> <span class="n">size</span><span class="p">;</span> <span class="p">}</span>
|
||
<span class="c1">#define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size)</span>
|
||
<span class="c1">#endif</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=39573">bpo-39573</a>.)</p>
|
||
</li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre"><Python.h></span></code> no longer includes the header files <code class="docutils literal notranslate"><span class="pre"><stdlib.h></span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre"><stdio.h></span></code>, <code class="docutils literal notranslate"><span class="pre"><errno.h></span></code> and <code class="docutils literal notranslate"><span class="pre"><string.h></span></code> when the <code class="docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code>
|
||
macro is set to <code class="docutils literal notranslate"><span class="pre">0x030b0000</span></code> (Python 3.11) or higher. C extensions should
|
||
explicitly include the header files after <code class="docutils literal notranslate"><span class="pre">#include</span> <span class="pre"><Python.h></span></code>.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45434">bpo-45434</a>.)</p></li>
|
||
<li><p>The non-limited API files <code class="docutils literal notranslate"><span class="pre">cellobject.h</span></code>, <code class="docutils literal notranslate"><span class="pre">classobject.h</span></code>, <code class="docutils literal notranslate"><span class="pre">code.h</span></code>, <code class="docutils literal notranslate"><span class="pre">context.h</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">funcobject.h</span></code>, <code class="docutils literal notranslate"><span class="pre">genobject.h</span></code> and <code class="docutils literal notranslate"><span class="pre">longintrepr.h</span></code> have been moved to
|
||
the <code class="docutils literal notranslate"><span class="pre">Include/cpython</span></code> directory. Moreover, the <code class="docutils literal notranslate"><span class="pre">eval.h</span></code> header file was
|
||
removed. These files must not be included directly, as they are already
|
||
included in <code class="docutils literal notranslate"><span class="pre">Python.h</span></code>: <a class="reference internal" href="../c-api/intro.html#api-includes"><span class="std std-ref">Include Files</span></a>. If they have
|
||
been included directly, consider including <code class="docutils literal notranslate"><span class="pre">Python.h</span></code> instead.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35134">bpo-35134</a>.)</p></li>
|
||
<li><p>The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_CHECK_INTERNED()</span></code> macro has been excluded from the
|
||
limited C API. It was never usable there, because it used internal structures
|
||
which are not available in the limited C API.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46007">bpo-46007</a>.)</p></li>
|
||
<li><p>The following frame functions and type are now directly available with
|
||
<code class="docutils literal notranslate"><span class="pre">#include</span> <span class="pre"><Python.h></span></code>, it’s no longer needed to add
|
||
<code class="docutils literal notranslate"><span class="pre">#include</span> <span class="pre"><frameobject.h></span></code>:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_Check" title="PyFrame_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_Check()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBack" title="PyFrame_GetBack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBack()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBuiltins" title="PyFrame_GetBuiltins"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBuiltins()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetGenerator" title="PyFrame_GetGenerator"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetGenerator()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetGlobals" title="PyFrame_GetGlobals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetGlobals()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLasti" title="PyFrame_GetLasti"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLasti()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLocals()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_Type" title="PyFrame_Type"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyFrame_Type</span></code></a></p></li>
|
||
</ul>
|
||
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/93937">gh-93937</a>.)</p>
|
||
</li>
|
||
</ul>
|
||
<ul id="pyframeobject-3-11-hiding">
|
||
<li><p>The <a class="reference internal" href="../c-api/frame.html#c.PyFrameObject" title="PyFrameObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyFrameObject</span></code></a> structure members have been removed from the
|
||
public C API.</p>
|
||
<p>While the documentation notes that the <a class="reference internal" href="../c-api/frame.html#c.PyFrameObject" title="PyFrameObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyFrameObject</span></code></a> fields are
|
||
subject to change at any time, they have been stable for a long time and were
|
||
used in several popular extensions.</p>
|
||
<p>In Python 3.11, the frame struct was reorganized to allow performance
|
||
optimizations. Some fields were removed entirely, as they were details of the
|
||
old implementation.</p>
|
||
<p><a class="reference internal" href="../c-api/frame.html#c.PyFrameObject" title="PyFrameObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyFrameObject</span></code></a> fields:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_back</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBack" title="PyFrame_GetBack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBack()</span></code></a>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_blockstack</span></code>: removed.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_builtins</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBuiltins" title="PyFrame_GetBuiltins"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBuiltins()</span></code></a>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_code</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetCode" title="PyFrame_GetCode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetCode()</span></code></a>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_gen</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetGenerator" title="PyFrame_GetGenerator"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetGenerator()</span></code></a>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_globals</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetGlobals" title="PyFrame_GetGlobals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetGlobals()</span></code></a>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_iblock</span></code>: removed.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_lasti</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLasti" title="PyFrame_GetLasti"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLasti()</span></code></a>.
|
||
Code using <code class="docutils literal notranslate"><span class="pre">f_lasti</span></code> with <code class="docutils literal notranslate"><span class="pre">PyCode_Addr2Line()</span></code> should use
|
||
<a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLineNumber" title="PyFrame_GetLineNumber"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLineNumber()</span></code></a> instead; it may be faster.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_lineno</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLineNumber" title="PyFrame_GetLineNumber"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLineNumber()</span></code></a></p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_locals</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLocals()</span></code></a>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_stackdepth</span></code>: removed.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_state</span></code>: no public API (renamed to <code class="docutils literal notranslate"><span class="pre">f_frame.f_state</span></code>).</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_trace</span></code>: no public API.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_trace_lines</span></code>: use <code class="docutils literal notranslate"><span class="pre">PyObject_GetAttrString((PyObject*)frame,</span> <span class="pre">"f_trace_lines")</span></code>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_trace_opcodes</span></code>: use <code class="docutils literal notranslate"><span class="pre">PyObject_GetAttrString((PyObject*)frame,</span> <span class="pre">"f_trace_opcodes")</span></code>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_localsplus</span></code>: no public API (renamed to <code class="docutils literal notranslate"><span class="pre">f_frame.localsplus</span></code>).</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">f_valuestack</span></code>: removed.</p></li>
|
||
</ul>
|
||
<p>The Python frame object is now created lazily. A side effect is that the
|
||
<a class="reference internal" href="../reference/datamodel.html#frame.f_back" title="frame.f_back"><code class="xref py py-attr docutils literal notranslate"><span class="pre">f_back</span></code></a> member must not be accessed directly,
|
||
since its value is now also
|
||
computed lazily. The <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBack" title="PyFrame_GetBack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBack()</span></code></a> function must be called
|
||
instead.</p>
|
||
<p>Debuggers that accessed the <a class="reference internal" href="../reference/datamodel.html#frame.f_locals" title="frame.f_locals"><code class="xref py py-attr docutils literal notranslate"><span class="pre">f_locals</span></code></a> directly <em>must</em> call
|
||
<a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLocals()</span></code></a> instead. They no longer need to call
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_FastToLocalsWithError()</span></code> or <code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_LocalsToFast()</span></code>,
|
||
in fact they should not call those functions. The necessary updating of the
|
||
frame is now managed by the virtual machine.</p>
|
||
<p>Code defining <code class="docutils literal notranslate"><span class="pre">PyFrame_GetCode()</span></code> on Python 3.8 and older:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX < 0x030900B1</span>
|
||
<span class="n">static</span> <span class="n">inline</span> <span class="n">PyCodeObject</span><span class="o">*</span> <span class="n">PyFrame_GetCode</span><span class="p">(</span><span class="n">PyFrameObject</span> <span class="o">*</span><span class="n">frame</span><span class="p">)</span>
|
||
<span class="p">{</span>
|
||
<span class="n">Py_INCREF</span><span class="p">(</span><span class="n">frame</span><span class="o">-></span><span class="n">f_code</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="n">frame</span><span class="o">-></span><span class="n">f_code</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="c1">#endif</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Code defining <code class="docutils literal notranslate"><span class="pre">PyFrame_GetBack()</span></code> on Python 3.8 and older:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX < 0x030900B1</span>
|
||
<span class="n">static</span> <span class="n">inline</span> <span class="n">PyFrameObject</span><span class="o">*</span> <span class="n">PyFrame_GetBack</span><span class="p">(</span><span class="n">PyFrameObject</span> <span class="o">*</span><span class="n">frame</span><span class="p">)</span>
|
||
<span class="p">{</span>
|
||
<span class="n">Py_XINCREF</span><span class="p">(</span><span class="n">frame</span><span class="o">-></span><span class="n">f_back</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="n">frame</span><span class="o">-></span><span class="n">f_back</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="c1">#endif</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Or use the <a class="reference external" href="https://github.com/python/pythoncapi-compat">pythoncapi_compat project</a> to get these two
|
||
functions on older Python versions.</p>
|
||
</li>
|
||
<li><p>Changes of the <a class="reference internal" href="../c-api/init.html#c.PyThreadState" title="PyThreadState"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyThreadState</span></code></a> structure members:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">frame</span></code>: removed, use <a class="reference internal" href="../c-api/init.html#c.PyThreadState_GetFrame" title="PyThreadState_GetFrame"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_GetFrame()</span></code></a> (function added
|
||
to Python 3.9 by <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=40429">bpo-40429</a>).
|
||
Warning: the function returns a <a class="reference internal" href="../glossary.html#term-strong-reference"><span class="xref std std-term">strong reference</span></a>, need to call
|
||
<a class="reference internal" href="../c-api/refcounting.html#c.Py_XDECREF" title="Py_XDECREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_XDECREF()</span></code></a>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">tracing</span></code>: changed, use <a class="reference internal" href="../c-api/init.html#c.PyThreadState_EnterTracing" title="PyThreadState_EnterTracing"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_EnterTracing()</span></code></a>
|
||
and <a class="reference internal" href="../c-api/init.html#c.PyThreadState_LeaveTracing" title="PyThreadState_LeaveTracing"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_LeaveTracing()</span></code></a>
|
||
(functions added to Python 3.11 by <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=43760">bpo-43760</a>).</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">recursion_depth</span></code>: removed,
|
||
use <code class="docutils literal notranslate"><span class="pre">(tstate->recursion_limit</span> <span class="pre">-</span> <span class="pre">tstate->recursion_remaining)</span></code> instead.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">stackcheck_counter</span></code>: removed.</p></li>
|
||
</ul>
|
||
<p>Code defining <code class="docutils literal notranslate"><span class="pre">PyThreadState_GetFrame()</span></code> on Python 3.8 and older:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX < 0x030900B1</span>
|
||
<span class="n">static</span> <span class="n">inline</span> <span class="n">PyFrameObject</span><span class="o">*</span> <span class="n">PyThreadState_GetFrame</span><span class="p">(</span><span class="n">PyThreadState</span> <span class="o">*</span><span class="n">tstate</span><span class="p">)</span>
|
||
<span class="p">{</span>
|
||
<span class="n">Py_XINCREF</span><span class="p">(</span><span class="n">tstate</span><span class="o">-></span><span class="n">frame</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="n">tstate</span><span class="o">-></span><span class="n">frame</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="c1">#endif</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Code defining <code class="docutils literal notranslate"><span class="pre">PyThreadState_EnterTracing()</span></code> and
|
||
<code class="docutils literal notranslate"><span class="pre">PyThreadState_LeaveTracing()</span></code> on Python 3.10 and older:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX < 0x030B00A2</span>
|
||
<span class="n">static</span> <span class="n">inline</span> <span class="n">void</span> <span class="n">PyThreadState_EnterTracing</span><span class="p">(</span><span class="n">PyThreadState</span> <span class="o">*</span><span class="n">tstate</span><span class="p">)</span>
|
||
<span class="p">{</span>
|
||
<span class="n">tstate</span><span class="o">-></span><span class="n">tracing</span><span class="o">++</span><span class="p">;</span>
|
||
<span class="c1">#if PY_VERSION_HEX >= 0x030A00A1</span>
|
||
<span class="n">tstate</span><span class="o">-></span><span class="n">cframe</span><span class="o">-></span><span class="n">use_tracing</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
|
||
<span class="c1">#else</span>
|
||
<span class="n">tstate</span><span class="o">-></span><span class="n">use_tracing</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
|
||
<span class="c1">#endif</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="n">static</span> <span class="n">inline</span> <span class="n">void</span> <span class="n">PyThreadState_LeaveTracing</span><span class="p">(</span><span class="n">PyThreadState</span> <span class="o">*</span><span class="n">tstate</span><span class="p">)</span>
|
||
<span class="p">{</span>
|
||
<span class="nb">int</span> <span class="n">use_tracing</span> <span class="o">=</span> <span class="p">(</span><span class="n">tstate</span><span class="o">-></span><span class="n">c_tracefunc</span> <span class="o">!=</span> <span class="n">NULL</span> <span class="o">||</span> <span class="n">tstate</span><span class="o">-></span><span class="n">c_profilefunc</span> <span class="o">!=</span> <span class="n">NULL</span><span class="p">);</span>
|
||
<span class="n">tstate</span><span class="o">-></span><span class="n">tracing</span><span class="o">--</span><span class="p">;</span>
|
||
<span class="c1">#if PY_VERSION_HEX >= 0x030A00A1</span>
|
||
<span class="n">tstate</span><span class="o">-></span><span class="n">cframe</span><span class="o">-></span><span class="n">use_tracing</span> <span class="o">=</span> <span class="n">use_tracing</span><span class="p">;</span>
|
||
<span class="c1">#else</span>
|
||
<span class="n">tstate</span><span class="o">-></span><span class="n">use_tracing</span> <span class="o">=</span> <span class="n">use_tracing</span><span class="p">;</span>
|
||
<span class="c1">#endif</span>
|
||
<span class="p">}</span>
|
||
<span class="c1">#endif</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Or use <a class="reference external" href="https://github.com/python/pythoncapi-compat">the pythoncapi-compat project</a> to get these functions
|
||
on old Python functions.</p>
|
||
</li>
|
||
<li><p>Distributors are encouraged to build Python with the optimized Blake2
|
||
library <a class="reference external" href="https://www.blake2.net/">libb2</a>.</p></li>
|
||
<li><p>The <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths_set" title="PyConfig.module_search_paths_set"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths_set</span></code></a> field must now be set to 1 for
|
||
initialization to use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths" title="PyConfig.module_search_paths"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths</span></code></a> to initialize
|
||
<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>. Otherwise, initialization will recalculate the path and replace
|
||
any values added to <code class="docutils literal notranslate"><span class="pre">module_search_paths</span></code>.</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_Read" title="PyConfig_Read"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Read()</span></code></a> no longer calculates the initial search path, and will not
|
||
fill any values into <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths" title="PyConfig.module_search_paths"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths</span></code></a>. To calculate default
|
||
paths and then modify them, finish initialization and use <a class="reference internal" href="../c-api/sys.html#c.PySys_GetObject" title="PySys_GetObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_GetObject()</span></code></a>
|
||
to retrieve <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> as a Python list object and modify it directly.</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="whatsnew311-c-api-deprecated">
|
||
<span id="id7"></span><h3>Deprecated<a class="headerlink" href="#whatsnew311-c-api-deprecated" title="Link to this heading">¶</a></h3>
|
||
<ul>
|
||
<li><p>Deprecate the following functions to configure the Python initialization:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddWarnOptionUnicode()</span></code></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddWarnOption()</span></code></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddXOption()</span></code></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_HasWarnOptions()</span></code></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_SetArgvEx()</span></code></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_SetArgv()</span></code></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_SetPath()</span></code></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetPath()</span></code></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetProgramName()</span></code></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetPythonHome()</span></code></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetStandardStreamEncoding()</span></code></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">_Py_SetProgramFullPath()</span></code></p></li>
|
||
</ul>
|
||
<p>Use the new <a class="reference internal" href="../c-api/init_config.html#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a> API of the <a class="reference internal" href="../c-api/init_config.html#init-config"><span class="std std-ref">Python Initialization Configuration</span></a> instead (<span class="target" id="index-39"></span><a class="pep reference external" href="https://peps.python.org/pep-0587/"><strong>PEP 587</strong></a>).
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/88279">gh-88279</a>.)</p>
|
||
</li>
|
||
<li><p>Deprecate the <code class="docutils literal notranslate"><span class="pre">ob_shash</span></code> member of the <a class="reference internal" href="../c-api/bytes.html#c.PyBytesObject" title="PyBytesObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyBytesObject</span></code></a>. Use <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.
|
||
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=46864">bpo-46864</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="whatsnew311-c-api-pending-removal">
|
||
<span id="id8"></span><h3>Pending Removal in Python 3.12<a class="headerlink" href="#whatsnew311-c-api-pending-removal" title="Link to this heading">¶</a></h3>
|
||
<p>The following C APIs have been deprecated in earlier Python releases,
|
||
and will be removed in Python 3.12.</p>
|
||
<ul class="simple">
|
||
<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_AS_UNICODE()</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_AsUnicode()</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_DATA_SIZE()</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_IS_COMPACT()</span></code></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_IS_READY()</span></code></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></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_WSTR_LENGTH()</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-macro docutils literal notranslate"><span class="pre">PyUnicode_WCHAR_KIND</span></code></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicodeObject" title="PyUnicodeObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyUnicodeObject</span></code></a></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_InternImmortal()</span></code></p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="whatsnew311-c-api-removed">
|
||
<span id="id9"></span><h3>Removed<a class="headerlink" href="#whatsnew311-c-api-removed" title="Link to this heading">¶</a></h3>
|
||
<ul>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_BlockSetup()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_BlockPop()</span></code> have been
|
||
removed.
|
||
(Contributed by Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=40222">bpo-40222</a>.)</p></li>
|
||
<li><p>Remove the following math macros using the <code class="docutils literal notranslate"><span class="pre">errno</span></code> variable:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">Py_ADJUST_ERANGE1()</span></code></p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">Py_ADJUST_ERANGE2()</span></code></p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">Py_OVERFLOWED()</span></code></p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">Py_SET_ERANGE_IF_OVERFLOW()</span></code></p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">Py_SET_ERRNO_ON_MATH_ERROR()</span></code></p></li>
|
||
</ul>
|
||
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45412">bpo-45412</a>.)</p>
|
||
</li>
|
||
<li><p>Remove <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_COPY()</span></code> and <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_FILL()</span></code> macros, deprecated
|
||
since Python 3.3. Use <code class="docutils literal notranslate"><span class="pre">PyUnicode_CopyCharacters()</span></code> or <code class="docutils literal notranslate"><span class="pre">memcpy()</span></code>
|
||
(<code class="docutils literal notranslate"><span class="pre">wchar_t*</span></code> string), and <code class="docutils literal notranslate"><span class="pre">PyUnicode_Fill()</span></code> functions instead.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=41123">bpo-41123</a>.)</p></li>
|
||
<li><p>Remove the <code class="docutils literal notranslate"><span class="pre">pystrhex.h</span></code> header file. It only contains private functions.
|
||
C extensions should only include the main <code class="docutils literal notranslate"><span class="pre"><Python.h></span></code> header file.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45434">bpo-45434</a>.)</p></li>
|
||
<li><p>Remove the <code class="docutils literal notranslate"><span class="pre">Py_FORCE_DOUBLE()</span></code> macro. It was used by the
|
||
<code class="docutils literal notranslate"><span class="pre">Py_IS_INFINITY()</span></code> macro.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45440">bpo-45440</a>.)</p></li>
|
||
<li><p>The following items are no longer available when <a class="reference internal" href="../c-api/stable.html#c.Py_LIMITED_API" title="Py_LIMITED_API"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code></a>
|
||
is defined:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../c-api/marshal.html#c.PyMarshal_WriteLongToFile" title="PyMarshal_WriteLongToFile"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMarshal_WriteLongToFile()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/marshal.html#c.PyMarshal_WriteObjectToFile" title="PyMarshal_WriteObjectToFile"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMarshal_WriteObjectToFile()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/marshal.html#c.PyMarshal_ReadObjectFromString" title="PyMarshal_ReadObjectFromString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMarshal_ReadObjectFromString()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/marshal.html#c.PyMarshal_WriteObjectToString" title="PyMarshal_WriteObjectToString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMarshal_WriteObjectToString()</span></code></a></p></li>
|
||
<li><p>the <code class="docutils literal notranslate"><span class="pre">Py_MARSHAL_VERSION</span></code> macro</p></li>
|
||
</ul>
|
||
<p>These are not part of the <a class="reference internal" href="../c-api/stable.html#limited-api-list"><span class="std std-ref">limited API</span></a>.</p>
|
||
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45474">bpo-45474</a>.)</p>
|
||
</li>
|
||
<li><p>Exclude <a class="reference internal" href="../c-api/weakref.html#c.PyWeakref_GET_OBJECT" title="PyWeakref_GET_OBJECT"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWeakref_GET_OBJECT()</span></code></a> from the limited C API. It never
|
||
worked since the <code class="xref c c-type docutils literal notranslate"><span class="pre">PyWeakReference</span></code> structure is opaque in the
|
||
limited C API.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35134">bpo-35134</a>.)</p></li>
|
||
<li><p>Remove the <code class="docutils literal notranslate"><span class="pre">PyHeapType_GET_MEMBERS()</span></code> macro. It was exposed in the
|
||
public C API by mistake, it must only be used by Python internally.
|
||
Use the <code class="docutils literal notranslate"><span class="pre">PyTypeObject.tp_members</span></code> member instead.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=40170">bpo-40170</a>.)</p></li>
|
||
<li><p>Remove the <code class="docutils literal notranslate"><span class="pre">HAVE_PY_SET_53BIT_PRECISION</span></code> macro (moved to the internal C
|
||
API).
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=45412">bpo-45412</a>.)</p></li>
|
||
</ul>
|
||
<ul id="whatsnew311-pep624">
|
||
<li><p>Remove the <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> encoder APIs,
|
||
as they have been deprecated since Python 3.3,
|
||
are little used
|
||
and are inefficient relative to the recommended alternatives.</p>
|
||
<p>The removed functions are:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_Encode()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeASCII()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeLatin1()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF7()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF8()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF16()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF32()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUnicodeEscape()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeRawUnicodeEscape()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeCharmap()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_TranslateCharmap()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeDecimal()</span></code></p></li>
|
||
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_TransformDecimalToASCII()</span></code></p></li>
|
||
</ul>
|
||
<p>See <span class="target" id="index-40"></span><a class="pep reference external" href="https://peps.python.org/pep-0624/"><strong>PEP 624</strong></a> for details and
|
||
<span class="target" id="index-41"></span><a class="pep reference external" href="https://peps.python.org/pep-0624/#alternative-apis"><strong>migration guidance</strong></a>.
|
||
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=44029">bpo-44029</a>.)</p>
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
</section>
|
||
<section id="notable-changes-in-3-11-4">
|
||
<h2>Notable changes in 3.11.4<a class="headerlink" href="#notable-changes-in-3-11-4" title="Link to this heading">¶</a></h2>
|
||
<section id="tarfile">
|
||
<h3>tarfile<a class="headerlink" href="#tarfile" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<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">Extraction filters</span></a> for details.
|
||
In Python 3.12, use without the <em>filter</em> argument will show 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>.
|
||
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-42"></span><a class="pep reference external" href="https://peps.python.org/pep-0706/"><strong>PEP 706</strong></a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
</section>
|
||
<section id="notable-changes-in-3-11-5">
|
||
<h2>Notable changes in 3.11.5<a class="headerlink" href="#notable-changes-in-3-11-5" title="Link to this heading">¶</a></h2>
|
||
<section id="openssl">
|
||
<h3>OpenSSL<a class="headerlink" href="#openssl" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Windows builds and macOS installers from python.org now use OpenSSL 3.0.</p></li>
|
||
</ul>
|
||
</section>
|
||
</section>
|
||
</section>
|
||
|
||
|
||
<div class="clearer"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="Main">
|
||
<div class="sphinxsidebarwrapper">
|
||
<div>
|
||
<h3><a href="../contents.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">What’s New In Python 3.11</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-657-fine-grained-error-locations-in-tracebacks">PEP 657: Fine-grained error locations in tracebacks</a></li>
|
||
<li><a class="reference internal" href="#pep-654-exception-groups-and-except">PEP 654: Exception Groups and <code class="docutils literal notranslate"><span class="pre">except*</span></code></a></li>
|
||
<li><a class="reference internal" href="#pep-678-exceptions-can-be-enriched-with-notes">PEP 678: Exceptions can be enriched with notes</a></li>
|
||
<li><a class="reference internal" href="#windows-py-exe-launcher-improvements">Windows <code class="docutils literal notranslate"><span class="pre">py.exe</span></code> launcher improvements</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-646-variadic-generics">PEP 646: Variadic generics</a></li>
|
||
<li><a class="reference internal" href="#pep-655-marking-individual-typeddict-items-as-required-or-not-required">PEP 655: Marking individual <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> items as required or not-required</a></li>
|
||
<li><a class="reference internal" href="#pep-673-self-type">PEP 673: <code class="docutils literal notranslate"><span class="pre">Self</span></code> type</a></li>
|
||
<li><a class="reference internal" href="#pep-675-arbitrary-literal-string-type">PEP 675: Arbitrary literal string type</a></li>
|
||
<li><a class="reference internal" href="#pep-681-data-class-transforms">PEP 681: Data class transforms</a></li>
|
||
<li><a class="reference internal" href="#pep-563-may-not-be-the-future">PEP 563 may not be the future</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
|
||
<li><a class="reference internal" href="#other-cpython-implementation-changes">Other CPython Implementation 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="#asyncio">asyncio</a></li>
|
||
<li><a class="reference internal" href="#contextlib">contextlib</a></li>
|
||
<li><a class="reference internal" href="#dataclasses">dataclasses</a></li>
|
||
<li><a class="reference internal" href="#datetime">datetime</a></li>
|
||
<li><a class="reference internal" href="#enum">enum</a></li>
|
||
<li><a class="reference internal" href="#fcntl">fcntl</a></li>
|
||
<li><a class="reference internal" href="#fractions">fractions</a></li>
|
||
<li><a class="reference internal" href="#functools">functools</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="#whatsnew311-idle">IDLE and idlelib</a></li>
|
||
<li><a class="reference internal" href="#inspect">inspect</a></li>
|
||
<li><a class="reference internal" href="#locale">locale</a></li>
|
||
<li><a class="reference internal" href="#logging">logging</a></li>
|
||
<li><a class="reference internal" href="#math">math</a></li>
|
||
<li><a class="reference internal" href="#operator">operator</a></li>
|
||
<li><a class="reference internal" href="#os">os</a></li>
|
||
<li><a class="reference internal" href="#pathlib">pathlib</a></li>
|
||
<li><a class="reference internal" href="#re">re</a></li>
|
||
<li><a class="reference internal" href="#shutil">shutil</a></li>
|
||
<li><a class="reference internal" href="#socket">socket</a></li>
|
||
<li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
|
||
<li><a class="reference internal" href="#string">string</a></li>
|
||
<li><a class="reference internal" href="#sys">sys</a></li>
|
||
<li><a class="reference internal" href="#sysconfig">sysconfig</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="#time">time</a></li>
|
||
<li><a class="reference internal" href="#tkinter">tkinter</a></li>
|
||
<li><a class="reference internal" href="#traceback">traceback</a></li>
|
||
<li><a class="reference internal" href="#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="#venv">venv</a></li>
|
||
<li><a class="reference internal" href="#warnings">warnings</a></li>
|
||
<li><a class="reference internal" href="#zipfile">zipfile</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#optimizations">Optimizations</a></li>
|
||
<li><a class="reference internal" href="#faster-cpython">Faster CPython</a><ul>
|
||
<li><a class="reference internal" href="#faster-startup">Faster Startup</a><ul>
|
||
<li><a class="reference internal" href="#frozen-imports-static-code-objects">Frozen imports / Static code objects</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#faster-runtime">Faster Runtime</a><ul>
|
||
<li><a class="reference internal" href="#cheaper-lazy-python-frames">Cheaper, lazy Python frames</a></li>
|
||
<li><a class="reference internal" href="#inlined-python-function-calls">Inlined Python function calls</a></li>
|
||
<li><a class="reference internal" href="#pep-659-specializing-adaptive-interpreter">PEP 659: Specializing Adaptive Interpreter</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#misc">Misc</a></li>
|
||
<li><a class="reference internal" href="#faq">FAQ</a><ul>
|
||
<li><a class="reference internal" href="#how-should-i-write-my-code-to-utilize-these-speedups">How should I write my code to utilize these speedups?</a></li>
|
||
<li><a class="reference internal" href="#will-cpython-3-11-use-more-memory">Will CPython 3.11 use more memory?</a></li>
|
||
<li><a class="reference internal" href="#i-don-t-see-any-speedups-in-my-workload-why">I don’t see any speedups in my workload. Why?</a></li>
|
||
<li><a class="reference internal" href="#is-there-a-jit-compiler">Is there a JIT compiler?</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#about">About</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a><ul>
|
||
<li><a class="reference internal" href="#new-opcodes">New opcodes</a></li>
|
||
<li><a class="reference internal" href="#replaced-opcodes">Replaced opcodes</a></li>
|
||
<li><a class="reference internal" href="#changed-removed-opcodes">Changed/removed opcodes</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
|
||
<li><a class="reference internal" href="#language-builtins">Language/Builtins</a></li>
|
||
<li><a class="reference internal" href="#modules">Modules</a></li>
|
||
<li><a class="reference internal" href="#standard-library">Standard Library</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#pending-removal-in-python-3-12">Pending Removal in Python 3.12</a></li>
|
||
<li><a class="reference internal" href="#removed">Removed</a></li>
|
||
<li><a class="reference internal" href="#porting-to-python-3-11">Porting to Python 3.11</a></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="#whatsnew311-c-api-new-features">New Features</a></li>
|
||
<li><a class="reference internal" href="#whatsnew311-c-api-porting">Porting to Python 3.11</a></li>
|
||
<li><a class="reference internal" href="#whatsnew311-c-api-deprecated">Deprecated</a></li>
|
||
<li><a class="reference internal" href="#whatsnew311-c-api-pending-removal">Pending Removal in Python 3.12</a></li>
|
||
<li><a class="reference internal" href="#whatsnew311-c-api-removed">Removed</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#notable-changes-in-3-11-4">Notable changes in 3.11.4</a><ul>
|
||
<li><a class="reference internal" href="#tarfile">tarfile</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#notable-changes-in-3-11-5">Notable changes in 3.11.5</a><ul>
|
||
<li><a class="reference internal" href="#openssl">OpenSSL</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
</div>
|
||
<div>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="3.12.html"
|
||
title="previous chapter">What’s New In Python 3.12</a></p>
|
||
</div>
|
||
<div>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="3.10.html"
|
||
title="next chapter">What’s New In Python 3.10</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.11.rst"
|
||
rel="nofollow">Show Source
|
||
</a>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div id="sidebarbutton" title="Collapse sidebar">
|
||
<span>«</span>
|
||
</div>
|
||
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="Related">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
>index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.10.html" title="What’s New In Python 3.10"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.12.html" title="What’s New In Python 3.12"
|
||
>previous</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.13.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.11</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-2025, 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 08, 2025 (14:33 UTC).
|
||
|
||
<a href="/bugs.html">Found a bug</a>?
|
||
|
||
<br />
|
||
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
|
||
</div>
|
||
|
||
</body>
|
||
</html> |