1870 lines
216 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="Whats New In Python 3.9" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/whatsnew/3.9.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="Editor, Łukasz Langa,. This article explains the new features in Python 3.9, compared to 3.8. Python 3.9 was released on October 5, 2020. For full details, see the changelog. Summary Release high..." />
<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, Łukasz Langa,. This article explains the new features in Python 3.9, compared to 3.8. Python 3.9 was released on October 5, 2020. For full details, see the changelog. Summary Release high..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>Whats New In Python 3.9 &#8212; 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="Whats New In Python 3.8" href="3.8.html" />
<link rel="prev" title="Whats New In Python 3.10" href="3.10.html" />
<link rel="canonical" href="https://docs.python.org/3/whatsnew/3.9.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="#">Whats New In Python 3.9</a><ul>
<li><a class="reference internal" href="#summary-release-highlights">Summary Release highlights</a></li>
<li><a class="reference internal" href="#you-should-check-for-deprecationwarning-in-your-code">You should check for DeprecationWarning in your code</a></li>
<li><a class="reference internal" href="#new-features">New Features</a><ul>
<li><a class="reference internal" href="#dictionary-merge-update-operators">Dictionary Merge &amp; Update Operators</a></li>
<li><a class="reference internal" href="#new-string-methods-to-remove-prefixes-and-suffixes">New String Methods to Remove Prefixes and Suffixes</a></li>
<li><a class="reference internal" href="#type-hinting-generics-in-standard-collections">Type Hinting Generics in Standard Collections</a></li>
<li><a class="reference internal" href="#new-parser">New Parser</a></li>
</ul>
</li>
<li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
<li><a class="reference internal" href="#new-modules">New Modules</a><ul>
<li><a class="reference internal" href="#zoneinfo">zoneinfo</a></li>
<li><a class="reference internal" href="#graphlib">graphlib</a></li>
</ul>
</li>
<li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
<li><a class="reference internal" href="#ast">ast</a></li>
<li><a class="reference internal" href="#asyncio">asyncio</a></li>
<li><a class="reference internal" href="#compileall">compileall</a></li>
<li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li>
<li><a class="reference internal" href="#curses">curses</a></li>
<li><a class="reference internal" href="#datetime">datetime</a></li>
<li><a class="reference internal" href="#distutils">distutils</a></li>
<li><a class="reference internal" href="#fcntl">fcntl</a></li>
<li><a class="reference internal" href="#ftplib">ftplib</a></li>
<li><a class="reference internal" href="#gc">gc</a></li>
<li><a class="reference internal" href="#hashlib">hashlib</a></li>
<li><a class="reference internal" href="#http">http</a></li>
<li><a class="reference internal" href="#idle-and-idlelib">IDLE and idlelib</a></li>
<li><a class="reference internal" href="#imaplib">imaplib</a></li>
<li><a class="reference internal" href="#importlib">importlib</a></li>
<li><a class="reference internal" href="#inspect">inspect</a></li>
<li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
<li><a class="reference internal" href="#math">math</a></li>
<li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
<li><a class="reference internal" href="#nntplib">nntplib</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="#pdb">pdb</a></li>
<li><a class="reference internal" href="#poplib">poplib</a></li>
<li><a class="reference internal" href="#pprint">pprint</a></li>
<li><a class="reference internal" href="#pydoc">pydoc</a></li>
<li><a class="reference internal" href="#random">random</a></li>
<li><a class="reference internal" href="#signal">signal</a></li>
<li><a class="reference internal" href="#smtplib">smtplib</a></li>
<li><a class="reference internal" href="#socket">socket</a></li>
<li><a class="reference internal" href="#time">time</a></li>
<li><a class="reference internal" href="#sys">sys</a></li>
<li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
<li><a class="reference internal" href="#typing">typing</a></li>
<li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
<li><a class="reference internal" href="#venv">venv</a></li>
<li><a class="reference internal" href="#xml">xml</a></li>
</ul>
</li>
<li><a class="reference internal" href="#optimizations">Optimizations</a></li>
<li><a class="reference internal" href="#deprecated">Deprecated</a></li>
<li><a class="reference internal" href="#removed">Removed</a></li>
<li><a class="reference internal" href="#porting-to-python-3-9">Porting to Python 3.9</a><ul>
<li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
<li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
<li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#build-changes">Build Changes</a></li>
<li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
<li><a class="reference internal" href="#id1">New Features</a></li>
<li><a class="reference internal" href="#id2">Porting to Python 3.9</a></li>
<li><a class="reference internal" href="#id3">Removed</a></li>
</ul>
</li>
<li><a class="reference internal" href="#notable-changes-in-python-3-9-1">Notable changes in Python 3.9.1</a><ul>
<li><a class="reference internal" href="#id4">typing</a></li>
<li><a class="reference internal" href="#macos-11-0-big-sur-and-apple-silicon-mac-support">macOS 11.0 (Big Sur) and Apple Silicon Mac support</a></li>
</ul>
</li>
<li><a class="reference internal" href="#notable-changes-in-python-3-9-2">Notable changes in Python 3.9.2</a><ul>
<li><a class="reference internal" href="#collections-abc">collections.abc</a></li>
<li><a class="reference internal" href="#urllib-parse">urllib.parse</a></li>
</ul>
</li>
<li><a class="reference internal" href="#notable-changes-in-python-3-9-3">Notable changes in Python 3.9.3</a></li>
<li><a class="reference internal" href="#notable-changes-in-python-3-9-5">Notable changes in Python 3.9.5</a><ul>
<li><a class="reference internal" href="#id5">urllib.parse</a></li>
</ul>
</li>
<li><a class="reference internal" href="#notable-security-feature-in-3-9-14">Notable security feature in 3.9.14</a></li>
<li><a class="reference internal" href="#notable-changes-in-3-9-17">Notable changes in 3.9.17</a><ul>
<li><a class="reference internal" href="#tarfile">tarfile</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="3.10.html"
title="previous chapter">Whats New In Python 3.10</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="3.8.html"
title="next chapter">Whats New In Python 3.8</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.9.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.8.html" title="Whats New In Python 3.8"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="3.10.html" title="Whats New In Python 3.10"
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> &#187;</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> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Whats New in Python</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Whats New In Python 3.9</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-9">
<h1>Whats New In Python 3.9<a class="headerlink" href="#what-s-new-in-python-3-9" 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>Łukasz Langa</p>
</dd>
</dl>
<p>This article explains the new features in Python 3.9, compared to 3.8.
Python 3.9 was released on October 5, 2020.
For full details, see the <a class="reference internal" href="changelog.html#changelog"><span class="std std-ref">changelog</span></a>.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0596/"><strong>PEP 596</strong></a> - Python 3.9 Release Schedule</p>
</div>
<section id="summary-release-highlights">
<h2>Summary Release highlights<a class="headerlink" href="#summary-release-highlights" title="Link to this heading"></a></h2>
<p>New syntax features:</p>
<ul class="simple">
<li><p><span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0584/"><strong>PEP 584</strong></a>, union operators added to <code class="docutils literal notranslate"><span class="pre">dict</span></code>;</p></li>
<li><p><span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0585/"><strong>PEP 585</strong></a>, type hinting generics in standard collections;</p></li>
<li><p><span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0614/"><strong>PEP 614</strong></a>, relaxed grammar restrictions on decorators.</p></li>
</ul>
<p>New built-in features:</p>
<ul class="simple">
<li><p><span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0616/"><strong>PEP 616</strong></a>, string methods to remove prefixes and suffixes.</p></li>
</ul>
<p>New features in the standard library:</p>
<ul class="simple">
<li><p><span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0593/"><strong>PEP 593</strong></a>, flexible function and variable annotations;</p></li>
<li><p><a class="reference internal" href="../library/os.html#os.pidfd_open" title="os.pidfd_open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pidfd_open()</span></code></a> added that allows process management without races
and signals.</p></li>
</ul>
<p>Interpreter improvements:</p>
<ul class="simple">
<li><p><span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0573/"><strong>PEP 573</strong></a>, fast access to module state from methods of C extension
types;</p></li>
<li><p><span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0617/"><strong>PEP 617</strong></a>, CPython now uses a new parser based on PEG;</p></li>
<li><p>a number of Python builtins (range, tuple, set, frozenset, list, dict) are
now sped up using <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0590/"><strong>PEP 590</strong></a> vectorcall;</p></li>
<li><p>garbage collection does not block on resurrected objects;</p></li>
<li><p>a number of Python modules (<code class="xref py py-mod docutils literal notranslate"><span class="pre">_abc</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_bz2</span></code>,
<code class="xref py py-mod docutils literal notranslate"><span class="pre">_codecs</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_contextvars</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_crypt</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_functools</span></code>,
<code class="xref py py-mod docutils literal notranslate"><span class="pre">_json</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_locale</span></code>, <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>, <a class="reference internal" href="../library/operator.html#module-operator" title="operator: Functions corresponding to the standard operators."><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code></a>, <a class="reference internal" href="../library/resource.html#module-resource" title="resource: An interface to provide resource usage information on the current process. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">resource</span></code></a>,
<a class="reference internal" href="../library/time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_weakref</span></code>) now use multiphase initialization as defined
by PEP 489;</p></li>
<li><p>a number of standard library modules (<code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code>, <a class="reference internal" href="../library/ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a>, <a class="reference internal" href="../library/grp.html#module-grp" title="grp: The group database (getgrnam() and friends). (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">grp</span></code></a>,
<code class="xref py py-mod docutils literal notranslate"><span class="pre">_hashlib</span></code>, <a class="reference internal" href="../library/pwd.html#module-pwd" title="pwd: The password database (getpwnam() and friends). (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pwd</span></code></a>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_posixsubprocess</span></code>, <a class="reference internal" href="../library/random.html#module-random" title="random: Generate pseudo-random numbers with various common distributions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">random</span></code></a>,
<a class="reference internal" href="../library/select.html#module-select" title="select: Wait for I/O completion on multiple streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code></a>, <a class="reference internal" href="../library/struct.html#module-struct" title="struct: Interpret bytes as packed binary data."><code class="xref py py-mod docutils literal notranslate"><span class="pre">struct</span></code></a>, <a class="reference internal" href="../library/termios.html#module-termios" title="termios: POSIX style tty control. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">termios</span></code></a>, <a class="reference internal" href="../library/zlib.html#module-zlib" title="zlib: Low-level interface to compression and decompression routines compatible with gzip."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zlib</span></code></a>) are now using
the stable ABI defined by PEP 384.</p></li>
</ul>
<p>New library modules:</p>
<ul class="simple">
<li><p><span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0615/"><strong>PEP 615</strong></a>, the IANA Time Zone Database is now present in the standard
library in the <a class="reference internal" href="../library/zoneinfo.html#module-zoneinfo" title="zoneinfo: IANA time zone support"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zoneinfo</span></code></a> module;</p></li>
<li><p>an implementation of a topological sort of a graph is now provided in
the new <a class="reference internal" href="../library/graphlib.html#module-graphlib" title="graphlib: Functionality to operate with graph-like structures"><code class="xref py py-mod docutils literal notranslate"><span class="pre">graphlib</span></code></a> module.</p></li>
</ul>
<p>Release process changes:</p>
<ul class="simple">
<li><p><span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0602/"><strong>PEP 602</strong></a>, CPython adopts an annual release cycle.</p></li>
</ul>
</section>
<section id="you-should-check-for-deprecationwarning-in-your-code">
<h2>You should check for DeprecationWarning in your code<a class="headerlink" href="#you-should-check-for-deprecationwarning-in-your-code" title="Link to this heading"></a></h2>
<p>When Python 2.7 was still supported, a lot of functionality in Python 3
was kept for backward compatibility with Python 2.7. With the end of Python
2 support, these backward compatibility layers have been removed, or will
be removed soon. Most of them emitted 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> warning for
several years. For example, using <code class="docutils literal notranslate"><span class="pre">collections.Mapping</span></code> instead of
<code class="docutils literal notranslate"><span class="pre">collections.abc.Mapping</span></code> 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> since Python
3.3, released in 2012.</p>
<p>Test your application with the <a class="reference internal" href="../using/cmdline.html#cmdoption-W"><code class="xref std std-option docutils literal notranslate"><span class="pre">-W</span></code></a> <code class="docutils literal notranslate"><span class="pre">default</span></code> command-line option to see
<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 <a class="reference internal" href="../library/exceptions.html#PendingDeprecationWarning" title="PendingDeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PendingDeprecationWarning</span></code></a>, or even with
<a class="reference internal" href="../using/cmdline.html#cmdoption-W"><code class="xref std std-option docutils literal notranslate"><span class="pre">-W</span></code></a> <code class="docutils literal notranslate"><span class="pre">error</span></code> to treat them as errors. <a class="reference internal" href="../library/warnings.html#warning-filter"><span class="std std-ref">Warnings Filter</span></a> can be used to ignore warnings from third-party code.</p>
<p>Python 3.9 is the last version providing those Python 2 backward compatibility
layers, to give more time to Python projects maintainers to organize the
removal of the Python 2 support and add support for Python 3.9.</p>
<p>Aliases to <a class="reference internal" href="../library/collections.abc.html#collections-abstract-base-classes"><span class="std std-ref">Abstract Base Classes</span></a> in
the <a class="reference internal" href="../library/collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a> module, like <code class="docutils literal notranslate"><span class="pre">collections.Mapping</span></code> alias to
<a class="reference internal" href="../library/collections.abc.html#collections.abc.Mapping" title="collections.abc.Mapping"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Mapping</span></code></a>, are kept for one last release for backward
compatibility. They will be removed from Python 3.10.</p>
<p>More generally, try to run your tests in the <a class="reference internal" href="../library/devmode.html#devmode"><span class="std std-ref">Python Development Mode</span></a> which helps to prepare your code to make it compatible with the
next Python version.</p>
<p>Note: a number of pre-existing deprecations were removed in this version of
Python as well. Consult the <a class="reference internal" href="#removed-in-python-39"><span class="std std-ref">Removed</span></a> section.</p>
</section>
<section id="new-features">
<h2>New Features<a class="headerlink" href="#new-features" title="Link to this heading"></a></h2>
<section id="dictionary-merge-update-operators">
<h3>Dictionary Merge &amp; Update Operators<a class="headerlink" href="#dictionary-merge-update-operators" title="Link to this heading"></a></h3>
<p>Merge (<code class="docutils literal notranslate"><span class="pre">|</span></code>) and update (<code class="docutils literal notranslate"><span class="pre">|=</span></code>) operators have been added to the built-in
<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> class. Those complement the existing <code class="docutils literal notranslate"><span class="pre">dict.update</span></code> and
<code class="docutils literal notranslate"><span class="pre">{**d1,</span> <span class="pre">**d2}</span></code> methods of merging dictionaries.</p>
<p>Example:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;key1&quot;</span><span class="p">:</span> <span class="s2">&quot;value1 from x&quot;</span><span class="p">,</span> <span class="s2">&quot;key2&quot;</span><span class="p">:</span> <span class="s2">&quot;value2 from x&quot;</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;key2&quot;</span><span class="p">:</span> <span class="s2">&quot;value2 from y&quot;</span><span class="p">,</span> <span class="s2">&quot;key3&quot;</span><span class="p">:</span> <span class="s2">&quot;value3 from y&quot;</span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">|</span> <span class="n">y</span>
<span class="go">{&#39;key1&#39;: &#39;value1 from x&#39;, &#39;key2&#39;: &#39;value2 from y&#39;, &#39;key3&#39;: &#39;value3 from y&#39;}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">|</span> <span class="n">x</span>
<span class="go">{&#39;key2&#39;: &#39;value2 from x&#39;, &#39;key3&#39;: &#39;value3 from y&#39;, &#39;key1&#39;: &#39;value1 from x&#39;}</span>
</pre></div>
</div>
<p>See <span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0584/"><strong>PEP 584</strong></a> for a full description.
(Contributed by Brandt Bucher in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36144">bpo-36144</a>.)</p>
</section>
<section id="new-string-methods-to-remove-prefixes-and-suffixes">
<h3>New String Methods to Remove Prefixes and Suffixes<a class="headerlink" href="#new-string-methods-to-remove-prefixes-and-suffixes" title="Link to this heading"></a></h3>
<p><a class="reference internal" href="../library/stdtypes.html#str.removeprefix" title="str.removeprefix"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.removeprefix(prefix)</span></code></a> and
<a class="reference internal" href="../library/stdtypes.html#str.removesuffix" title="str.removesuffix"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.removesuffix(suffix)</span></code></a> have been added
to easily remove an unneeded prefix or a suffix from a string. Corresponding
<code class="docutils literal notranslate"><span class="pre">bytes</span></code>, <code class="docutils literal notranslate"><span class="pre">bytearray</span></code>, and <code class="docutils literal notranslate"><span class="pre">collections.UserString</span></code> methods have also been
added. See <span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0616/"><strong>PEP 616</strong></a> for a full description. (Contributed by Dennis Sweeney in
<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39939">bpo-39939</a>.)</p>
</section>
<section id="type-hinting-generics-in-standard-collections">
<h3>Type Hinting Generics in Standard Collections<a class="headerlink" href="#type-hinting-generics-in-standard-collections" title="Link to this heading"></a></h3>
<p>In type annotations you can now use built-in collection types such as
<code class="docutils literal notranslate"><span class="pre">list</span></code> and <code class="docutils literal notranslate"><span class="pre">dict</span></code> as generic types instead of importing the
corresponding capitalized types (e.g. <code class="docutils literal notranslate"><span class="pre">List</span></code> or <code class="docutils literal notranslate"><span class="pre">Dict</span></code>) from
<code class="docutils literal notranslate"><span class="pre">typing</span></code>. Some other types in the standard library are also now generic,
for example <code class="docutils literal notranslate"><span class="pre">queue.Queue</span></code>.</p>
<p>Example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">greet_all</span><span class="p">(</span><span class="n">names</span><span class="p">:</span> <span class="nb">list</span><span class="p">[</span><span class="nb">str</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Hello&quot;</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
</pre></div>
</div>
<p>See <span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0585/"><strong>PEP 585</strong></a> for more details. (Contributed by Guido van Rossum,
Ethan Smith, and Batuhan Taşkaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39481">bpo-39481</a>.)</p>
</section>
<section id="new-parser">
<h3>New Parser<a class="headerlink" href="#new-parser" title="Link to this heading"></a></h3>
<p>Python 3.9 uses a new parser, based on <a class="reference external" href="https://en.wikipedia.org/wiki/Parsing_expression_grammar">PEG</a> instead
of <a class="reference external" href="https://en.wikipedia.org/wiki/LL_parser">LL(1)</a>. The new
parsers performance is roughly comparable to that of the old parser,
but the PEG formalism is more flexible than LL(1) when it comes to
designing new language features. Well start using this flexibility
in Python 3.10 and later.</p>
<p>The <a class="reference internal" href="../library/ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a> module uses the new parser and produces the same AST as
the old parser.</p>
<p>In Python 3.10, the old parser will be deleted and so will all
functionality that depends on it (primarily the <code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code> module,
which has long been deprecated). In Python 3.9 <em>only</em>, you can switch
back to the LL(1) parser using a command line switch (<code class="docutils literal notranslate"><span class="pre">-X</span>
<span class="pre">oldparser</span></code>) or an environment variable (<code class="docutils literal notranslate"><span class="pre">PYTHONOLDPARSER=1</span></code>).</p>
<p>See <span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0617/"><strong>PEP 617</strong></a> for more details. (Contributed by Guido van Rossum,
Pablo Galindo and Lysandros Nikolaou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40334">bpo-40334</a>.)</p>
</section>
</section>
<section id="other-language-changes">
<h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading"></a></h2>
<ul>
<li><p><a class="reference internal" href="../library/functions.html#import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> now raises <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> instead of
<a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>, which used to occur when a relative import went past
its top-level package.
(Contributed by Ngalim Siregar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37444">bpo-37444</a>.)</p></li>
<li><p>Python now gets the absolute path of the script filename specified on
the command line (ex: <code class="docutils literal notranslate"><span class="pre">python3</span> <span class="pre">script.py</span></code>): the <code class="docutils literal notranslate"><span class="pre">__file__</span></code> attribute of
the <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> module became an absolute path, rather than a relative
path. These paths now remain valid after the current directory is changed
by <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">os.chdir()</span></code></a>. As a side effect, the traceback also displays the
absolute path for <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> module frames in this case.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20443">bpo-20443</a>.)</p></li>
<li><p>In the <a class="reference internal" href="../library/devmode.html#devmode"><span class="std std-ref">Python Development Mode</span></a> and in <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug build</span></a>, the
<em>encoding</em> and <em>errors</em> arguments are now checked for string encoding and
decoding operations. Examples: <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/stdtypes.html#str.encode" title="str.encode"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.encode()</span></code></a> and
<a class="reference internal" href="../library/stdtypes.html#bytes.decode" title="bytes.decode"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytes.decode()</span></code></a>.</p>
<p>By default, for best performance, the <em>errors</em> argument is only checked at
the first encoding/decoding error and the <em>encoding</em> argument is sometimes
ignored for empty strings.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37388">bpo-37388</a>.)</p>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">&quot;&quot;.replace(&quot;&quot;,</span> <span class="pre">s,</span> <span class="pre">n)</span></code> now returns <code class="docutils literal notranslate"><span class="pre">s</span></code> instead of an empty string for
all non-zero <code class="docutils literal notranslate"><span class="pre">n</span></code>. It is now consistent with <code class="docutils literal notranslate"><span class="pre">&quot;&quot;.replace(&quot;&quot;,</span> <span class="pre">s)</span></code>.
There are similar changes 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> and <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> objects.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28029">bpo-28029</a>.)</p></li>
<li><p>Any valid expression can now be used as a <a class="reference internal" href="../glossary.html#term-decorator"><span class="xref std std-term">decorator</span></a>. Previously, the
grammar was much more restrictive. See <span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0614/"><strong>PEP 614</strong></a> for details.
(Contributed by Brandt Bucher in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39702">bpo-39702</a>.)</p></li>
<li><p>Improved help for 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. Docstrings are now shown for
all special forms and special generic aliases (like <code class="docutils literal notranslate"><span class="pre">Union</span></code> and <code class="docutils literal notranslate"><span class="pre">List</span></code>).
Using <a class="reference internal" href="../library/functions.html#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a> with generic alias like <code class="docutils literal notranslate"><span class="pre">List[int]</span></code> will show the help
for the correspondent concrete type (<code class="docutils literal notranslate"><span class="pre">list</span></code> in this case).
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40257">bpo-40257</a>.)</p></li>
<li><p>Parallel running of <a class="reference internal" href="../reference/expressions.html#agen.aclose" title="agen.aclose"><code class="xref py py-meth docutils literal notranslate"><span class="pre">aclose()</span></code></a> / <a class="reference internal" href="../reference/expressions.html#agen.asend" title="agen.asend"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asend()</span></code></a> /
<a class="reference internal" href="../reference/expressions.html#agen.athrow" title="agen.athrow"><code class="xref py py-meth docutils literal notranslate"><span class="pre">athrow()</span></code></a> is now prohibited, and <code class="docutils literal notranslate"><span class="pre">ag_running</span></code> now reflects
the actual running status of the async generator.
(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30773">bpo-30773</a>.)</p></li>
<li><p>Unexpected errors in calling the <code class="docutils literal notranslate"><span class="pre">__iter__</span></code> method are no longer masked by
<code class="docutils literal notranslate"><span class="pre">TypeError</span></code> in the <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> operator and functions
<a class="reference internal" href="../library/operator.html#operator.contains" title="operator.contains"><code class="xref py py-func docutils literal notranslate"><span class="pre">contains()</span></code></a>, <a class="reference internal" href="../library/operator.html#operator.indexOf" title="operator.indexOf"><code class="xref py py-func docutils literal notranslate"><span class="pre">indexOf()</span></code></a> and
<a class="reference internal" href="../library/operator.html#operator.countOf" title="operator.countOf"><code class="xref py py-func docutils literal notranslate"><span class="pre">countOf()</span></code></a> of the <a class="reference internal" href="../library/operator.html#module-operator" title="operator: Functions corresponding to the standard operators."><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code></a> module.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40824">bpo-40824</a>.)</p></li>
<li><p>Unparenthesized lambda expressions can no longer be the expression part in an
<code class="docutils literal notranslate"><span class="pre">if</span></code> clause in comprehensions and generator expressions. See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41848">bpo-41848</a>
and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43755">bpo-43755</a> for details.</p></li>
</ul>
</section>
<section id="new-modules">
<h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading"></a></h2>
<section id="zoneinfo">
<h3>zoneinfo<a class="headerlink" href="#zoneinfo" title="Link to this heading"></a></h3>
<p>The <a class="reference internal" href="../library/zoneinfo.html#module-zoneinfo" title="zoneinfo: IANA time zone support"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zoneinfo</span></code></a> module brings support for the IANA time zone database to
the standard library. It adds <a class="reference internal" href="../library/zoneinfo.html#zoneinfo.ZoneInfo" title="zoneinfo.ZoneInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">zoneinfo.ZoneInfo</span></code></a>, a concrete
<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> implementation backed by the systems time zone data.</p>
<p>Example:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span><span class="w"> </span><span class="nn">zoneinfo</span><span class="w"> </span><span class="kn">import</span> <span class="n">ZoneInfo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span><span class="w"> </span><span class="nn">datetime</span><span class="w"> </span><span class="kn">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timedelta</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Daylight saving time</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dt</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2020</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">31</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="n">tzinfo</span><span class="o">=</span><span class="n">ZoneInfo</span><span class="p">(</span><span class="s2">&quot;America/Los_Angeles&quot;</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span>
<span class="go">2020-10-31 12:00:00-07:00</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dt</span><span class="o">.</span><span class="n">tzname</span><span class="p">()</span>
<span class="go">&#39;PDT&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># Standard time</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dt</span> <span class="o">+=</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">7</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span>
<span class="go">2020-11-07 12:00:00-08:00</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">dt</span><span class="o">.</span><span class="n">tzname</span><span class="p">())</span>
<span class="go">PST</span>
</pre></div>
</div>
<p>As a fall-back source of data for platforms that dont ship the IANA database,
the <a class="extlink-pypi reference external" href="https://pypi.org/project/tzdata/">tzdata</a> module was released as a first-party package distributed via
PyPI and maintained by the CPython core team.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0615/"><strong>PEP 615</strong></a> Support for the IANA Time Zone Database in the Standard Library</dt><dd><p>PEP written and implemented by Paul Ganssle</p>
</dd>
</dl>
</div>
</section>
<section id="graphlib">
<h3>graphlib<a class="headerlink" href="#graphlib" title="Link to this heading"></a></h3>
<p>A new module, <a class="reference internal" href="../library/graphlib.html#module-graphlib" title="graphlib: Functionality to operate with graph-like structures"><code class="xref py py-mod docutils literal notranslate"><span class="pre">graphlib</span></code></a>, was added that contains the
<a class="reference internal" href="../library/graphlib.html#graphlib.TopologicalSorter" title="graphlib.TopologicalSorter"><code class="xref py py-class docutils literal notranslate"><span class="pre">graphlib.TopologicalSorter</span></code></a> class to offer functionality to perform
topological sorting of graphs. (Contributed by Pablo Galindo, Tim Peters and
Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17005">bpo-17005</a>.)</p>
</section>
</section>
<section id="improved-modules">
<h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading"></a></h2>
<section id="ast">
<h3>ast<a class="headerlink" href="#ast" title="Link to this heading"></a></h3>
<p>Added the <em>indent</em> option to <a class="reference internal" href="../library/ast.html#ast.dump" title="ast.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump()</span></code></a> which allows it to produce a
multiline indented output.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37995">bpo-37995</a>.)</p>
<p>Added <a class="reference internal" href="../library/ast.html#ast.unparse" title="ast.unparse"><code class="xref py py-func docutils literal notranslate"><span class="pre">ast.unparse()</span></code></a> as a function in the <a class="reference internal" href="../library/ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a> module that can
be used to unparse an <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> object and produce a string with code
that would produce an equivalent <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> object when parsed.
(Contributed by Pablo Galindo and Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38870">bpo-38870</a>.)</p>
<p>Added docstrings to AST nodes that contains the ASDL signature used to
construct that node. (Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39638">bpo-39638</a>.)</p>
</section>
<section id="asyncio">
<h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading"></a></h3>
<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> is no longer supported. This is
because of the behavior of the socket option <code class="docutils literal notranslate"><span class="pre">SO_REUSEADDR</span></code> in UDP. For more
details, see the documentation for <code class="docutils literal notranslate"><span class="pre">loop.create_datagram_endpoint()</span></code>.
(Contributed by Kyle Stanley, Antoine Pitrou, and Yury Selivanov in
<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37228">bpo-37228</a>.)</p>
<p>Added a new <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.shutdown_default_executor" title="asyncio.loop.shutdown_default_executor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">shutdown_default_executor()</span></code></a>
that schedules a shutdown for the default executor that waits on the
<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">ThreadPoolExecutor</span></code></a> to finish closing. Also,
<a class="reference internal" href="../library/asyncio-runner.html#asyncio.run" title="asyncio.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.run()</span></code></a> has been updated to use the new <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a>.
(Contributed by Kyle Stanley in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34037">bpo-34037</a>.)</p>
<p>Added <a class="reference internal" href="../library/asyncio-policy.html#asyncio.PidfdChildWatcher" title="asyncio.PidfdChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.PidfdChildWatcher</span></code></a>, a Linux-specific child watcher
implementation that polls process file descriptors. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38692">bpo-38692</a>)</p>
<p>Added a new <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> <a class="reference internal" href="../library/asyncio-task.html#asyncio.to_thread" title="asyncio.to_thread"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.to_thread()</span></code></a>. It is mainly used for
running IO-bound functions in a separate thread to avoid blocking the event
loop, and essentially works as a high-level version of
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.run_in_executor" title="asyncio.loop.run_in_executor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">run_in_executor()</span></code></a> that can directly take keyword arguments.
(Contributed by Kyle Stanley and Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32309">bpo-32309</a>.)</p>
<p>When cancelling the task due to a timeout, <a class="reference internal" href="../library/asyncio-task.html#asyncio.wait_for" title="asyncio.wait_for"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.wait_for()</span></code></a> will now
wait until the cancellation is complete also in the case when <em>timeout</em> is
&lt;= 0, like it does with positive timeouts.
(Contributed by Elvis Pranskevichus in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32751">bpo-32751</a>.)</p>
<p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> now raises <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> when calling incompatible
methods with an <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket" title="ssl.SSLSocket"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLSocket</span></code></a> socket.
(Contributed by Ido Michael in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37404">bpo-37404</a>.)</p>
</section>
<section id="compileall">
<h3>compileall<a class="headerlink" href="#compileall" title="Link to this heading"></a></h3>
<p>Added new possibility to use hardlinks for duplicated <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files: <em>hardlink_dupes</em> parameter and hardlink-dupes command line option.
(Contributed by Lumír Frenzy Balhar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40495">bpo-40495</a>.)</p>
<p>Added new options for path manipulation in resulting <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files: <em>stripdir</em>, <em>prependdir</em>, <em>limit_sl_dest</em> parameters and -s, -p, -e command line options.
Added the possibility to specify the option for an optimization level multiple times.
(Contributed by Lumír Frenzy Balhar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38112">bpo-38112</a>.)</p>
</section>
<section id="concurrent-futures">
<h3>concurrent.futures<a class="headerlink" href="#concurrent-futures" title="Link to this heading"></a></h3>
<p>Added a new <em>cancel_futures</em> parameter to
<a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.Executor.shutdown" title="concurrent.futures.Executor.shutdown"><code class="xref py py-meth docutils literal notranslate"><span class="pre">concurrent.futures.Executor.shutdown()</span></code></a> that cancels all pending futures
which have not started running, instead of waiting for them to complete before
shutting down the executor.
(Contributed by Kyle Stanley in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39349">bpo-39349</a>.)</p>
<p>Removed daemon threads from <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">ThreadPoolExecutor</span></code></a>
and <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor" title="concurrent.futures.ProcessPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProcessPoolExecutor</span></code></a>. This improves
compatibility with subinterpreters and predictability in their shutdown
processes. (Contributed by Kyle Stanley in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39812">bpo-39812</a>.)</p>
<p>Workers in <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor" title="concurrent.futures.ProcessPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProcessPoolExecutor</span></code></a> are now spawned on
demand, only when there are no available idle workers to reuse. This optimizes
startup overhead and reduces the amount of lost CPU time to idle workers.
(Contributed by Kyle Stanley in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39207">bpo-39207</a>.)</p>
</section>
<section id="curses">
<h3>curses<a class="headerlink" href="#curses" title="Link to this heading"></a></h3>
<p>Added <a class="reference internal" href="../library/curses.html#curses.get_escdelay" title="curses.get_escdelay"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.get_escdelay()</span></code></a>, <a class="reference internal" href="../library/curses.html#curses.set_escdelay" title="curses.set_escdelay"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.set_escdelay()</span></code></a>,
<a class="reference internal" href="../library/curses.html#curses.get_tabsize" title="curses.get_tabsize"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.get_tabsize()</span></code></a>, and <a class="reference internal" href="../library/curses.html#curses.set_tabsize" title="curses.set_tabsize"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.set_tabsize()</span></code></a> functions.
(Contributed by Anthony Sottile in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38312">bpo-38312</a>.)</p>
</section>
<section id="datetime">
<h3>datetime<a class="headerlink" href="#datetime" title="Link to this heading"></a></h3>
<p>The <a class="reference internal" href="../library/datetime.html#datetime.date.isocalendar" title="datetime.date.isocalendar"><code class="xref py py-meth docutils literal notranslate"><span class="pre">isocalendar()</span></code></a> of <a class="reference internal" href="../library/datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a>
and <a class="reference internal" href="../library/datetime.html#datetime.datetime.isocalendar" title="datetime.datetime.isocalendar"><code class="xref py py-meth docutils literal notranslate"><span class="pre">isocalendar()</span></code></a> of <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.datetime</span></code></a>
methods now returns a <a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a> instead of 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>.
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24416">bpo-24416</a>.)</p>
</section>
<section id="distutils">
<h3>distutils<a class="headerlink" href="#distutils" title="Link to this heading"></a></h3>
<p>The <strong class="command">upload</strong> command now creates SHA2-256 and Blake2b-256 hash
digests. It skips MD5 on platforms that block MD5 digest.
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40698">bpo-40698</a>.)</p>
</section>
<section id="fcntl">
<h3>fcntl<a class="headerlink" href="#fcntl" title="Link to this heading"></a></h3>
<p>Added constants <code class="xref py py-const docutils literal notranslate"><span class="pre">F_OFD_GETLK</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">F_OFD_SETLK</span></code>
and <code class="xref py py-const docutils literal notranslate"><span class="pre">F_OFD_SETLKW</span></code>.
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38602">bpo-38602</a>.)</p>
</section>
<section id="ftplib">
<h3>ftplib<a class="headerlink" href="#ftplib" title="Link to this heading"></a></h3>
<p><a class="reference internal" href="../library/ftplib.html#ftplib.FTP" title="ftplib.FTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">FTP</span></code></a> and <a class="reference internal" href="../library/ftplib.html#ftplib.FTP_TLS" title="ftplib.FTP_TLS"><code class="xref py py-class docutils literal notranslate"><span class="pre">FTP_TLS</span></code></a> now raise a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a>
if the given timeout for their constructor is zero to prevent the creation of
a non-blocking socket. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39259">bpo-39259</a>.)</p>
</section>
<section id="gc">
<h3>gc<a class="headerlink" href="#gc" title="Link to this heading"></a></h3>
<p>When the garbage collector makes a collection in which some objects resurrect
(they are reachable from outside the isolated cycles after the finalizers have
been executed), do not block the collection of all objects that are still
unreachable. (Contributed by Pablo Galindo and Tim Peters in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38379">bpo-38379</a>.)</p>
<p>Added a new function <a class="reference internal" href="../library/gc.html#gc.is_finalized" title="gc.is_finalized"><code class="xref py py-func docutils literal notranslate"><span class="pre">gc.is_finalized()</span></code></a> to check if an object has been
finalized by the garbage collector. (Contributed by Pablo Galindo in
<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39322">bpo-39322</a>.)</p>
</section>
<section id="hashlib">
<h3>hashlib<a class="headerlink" href="#hashlib" title="Link to this heading"></a></h3>
<p>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 can now use SHA3 hashes and SHAKE XOF from OpenSSL
when available.
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37630">bpo-37630</a>.)</p>
<p>Builtin hash modules can now be disabled with
<code class="docutils literal notranslate"><span class="pre">./configure</span> <span class="pre">--without-builtin-hashlib-hashes</span></code> or selectively enabled with
e.g. <code class="docutils literal notranslate"><span class="pre">./configure</span> <span class="pre">--with-builtin-hashlib-hashes=sha3,blake2</span></code> to force use
of OpenSSL based implementation.
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40479">bpo-40479</a>)</p>
</section>
<section id="http">
<h3>http<a class="headerlink" href="#http" title="Link to this heading"></a></h3>
<p>HTTP status codes <code class="docutils literal notranslate"><span class="pre">103</span> <span class="pre">EARLY_HINTS</span></code>, <code class="docutils literal notranslate"><span class="pre">418</span> <span class="pre">IM_A_TEAPOT</span></code> and <code class="docutils literal notranslate"><span class="pre">425</span> <span class="pre">TOO_EARLY</span></code> are added to
<a class="reference internal" href="../library/http.html#http.HTTPStatus" title="http.HTTPStatus"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.HTTPStatus</span></code></a>. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39509">bpo-39509</a> and Ross Rhodes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39507">bpo-39507</a>.)</p>
</section>
<section id="idle-and-idlelib">
<h3>IDLE and idlelib<a class="headerlink" href="#idle-and-idlelib" title="Link to this heading"></a></h3>
<p>Added option to toggle cursor blink off. (Contributed by Zackery Spytz
in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4603">bpo-4603</a>.)</p>
<p>Escape key now closes IDLE completion windows. (Contributed by Johnny
Najera in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38944">bpo-38944</a>.)</p>
<p>Added keywords to module name completion list. (Contributed by Terry J.
Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37765">bpo-37765</a>.)</p>
<p>New in 3.9 maintenance releases</p>
<p>Make IDLE invoke <a class="reference internal" href="../library/sys.html#sys.excepthook" title="sys.excepthook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.excepthook()</span></code></a> (when started without -n).
User hooks were previously ignored. (Contributed by Ken Hilton in
<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43008">bpo-43008</a>.)</p>
<p>The changes above have been backported to 3.8 maintenance releases.</p>
<p>Rearrange the settings dialog. Split the General tab into Windows
and Shell/Ed tabs. Move help sources, which extend the Help menu, to the
Extensions tab. Make space for new options and shorten the dialog. The
latter makes the dialog better fit small screens. (Contributed by Terry Jan
Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40468">bpo-40468</a>.) Move the indent space setting from the Font tab to
the new Windows tab. (Contributed by Mark Roseman and Terry Jan Reedy in
<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33962">bpo-33962</a>.)</p>
<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?&#64;action=redirect&amp;bpo=45447">bpo-45447</a>.)</p>
</section>
<section id="imaplib">
<h3>imaplib<a class="headerlink" href="#imaplib" title="Link to this heading"></a></h3>
<p><a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4</span></code></a> and <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4_SSL" title="imaplib.IMAP4_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4_SSL</span></code></a> now have
an optional <em>timeout</em> parameter for their constructors.
Also, the <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4.open" title="imaplib.IMAP4.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">open()</span></code></a> method now has an optional <em>timeout</em> parameter
with this change. The overridden methods of <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4_SSL" title="imaplib.IMAP4_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4_SSL</span></code></a> and
<a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4_stream" title="imaplib.IMAP4_stream"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4_stream</span></code></a> were applied to this change.
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38615">bpo-38615</a>.)</p>
<p><a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4.unselect" title="imaplib.IMAP4.unselect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">imaplib.IMAP4.unselect()</span></code></a> is added.
<a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4.unselect" title="imaplib.IMAP4.unselect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">imaplib.IMAP4.unselect()</span></code></a> frees servers resources associated with the
selected mailbox and returns the server to the authenticated
state. This command performs the same actions as <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4.close" title="imaplib.IMAP4.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">imaplib.IMAP4.close()</span></code></a>, except
that no messages are permanently removed from the currently
selected mailbox. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40375">bpo-40375</a>.)</p>
</section>
<section id="importlib">
<h3>importlib<a class="headerlink" href="#importlib" title="Link to this heading"></a></h3>
<p>To improve consistency with import statements, <a class="reference internal" href="../library/importlib.html#importlib.util.resolve_name" title="importlib.util.resolve_name"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.resolve_name()</span></code></a>
now raises <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> instead of <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> for invalid relative
import attempts.
(Contributed by Ngalim Siregar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37444">bpo-37444</a>.)</p>
<p>Import loaders which publish immutable module objects can now publish
immutable packages in addition to individual modules.
(Contributed by Dino Viehland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39336">bpo-39336</a>.)</p>
<p>Added <a class="reference internal" href="../library/importlib.resources.html#importlib.resources.files" title="importlib.resources.files"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.files()</span></code></a> function with support for
subdirectories in package data, matching backport in <code class="docutils literal notranslate"><span class="pre">importlib_resources</span></code>
version 1.5.
(Contributed by Jason R. Coombs in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39791">bpo-39791</a>.)</p>
<p>Refreshed <code class="docutils literal notranslate"><span class="pre">importlib.metadata</span></code> from <code class="docutils literal notranslate"><span class="pre">importlib_metadata</span></code> version 1.6.1.</p>
</section>
<section id="inspect">
<h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading"></a></h3>
<p><a class="reference internal" href="../library/inspect.html#inspect.BoundArguments.arguments" title="inspect.BoundArguments.arguments"><code class="xref py py-attr docutils literal notranslate"><span class="pre">inspect.BoundArguments.arguments</span></code></a> is changed from <code class="docutils literal notranslate"><span class="pre">OrderedDict</span></code> to regular
dict. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36350">bpo-36350</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39775">bpo-39775</a>.)</p>
</section>
<section id="ipaddress">
<h3>ipaddress<a class="headerlink" href="#ipaddress" title="Link to this heading"></a></h3>
<p><a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ipaddress</span></code></a> now supports IPv6 Scoped Addresses (IPv6 address with suffix <code class="docutils literal notranslate"><span class="pre">%&lt;scope_id&gt;</span></code>).</p>
<p>Scoped IPv6 addresses can be parsed using <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Address" title="ipaddress.IPv6Address"><code class="xref py py-class docutils literal notranslate"><span class="pre">ipaddress.IPv6Address</span></code></a>.
If present, scope zone ID is available through the <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Address.scope_id" title="ipaddress.IPv6Address.scope_id"><code class="xref py py-attr docutils literal notranslate"><span class="pre">scope_id</span></code></a> attribute.
(Contributed by Oleksandr Pavliuk in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34788">bpo-34788</a>.)</p>
<p>Starting with Python 3.9.5 the <a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ipaddress</span></code></a> module no longer
accepts any leading zeros in IPv4 address strings.
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36384">bpo-36384</a>).</p>
</section>
<section id="math">
<h3>math<a class="headerlink" href="#math" title="Link to this heading"></a></h3>
<p>Expanded the <a class="reference internal" href="../library/math.html#math.gcd" title="math.gcd"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.gcd()</span></code></a> function to handle multiple arguments.
Formerly, it only supported two arguments.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39648">bpo-39648</a>.)</p>
<p>Added <a class="reference internal" href="../library/math.html#math.lcm" title="math.lcm"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.lcm()</span></code></a>: return the least common multiple of specified arguments.
(Contributed by Mark Dickinson, Ananthakrishnan and Serhiy Storchaka in
<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39479">bpo-39479</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39648">bpo-39648</a>.)</p>
<p>Added <a class="reference internal" href="../library/math.html#math.nextafter" title="math.nextafter"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.nextafter()</span></code></a>: return the next floating-point value after <em>x</em>
towards <em>y</em>.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39288">bpo-39288</a>.)</p>
<p>Added <a class="reference internal" href="../library/math.html#math.ulp" title="math.ulp"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.ulp()</span></code></a>: return the value of the least significant bit
of a float.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39310">bpo-39310</a>.)</p>
</section>
<section id="multiprocessing">
<h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Link to this heading"></a></h3>
<p>The <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.SimpleQueue" title="multiprocessing.SimpleQueue"><code class="xref py py-class docutils literal notranslate"><span class="pre">multiprocessing.SimpleQueue</span></code></a> class has a new
<a class="reference internal" href="../library/multiprocessing.html#multiprocessing.SimpleQueue.close" title="multiprocessing.SimpleQueue.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> method to explicitly close the
queue.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30966">bpo-30966</a>.)</p>
</section>
<section id="nntplib">
<h3>nntplib<a class="headerlink" href="#nntplib" title="Link to this heading"></a></h3>
<p><code class="xref py py-class docutils literal notranslate"><span class="pre">NNTP</span></code> and <code class="xref py py-class docutils literal notranslate"><span class="pre">NNTP_SSL</span></code> now raise a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a>
if the given timeout for their constructor is zero to prevent the creation of
a non-blocking socket. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39259">bpo-39259</a>.)</p>
</section>
<section id="os">
<h3>os<a class="headerlink" href="#os" title="Link to this heading"></a></h3>
<p>Added <a class="reference internal" href="../library/os.html#os.CLD_KILLED" title="os.CLD_KILLED"><code class="xref py py-const docutils literal notranslate"><span class="pre">CLD_KILLED</span></code></a> and <a class="reference internal" href="../library/os.html#os.CLD_STOPPED" title="os.CLD_STOPPED"><code class="xref py py-const docutils literal notranslate"><span class="pre">CLD_STOPPED</span></code></a> for <code class="xref py py-attr docutils literal notranslate"><span class="pre">si_code</span></code>.
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38493">bpo-38493</a>.)</p>
<p>Exposed the Linux-specific <a class="reference internal" href="../library/os.html#os.pidfd_open" title="os.pidfd_open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pidfd_open()</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38692">bpo-38692</a>) and
<a class="reference internal" href="../library/os.html#os.P_PIDFD" title="os.P_PIDFD"><code class="xref py py-const docutils literal notranslate"><span class="pre">os.P_PIDFD</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38713">bpo-38713</a>) for process management with file
descriptors.</p>
<p>The <a class="reference internal" href="../library/os.html#os.unsetenv" title="os.unsetenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.unsetenv()</span></code></a> function is now also available on Windows.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39413">bpo-39413</a>.)</p>
<p>The <a class="reference internal" href="../library/os.html#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.putenv()</span></code></a> and <a class="reference internal" href="../library/os.html#os.unsetenv" title="os.unsetenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.unsetenv()</span></code></a> functions are now always
available.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39395">bpo-39395</a>.)</p>
<p>Added <a class="reference internal" href="../library/os.html#os.waitstatus_to_exitcode" title="os.waitstatus_to_exitcode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.waitstatus_to_exitcode()</span></code></a> function:
convert a wait status to an exit code.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40094">bpo-40094</a>.)</p>
</section>
<section id="pathlib">
<h3>pathlib<a class="headerlink" href="#pathlib" title="Link to this heading"></a></h3>
<p>Added <a class="reference internal" href="../library/pathlib.html#pathlib.Path.readlink" title="pathlib.Path.readlink"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.readlink()</span></code></a> which acts similarly to
<a class="reference internal" href="../library/os.html#os.readlink" title="os.readlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.readlink()</span></code></a>.
(Contributed by Girts Folkmanis in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30618">bpo-30618</a>)</p>
</section>
<section id="pdb">
<h3>pdb<a class="headerlink" href="#pdb" title="Link to this heading"></a></h3>
<p>On Windows now <a class="reference internal" href="../library/pdb.html#pdb.Pdb" title="pdb.Pdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pdb</span></code></a> supports <code class="docutils literal notranslate"><span class="pre">~/.pdbrc</span></code>.
(Contributed by Tim Hopper and Dan Lidral-Porter in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20523">bpo-20523</a>.)</p>
</section>
<section id="poplib">
<h3>poplib<a class="headerlink" href="#poplib" title="Link to this heading"></a></h3>
<p><a class="reference internal" href="../library/poplib.html#poplib.POP3" title="poplib.POP3"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code></a> and <a class="reference internal" href="../library/poplib.html#poplib.POP3_SSL" title="poplib.POP3_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3_SSL</span></code></a> now raise a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a>
if the given timeout for their constructor is zero to prevent the creation of
a non-blocking socket. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39259">bpo-39259</a>.)</p>
</section>
<section id="pprint">
<h3>pprint<a class="headerlink" href="#pprint" title="Link to this heading"></a></h3>
<p><a class="reference internal" href="../library/pprint.html#module-pprint" title="pprint: Data pretty printer."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pprint</span></code></a> can now pretty-print <a class="reference internal" href="../library/types.html#types.SimpleNamespace" title="types.SimpleNamespace"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.SimpleNamespace</span></code></a>.
(Contributed by Carl Bordum Hansen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37376">bpo-37376</a>.)</p>
</section>
<section id="pydoc">
<h3>pydoc<a class="headerlink" href="#pydoc" title="Link to this heading"></a></h3>
<p>The documentation string is now shown not only for class, function,
method etc, but for any object that has its own <a class="reference internal" href="../library/stdtypes.html#definition.__doc__" title="definition.__doc__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__doc__</span></code></a>
attribute.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40257">bpo-40257</a>.)</p>
</section>
<section id="random">
<h3>random<a class="headerlink" href="#random" title="Link to this heading"></a></h3>
<p>Added a new <code class="xref py py-attr docutils literal notranslate"><span class="pre">random.Random.randbytes</span></code> method: generate random bytes.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40286">bpo-40286</a>.)</p>
</section>
<section id="signal">
<h3>signal<a class="headerlink" href="#signal" title="Link to this heading"></a></h3>
<p>Exposed the Linux-specific <a class="reference internal" href="../library/signal.html#signal.pidfd_send_signal" title="signal.pidfd_send_signal"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.pidfd_send_signal()</span></code></a> for sending to
signals to a process using a file descriptor instead of a pid. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38712">bpo-38712</a>)</p>
</section>
<section id="smtplib">
<h3>smtplib<a class="headerlink" href="#smtplib" title="Link to this heading"></a></h3>
<p><a class="reference internal" href="../library/smtplib.html#smtplib.SMTP" title="smtplib.SMTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTP</span></code></a> and <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP_SSL" title="smtplib.SMTP_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTP_SSL</span></code></a> now raise a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a>
if the given timeout for their constructor is zero to prevent the creation of
a non-blocking socket. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39259">bpo-39259</a>.)</p>
<p><a class="reference internal" href="../library/smtplib.html#smtplib.LMTP" title="smtplib.LMTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">LMTP</span></code></a> constructor now has an optional <em>timeout</em> parameter.
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39329">bpo-39329</a>.)</p>
</section>
<section id="socket">
<h3>socket<a class="headerlink" href="#socket" title="Link to this heading"></a></h3>
<p>The <a class="reference internal" href="../library/socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socket</span></code></a> module now exports the <a class="reference internal" href="../library/socket.html#socket.CAN_RAW_JOIN_FILTERS" title="socket.CAN_RAW_JOIN_FILTERS"><code class="xref py py-const docutils literal notranslate"><span class="pre">CAN_RAW_JOIN_FILTERS</span></code></a>
constant on Linux 4.1 and greater.
(Contributed by Stefan Tatschner and Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25780">bpo-25780</a>.)</p>
<p>The socket module now supports the <a class="reference internal" href="../library/socket.html#socket.CAN_J1939" title="socket.CAN_J1939"><code class="xref py py-const docutils literal notranslate"><span class="pre">CAN_J1939</span></code></a> protocol on
platforms that support it. (Contributed by Karl Ding in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40291">bpo-40291</a>.)</p>
<p>The socket module now has the <a class="reference internal" href="../library/socket.html#socket.send_fds" title="socket.send_fds"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.send_fds()</span></code></a> and
<a class="reference internal" href="../library/socket.html#socket.recv_fds" title="socket.recv_fds"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.recv_fds()</span></code></a> functions. (Contributed by Joannah Nanjekye, Shinya
Okano and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28724">bpo-28724</a>.)</p>
</section>
<section id="time">
<h3>time<a class="headerlink" href="#time" title="Link to this heading"></a></h3>
<p>On AIX, <a class="reference internal" href="../library/time.html#time.thread_time" title="time.thread_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">thread_time()</span></code></a> is now implemented with <code class="docutils literal notranslate"><span class="pre">thread_cputime()</span></code>
which has nanosecond resolution, rather than
<code class="docutils literal notranslate"><span class="pre">clock_gettime(CLOCK_THREAD_CPUTIME_ID)</span></code> which has a resolution of 10 milliseconds.
(Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40192">bpo-40192</a>)</p>
</section>
<section id="sys">
<h3>sys<a class="headerlink" href="#sys" title="Link to this heading"></a></h3>
<p>Added a new <a class="reference internal" href="../library/sys.html#sys.platlibdir" title="sys.platlibdir"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platlibdir</span></code></a> attribute: name of the platform-specific
library directory. It is used to build the path of standard library and the
paths of installed extension modules. It is equal to <code class="docutils literal notranslate"><span class="pre">&quot;lib&quot;</span></code> on most
platforms. On Fedora and SuSE, it is equal to <code class="docutils literal notranslate"><span class="pre">&quot;lib64&quot;</span></code> on 64-bit platforms.
(Contributed by Jan Matějek, Matěj Cepl, Charalampos Stratakis and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1294959">bpo-1294959</a>.)</p>
<p>Previously, <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> was block-buffered when non-interactive. Now
<code class="docutils literal notranslate"><span class="pre">stderr</span></code> defaults to always being line-buffered.
(Contributed by Jendrik Seipp in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13601">bpo-13601</a>.)</p>
</section>
<section id="tracemalloc">
<h3>tracemalloc<a class="headerlink" href="#tracemalloc" title="Link to this heading"></a></h3>
<p>Added <a class="reference internal" href="../library/tracemalloc.html#tracemalloc.reset_peak" title="tracemalloc.reset_peak"><code class="xref py py-func docutils literal notranslate"><span class="pre">tracemalloc.reset_peak()</span></code></a> to set the peak size of traced memory
blocks to the current size, to measure the peak of specific pieces of code.
(Contributed by Huon Wilson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40630">bpo-40630</a>.)</p>
</section>
<section id="typing">
<h3>typing<a class="headerlink" href="#typing" title="Link to this heading"></a></h3>
<p><span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0593/"><strong>PEP 593</strong></a> introduced an <a class="reference internal" href="../library/typing.html#typing.Annotated" title="typing.Annotated"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.Annotated</span></code></a> type to decorate existing
types with context-specific metadata and new <code class="docutils literal notranslate"><span class="pre">include_extras</span></code> parameter to
<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> to access the metadata at runtime. (Contributed
by Till Varoquaux and Konstantin Kashin.)</p>
</section>
<section id="unicodedata">
<h3>unicodedata<a class="headerlink" href="#unicodedata" title="Link to this heading"></a></h3>
<p>The Unicode database has been updated to version 13.0.0. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39926">bpo-39926</a>).</p>
</section>
<section id="venv">
<h3>venv<a class="headerlink" href="#venv" title="Link to this heading"></a></h3>
<p>The activation scripts provided by <a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a> now all specify their prompt
customization consistently by always using the value specified by
<code class="docutils literal notranslate"><span class="pre">__VENV_PROMPT__</span></code>. Previously some scripts unconditionally used
<code class="docutils literal notranslate"><span class="pre">__VENV_PROMPT__</span></code>, others only if it happened to be set (which was the default
case), and one used <code class="docutils literal notranslate"><span class="pre">__VENV_NAME__</span></code> instead.
(Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37663">bpo-37663</a>.)</p>
</section>
<section id="xml">
<h3>xml<a class="headerlink" href="#xml" title="Link to this heading"></a></h3>
<p>White space characters within attributes are now preserved when serializing
<a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code></a> to XML file. EOLNs are no longer normalized
to “n”. This is the result of discussion about how to interpret
section 2.11 of XML spec.
(Contributed by Mefistotelis in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39011">bpo-39011</a>.)</p>
</section>
</section>
<section id="optimizations">
<h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading"></a></h2>
<ul>
<li><p>Optimized the idiom for assignment a temporary variable in comprehensions.
Now <code class="docutils literal notranslate"><span class="pre">for</span> <span class="pre">y</span> <span class="pre">in</span> <span class="pre">[expr]</span></code> in comprehensions is as fast as a simple assignment
<code class="docutils literal notranslate"><span class="pre">y</span> <span class="pre">=</span> <span class="pre">expr</span></code>. For example:</p>
<blockquote>
<div><p>sums = [s for s in [0] for x in data for s in [s + x]]</p>
</div></blockquote>
<p>Unlike the <code class="docutils literal notranslate"><span class="pre">:=</span></code> operator this idiom does not leak a variable to the
outer scope.</p>
<p>(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32856">bpo-32856</a>.)</p>
</li>
<li><p>Optimized signal handling in multithreaded applications. If a thread different
than the main thread gets a signal, the bytecode evaluation loop is no longer
interrupted at each bytecode instruction to check for pending signals which
cannot be handled. Only the main thread of the main interpreter can handle
signals.</p>
<p>Previously, the bytecode evaluation loop was interrupted at each instruction
until the main thread handles signals.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40010">bpo-40010</a>.)</p>
</li>
<li><p>Optimized the <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module on FreeBSD using <code class="docutils literal notranslate"><span class="pre">closefrom()</span></code>.
(Contributed by Ed Maste, Conrad Meyer, Kyle Evans, Kubilay Kocak and Victor
Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38061">bpo-38061</a>.)</p></li>
<li><p><a class="reference internal" href="../c-api/long.html#c.PyLong_FromDouble" title="PyLong_FromDouble"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyLong_FromDouble()</span></code></a> is now up to 1.87x faster for values that
fit into <span class="c-expr sig sig-inline c"><span class="kt">long</span></span>.
(Contributed by Sergey Fedoseev in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37986">bpo-37986</a>.)</p></li>
<li><p>A number of Python builtins (<a class="reference internal" href="../library/stdtypes.html#range" title="range"><code class="xref py py-class docutils literal notranslate"><span class="pre">range</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>, <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/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#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>) are now sped up by using
<span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0590/"><strong>PEP 590</strong></a> vectorcall protocol.
(Contributed by Donghee Na, Mark Shannon, Jeroen Demeyer and Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37207">bpo-37207</a>.)</p></li>
<li><p>Optimized <code class="xref py py-func docutils literal notranslate"><span class="pre">difference_update()</span></code> for the case when the other set
is much larger than the base set.
(Suggested by Evgeny Kapun with code contributed by Michele Orrù in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8425">bpo-8425</a>.)</p></li>
<li><p>Pythons small object allocator (<code class="docutils literal notranslate"><span class="pre">obmalloc.c</span></code>) now allows (no more than)
one empty arena to remain available for immediate reuse, without returning
it to the OS. This prevents thrashing in simple loops where an arena could
be created and destroyed anew on each iteration.
(Contributed by Tim Peters in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37257">bpo-37257</a>.)</p></li>
<li><p><a class="reference internal" href="../glossary.html#term-floor-division"><span class="xref std std-term">floor division</span></a> of float operation now has a better performance. Also
the message of <a class="reference internal" href="../library/exceptions.html#ZeroDivisionError" title="ZeroDivisionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ZeroDivisionError</span></code></a> for this operation is updated.
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39434">bpo-39434</a>.)</p></li>
<li><p>Decoding short ASCII strings with UTF-8 and ascii codecs is now about
15% faster. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37348">bpo-37348</a>.)</p></li>
</ul>
<p>Heres a summary of performance improvements from Python 3.4 through Python 3.9:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Python version 3.4 3.5 3.6 3.7 3.8 3.9
-------------- --- --- --- --- --- ---
Variable and attribute read access:
read_local 7.1 7.1 5.4 5.1 3.9 3.9
read_nonlocal 7.1 8.1 5.8 5.4 4.4 4.5
read_global 15.5 19.0 14.3 13.6 7.6 7.8
read_builtin 21.1 21.6 18.5 19.0 7.5 7.8
read_classvar_from_class 25.6 26.5 20.7 19.5 18.4 17.9
read_classvar_from_instance 22.8 23.5 18.8 17.1 16.4 16.9
read_instancevar 32.4 33.1 28.0 26.3 25.4 25.3
read_instancevar_slots 27.8 31.3 20.8 20.8 20.2 20.5
read_namedtuple 73.8 57.5 45.0 46.8 18.4 18.7
read_boundmethod 37.6 37.9 29.6 26.9 27.7 41.1
Variable and attribute write access:
write_local 8.7 9.3 5.5 5.3 4.3 4.3
write_nonlocal 10.5 11.1 5.6 5.5 4.7 4.8
write_global 19.7 21.2 18.0 18.0 15.8 16.7
write_classvar 92.9 96.0 104.6 102.1 39.2 39.8
write_instancevar 44.6 45.8 40.0 38.9 35.5 37.4
write_instancevar_slots 35.6 36.1 27.3 26.6 25.7 25.8
Data structure read access:
read_list 24.2 24.5 20.8 20.8 19.0 19.5
read_deque 24.7 25.5 20.2 20.6 19.8 20.2
read_dict 24.3 25.7 22.3 23.0 21.0 22.4
read_strdict 22.6 24.3 19.5 21.2 18.9 21.5
Data structure write access:
write_list 27.1 28.5 22.5 21.6 20.0 20.0
write_deque 28.7 30.1 22.7 21.8 23.5 21.7
write_dict 31.4 33.3 29.3 29.2 24.7 25.4
write_strdict 28.4 29.9 27.5 25.2 23.1 24.5
Stack (or queue) operations:
list_append_pop 93.4 112.7 75.4 74.2 50.8 50.6
deque_append_pop 43.5 57.0 49.4 49.2 42.5 44.2
deque_append_popleft 43.7 57.3 49.7 49.7 42.8 46.4
Timing loop:
loop_overhead 0.5 0.6 0.4 0.3 0.3 0.3
</pre></div>
</div>
<p>These results were generated from the variable access benchmark script at:
<code class="docutils literal notranslate"><span class="pre">Tools/scripts/var_access_benchmark.py</span></code>. The benchmark script displays timings
in nanoseconds. The benchmarks were measured on an
<a class="reference external" href="https://ark.intel.com/content/www/us/en/ark/products/76088/intel-core-i7-4960hq-processor-6m-cache-up-to-3-80-ghz.html">Intel® Core™ i7-4960HQ processor</a>
running the macOS 64-bit builds found at
<a class="reference external" href="https://www.python.org/downloads/macos/">python.org</a>.</p>
</section>
<section id="deprecated">
<h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading"></a></h2>
<ul>
<li><p>The distutils <code class="docutils literal notranslate"><span class="pre">bdist_msi</span></code> command is now deprecated, 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?&#64;action=redirect&amp;bpo=39586">bpo-39586</a>.)</p></li>
<li><p>Currently <a class="reference internal" href="../library/math.html#math.factorial" title="math.factorial"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.factorial()</span></code></a> accepts <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> instances with
non-negative integer values (like <code class="docutils literal notranslate"><span class="pre">5.0</span></code>). It 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>
for non-integral and negative floats. It is now deprecated. In future
Python versions it will raise 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> for all floats.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37315">bpo-37315</a>.)</p></li>
<li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">symbol</span></code> modules are deprecated and will be
removed in future versions of Python. For the majority of use cases,
users can leverage the Abstract Syntax Tree (AST) generation and compilation
stage, using the <a class="reference internal" href="../library/ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a> module.</p></li>
<li><p>The Public C API functions <code class="xref c c-func docutils literal notranslate"><span class="pre">PyParser_SimpleParseStringFlags()</span></code>,
<code class="xref c c-func docutils literal notranslate"><span class="pre">PyParser_SimpleParseStringFlagsFilename()</span></code>,
<code class="xref c c-func docutils literal notranslate"><span class="pre">PyParser_SimpleParseFileFlags()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyNode_Compile()</span></code>
are deprecated and will be removed in Python 3.10 together with the old parser.</p></li>
<li><p>Using <a class="reference internal" href="../library/constants.html#NotImplemented" title="NotImplemented"><code class="xref py py-data docutils literal notranslate"><span class="pre">NotImplemented</span></code></a> in a boolean context has been deprecated,
as it is almost exclusively the result of incorrect rich comparator
implementations. It will be made 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> in a future version
of Python.
(Contributed by Josh Rosenberg in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35712">bpo-35712</a>.)</p></li>
<li><p>The <a class="reference internal" href="../library/random.html#module-random" title="random: Generate pseudo-random numbers with various common distributions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">random</span></code></a> module currently accepts any hashable type as a
possible seed value. Unfortunately, some of those types are not
guaranteed to have a deterministic hash value. After Python 3.9,
the module will restrict its seeds to <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>, <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>, <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 <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>.</p></li>
<li><p>Opening the <a class="reference internal" href="../library/gzip.html#gzip.GzipFile" title="gzip.GzipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">GzipFile</span></code></a> file for writing without specifying
the <em>mode</em> argument is deprecated. In future Python versions it will always
be opened for reading by default. Specify the <em>mode</em> argument for opening
it for writing and silencing a warning.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28286">bpo-28286</a>.)</p></li>
<li><p>Deprecated the <code class="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> in
favour of the <code class="docutils literal notranslate"><span class="pre">splitlist()</span></code> method which has more consistent and
predictable behavior.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38371">bpo-38371</a>.)</p></li>
<li><p>The explicit passing of coroutine objects to <a class="reference internal" href="../library/asyncio-task.html#asyncio.wait" title="asyncio.wait"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.wait()</span></code></a> has been
deprecated and will be removed in version 3.11.
(Contributed by Yury Selivanov and Kyle Stanley in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34790">bpo-34790</a>.)</p></li>
<li><p>binhex4 and hexbin4 standards are now deprecated. The <code class="xref py py-mod docutils literal notranslate"><span class="pre">binhex</span></code> module
and the following <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 are now deprecated:</p>
<ul class="simple">
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">b2a_hqx()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">a2b_hqx()</span></code></p></li>
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">rlecode_hqx()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">rledecode_hqx()</span></code></p></li>
</ul>
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39353">bpo-39353</a>.)</p>
</li>
<li><p><a class="reference internal" href="../library/ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a> classes <code class="docutils literal notranslate"><span class="pre">slice</span></code>, <code class="docutils literal notranslate"><span class="pre">Index</span></code> and <code class="docutils literal notranslate"><span class="pre">ExtSlice</span></code> are considered deprecated
and will be removed in future Python versions. <code class="docutils literal notranslate"><span class="pre">value</span></code> itself should be
used instead of <code class="docutils literal notranslate"><span class="pre">Index(value)</span></code>. <code class="docutils literal notranslate"><span class="pre">Tuple(slices,</span> <span class="pre">Load())</span></code> should be
used instead of <code class="docutils literal notranslate"><span class="pre">ExtSlice(slices)</span></code>.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34822">bpo-34822</a>.)</p></li>
<li><p><a class="reference internal" href="../library/ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a> classes <code class="docutils literal notranslate"><span class="pre">Suite</span></code>, <code class="docutils literal notranslate"><span class="pre">Param</span></code>, <code class="docutils literal notranslate"><span class="pre">AugLoad</span></code> and <code class="docutils literal notranslate"><span class="pre">AugStore</span></code>
are considered deprecated and will be removed in future Python versions.
They were not generated by the parser and not accepted by the code
generator in Python 3.
(Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39639">bpo-39639</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39969">bpo-39969</a>
and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39988">bpo-39988</a>.)</p></li>
<li><p>The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_InitThreads()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_ThreadsInitialized()</span></code>
functions are now deprecated and will be removed in Python 3.11. Calling
<code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_InitThreads()</span></code> now does nothing. The <a class="reference internal" href="../glossary.html#term-GIL"><span class="xref std std-term">GIL</span></a> is initialized
by <a class="reference internal" href="../c-api/init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code></a> since Python 3.7.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39877">bpo-39877</a>.)</p></li>
<li><p>Passing <code class="docutils literal notranslate"><span class="pre">None</span></code> as the first argument to the <a class="reference internal" href="../library/shlex.html#shlex.split" title="shlex.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">shlex.split()</span></code></a> function
has been deprecated. (Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33262">bpo-33262</a>.)</p></li>
<li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">smtpd.MailmanProxy()</span></code> is now deprecated as it is unusable without
an external module, <code class="docutils literal notranslate"><span class="pre">mailman</span></code>. (Contributed by Samuel Colvin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35800">bpo-35800</a>.)</p></li>
<li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">lib2to3</span></code> module now emits a <a class="reference internal" href="../library/exceptions.html#PendingDeprecationWarning" title="PendingDeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PendingDeprecationWarning</span></code></a>.
Python 3.9 switched to a PEG parser (see <span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0617/"><strong>PEP 617</strong></a>), and Python 3.10 may
include new language syntax that is not parsable by lib2to3s LL(1) parser.
The <code class="xref py py-mod docutils literal notranslate"><span class="pre">lib2to3</span></code> module may be removed from the standard library in a future
Python version. Consider third-party alternatives such as <a class="reference external" href="https://libcst.readthedocs.io/">LibCST</a> or
<a class="reference external" href="https://parso.readthedocs.io/">parso</a>.
(Contributed by Carl Meyer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40360">bpo-40360</a>.)</p></li>
<li><p>The <em>random</em> 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> has been deprecated.
(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40465">bpo-40465</a>)</p></li>
</ul>
</section>
<section id="removed">
<span id="removed-in-python-39"></span><h2>Removed<a class="headerlink" href="#removed" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p>The erroneous version at <code class="xref py py-data docutils literal notranslate"><span class="pre">unittest.mock.__version__</span></code> has been removed.</p></li>
<li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">nntplib.NNTP</span></code>: <code class="docutils literal notranslate"><span class="pre">xpath()</span></code> and <code class="docutils literal notranslate"><span class="pre">xgtitle()</span></code> methods have been removed.
These methods are deprecated since Python 3.3. Generally, these extensions
are not supported or not enabled by NNTP server administrators.
For <code class="docutils literal notranslate"><span class="pre">xgtitle()</span></code>, please use <code class="xref py py-meth docutils literal notranslate"><span class="pre">nntplib.NNTP.descriptions()</span></code> or
<code class="xref py py-meth docutils literal notranslate"><span class="pre">nntplib.NNTP.description()</span></code> instead.
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39366">bpo-39366</a>.)</p></li>
<li><p><a class="reference internal" href="../library/array.html#array.array" title="array.array"><code class="xref py py-class docutils literal notranslate"><span class="pre">array.array</span></code></a>: <code class="docutils literal notranslate"><span class="pre">tostring()</span></code> and <code class="docutils literal notranslate"><span class="pre">fromstring()</span></code> methods have been
removed. They were aliases to <code class="docutils literal notranslate"><span class="pre">tobytes()</span></code> and <code class="docutils literal notranslate"><span class="pre">frombytes()</span></code>, deprecated
since Python 3.2.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38916">bpo-38916</a>.)</p></li>
<li><p>The undocumented <code class="docutils literal notranslate"><span class="pre">sys.callstats()</span></code> function has been removed. Since Python
3.7, it was deprecated and always returned <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>. It required a special
build option <code class="docutils literal notranslate"><span class="pre">CALL_PROFILE</span></code> which was already removed in Python 3.7.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37414">bpo-37414</a>.)</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">sys.getcheckinterval()</span></code> and <code class="docutils literal notranslate"><span class="pre">sys.setcheckinterval()</span></code> functions have
been removed. They were deprecated since Python 3.2. Use
<a class="reference internal" href="../library/sys.html#sys.getswitchinterval" title="sys.getswitchinterval"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getswitchinterval()</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.setswitchinterval" title="sys.setswitchinterval"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.setswitchinterval()</span></code></a> instead.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37392">bpo-37392</a>.)</p></li>
<li><p>The C function <code class="docutils literal notranslate"><span class="pre">PyImport_Cleanup()</span></code> has been removed. It was documented as:
“Empty the module table. For internal use only.”
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36710">bpo-36710</a>.)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">_dummy_thread</span></code> and <code class="docutils literal notranslate"><span class="pre">dummy_threading</span></code> modules have been removed. These
modules were deprecated since Python 3.7 which requires threading support.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37312">bpo-37312</a>.)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">aifc.openfp()</span></code> alias to <code class="docutils literal notranslate"><span class="pre">aifc.open()</span></code>, <code class="docutils literal notranslate"><span class="pre">sunau.openfp()</span></code> alias to
<code class="docutils literal notranslate"><span class="pre">sunau.open()</span></code>, and <code class="docutils literal notranslate"><span class="pre">wave.openfp()</span></code> alias to <a class="reference internal" href="../library/wave.html#wave.open" title="wave.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">wave.open()</span></code></a> have been
removed. They were deprecated since Python 3.7.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37320">bpo-37320</a>.)</p></li>
<li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">isAlive()</span></code> method of <a class="reference internal" href="../library/threading.html#threading.Thread" title="threading.Thread"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Thread</span></code></a>
has been removed. It was deprecated since Python 3.8.
Use <a class="reference internal" href="../library/threading.html#threading.Thread.is_alive" title="threading.Thread.is_alive"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_alive()</span></code></a> instead.
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37804">bpo-37804</a>.)</p></li>
<li><p>Methods <code class="docutils literal notranslate"><span class="pre">getchildren()</span></code> and <code class="docutils literal notranslate"><span class="pre">getiterator()</span></code> of classes
<a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree" title="xml.etree.ElementTree.ElementTree"><code class="xref py py-class docutils literal notranslate"><span class="pre">ElementTree</span></code></a> and
<a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.Element" title="xml.etree.ElementTree.Element"><code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code></a> in the <a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ElementTree</span></code></a>
module have been removed. They were deprecated in Python 3.2.
Use <code class="docutils literal notranslate"><span class="pre">iter(x)</span></code> or <code class="docutils literal notranslate"><span class="pre">list(x)</span></code> instead of <code class="docutils literal notranslate"><span class="pre">x.getchildren()</span></code> and
<code class="docutils literal notranslate"><span class="pre">x.iter()</span></code> or <code class="docutils literal notranslate"><span class="pre">list(x.iter())</span></code> instead of <code class="docutils literal notranslate"><span class="pre">x.getiterator()</span></code>.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36543">bpo-36543</a>.)</p></li>
<li><p>The old <a class="reference internal" href="../library/plistlib.html#module-plistlib" title="plistlib: Generate and parse Apple plist files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code></a> API has been removed, it was deprecated since Python
3.4. Use the <a class="reference internal" href="../library/plistlib.html#plistlib.load" title="plistlib.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">load()</span></code></a>, <a class="reference internal" href="../library/plistlib.html#plistlib.loads" title="plistlib.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">loads()</span></code></a>, <a class="reference internal" href="../library/plistlib.html#plistlib.dump" title="plistlib.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump()</span></code></a>, and
<a class="reference internal" href="../library/plistlib.html#plistlib.dumps" title="plistlib.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">dumps()</span></code></a> functions. Additionally, the <em>use_builtin_types</em> parameter was
removed, standard <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> objects are always used instead.
(Contributed by Jon Janzen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36409">bpo-36409</a>.)</p></li>
<li><p>The C function <code class="docutils literal notranslate"><span class="pre">PyGen_NeedsFinalizing</span></code> has been removed. It was not
documented, tested, or used anywhere within CPython after the implementation
of <span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0442/"><strong>PEP 442</strong></a>. Patch by Joannah Nanjekye.
(Contributed by Joannah Nanjekye in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15088">bpo-15088</a>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">base64.encodestring()</span></code> and <code class="docutils literal notranslate"><span class="pre">base64.decodestring()</span></code>, aliases deprecated
since Python 3.1, have been removed: use <a class="reference internal" href="../library/base64.html#base64.encodebytes" title="base64.encodebytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">base64.encodebytes()</span></code></a> and
<a class="reference internal" href="../library/base64.html#base64.decodebytes" title="base64.decodebytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">base64.decodebytes()</span></code></a> instead.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39351">bpo-39351</a>.)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">fractions.gcd()</span></code> function has been removed, it was deprecated since Python
3.5 (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22486">bpo-22486</a>): use <a class="reference internal" href="../library/math.html#math.gcd" title="math.gcd"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.gcd()</span></code></a> instead.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39350">bpo-39350</a>.)</p></li>
<li><p>The <em>buffering</em> parameter of <a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><code class="xref py py-class docutils literal notranslate"><span class="pre">bz2.BZ2File</span></code></a> has been removed. Since
Python 3.0, it was ignored and using it emitted 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>.
Pass an open file object to control how the file is opened.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39357">bpo-39357</a>.)</p></li>
<li><p>The <em>encoding</em> parameter of <a class="reference internal" href="../library/json.html#json.loads" title="json.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.loads()</span></code></a> has been removed.
As of Python 3.1, it was deprecated and ignored; using it has emitted 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> since Python 3.8.
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39377">bpo-39377</a>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">with</span> <span class="pre">(await</span> <span class="pre">asyncio.lock):</span></code> and <code class="docutils literal notranslate"><span class="pre">with</span> <span class="pre">(yield</span> <span class="pre">from</span> <span class="pre">asyncio.lock):</span></code> statements are
not longer supported, use <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">with</span> <span class="pre">lock</span></code> instead. The same is correct for
<code class="docutils literal notranslate"><span class="pre">asyncio.Condition</span></code> and <code class="docutils literal notranslate"><span class="pre">asyncio.Semaphore</span></code>.
(Contributed by Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34793">bpo-34793</a>.)</p></li>
<li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getcounts()</span></code> function, the <code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">showalloccount</span></code> command line
option and the <code class="docutils literal notranslate"><span class="pre">show_alloc_count</span></code> field of the C structure
<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> have been removed. They required a special Python build by
defining <code class="docutils literal notranslate"><span class="pre">COUNT_ALLOCS</span></code> macro.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39489">bpo-39489</a>.)</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">_field_types</span></code> attribute of the <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">typing.NamedTuple</span></code></a> class
has been removed. It was deprecated since Python 3.8. Use
the <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code> attribute instead.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40182">bpo-40182</a>.)</p></li>
<li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">symtable.SymbolTable.has_exec()</span></code> method has been removed. It was
deprecated since 2006, and only returning <code class="docutils literal notranslate"><span class="pre">False</span></code> when its called.
(Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40208">bpo-40208</a>)</p></li>
<li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.Task.current_task()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.Task.all_tasks()</span></code>
have been removed. They were deprecated since Python 3.7 and you can use
<a class="reference internal" href="../library/asyncio-task.html#asyncio.current_task" title="asyncio.current_task"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.current_task()</span></code></a> and <a class="reference internal" href="../library/asyncio-task.html#asyncio.all_tasks" title="asyncio.all_tasks"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.all_tasks()</span></code></a> instead.
(Contributed by Rémi Lapeyre in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40967">bpo-40967</a>)</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">unescape()</span></code> method in the <a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">html.parser.HTMLParser</span></code></a> class
has been removed (it was deprecated since Python 3.4). <a class="reference internal" href="../library/html.html#html.unescape" title="html.unescape"><code class="xref py py-func docutils literal notranslate"><span class="pre">html.unescape()</span></code></a>
should be used for converting character references to the corresponding
unicode characters.</p></li>
</ul>
</section>
<section id="porting-to-python-3-9">
<h2>Porting to Python 3.9<a class="headerlink" href="#porting-to-python-3-9" title="Link to this heading"></a></h2>
<p>This section lists previously described changes and other bugfixes
that may require changes to your code.</p>
<section id="changes-in-the-python-api">
<h3>Changes in the Python API<a class="headerlink" href="#changes-in-the-python-api" title="Link to this heading"></a></h3>
<ul class="simple">
<li><p><a class="reference internal" href="../library/functions.html#import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> and <a class="reference internal" href="../library/importlib.html#importlib.util.resolve_name" title="importlib.util.resolve_name"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.resolve_name()</span></code></a> now raise
<a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> where it previously 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>. Callers
catching the specific exception type and supporting both Python 3.9 and
earlier versions will need to catch both using <code class="docutils literal notranslate"><span class="pre">except</span> <span class="pre">(ImportError,</span> <span class="pre">ValueError):</span></code>.</p></li>
<li><p>The <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> activation scripts no longer special-case when
<code class="docutils literal notranslate"><span class="pre">__VENV_PROMPT__</span></code> is set to <code class="docutils literal notranslate"><span class="pre">&quot;&quot;</span></code>.</p></li>
<li><p>The <a class="reference internal" href="../library/select.html#select.epoll.unregister" title="select.epoll.unregister"><code class="xref py py-meth docutils literal notranslate"><span class="pre">select.epoll.unregister()</span></code></a> method no longer ignores the
<a class="reference internal" href="../library/errno.html#errno.EBADF" title="errno.EBADF"><code class="xref py py-const docutils literal notranslate"><span class="pre">EBADF</span></code></a> error.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39239">bpo-39239</a>.)</p></li>
<li><p>The <em>compresslevel</em> parameter of <a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><code class="xref py py-class docutils literal notranslate"><span class="pre">bz2.BZ2File</span></code></a> became keyword-only,
since the <em>buffering</em> parameter has been removed.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39357">bpo-39357</a>.)</p></li>
<li><p>Simplified AST for subscription. Simple indices will be represented by
their value, extended slices will be represented as tuples.
<code class="docutils literal notranslate"><span class="pre">Index(value)</span></code> will return a <code class="docutils literal notranslate"><span class="pre">value</span></code> itself, <code class="docutils literal notranslate"><span class="pre">ExtSlice(slices)</span></code>
will return <code class="docutils literal notranslate"><span class="pre">Tuple(slices,</span> <span class="pre">Load())</span></code>.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34822">bpo-34822</a>.)</p></li>
<li><p>The <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> module now ignores the <span class="target" id="index-21"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONCASEOK"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONCASEOK</span></code></a>
environment variable when the <a class="reference internal" href="../using/cmdline.html#cmdoption-E"><code class="xref std std-option docutils literal notranslate"><span class="pre">-E</span></code></a> or <a class="reference internal" href="../using/cmdline.html#cmdoption-I"><code class="xref std std-option docutils literal notranslate"><span class="pre">-I</span></code></a> command line
options are being used.</p></li>
<li><p>The <em>encoding</em> parameter has been added to the classes <a class="reference internal" href="../library/ftplib.html#ftplib.FTP" title="ftplib.FTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">ftplib.FTP</span></code></a> and
<a class="reference internal" href="../library/ftplib.html#ftplib.FTP_TLS" title="ftplib.FTP_TLS"><code class="xref py py-class docutils literal notranslate"><span class="pre">ftplib.FTP_TLS</span></code></a> as a keyword-only parameter, and the default encoding
is changed from Latin-1 to UTF-8 to follow <span class="target" id="index-22"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2640.html"><strong>RFC 2640</strong></a>.</p></li>
<li><p><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.shutdown_default_executor" title="asyncio.loop.shutdown_default_executor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.shutdown_default_executor()</span></code></a> has been added to
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.AbstractEventLoop" title="asyncio.AbstractEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">AbstractEventLoop</span></code></a>, meaning alternative event loops that
inherit from it should have this method defined.
(Contributed by Kyle Stanley in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34037">bpo-34037</a>.)</p></li>
<li><p>The constant values of future flags in the <a class="reference internal" href="../library/__future__.html#module-__future__" title="__future__: Future statement definitions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">__future__</span></code></a> module
is updated in order to prevent collision with compiler flags. Previously
<code class="docutils literal notranslate"><span class="pre">PyCF_ALLOW_TOP_LEVEL_AWAIT</span></code> was clashing with <code class="docutils literal notranslate"><span class="pre">CO_FUTURE_DIVISION</span></code>.
(Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39562">bpo-39562</a>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">array('u')</span></code> now uses <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code> as C type instead of <code class="docutils literal notranslate"><span class="pre">Py_UNICODE</span></code>.
This change doesnt affect to its behavior because <code class="docutils literal notranslate"><span class="pre">Py_UNICODE</span></code> is alias
of <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code> since Python 3.3.
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34538">bpo-34538</a>.)</p></li>
<li><p>The <a class="reference internal" href="../library/logging.html#logging.getLogger" title="logging.getLogger"><code class="xref py py-func docutils literal notranslate"><span class="pre">logging.getLogger()</span></code></a> API now returns the root logger when passed
the name <code class="docutils literal notranslate"><span class="pre">'root'</span></code>, whereas previously it returned a non-root logger named
<code class="docutils literal notranslate"><span class="pre">'root'</span></code>. This could affect cases where user code explicitly wants a
non-root logger named <code class="docutils literal notranslate"><span class="pre">'root'</span></code>, or instantiates a logger using
<code class="docutils literal notranslate"><span class="pre">logging.getLogger(__name__)</span></code> in some top-level module called <code class="docutils literal notranslate"><span class="pre">'root.py'</span></code>.
(Contributed by Vinay Sajip in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37742">bpo-37742</a>.)</p></li>
<li><p>Division handling of <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">PurePath</span></code></a> now returns <a class="reference internal" href="../library/constants.html#NotImplemented" title="NotImplemented"><code class="xref py py-data docutils literal notranslate"><span class="pre">NotImplemented</span></code></a>
instead of raising 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> when passed something other than an
instance of <code class="docutils literal notranslate"><span class="pre">str</span></code> or <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">PurePath</span></code></a>. This allows creating
compatible classes that dont inherit from those mentioned types.
(Contributed by Roger Aiudi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34775">bpo-34775</a>).</p></li>
<li><p>Starting with Python 3.9.5 the <a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ipaddress</span></code></a> module no longer
accepts any leading zeros in IPv4 address strings. Leading zeros are
ambiguous and interpreted as octal notation by some libraries. For example
the legacy function <a class="reference internal" href="../library/socket.html#socket.inet_aton" title="socket.inet_aton"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.inet_aton()</span></code></a> treats leading zeros as octal
notatation. glibc implementation of modern <a class="reference internal" href="../library/socket.html#socket.inet_pton" title="socket.inet_pton"><code class="xref py py-func docutils literal notranslate"><span class="pre">inet_pton()</span></code></a> does
not accept any leading zeros.
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36384">bpo-36384</a>).</p></li>
<li><p><a class="reference internal" href="../library/codecs.html#codecs.lookup" title="codecs.lookup"><code class="xref py py-func docutils literal notranslate"><span class="pre">codecs.lookup()</span></code></a> now normalizes the encoding name the same way as
<code class="xref py py-func docutils literal notranslate"><span class="pre">encodings.normalize_encoding()</span></code>, except that <a class="reference internal" href="../library/codecs.html#codecs.lookup" title="codecs.lookup"><code class="xref py py-func docutils literal notranslate"><span class="pre">codecs.lookup()</span></code></a> also
converts the name to lower case. For example, <code class="docutils literal notranslate"><span class="pre">&quot;latex+latin1&quot;</span></code> encoding
name is now normalized to <code class="docutils literal notranslate"><span class="pre">&quot;latex_latin1&quot;</span></code>.
(Contributed by Jordon Xu in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37751">bpo-37751</a>.)</p></li>
</ul>
</section>
<section id="changes-in-the-c-api">
<h3>Changes in the C API<a class="headerlink" href="#changes-in-the-c-api" title="Link to this heading"></a></h3>
<ul>
<li><p>Instances of <a class="reference internal" href="../c-api/typeobj.html#heap-types"><span class="std std-ref">heap-allocated types</span></a> (such as those created with
<a class="reference internal" href="../c-api/type.html#c.PyType_FromSpec" title="PyType_FromSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromSpec()</span></code></a> and similar APIs) hold a reference to their type
object since Python 3.8. As indicated in the “Changes in the C API” of Python
3.8, for the vast majority of cases, there should be no side effect but for
types that have a custom <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">tp_traverse</span></code></a> function,
ensure that all custom <code class="docutils literal notranslate"><span class="pre">tp_traverse</span></code> functions of heap-allocated types
visit the objects type.</p>
<blockquote>
<div><p>Example:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span>
<span class="nf">foo_traverse</span><span class="p">(</span><span class="n">foo_struct</span><span class="w"> </span><span class="o">*</span><span class="n">self</span><span class="p">,</span><span class="w"> </span><span class="n">visitproc</span><span class="w"> </span><span class="n">visit</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="c1">// Rest of the traverse function</span>
<span class="cp">#if PY_VERSION_HEX &gt;= 0x03090000</span>
<span class="w"> </span><span class="c1">// This was not needed before Python 3.9 (Python issue 35810 and 40217)</span>
<span class="w"> </span><span class="n">Py_VISIT</span><span class="p">(</span><span class="n">Py_TYPE</span><span class="p">(</span><span class="n">self</span><span class="p">));</span>
<span class="cp">#endif</span>
<span class="p">}</span>
</pre></div>
</div>
</div></blockquote>
<p>If your traverse function delegates to <code class="docutils literal notranslate"><span class="pre">tp_traverse</span></code> of its base class
(or another type), ensure that <code class="docutils literal notranslate"><span class="pre">Py_TYPE(self)</span></code> is visited only once.
Note that only <a class="reference internal" href="../c-api/typeobj.html#heap-types"><span class="std std-ref">heap type</span></a> are expected to visit the type
in <code class="docutils literal notranslate"><span class="pre">tp_traverse</span></code>.</p>
<blockquote>
<div><p>For example, if your <code class="docutils literal notranslate"><span class="pre">tp_traverse</span></code> function includes:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">base</span><span class="o">-&gt;</span><span class="n">tp_traverse</span><span class="p">(</span><span class="n">self</span><span class="p">,</span><span class="w"> </span><span class="n">visit</span><span class="p">,</span><span class="w"> </span><span class="n">arg</span><span class="p">)</span>
</pre></div>
</div>
<p>then add:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cp">#if PY_VERSION_HEX &gt;= 0x03090000</span>
<span class="w"> </span><span class="c1">// This was not needed before Python 3.9 (bpo-35810 and bpo-40217)</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">base</span><span class="o">-&gt;</span><span class="n">tp_flags</span><span class="w"> </span><span class="o">&amp;</span><span class="w"> </span><span class="n">Py_TPFLAGS_HEAPTYPE</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="c1">// a heap type&#39;s tp_traverse already visited Py_TYPE(self)</span>
<span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Py_VISIT</span><span class="p">(</span><span class="n">Py_TYPE</span><span class="p">(</span><span class="n">self</span><span class="p">));</span>
<span class="w"> </span><span class="p">}</span>
<span class="cp">#else</span>
</pre></div>
</div>
</div></blockquote>
<p>(See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35810">bpo-35810</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40217">bpo-40217</a> for more information.)</p>
</li>
<li><p>The functions <code class="docutils literal notranslate"><span class="pre">PyEval_CallObject</span></code>, <code class="docutils literal notranslate"><span class="pre">PyEval_CallFunction</span></code>,
<code class="docutils literal notranslate"><span class="pre">PyEval_CallMethod</span></code> and <code class="docutils literal notranslate"><span class="pre">PyEval_CallObjectWithKeywords</span></code> are deprecated.
Use <a class="reference internal" href="../c-api/call.html#c.PyObject_Call" title="PyObject_Call"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Call()</span></code></a> and its variants instead.
(See more details in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29548">bpo-29548</a>.)</p></li>
</ul>
</section>
<section id="cpython-bytecode-changes">
<h3>CPython bytecode changes<a class="headerlink" href="#cpython-bytecode-changes" title="Link to this heading"></a></h3>
<ul>
<li><p>The <a class="reference internal" href="../library/dis.html#opcode-LOAD_ASSERTION_ERROR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_ASSERTION_ERROR</span></code></a> opcode was added for handling the
<a class="reference internal" href="../reference/simple_stmts.html#assert"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">assert</span></code></a> statement. Previously, the assert statement would not work
correctly if the <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> exception was being shadowed.
(Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34880">bpo-34880</a>.)</p></li>
<li><p>The <a class="reference internal" href="../library/dis.html#opcode-COMPARE_OP"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">COMPARE_OP</span></code></a> opcode was split into four distinct instructions:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">COMPARE_OP</span></code> for rich comparisons</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">IS_OP</span></code> for is and is not tests</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">CONTAINS_OP</span></code> for in and not in tests</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">JUMP_IF_NOT_EXC_MATCH</span></code> for checking exceptions in try-except
statements.</p></li>
</ul>
<p>(Contributed by Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39156">bpo-39156</a>.)</p>
</li>
</ul>
</section>
</section>
<section id="build-changes">
<h2>Build Changes<a class="headerlink" href="#build-changes" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p>Added <code class="docutils literal notranslate"><span class="pre">--with-platlibdir</span></code> option to the <code class="docutils literal notranslate"><span class="pre">configure</span></code> script: name of the
platform-specific library directory, stored in the new <a class="reference internal" href="../library/sys.html#sys.platlibdir" title="sys.platlibdir"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platlibdir</span></code></a>
attribute. See <a class="reference internal" href="../library/sys.html#sys.platlibdir" title="sys.platlibdir"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platlibdir</span></code></a> attribute for more information.
(Contributed by Jan Matějek, Matěj Cepl, Charalampos Stratakis
and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1294959">bpo-1294959</a>.)</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">COUNT_ALLOCS</span></code> special build macro has been removed.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39489">bpo-39489</a>.)</p></li>
<li><p>On non-Windows platforms, the <code class="xref c c-func docutils literal notranslate"><span class="pre">setenv()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">unsetenv()</span></code>
functions are now required to build Python.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39395">bpo-39395</a>.)</p></li>
<li><p>On non-Windows platforms, creating <code class="docutils literal notranslate"><span class="pre">bdist_wininst</span></code> installers is now
officially unsupported. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10945">bpo-10945</a> for more details.)</p></li>
<li><p>When building Python on macOS from source, <code class="docutils literal notranslate"><span class="pre">_tkinter</span></code> now links with
non-system Tcl and Tk frameworks if they are installed in
<code class="docutils literal notranslate"><span class="pre">/Library/Frameworks</span></code>, as had been the case on older releases
of macOS. If a macOS SDK is explicitly configured, by using
<a class="reference internal" href="../using/configure.html#cmdoption-enable-universalsdk"><code class="xref std std-option docutils literal notranslate"><span class="pre">--enable-universalsdk</span></code></a> or <code class="docutils literal notranslate"><span class="pre">-isysroot</span></code>, only the SDK itself is
searched. The default behavior can still be overridden with
<code class="docutils literal notranslate"><span class="pre">--with-tcltk-includes</span></code> and <code class="docutils literal notranslate"><span class="pre">--with-tcltk-libs</span></code>.
(Contributed by Ned Deily in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34956">bpo-34956</a>.)</p></li>
<li><p>Python can now be built for Windows 10 ARM64.
(Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33125">bpo-33125</a>.)</p></li>
<li><p>Some individual tests are now skipped when <code class="docutils literal notranslate"><span class="pre">--pgo</span></code> is used. The tests
in question increased the PGO task time significantly and likely
didnt help improve optimization of the final executable. This
speeds up the task by a factor of about 15x. Running the full unit test
suite is slow. This change may result in a slightly less optimized build
since not as many code branches will be executed. If you are willing to
wait for the much slower build, the old behavior can be restored using
<code class="docutils literal notranslate"><span class="pre">./configure</span> <span class="pre">[..]</span> <span class="pre">PROFILE_TASK=&quot;-m</span> <span class="pre">test</span> <span class="pre">--pgo-extended&quot;</span></code>. We make no
guarantees as to which PGO task set produces a faster build. Users who care
should run their own relevant benchmarks as results can depend on the
environment, workload, and compiler tool chain.
(See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36044">bpo-36044</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37707">bpo-37707</a> for more details.)</p></li>
</ul>
</section>
<section id="c-api-changes">
<h2>C API Changes<a class="headerlink" href="#c-api-changes" title="Link to this heading"></a></h2>
<section id="id1">
<h3>New Features<a class="headerlink" href="#id1" title="Link to this heading"></a></h3>
<ul>
<li><p><span class="target" id="index-23"></span><a class="pep reference external" href="https://peps.python.org/pep-0573/"><strong>PEP 573</strong></a>: Added <a class="reference internal" href="../c-api/type.html#c.PyType_FromModuleAndSpec" title="PyType_FromModuleAndSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromModuleAndSpec()</span></code></a> to associate
a module with a class; <a class="reference internal" href="../c-api/type.html#c.PyType_GetModule" title="PyType_GetModule"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetModule()</span></code></a> and
<a class="reference internal" href="../c-api/type.html#c.PyType_GetModuleState" title="PyType_GetModuleState"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetModuleState()</span></code></a> to retrieve the module and its state; and
<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> and <a class="reference internal" href="../c-api/structures.html#c.METH_METHOD" title="METH_METHOD"><code class="xref c c-macro docutils literal notranslate"><span class="pre">METH_METHOD</span></code></a> to allow a method to
access the class it was defined in.
(Contributed by Marcel Plch and Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38787">bpo-38787</a>.)</p></li>
<li><p>Added <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> function: get a frame code.
Added <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: get the frame next outer frame.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40421">bpo-40421</a>.)</p></li>
<li><p>Added <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> to the limited C API.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40421">bpo-40421</a>.)</p></li>
<li><p>Added <a class="reference internal" href="../c-api/init.html#c.PyThreadState_GetInterpreter" title="PyThreadState_GetInterpreter"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_GetInterpreter()</span></code></a> and
<a class="reference internal" href="../c-api/init.html#c.PyInterpreterState_Get" title="PyInterpreterState_Get"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyInterpreterState_Get()</span></code></a> functions to get the interpreter.
Added <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 to get the current frame of a
Python thread state.
Added <a class="reference internal" href="../c-api/init.html#c.PyThreadState_GetID" title="PyThreadState_GetID"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_GetID()</span></code></a> function: get the unique identifier of a
Python thread state.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39947">bpo-39947</a>.)</p></li>
<li><p>Added a new public <a class="reference internal" href="../c-api/call.html#c.PyObject_CallNoArgs" title="PyObject_CallNoArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CallNoArgs()</span></code></a> function to the C API, which
calls a callable Python object without any arguments. It is the most efficient
way to call a callable Python object without any argument.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37194">bpo-37194</a>.)</p></li>
<li><p>Changes in the limited C API (if <code class="docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code> macro is defined):</p>
<ul class="simple">
<li><p>Provide <a class="reference internal" href="../c-api/exceptions.html#c.Py_EnterRecursiveCall" title="Py_EnterRecursiveCall"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_EnterRecursiveCall()</span></code></a> and <a class="reference internal" href="../c-api/exceptions.html#c.Py_LeaveRecursiveCall" title="Py_LeaveRecursiveCall"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_LeaveRecursiveCall()</span></code></a>
as regular functions for the limited API. Previously, there were defined as
macros, but these macros didnt compile with the limited C API which cannot
access <code class="docutils literal notranslate"><span class="pre">PyThreadState.recursion_depth</span></code> field (the structure is opaque in
the limited C API).</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PyObject_INIT()</span></code> and <code class="docutils literal notranslate"><span class="pre">PyObject_INIT_VAR()</span></code> become regular “opaque”
function to hide implementation details.</p></li>
</ul>
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38644">bpo-38644</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39542">bpo-39542</a>.)</p>
</li>
<li><p>The <a class="reference internal" href="../c-api/module.html#c.PyModule_AddType" title="PyModule_AddType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_AddType()</span></code></a> function is added to help adding a type
to a module.
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40024">bpo-40024</a>.)</p></li>
<li><p>Added the functions <a class="reference internal" href="../c-api/gcsupport.html#c.PyObject_GC_IsTracked" title="PyObject_GC_IsTracked"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GC_IsTracked()</span></code></a> and
<a class="reference internal" href="../c-api/gcsupport.html#c.PyObject_GC_IsFinalized" title="PyObject_GC_IsFinalized"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GC_IsFinalized()</span></code></a> to the public API to allow to query if
Python objects are being currently tracked or have been already finalized by
the garbage collector respectively.
(Contributed by Pablo Galindo Salgado in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40241">bpo-40241</a>.)</p></li>
<li><p>Added <code class="xref c c-func docutils literal notranslate"><span class="pre">_PyObject_FunctionStr()</span></code> to get a user-friendly string
representation of a function-like object.
(Patch by Jeroen Demeyer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37645">bpo-37645</a>.)</p></li>
<li><p>Added <a class="reference internal" href="../c-api/call.html#c.PyObject_CallOneArg" title="PyObject_CallOneArg"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CallOneArg()</span></code></a> for calling an object with one
positional argument
(Patch by Jeroen Demeyer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37483">bpo-37483</a>.)</p></li>
</ul>
</section>
<section id="id2">
<h3>Porting to Python 3.9<a class="headerlink" href="#id2" title="Link to this heading"></a></h3>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">PyInterpreterState.eval_frame</span></code> (<span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0523/"><strong>PEP 523</strong></a>) now requires a new mandatory
<em>tstate</em> parameter (<code class="docutils literal notranslate"><span class="pre">PyThreadState*</span></code>).
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38500">bpo-38500</a>.)</p></li>
<li><p>Extension modules: <a class="reference internal" href="../c-api/module.html#c.PyModuleDef.m_traverse" title="PyModuleDef.m_traverse"><code class="xref c c-member docutils literal notranslate"><span class="pre">m_traverse</span></code></a>,
<a class="reference internal" href="../c-api/module.html#c.PyModuleDef.m_clear" title="PyModuleDef.m_clear"><code class="xref c c-member docutils literal notranslate"><span class="pre">m_clear</span></code></a> and <a class="reference internal" href="../c-api/module.html#c.PyModuleDef.m_free" title="PyModuleDef.m_free"><code class="xref c c-member docutils literal notranslate"><span class="pre">m_free</span></code></a>
functions of <a class="reference internal" href="../c-api/module.html#c.PyModuleDef" title="PyModuleDef"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyModuleDef</span></code></a> are no longer called if the module state
was requested but is not allocated yet. This is the case immediately after
the module is created and before the module is executed
(<a class="reference internal" href="../c-api/module.html#c.Py_mod_exec" title="Py_mod_exec"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_mod_exec</span></code></a> function). More precisely, these functions are not called
if <a class="reference internal" href="../c-api/module.html#c.PyModuleDef.m_size" title="PyModuleDef.m_size"><code class="xref c c-member docutils literal notranslate"><span class="pre">m_size</span></code></a> is greater than 0 and the module state (as
returned by <a class="reference internal" href="../c-api/module.html#c.PyModule_GetState" title="PyModule_GetState"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_GetState()</span></code></a>) is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
<p>Extension modules without module state (<code class="docutils literal notranslate"><span class="pre">m_size</span> <span class="pre">&lt;=</span> <span class="pre">0</span></code>) are not affected.</p>
</li>
<li><p>If <a class="reference internal" href="../c-api/init.html#c.Py_AddPendingCall" title="Py_AddPendingCall"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_AddPendingCall()</span></code></a> is called in a subinterpreter, the function is
now scheduled to be called from the subinterpreter, rather than being called
from the main interpreter. Each subinterpreter now has its own list of
scheduled calls.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39984">bpo-39984</a>.)</p></li>
<li><p>The Windows registry is no longer used 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> when
the <code class="docutils literal notranslate"><span class="pre">-E</span></code> option is used (if <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.use_environment" title="PyConfig.use_environment"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.use_environment</span></code></a> is set to
<code class="docutils literal notranslate"><span class="pre">0</span></code>). This is significant when embedding Python on Windows.
(Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8901">bpo-8901</a>.)</p></li>
<li><p>The global variable <a class="reference internal" href="../c-api/tuple.html#c.PyStructSequence_UnnamedField" title="PyStructSequence_UnnamedField"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyStructSequence_UnnamedField</span></code></a> is now a constant
and refers to a constant string.
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38650">bpo-38650</a>.)</p></li>
<li><p>The <code class="xref c c-type docutils literal notranslate"><span class="pre">PyGC_Head</span></code> structure is now opaque. It is only defined in the
internal C API (<code class="docutils literal notranslate"><span class="pre">pycore_gc.h</span></code>).
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40241">bpo-40241</a>.)</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_COPY</span></code>, <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_FILL</span></code>, <code class="docutils literal notranslate"><span class="pre">PyUnicode_WSTR_LENGTH</span></code>,
<code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromUnicode()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicode()</span></code>,
<code class="docutils literal notranslate"><span class="pre">_PyUnicode_AsUnicode</span></code>, and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicodeAndSize()</span></code> are
marked as deprecated in C. They have been deprecated by <span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a> since
Python 3.3.
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36346">bpo-36346</a>.)</p></li>
<li><p>The <a class="reference internal" href="../c-api/sys.html#c.Py_FatalError" title="Py_FatalError"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_FatalError()</span></code></a> function is replaced with a macro which logs
automatically the name of the current function, unless the
<code class="docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code> macro is defined.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39882">bpo-39882</a>.)</p></li>
<li><p>The vectorcall protocol now requires that the caller passes only strings as
keyword names. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37540">bpo-37540</a> for more information.)</p></li>
<li><p>Implementation details of a number of macros and functions are now hidden:</p>
<ul class="simple">
<li><p><a class="reference internal" href="../c-api/gcsupport.html#c.PyObject_IS_GC" title="PyObject_IS_GC"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_IS_GC()</span></code></a> macro was converted to a function.</p></li>
<li><p>The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_NEW()</span></code> macro becomes an alias to the
<a class="reference internal" href="../c-api/allocation.html#c.PyObject_New" title="PyObject_New"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyObject_New</span></code></a> macro, and the <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_NEW_VAR()</span></code> macro
becomes an alias to the <a class="reference internal" href="../c-api/allocation.html#c.PyObject_NewVar" title="PyObject_NewVar"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyObject_NewVar</span></code></a> macro. They no longer
access directly the <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_basicsize" title="PyTypeObject.tp_basicsize"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_basicsize</span></code></a> member.</p></li>
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GET_WEAKREFS_LISTPTR()</span></code> macro was converted to a function:
the macro accessed directly the <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_weaklistoffset" title="PyTypeObject.tp_weaklistoffset"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_weaklistoffset</span></code></a>
member.</p></li>
<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> macro was converted to a function: the macro
accessed directly the <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_as_buffer" title="PyTypeObject.tp_as_buffer"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_as_buffer</span></code></a> member.</p></li>
<li><p><a class="reference internal" href="../c-api/number.html#c.PyIndex_Check" title="PyIndex_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyIndex_Check()</span></code></a> is now always declared as an opaque function to hide
implementation details: removed the <code class="docutils literal notranslate"><span class="pre">PyIndex_Check()</span></code> macro. The macro accessed
directly the <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_as_number" title="PyTypeObject.tp_as_number"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_as_number</span></code></a> member.</p></li>
</ul>
<p>(See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40170">bpo-40170</a> for more details.)</p>
</li>
</ul>
</section>
<section id="id3">
<h3>Removed<a class="headerlink" href="#id3" title="Link to this heading"></a></h3>
<ul>
<li><p>Excluded <code class="docutils literal notranslate"><span class="pre">PyFPE_START_PROTECT()</span></code> and <code class="docutils literal notranslate"><span class="pre">PyFPE_END_PROTECT()</span></code> macros of
<code class="docutils literal notranslate"><span class="pre">pyfpe.h</span></code> from the limited C API.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38835">bpo-38835</a>.)</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">tp_print</span></code> slot of <a class="reference internal" href="../c-api/typeobj.html#type-structs"><span class="std std-ref">PyTypeObject</span></a> has been removed.
It was used for printing objects to files in Python 2.7 and before. Since
Python 3.0, it has been ignored and unused.
(Contributed by Jeroen Demeyer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36974">bpo-36974</a>.)</p></li>
<li><p>Changes in the limited C API (if <code class="docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code> macro is defined):</p>
<ul class="simple">
<li><p>Excluded the following functions from the limited C API:</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">PyThreadState_DeleteCurrent()</span></code>
(Contributed by Joannah Nanjekye in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37878">bpo-37878</a>.)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">_Py_CheckRecursionLimit</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">_Py_NewReference()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">_Py_ForgetReference()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">_PyTraceMalloc_NewReference()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">_Py_GetRefTotal()</span></code></p></li>
<li><p>The trashcan mechanism which never worked in the limited C API.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PyTrash_UNWIND_LEVEL</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_BEGIN_CONDITION</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_BEGIN</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_END</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_SAFE_BEGIN</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_SAFE_END</span></code></p></li>
</ul>
</li>
<li><p>Moved following functions and definitions to the internal C API:</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">_PyDebug_PrintTotalRefs()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">_Py_PrintReferences()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">_Py_PrintReferenceAddresses()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">_Py_tracemalloc_config</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">_Py_AddToAllObjects()</span></code> (specific to <code class="docutils literal notranslate"><span class="pre">Py_TRACE_REFS</span></code> build)</p></li>
</ul>
</li>
</ul>
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38644">bpo-38644</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39542">bpo-39542</a>.)</p>
</li>
<li><p>Removed <code class="docutils literal notranslate"><span class="pre">_PyRuntime.getframe</span></code> hook and removed <code class="docutils literal notranslate"><span class="pre">_PyThreadState_GetFrame</span></code>
macro which was an alias to <code class="docutils literal notranslate"><span class="pre">_PyRuntime.getframe</span></code>. They were only exposed
by the internal C API. Removed also <code class="docutils literal notranslate"><span class="pre">PyThreadFrameGetter</span></code> type.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39946">bpo-39946</a>.)</p></li>
<li><p>Removed the following functions from the C API. Call <a class="reference internal" href="../c-api/gcsupport.html#c.PyGC_Collect" title="PyGC_Collect"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyGC_Collect()</span></code></a>
explicitly to clear all free lists.
(Contributed by Inada Naoki and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37340">bpo-37340</a>,
<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38896">bpo-38896</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40428">bpo-40428</a>.)</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">PyAsyncGen_ClearFreeLists()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PyContext_ClearFreeList()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PyDict_ClearFreeList()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PyFloat_ClearFreeList()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PyFrame_ClearFreeList()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PyList_ClearFreeList()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PyMethod_ClearFreeList()</span></code> and <code class="docutils literal notranslate"><span class="pre">PyCFunction_ClearFreeList()</span></code>:
the free lists of bound method objects have been removed.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PySet_ClearFreeList()</span></code>: the set free list has been removed
in Python 3.4.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PyTuple_ClearFreeList()</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PyUnicode_ClearFreeList()</span></code>: the Unicode free list has been removed in
Python 3.3.</p></li>
</ul>
</li>
<li><p>Removed <code class="docutils literal notranslate"><span class="pre">_PyUnicode_ClearStaticStrings()</span></code> function.
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39465">bpo-39465</a>.)</p></li>
<li><p>Removed <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_MATCH</span></code>. It has been deprecated by <span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a>, and
broken since Python 3.3. The <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Tailmatch" title="PyUnicode_Tailmatch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Tailmatch()</span></code></a> function can be
used instead.
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36346">bpo-36346</a>.)</p></li>
<li><p>Cleaned header files of interfaces defined but with no implementation.
The public API symbols being removed are:
<code class="docutils literal notranslate"><span class="pre">_PyBytes_InsertThousandsGroupingLocale</span></code>,
<code class="docutils literal notranslate"><span class="pre">_PyBytes_InsertThousandsGrouping</span></code>, <code class="docutils literal notranslate"><span class="pre">_Py_InitializeFromArgs</span></code>,
<code class="docutils literal notranslate"><span class="pre">_Py_InitializeFromWideArgs</span></code>, <code class="docutils literal notranslate"><span class="pre">_PyFloat_Repr</span></code>, <code class="docutils literal notranslate"><span class="pre">_PyFloat_Digits</span></code>,
<code class="docutils literal notranslate"><span class="pre">_PyFloat_DigitsInit</span></code>, <code class="docutils literal notranslate"><span class="pre">PyFrame_ExtendStack</span></code>, <code class="docutils literal notranslate"><span class="pre">_PyAIterWrapper_Type</span></code>,
<code class="docutils literal notranslate"><span class="pre">PyNullImporter_Type</span></code>, <code class="docutils literal notranslate"><span class="pre">PyCmpWrapper_Type</span></code>, <code class="docutils literal notranslate"><span class="pre">PySortWrapper_Type</span></code>,
<code class="docutils literal notranslate"><span class="pre">PyNoArgsFunction</span></code>.
(Contributed by Pablo Galindo Salgado in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39372">bpo-39372</a>.)</p></li>
</ul>
</section>
</section>
<section id="notable-changes-in-python-3-9-1">
<h2>Notable changes in Python 3.9.1<a class="headerlink" href="#notable-changes-in-python-3-9-1" title="Link to this heading"></a></h2>
<section id="id4">
<h3>typing<a class="headerlink" href="#id4" title="Link to this heading"></a></h3>
<p>The behavior of <a class="reference internal" href="../library/typing.html#typing.Literal" title="typing.Literal"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Literal</span></code></a> was changed to conform with <span class="target" id="index-27"></span><a class="pep reference external" href="https://peps.python.org/pep-0586/"><strong>PEP 586</strong></a>
and to match the behavior of static type checkers specified in the PEP.</p>
<ol class="arabic">
<li><p><code class="docutils literal notranslate"><span class="pre">Literal</span></code> now de-duplicates parameters.</p></li>
<li><p>Equality comparisons between <code class="docutils literal notranslate"><span class="pre">Literal</span></code> objects are now order independent.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">Literal</span></code> comparisons now respect types. For example,
<code class="docutils literal notranslate"><span class="pre">Literal[0]</span> <span class="pre">==</span> <span class="pre">Literal[False]</span></code> previously evaluated to <code class="docutils literal notranslate"><span class="pre">True</span></code>. It is
now <code class="docutils literal notranslate"><span class="pre">False</span></code>. To support this change, the internally used type cache now
supports differentiating types.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">Literal</span></code> objects will now raise 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> exception during
equality comparisons if any of their parameters are not <a class="reference internal" href="../glossary.html#term-hashable"><span class="xref std std-term">hashable</span></a>.
Note that declaring <code class="docutils literal notranslate"><span class="pre">Literal</span></code> with mutable parameters will not throw
an error:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </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">Literal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Literal</span><span class="p">[{</span><span class="mi">0</span><span class="p">}]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Literal</span><span class="p">[{</span><span class="mi">0</span><span class="p">}]</span> <span class="o">==</span> <span class="n">Literal</span><span class="p">[{</span><span class="kc">False</span><span class="p">}]</span>
<span class="gt">Traceback (most recent call last):</span>
File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
<span class="gr">TypeError</span>: <span class="n">unhashable type: &#39;set&#39;</span>
</pre></div>
</div>
</li>
</ol>
<p>(Contributed by Yurii Karabas in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42345">bpo-42345</a>.)</p>
</section>
<section id="macos-11-0-big-sur-and-apple-silicon-mac-support">
<h3>macOS 11.0 (Big Sur) and Apple Silicon Mac support<a class="headerlink" href="#macos-11-0-big-sur-and-apple-silicon-mac-support" title="Link to this heading"></a></h3>
<p>As of 3.9.1, Python now fully supports building and running on macOS 11.0
(Big Sur) and on Apple Silicon Macs (based on the <code class="docutils literal notranslate"><span class="pre">ARM64</span></code> architecture).
A new universal build variant, <code class="docutils literal notranslate"><span class="pre">universal2</span></code>, is now available to natively
support both <code class="docutils literal notranslate"><span class="pre">ARM64</span></code> and <code class="docutils literal notranslate"><span class="pre">Intel</span> <span class="pre">64</span></code> in one set of executables. Binaries
can also now be built on current versions of macOS to be deployed on a range
of older macOS versions (tested to 10.9) while making some newer OS
functions and options conditionally available based on the operating system
version in use at runtime (“weaklinking”).</p>
<p>(Contributed by Ronald Oussoren and Lawrence DAnna in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41100">bpo-41100</a>.)</p>
</section>
</section>
<section id="notable-changes-in-python-3-9-2">
<h2>Notable changes in Python 3.9.2<a class="headerlink" href="#notable-changes-in-python-3-9-2" title="Link to this heading"></a></h2>
<section id="collections-abc">
<h3>collections.abc<a class="headerlink" href="#collections-abc" title="Link to this heading"></a></h3>
<p><a class="reference internal" href="../library/collections.abc.html#collections.abc.Callable" title="collections.abc.Callable"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Callable</span></code></a> generic now flattens type parameters, similar
to what <a class="reference internal" href="../library/typing.html#typing.Callable" title="typing.Callable"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.Callable</span></code></a> currently does. This means that
<code class="docutils literal notranslate"><span class="pre">collections.abc.Callable[[int,</span> <span class="pre">str],</span> <span class="pre">str]</span></code> will have <code class="docutils literal notranslate"><span class="pre">__args__</span></code> of
<code class="docutils literal notranslate"><span class="pre">(int,</span> <span class="pre">str,</span> <span class="pre">str)</span></code>; previously this was <code class="docutils literal notranslate"><span class="pre">([int,</span> <span class="pre">str],</span> <span class="pre">str)</span></code>. To allow this
change, <a class="reference internal" href="../library/types.html#types.GenericAlias" title="types.GenericAlias"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.GenericAlias</span></code></a> can now be subclassed, and a subclass will
be returned when subscripting the <a class="reference internal" href="../library/collections.abc.html#collections.abc.Callable" title="collections.abc.Callable"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Callable</span></code></a> type.
Code which accesses the arguments via <a class="reference internal" href="../library/typing.html#typing.get_args" title="typing.get_args"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_args()</span></code></a> or <code class="docutils literal notranslate"><span class="pre">__args__</span></code>
need to account for this change. A <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> may be emitted for
invalid forms of parameterizing <a class="reference internal" href="../library/collections.abc.html#collections.abc.Callable" title="collections.abc.Callable"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Callable</span></code></a> which may have
passed silently in Python 3.9.1. This <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> will
become 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> in Python 3.10.
(Contributed by Ken Jin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42195">bpo-42195</a>.)</p>
</section>
<section id="urllib-parse">
<h3>urllib.parse<a class="headerlink" href="#urllib-parse" title="Link to this heading"></a></h3>
<p>Earlier Python versions allowed using both <code class="docutils literal notranslate"><span class="pre">;</span></code> and <code class="docutils literal notranslate"><span class="pre">&amp;</span></code> as
query parameter separators in <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.parse_qs" title="urllib.parse.parse_qs"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.parse_qs()</span></code></a> and
<a class="reference internal" href="../library/urllib.parse.html#urllib.parse.parse_qsl" title="urllib.parse.parse_qsl"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.parse_qsl()</span></code></a>. Due to security concerns, and to conform with
newer W3C recommendations, this has been changed to allow only a single
separator key, with <code class="docutils literal notranslate"><span class="pre">&amp;</span></code> as the default. This change also affects
<code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.parse()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.parse_multipart()</span></code> as they use the affected
functions internally. For more details, please see their respective
documentation.
(Contributed by Adam Goldschmidt, Senthil Kumaran and Ken Jin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42967">bpo-42967</a>.)</p>
</section>
</section>
<section id="notable-changes-in-python-3-9-3">
<h2>Notable changes in Python 3.9.3<a class="headerlink" href="#notable-changes-in-python-3-9-3" title="Link to this heading"></a></h2>
<p>A security fix alters the <a class="reference internal" href="../library/ftplib.html#ftplib.FTP" title="ftplib.FTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">ftplib.FTP</span></code></a> behavior to not trust the
IPv4 address sent from the remote server when setting up a passive data
channel. We reuse the ftp server IP address instead. For unusual code
requiring the old behavior, set a <code class="docutils literal notranslate"><span class="pre">trust_server_pasv_ipv4_address</span></code>
attribute on your FTP instance to <code class="docutils literal notranslate"><span class="pre">True</span></code>. (See <a class="reference external" href="https://github.com/python/cpython/issues/87451">gh-87451</a>)</p>
</section>
<section id="notable-changes-in-python-3-9-5">
<h2>Notable changes in Python 3.9.5<a class="headerlink" href="#notable-changes-in-python-3-9-5" title="Link to this heading"></a></h2>
<section id="id5">
<h3>urllib.parse<a class="headerlink" href="#id5" title="Link to this heading"></a></h3>
<p>The presence of newline or tab characters in parts of a URL allows for some
forms of attacks. Following the WHATWG specification that updates <span class="target" id="index-28"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc3986.html"><strong>RFC 3986</strong></a>,
ASCII newline <code class="docutils literal notranslate"><span class="pre">\n</span></code>, <code class="docutils literal notranslate"><span class="pre">\r</span></code> and tab <code class="docutils literal notranslate"><span class="pre">\t</span></code> characters are stripped from the
URL by the parser in <a class="reference internal" href="../library/urllib.parse.html#module-urllib.parse" title="urllib.parse: Parse URLs into or assemble them from components."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.parse</span></code></a> preventing such attacks. The removal
characters are controlled by a new module level variable
<code class="docutils literal notranslate"><span class="pre">urllib.parse._UNSAFE_URL_BYTES_TO_REMOVE</span></code>. (See <a class="reference external" href="https://github.com/python/cpython/issues/88048">gh-88048</a>)</p>
</section>
</section>
<section id="notable-security-feature-in-3-9-14">
<h2>Notable security feature in 3.9.14<a class="headerlink" href="#notable-security-feature-in-3-9-14" title="Link to this heading"></a></h2>
<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-29"></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>
</section>
<section id="notable-changes-in-3-9-17">
<h2>Notable changes in 3.9.17<a class="headerlink" href="#notable-changes-in-3-9-17" 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-30"></span><a class="pep reference external" href="https://peps.python.org/pep-0706/"><strong>PEP 706</strong></a>.)</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="#">Whats New In Python 3.9</a><ul>
<li><a class="reference internal" href="#summary-release-highlights">Summary Release highlights</a></li>
<li><a class="reference internal" href="#you-should-check-for-deprecationwarning-in-your-code">You should check for DeprecationWarning in your code</a></li>
<li><a class="reference internal" href="#new-features">New Features</a><ul>
<li><a class="reference internal" href="#dictionary-merge-update-operators">Dictionary Merge &amp; Update Operators</a></li>
<li><a class="reference internal" href="#new-string-methods-to-remove-prefixes-and-suffixes">New String Methods to Remove Prefixes and Suffixes</a></li>
<li><a class="reference internal" href="#type-hinting-generics-in-standard-collections">Type Hinting Generics in Standard Collections</a></li>
<li><a class="reference internal" href="#new-parser">New Parser</a></li>
</ul>
</li>
<li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
<li><a class="reference internal" href="#new-modules">New Modules</a><ul>
<li><a class="reference internal" href="#zoneinfo">zoneinfo</a></li>
<li><a class="reference internal" href="#graphlib">graphlib</a></li>
</ul>
</li>
<li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
<li><a class="reference internal" href="#ast">ast</a></li>
<li><a class="reference internal" href="#asyncio">asyncio</a></li>
<li><a class="reference internal" href="#compileall">compileall</a></li>
<li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li>
<li><a class="reference internal" href="#curses">curses</a></li>
<li><a class="reference internal" href="#datetime">datetime</a></li>
<li><a class="reference internal" href="#distutils">distutils</a></li>
<li><a class="reference internal" href="#fcntl">fcntl</a></li>
<li><a class="reference internal" href="#ftplib">ftplib</a></li>
<li><a class="reference internal" href="#gc">gc</a></li>
<li><a class="reference internal" href="#hashlib">hashlib</a></li>
<li><a class="reference internal" href="#http">http</a></li>
<li><a class="reference internal" href="#idle-and-idlelib">IDLE and idlelib</a></li>
<li><a class="reference internal" href="#imaplib">imaplib</a></li>
<li><a class="reference internal" href="#importlib">importlib</a></li>
<li><a class="reference internal" href="#inspect">inspect</a></li>
<li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
<li><a class="reference internal" href="#math">math</a></li>
<li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
<li><a class="reference internal" href="#nntplib">nntplib</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="#pdb">pdb</a></li>
<li><a class="reference internal" href="#poplib">poplib</a></li>
<li><a class="reference internal" href="#pprint">pprint</a></li>
<li><a class="reference internal" href="#pydoc">pydoc</a></li>
<li><a class="reference internal" href="#random">random</a></li>
<li><a class="reference internal" href="#signal">signal</a></li>
<li><a class="reference internal" href="#smtplib">smtplib</a></li>
<li><a class="reference internal" href="#socket">socket</a></li>
<li><a class="reference internal" href="#time">time</a></li>
<li><a class="reference internal" href="#sys">sys</a></li>
<li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
<li><a class="reference internal" href="#typing">typing</a></li>
<li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
<li><a class="reference internal" href="#venv">venv</a></li>
<li><a class="reference internal" href="#xml">xml</a></li>
</ul>
</li>
<li><a class="reference internal" href="#optimizations">Optimizations</a></li>
<li><a class="reference internal" href="#deprecated">Deprecated</a></li>
<li><a class="reference internal" href="#removed">Removed</a></li>
<li><a class="reference internal" href="#porting-to-python-3-9">Porting to Python 3.9</a><ul>
<li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
<li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
<li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#build-changes">Build Changes</a></li>
<li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
<li><a class="reference internal" href="#id1">New Features</a></li>
<li><a class="reference internal" href="#id2">Porting to Python 3.9</a></li>
<li><a class="reference internal" href="#id3">Removed</a></li>
</ul>
</li>
<li><a class="reference internal" href="#notable-changes-in-python-3-9-1">Notable changes in Python 3.9.1</a><ul>
<li><a class="reference internal" href="#id4">typing</a></li>
<li><a class="reference internal" href="#macos-11-0-big-sur-and-apple-silicon-mac-support">macOS 11.0 (Big Sur) and Apple Silicon Mac support</a></li>
</ul>
</li>
<li><a class="reference internal" href="#notable-changes-in-python-3-9-2">Notable changes in Python 3.9.2</a><ul>
<li><a class="reference internal" href="#collections-abc">collections.abc</a></li>
<li><a class="reference internal" href="#urllib-parse">urllib.parse</a></li>
</ul>
</li>
<li><a class="reference internal" href="#notable-changes-in-python-3-9-3">Notable changes in Python 3.9.3</a></li>
<li><a class="reference internal" href="#notable-changes-in-python-3-9-5">Notable changes in Python 3.9.5</a><ul>
<li><a class="reference internal" href="#id5">urllib.parse</a></li>
</ul>
</li>
<li><a class="reference internal" href="#notable-security-feature-in-3-9-14">Notable security feature in 3.9.14</a></li>
<li><a class="reference internal" href="#notable-changes-in-3-9-17">Notable changes in 3.9.17</a><ul>
<li><a class="reference internal" href="#tarfile">tarfile</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="3.10.html"
title="previous chapter">Whats New In Python 3.10</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="3.8.html"
title="next chapter">Whats New In Python 3.8</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.9.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.8.html" title="Whats New In Python 3.8"
>next</a> |</li>
<li class="right" >
<a href="3.10.html" title="Whats New In Python 3.10"
>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> &#187;</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> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Whats New in Python</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Whats New In Python 3.9</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">
&copy;
<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>