2505 lines
306 KiB
HTML
2505 lines
306 KiB
HTML
<!DOCTYPE html>
|
||
|
||
<html lang="en" data-content_root="../">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
<meta property="og:title" content="What’s New In Python 3.8" />
|
||
<meta property="og:type" content="website" />
|
||
<meta property="og:url" content="https://docs.python.org/3/whatsnew/3.8.html" />
|
||
<meta property="og:site_name" content="Python documentation" />
|
||
<meta property="og:description" content="Editor, Raymond Hettinger,. This article explains the new features in Python 3.8, compared to 3.7. Python 3.8 was released on October 14, 2019. For full details, see the changelog. Summary – Releas..." />
|
||
<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, Raymond Hettinger,. This article explains the new features in Python 3.8, compared to 3.7. Python 3.8 was released on October 14, 2019. For full details, see the changelog. Summary – Releas..." />
|
||
<meta property="og:image:width" content="200">
|
||
<meta property="og:image:height" content="200">
|
||
<meta name="theme-color" content="#3776ab">
|
||
|
||
<title>What’s New In Python 3.8 — Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
|
||
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
|
||
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
|
||
|
||
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
|
||
<script src="../_static/doctools.js?v=9bcbadda"></script>
|
||
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||
|
||
<script src="../_static/sidebar.js"></script>
|
||
|
||
<link rel="search" type="application/opensearchdescription+xml"
|
||
title="Search within Python 3.13.3 documentation"
|
||
href="../_static/opensearch.xml"/>
|
||
<link rel="author" title="About these documents" href="../about.html" />
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
<link rel="copyright" title="Copyright" href="../copyright.html" />
|
||
<link rel="next" title="What’s New In Python 3.7" href="3.7.html" />
|
||
<link rel="prev" title="What’s New In Python 3.9" href="3.9.html" />
|
||
|
||
<link rel="canonical" href="https://docs.python.org/3/whatsnew/3.8.html">
|
||
|
||
|
||
|
||
|
||
|
||
<style>
|
||
@media only screen {
|
||
table.full-width-table {
|
||
width: 100%;
|
||
}
|
||
}
|
||
</style>
|
||
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
|
||
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
|
||
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
||
<script type="text/javascript" src="../_static/menu.js"></script>
|
||
<script type="text/javascript" src="../_static/search-focus.js"></script>
|
||
<script type="text/javascript" src="../_static/themetoggle.js"></script>
|
||
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
|
||
<meta name="readthedocs-addons-api-version" content="1">
|
||
|
||
</head>
|
||
<body>
|
||
<div class="mobile-nav">
|
||
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
|
||
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
|
||
<nav class="nav-content" role="navigation">
|
||
<label for="menuToggler" class="toggler__label">
|
||
<span></span>
|
||
</label>
|
||
<span class="nav-items-wrapper">
|
||
<a href="https://www.python.org/" class="nav-logo">
|
||
<img src="../_static/py.svg" alt="Python logo"/>
|
||
</a>
|
||
<span class="version_switcher_placeholder"></span>
|
||
<form role="search" class="search" action="../search.html" method="get">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
|
||
<path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
|
||
</svg>
|
||
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
|
||
<input type="submit" value="Go"/>
|
||
</form>
|
||
</span>
|
||
</nav>
|
||
<div class="menu-wrapper">
|
||
<nav class="menu" role="navigation" aria-label="main navigation">
|
||
<div class="language_switcher_placeholder"></div>
|
||
|
||
<label class="theme-selector-label">
|
||
Theme
|
||
<select class="theme-selector" oninput="activateTheme(this.value)">
|
||
<option value="auto" selected>Auto</option>
|
||
<option value="light">Light</option>
|
||
<option value="dark">Dark</option>
|
||
</select>
|
||
</label>
|
||
<div>
|
||
<h3><a href="../contents.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">What’s New In Python 3.8</a><ul>
|
||
<li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
|
||
<li><a class="reference internal" href="#new-features">New Features</a><ul>
|
||
<li><a class="reference internal" href="#assignment-expressions">Assignment expressions</a></li>
|
||
<li><a class="reference internal" href="#positional-only-parameters">Positional-only parameters</a></li>
|
||
<li><a class="reference internal" href="#parallel-filesystem-cache-for-compiled-bytecode-files">Parallel filesystem cache for compiled bytecode files</a></li>
|
||
<li><a class="reference internal" href="#debug-build-uses-the-same-abi-as-release-build">Debug build uses the same ABI as release build</a></li>
|
||
<li><a class="reference internal" href="#f-strings-support-for-self-documenting-expressions-and-debugging">f-strings support <code class="docutils literal notranslate"><span class="pre">=</span></code> for self-documenting expressions and debugging</a></li>
|
||
<li><a class="reference internal" href="#pep-578-python-runtime-audit-hooks">PEP 578: Python Runtime Audit Hooks</a></li>
|
||
<li><a class="reference internal" href="#pep-587-python-initialization-configuration">PEP 587: Python Initialization Configuration</a></li>
|
||
<li><a class="reference internal" href="#pep-590-vectorcall-a-fast-calling-protocol-for-cpython">PEP 590: Vectorcall: a fast calling protocol for CPython</a></li>
|
||
<li><a class="reference internal" href="#pickle-protocol-5-with-out-of-band-data-buffers">Pickle protocol 5 with out-of-band data buffers</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
|
||
<li><a class="reference internal" href="#new-modules">New Modules</a></li>
|
||
<li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
|
||
<li><a class="reference internal" href="#ast">ast</a></li>
|
||
<li><a class="reference internal" href="#asyncio">asyncio</a></li>
|
||
<li><a class="reference internal" href="#builtins">builtins</a></li>
|
||
<li><a class="reference internal" href="#collections">collections</a></li>
|
||
<li><a class="reference internal" href="#cprofile">cProfile</a></li>
|
||
<li><a class="reference internal" href="#csv">csv</a></li>
|
||
<li><a class="reference internal" href="#curses">curses</a></li>
|
||
<li><a class="reference internal" href="#ctypes">ctypes</a></li>
|
||
<li><a class="reference internal" href="#datetime">datetime</a></li>
|
||
<li><a class="reference internal" href="#functools">functools</a></li>
|
||
<li><a class="reference internal" href="#gc">gc</a></li>
|
||
<li><a class="reference internal" href="#gettext">gettext</a></li>
|
||
<li><a class="reference internal" href="#gzip">gzip</a></li>
|
||
<li><a class="reference internal" href="#idle-and-idlelib">IDLE and idlelib</a></li>
|
||
<li><a class="reference internal" href="#inspect">inspect</a></li>
|
||
<li><a class="reference internal" href="#io">io</a></li>
|
||
<li><a class="reference internal" href="#itertools">itertools</a></li>
|
||
<li><a class="reference internal" href="#json-tool">json.tool</a></li>
|
||
<li><a class="reference internal" href="#logging">logging</a></li>
|
||
<li><a class="reference internal" href="#math">math</a></li>
|
||
<li><a class="reference internal" href="#mmap">mmap</a></li>
|
||
<li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
|
||
<li><a class="reference internal" href="#os">os</a></li>
|
||
<li><a class="reference internal" href="#os-path">os.path</a></li>
|
||
<li><a class="reference internal" href="#pathlib">pathlib</a></li>
|
||
<li><a class="reference internal" href="#pickle">pickle</a></li>
|
||
<li><a class="reference internal" href="#plistlib">plistlib</a></li>
|
||
<li><a class="reference internal" href="#pprint">pprint</a></li>
|
||
<li><a class="reference internal" href="#py-compile">py_compile</a></li>
|
||
<li><a class="reference internal" href="#shlex">shlex</a></li>
|
||
<li><a class="reference internal" href="#shutil">shutil</a></li>
|
||
<li><a class="reference internal" href="#socket">socket</a></li>
|
||
<li><a class="reference internal" href="#ssl">ssl</a></li>
|
||
<li><a class="reference internal" href="#statistics">statistics</a></li>
|
||
<li><a class="reference internal" href="#sys">sys</a></li>
|
||
<li><a class="reference internal" href="#tarfile">tarfile</a></li>
|
||
<li><a class="reference internal" href="#threading">threading</a></li>
|
||
<li><a class="reference internal" href="#tokenize">tokenize</a></li>
|
||
<li><a class="reference internal" href="#tkinter">tkinter</a></li>
|
||
<li><a class="reference internal" href="#time">time</a></li>
|
||
<li><a class="reference internal" href="#typing">typing</a></li>
|
||
<li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
|
||
<li><a class="reference internal" href="#unittest">unittest</a></li>
|
||
<li><a class="reference internal" href="#venv">venv</a></li>
|
||
<li><a class="reference internal" href="#weakref">weakref</a></li>
|
||
<li><a class="reference internal" href="#xml">xml</a></li>
|
||
<li><a class="reference internal" href="#xmlrpc">xmlrpc</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#optimizations">Optimizations</a></li>
|
||
<li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
|
||
<li><a class="reference internal" href="#deprecated">Deprecated</a></li>
|
||
<li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
|
||
<li><a class="reference internal" href="#porting-to-python-3-8">Porting to Python 3.8</a><ul>
|
||
<li><a class="reference internal" href="#changes-in-python-behavior">Changes in Python behavior</a></li>
|
||
<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>
|
||
<li><a class="reference internal" href="#demos-and-tools">Demos and Tools</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-8-1">Notable changes in Python 3.8.1</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-8-2">Notable changes in Python 3.8.2</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-8-3">Notable changes in Python 3.8.3</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-8-8">Notable changes in Python 3.8.8</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-8-9">Notable changes in Python 3.8.9</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-8-10">Notable changes in Python 3.8.10</a><ul>
|
||
<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="#id1">Notable changes in Python 3.8.10</a><ul>
|
||
<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-8-12">Notable changes in Python 3.8.12</a><ul>
|
||
<li><a class="reference internal" href="#id2">Changes in the Python API</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#notable-security-feature-in-3-8-14">Notable security feature in 3.8.14</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-3-8-17">Notable changes in 3.8.17</a><ul>
|
||
<li><a class="reference internal" href="#id3">tarfile</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
</div>
|
||
<div>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="3.9.html"
|
||
title="previous chapter">What’s New In Python 3.9</a></p>
|
||
</div>
|
||
<div>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="3.7.html"
|
||
title="next chapter">What’s New In Python 3.7</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.8.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.7.html" title="What’s New In Python 3.7"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.9.html" title="What’s New In Python 3.9"
|
||
accesskey="P">previous</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.13.3 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">What’s New In Python 3.8</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-8">
|
||
<h1>What’s New In Python 3.8<a class="headerlink" href="#what-s-new-in-python-3-8" 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>Raymond Hettinger</p>
|
||
</dd>
|
||
</dl>
|
||
<p>This article explains the new features in Python 3.8, compared to 3.7.
|
||
Python 3.8 was released on October 14, 2019.
|
||
For full details, see the <a class="reference internal" href="changelog.html#changelog"><span class="std std-ref">changelog</span></a>.</p>
|
||
<section id="summary-release-highlights">
|
||
<h2>Summary – Release highlights<a class="headerlink" href="#summary-release-highlights" title="Link to this heading">¶</a></h2>
|
||
</section>
|
||
<section id="new-features">
|
||
<h2>New Features<a class="headerlink" href="#new-features" title="Link to this heading">¶</a></h2>
|
||
<section id="assignment-expressions">
|
||
<h3>Assignment expressions<a class="headerlink" href="#assignment-expressions" title="Link to this heading">¶</a></h3>
|
||
<p>There is new syntax <code class="docutils literal notranslate"><span class="pre">:=</span></code> that assigns values to variables as part of a larger
|
||
expression. It is affectionately known as “the walrus operator” due to
|
||
its resemblance to <a class="reference external" href="https://en.wikipedia.org/wiki/Walrus#/media/File:Pacific_Walrus_-_Bull_(8247646168).jpg">the eyes and tusks of a walrus</a>.</p>
|
||
<p>In this example, the assignment expression helps avoid calling
|
||
<a class="reference internal" href="../library/functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a> twice:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o">:=</span> <span class="nb">len</span><span class="p">(</span><span class="n">a</span><span class="p">))</span> <span class="o">></span> <span class="mi">10</span><span class="p">:</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"List is too long (</span><span class="si">{</span><span class="n">n</span><span class="si">}</span><span class="s2"> elements, expected <= 10)"</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>A similar benefit arises during regular expression matching where
|
||
match objects are needed twice, once to test whether a match
|
||
occurred and another to extract a subgroup:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">discount</span> <span class="o">=</span> <span class="mf">0.0</span>
|
||
<span class="k">if</span> <span class="p">(</span><span class="n">mo</span> <span class="o">:=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="sa">r</span><span class="s1">'(\d+)</span><span class="si">% d</span><span class="s1">iscount'</span><span class="p">,</span> <span class="n">advertisement</span><span class="p">)):</span>
|
||
<span class="n">discount</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">mo</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span> <span class="o">/</span> <span class="mf">100.0</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The operator is also useful with while-loops that compute
|
||
a value to test loop termination and then need that same
|
||
value again in the body of the loop:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Loop over fixed length blocks</span>
|
||
<span class="k">while</span> <span class="p">(</span><span class="n">block</span> <span class="o">:=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">256</span><span class="p">))</span> <span class="o">!=</span> <span class="s1">''</span><span class="p">:</span>
|
||
<span class="n">process</span><span class="p">(</span><span class="n">block</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Another motivating use case arises in list comprehensions where
|
||
a value computed in a filtering condition is also needed in
|
||
the expression body:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="n">clean_name</span><span class="o">.</span><span class="n">title</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="k">if</span> <span class="p">(</span><span class="n">clean_name</span> <span class="o">:=</span> <span class="n">normalize</span><span class="p">(</span><span class="s1">'NFC'</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span> <span class="ow">in</span> <span class="n">allowed_names</span><span class="p">]</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Try to limit use of the walrus operator to clean cases that reduce
|
||
complexity and improve readability.</p>
|
||
<p>See <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0572/"><strong>PEP 572</strong></a> for a full description.</p>
|
||
<p>(Contributed by Emily Morehouse in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35224">bpo-35224</a>.)</p>
|
||
</section>
|
||
<section id="positional-only-parameters">
|
||
<h3>Positional-only parameters<a class="headerlink" href="#positional-only-parameters" title="Link to this heading">¶</a></h3>
|
||
<p>There is a new function parameter syntax <code class="docutils literal notranslate"><span class="pre">/</span></code> to indicate that some
|
||
function parameters must be specified positionally and cannot be used as
|
||
keyword arguments. This is the same notation shown by <code class="docutils literal notranslate"><span class="pre">help()</span></code> for C
|
||
functions annotated with Larry Hastings’
|
||
<a class="reference external" href="https://devguide.python.org/development-tools/clinic/">Argument Clinic</a> tool.</p>
|
||
<p>In the following example, parameters <em>a</em> and <em>b</em> are positional-only,
|
||
while <em>c</em> or <em>d</em> can be positional or keyword, and <em>e</em> or <em>f</em> are
|
||
required to be keywords:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">f</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="o">/</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">f</span><span class="p">):</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The following is a valid call:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">f</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="mi">40</span><span class="p">,</span> <span class="n">e</span><span class="o">=</span><span class="mi">50</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="mi">60</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>However, these are invalid calls:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">f</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="mi">40</span><span class="p">,</span> <span class="n">e</span><span class="o">=</span><span class="mi">50</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="mi">60</span><span class="p">)</span> <span class="c1"># b cannot be a keyword argument</span>
|
||
<span class="n">f</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="mi">60</span><span class="p">)</span> <span class="c1"># e must be a keyword argument</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>One use case for this notation is that it allows pure Python functions
|
||
to fully emulate behaviors of existing C coded functions. For example,
|
||
the built-in <a class="reference internal" href="../library/functions.html#divmod" title="divmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">divmod()</span></code></a> function does not accept keyword arguments:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">divmod</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="o">/</span><span class="p">):</span>
|
||
<span class="s2">"Emulate the built in divmod() function"</span>
|
||
<span class="k">return</span> <span class="p">(</span><span class="n">a</span> <span class="o">//</span> <span class="n">b</span><span class="p">,</span> <span class="n">a</span> <span class="o">%</span> <span class="n">b</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Another use case is to preclude keyword arguments when the parameter
|
||
name is not helpful. For example, the builtin <a class="reference internal" href="../library/functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a> function has
|
||
the signature <code class="docutils literal notranslate"><span class="pre">len(obj,</span> <span class="pre">/)</span></code>. This precludes awkward calls such as:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">len</span><span class="p">(</span><span class="n">obj</span><span class="o">=</span><span class="s1">'hello'</span><span class="p">)</span> <span class="c1"># The "obj" keyword argument impairs readability</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>A further benefit of marking a parameter as positional-only is that it
|
||
allows the parameter name to be changed in the future without risk of
|
||
breaking client code. For example, in the <a class="reference internal" href="../library/statistics.html#module-statistics" title="statistics: Mathematical statistics functions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">statistics</span></code></a> module, the
|
||
parameter name <em>dist</em> may be changed in the future. This was made
|
||
possible with the following function specification:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">quantiles</span><span class="p">(</span><span class="n">dist</span><span class="p">,</span> <span class="o">/</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">'exclusive'</span><span class="p">)</span>
|
||
<span class="o">...</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Since the parameters to the left of <code class="docutils literal notranslate"><span class="pre">/</span></code> are not exposed as possible
|
||
keywords, the parameters names remain available for use in <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code>:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span><span class="w"> </span><span class="nf">f</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="o">/</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="n">f</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span> <span class="c1"># a and b are used in two ways</span>
|
||
<span class="go">10 20 {'a': 1, 'b': 2, 'c': 3}</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>This greatly simplifies the implementation of functions and methods
|
||
that need to accept arbitrary keyword arguments. For example, here
|
||
is an excerpt from code 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:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span><span class="w"> </span><span class="nc">Counter</span><span class="p">(</span><span class="nb">dict</span><span class="p">):</span>
|
||
|
||
<span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">iterable</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">/</span><span class="p">,</span> <span class="o">**</span><span class="n">kwds</span><span class="p">):</span>
|
||
<span class="c1"># Note "iterable" is a possible keyword argument</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>See <span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0570/"><strong>PEP 570</strong></a> for a full description.</p>
|
||
<p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36540">bpo-36540</a>.)</p>
|
||
</section>
|
||
<section id="parallel-filesystem-cache-for-compiled-bytecode-files">
|
||
<h3>Parallel filesystem cache for compiled bytecode files<a class="headerlink" href="#parallel-filesystem-cache-for-compiled-bytecode-files" title="Link to this heading">¶</a></h3>
|
||
<p>The new <span class="target" id="index-2"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPYCACHEPREFIX"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPYCACHEPREFIX</span></code></a> setting (also available as
|
||
<a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> <code class="docutils literal notranslate"><span class="pre">pycache_prefix</span></code>) configures the implicit bytecode
|
||
cache to use a separate parallel filesystem tree, rather than
|
||
the default <code class="docutils literal notranslate"><span class="pre">__pycache__</span></code> subdirectories within each source
|
||
directory.</p>
|
||
<p>The location of the cache is reported in <a class="reference internal" href="../library/sys.html#sys.pycache_prefix" title="sys.pycache_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.pycache_prefix</span></code></a>
|
||
(<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> indicates the default location in <code class="docutils literal notranslate"><span class="pre">__pycache__</span></code>
|
||
subdirectories).</p>
|
||
<p>(Contributed by Carl Meyer in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33499">bpo-33499</a>.)</p>
|
||
</section>
|
||
<section id="debug-build-uses-the-same-abi-as-release-build">
|
||
<h3>Debug build uses the same ABI as release build<a class="headerlink" href="#debug-build-uses-the-same-abi-as-release-build" title="Link to this heading">¶</a></h3>
|
||
<p>Python now uses the same ABI whether it’s built in release or debug mode. On
|
||
Unix, when Python is built in debug mode, it is now possible to load C
|
||
extensions built in release mode and C extensions built using the stable ABI.</p>
|
||
<p>Release builds and <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug builds</span></a> are now ABI compatible: defining the
|
||
<code class="docutils literal notranslate"><span class="pre">Py_DEBUG</span></code> macro no longer implies the <code class="docutils literal notranslate"><span class="pre">Py_TRACE_REFS</span></code> macro, which
|
||
introduces the only ABI incompatibility. The <code class="docutils literal notranslate"><span class="pre">Py_TRACE_REFS</span></code> macro, which
|
||
adds the <a class="reference internal" href="../library/sys.html#sys.getobjects" title="sys.getobjects"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getobjects()</span></code></a> function and the <span class="target" id="index-3"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONDUMPREFS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONDUMPREFS</span></code></a>
|
||
environment variable, can be set using the new <a class="reference internal" href="../using/configure.html#cmdoption-with-trace-refs"><code class="xref std std-option docutils literal notranslate"><span class="pre">./configure</span>
|
||
<span class="pre">--with-trace-refs</span></code></a> build option.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36465">bpo-36465</a>.)</p>
|
||
<p>On Unix, C extensions are no longer linked to libpython except on Android
|
||
and Cygwin.
|
||
It is now possible
|
||
for a statically linked Python to load a C extension built using a shared
|
||
library Python.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=21536">bpo-21536</a>.)</p>
|
||
<p>On Unix, when Python is built in debug mode, import now also looks for C
|
||
extensions compiled in release mode and for C extensions compiled with the
|
||
stable ABI.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36722">bpo-36722</a>.)</p>
|
||
<p>To embed Python into an application, a new <code class="docutils literal notranslate"><span class="pre">--embed</span></code> option must be passed to
|
||
<code class="docutils literal notranslate"><span class="pre">python3-config</span> <span class="pre">--libs</span> <span class="pre">--embed</span></code> to get <code class="docutils literal notranslate"><span class="pre">-lpython3.8</span></code> (link the application
|
||
to libpython). To support both 3.8 and older, try <code class="docutils literal notranslate"><span class="pre">python3-config</span> <span class="pre">--libs</span>
|
||
<span class="pre">--embed</span></code> first and fallback to <code class="docutils literal notranslate"><span class="pre">python3-config</span> <span class="pre">--libs</span></code> (without <code class="docutils literal notranslate"><span class="pre">--embed</span></code>)
|
||
if the previous command fails.</p>
|
||
<p>Add a pkg-config <code class="docutils literal notranslate"><span class="pre">python-3.8-embed</span></code> module to embed Python into an
|
||
application: <code class="docutils literal notranslate"><span class="pre">pkg-config</span> <span class="pre">python-3.8-embed</span> <span class="pre">--libs</span></code> includes <code class="docutils literal notranslate"><span class="pre">-lpython3.8</span></code>.
|
||
To support both 3.8 and older, try <code class="docutils literal notranslate"><span class="pre">pkg-config</span> <span class="pre">python-X.Y-embed</span> <span class="pre">--libs</span></code> first
|
||
and fallback to <code class="docutils literal notranslate"><span class="pre">pkg-config</span> <span class="pre">python-X.Y</span> <span class="pre">--libs</span></code> (without <code class="docutils literal notranslate"><span class="pre">--embed</span></code>) if the
|
||
previous command fails (replace <code class="docutils literal notranslate"><span class="pre">X.Y</span></code> with the Python version).</p>
|
||
<p>On the other hand, <code class="docutils literal notranslate"><span class="pre">pkg-config</span> <span class="pre">python3.8</span> <span class="pre">--libs</span></code> no longer contains
|
||
<code class="docutils literal notranslate"><span class="pre">-lpython3.8</span></code>. C extensions must not be linked to libpython (except on
|
||
Android and Cygwin, whose cases are handled by the script);
|
||
this change is backward incompatible on purpose.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36721">bpo-36721</a>.)</p>
|
||
</section>
|
||
<section id="f-strings-support-for-self-documenting-expressions-and-debugging">
|
||
<span id="bpo-36817-whatsnew"></span><h3>f-strings support <code class="docutils literal notranslate"><span class="pre">=</span></code> for self-documenting expressions and debugging<a class="headerlink" href="#f-strings-support-for-self-documenting-expressions-and-debugging" title="Link to this heading">¶</a></h3>
|
||
<p>Added an <code class="docutils literal notranslate"><span class="pre">=</span></code> specifier to <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-string</span></a>s. An f-string such as
|
||
<code class="docutils literal notranslate"><span class="pre">f'{expr=}'</span></code> will expand to the text of the expression, an equal sign,
|
||
then the representation of the evaluated expression. For example:</p>
|
||
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">user</span> <span class="o">=</span> <span class="s1">'eric_idle'</span>
|
||
<span class="gp">>>> </span><span class="n">member_since</span> <span class="o">=</span> <span class="n">date</span><span class="p">(</span><span class="mi">1975</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">31</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">user</span><span class="si">=}</span><span class="s1"> </span><span class="si">{</span><span class="n">member_since</span><span class="si">=}</span><span class="s1">'</span>
|
||
<span class="go">"user='eric_idle' member_since=datetime.date(1975, 7, 31)"</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The usual <a class="reference internal" href="../reference/lexical_analysis.html#f-strings"><span class="std std-ref">f-string format specifiers</span></a> allow more
|
||
control over how the result of the expression is displayed:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">delta</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">today</span><span class="p">()</span> <span class="o">-</span> <span class="n">member_since</span>
|
||
<span class="gp">>>> </span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">user</span><span class="si">=!s}</span><span class="s1"> </span><span class="si">{</span><span class="n">delta</span><span class="o">.</span><span class="n">days</span><span class="si">=:</span><span class="s1">,d</span><span class="si">}</span><span class="s1">'</span>
|
||
<span class="go">'user=eric_idle delta.days=16,075'</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">=</span></code> specifier will display the whole expression so that
|
||
calculations can be shown:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">theta</span><span class="si">=}</span><span class="s1"> </span><span class="si">{</span><span class="n">cos</span><span class="p">(</span><span class="n">radians</span><span class="p">(</span><span class="n">theta</span><span class="p">))</span><span class="si">=:</span><span class="s1">.3f</span><span class="si">}</span><span class="s1">'</span><span class="p">)</span>
|
||
<span class="go">theta=30 cos(radians(theta))=0.866</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Eric V. Smith and Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36817">bpo-36817</a>.)</p>
|
||
</section>
|
||
<section id="pep-578-python-runtime-audit-hooks">
|
||
<h3>PEP 578: Python Runtime Audit Hooks<a class="headerlink" href="#pep-578-python-runtime-audit-hooks" title="Link to this heading">¶</a></h3>
|
||
<p>The PEP adds an Audit Hook and Verified Open Hook. Both are available from
|
||
Python and native code, allowing applications and frameworks written in pure
|
||
Python code to take advantage of extra notifications, while also allowing
|
||
embedders or system administrators to deploy builds of Python where auditing is
|
||
always enabled.</p>
|
||
<p>See <span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0578/"><strong>PEP 578</strong></a> for full details.</p>
|
||
</section>
|
||
<section id="pep-587-python-initialization-configuration">
|
||
<h3>PEP 587: Python Initialization Configuration<a class="headerlink" href="#pep-587-python-initialization-configuration" title="Link to this heading">¶</a></h3>
|
||
<p>The <span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0587/"><strong>PEP 587</strong></a> adds a new C API to configure the Python Initialization
|
||
providing finer control on the whole configuration and better error reporting.</p>
|
||
<p>New structures:</p>
|
||
<ul class="simple">
|
||
<li><p><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></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig" title="PyPreConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyPreConfig</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus" title="PyStatus"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyStatus</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyWideStringList" title="PyWideStringList"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyWideStringList</span></code></a></p></li>
|
||
</ul>
|
||
<p>New functions:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_Clear" title="PyConfig_Clear"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Clear()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_InitIsolatedConfig" title="PyConfig_InitIsolatedConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_InitIsolatedConfig()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_InitPythonConfig" title="PyConfig_InitPythonConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_InitPythonConfig()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_Read" title="PyConfig_Read"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Read()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_SetArgv" title="PyConfig_SetArgv"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_SetArgv()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_SetBytesArgv" title="PyConfig_SetBytesArgv"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_SetBytesArgv()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_SetBytesString" title="PyConfig_SetBytesString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_SetBytesString()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_SetString" title="PyConfig_SetString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_SetString()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig_InitIsolatedConfig" title="PyPreConfig_InitIsolatedConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyPreConfig_InitIsolatedConfig()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig_InitPythonConfig" title="PyPreConfig_InitPythonConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyPreConfig_InitPythonConfig()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_Error" title="PyStatus_Error"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_Error()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_Exception" title="PyStatus_Exception"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_Exception()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_Exit" title="PyStatus_Exit"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_Exit()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_IsError" title="PyStatus_IsError"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_IsError()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_IsExit" title="PyStatus_IsExit"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_IsExit()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_NoMemory" title="PyStatus_NoMemory"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_NoMemory()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_Ok" title="PyStatus_Ok"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_Ok()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyWideStringList_Append" title="PyWideStringList_Append"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWideStringList_Append()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.PyWideStringList_Insert" title="PyWideStringList_Insert"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWideStringList_Insert()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init.html#c.Py_BytesMain" title="Py_BytesMain"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_BytesMain()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.Py_ExitStatusException" title="Py_ExitStatusException"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_ExitStatusException()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init.html#c.Py_InitializeFromConfig" title="Py_InitializeFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_InitializeFromConfig()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.Py_PreInitialize" title="Py_PreInitialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitialize()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.Py_PreInitializeFromArgs" title="Py_PreInitializeFromArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitializeFromArgs()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init_config.html#c.Py_PreInitializeFromBytesArgs" title="Py_PreInitializeFromBytesArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitializeFromBytesArgs()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init.html#c.Py_RunMain" title="Py_RunMain"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_RunMain()</span></code></a></p></li>
|
||
</ul>
|
||
<p>This PEP also adds <code class="docutils literal notranslate"><span class="pre">_PyRuntimeState.preconfig</span></code> (<a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig" title="PyPreConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyPreConfig</span></code></a> type)
|
||
and <code class="docutils literal notranslate"><span class="pre">PyInterpreterState.config</span></code> (<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> type) fields to these
|
||
internal structures. <code class="docutils literal notranslate"><span class="pre">PyInterpreterState.config</span></code> becomes the new
|
||
reference configuration, replacing global configuration variables and
|
||
other private variables.</p>
|
||
<p>See <a class="reference internal" href="../c-api/init_config.html#init-config"><span class="std std-ref">Python Initialization Configuration</span></a> for the
|
||
documentation.</p>
|
||
<p>See <span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0587/"><strong>PEP 587</strong></a> for a full description.</p>
|
||
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36763">bpo-36763</a>.)</p>
|
||
</section>
|
||
<section id="pep-590-vectorcall-a-fast-calling-protocol-for-cpython">
|
||
<h3>PEP 590: Vectorcall: a fast calling protocol for CPython<a class="headerlink" href="#pep-590-vectorcall-a-fast-calling-protocol-for-cpython" title="Link to this heading">¶</a></h3>
|
||
<p><a class="reference internal" href="../c-api/call.html#vectorcall"><span class="std std-ref">The Vectorcall Protocol</span></a> is added to the Python/C API.
|
||
It is meant to formalize existing optimizations which were already done
|
||
for various classes.
|
||
Any <a class="reference internal" href="../c-api/typeobj.html#static-types"><span class="std std-ref">static type</span></a> implementing a callable can use this
|
||
protocol.</p>
|
||
<p>This is currently provisional.
|
||
The aim is to make it fully public in Python 3.9.</p>
|
||
<p>See <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0590/"><strong>PEP 590</strong></a> for a full description.</p>
|
||
<p>(Contributed by Jeroen Demeyer, Mark Shannon and Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36974">bpo-36974</a>.)</p>
|
||
</section>
|
||
<section id="pickle-protocol-5-with-out-of-band-data-buffers">
|
||
<h3>Pickle protocol 5 with out-of-band data buffers<a class="headerlink" href="#pickle-protocol-5-with-out-of-band-data-buffers" title="Link to this heading">¶</a></h3>
|
||
<p>When <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> is used to transfer large data between Python processes
|
||
in order to take advantage of multi-core or multi-machine processing,
|
||
it is important to optimize the transfer by reducing memory copies, and
|
||
possibly by applying custom techniques such as data-dependent compression.</p>
|
||
<p>The <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> protocol 5 introduces support for out-of-band buffers
|
||
where <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-3118/"><strong>PEP 3118</strong></a>-compatible data can be transmitted separately from the
|
||
main pickle stream, at the discretion of the communication layer.</p>
|
||
<p>See <span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0574/"><strong>PEP 574</strong></a> for a full description.</p>
|
||
<p>(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36785">bpo-36785</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 <a class="reference internal" href="../reference/simple_stmts.html#continue"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">continue</span></code></a> statement was illegal in the <a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">finally</span></code></a> clause
|
||
due to a problem with the implementation. In Python 3.8 this restriction
|
||
was lifted.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32489">bpo-32489</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a>, <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/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">fractions.Fraction</span></code></a> types
|
||
now have an <a class="reference internal" href="../library/stdtypes.html#int.as_integer_ratio" title="int.as_integer_ratio"><code class="xref py py-meth docutils literal notranslate"><span class="pre">as_integer_ratio()</span></code></a> method like that found in
|
||
<a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> and <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">decimal.Decimal</span></code></a>. This minor API extension
|
||
makes it possible to write <code class="docutils literal notranslate"><span class="pre">numerator,</span> <span class="pre">denominator</span> <span class="pre">=</span>
|
||
<span class="pre">x.as_integer_ratio()</span></code> and have it work across multiple numeric types.
|
||
(Contributed by Lisa Roach in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33073">bpo-33073</a> and Raymond Hettinger in
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37819">bpo-37819</a>.)</p></li>
|
||
<li><p>Constructors of <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>, <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> and <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a> will now
|
||
use the <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> special method, if available and the
|
||
corresponding method <a class="reference internal" href="../reference/datamodel.html#object.__int__" title="object.__int__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__int__()</span></code></a>, <a class="reference internal" href="../reference/datamodel.html#object.__float__" title="object.__float__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__float__()</span></code></a>
|
||
or <a class="reference internal" href="../reference/datamodel.html#object.__complex__" title="object.__complex__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__complex__()</span></code></a> is not available.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=20092">bpo-20092</a>.)</p></li>
|
||
<li><p>Added support of <code class="samp docutils literal notranslate"><span class="pre">\N{</span><em><span class="pre">name</span></em><span class="pre">}</span></code> escapes in <a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">regular</span> <span class="pre">expressions</span></code></a>:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">notice</span> <span class="o">=</span> <span class="s1">'Copyright © 2019'</span>
|
||
<span class="gp">>>> </span><span class="n">copyright_year_pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s1">'\N{copyright sign}\s*(\d</span><span class="si">{4}</span><span class="s1">)'</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="nb">int</span><span class="p">(</span><span class="n">copyright_year_pattern</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">notice</span><span class="p">)</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
|
||
<span class="go">2019</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Jonathan Eunice and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=30688">bpo-30688</a>.)</p>
|
||
</li>
|
||
<li><p>Dict and dictviews are now iterable in reversed insertion order using
|
||
<a class="reference internal" href="../library/functions.html#reversed" title="reversed"><code class="xref py py-func docutils literal notranslate"><span class="pre">reversed()</span></code></a>. (Contributed by Rémi Lapeyre in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33462">bpo-33462</a>.)</p></li>
|
||
<li><p>The syntax allowed for keyword names in function calls was further
|
||
restricted. In particular, <code class="docutils literal notranslate"><span class="pre">f((keyword)=arg)</span></code> is no longer allowed. It was
|
||
never intended to permit more than a bare name on the left-hand side of a
|
||
keyword argument assignment term.
|
||
(Contributed by Benjamin Peterson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34641">bpo-34641</a>.)</p></li>
|
||
<li><p>Generalized iterable unpacking in <a class="reference internal" href="../reference/simple_stmts.html#yield"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">yield</span></code></a> and
|
||
<a class="reference internal" href="../reference/simple_stmts.html#return"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">return</span></code></a> statements no longer requires enclosing parentheses.
|
||
This brings the <em>yield</em> and <em>return</em> syntax into better agreement with
|
||
normal assignment syntax:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span><span class="w"> </span><span class="nf">parse</span><span class="p">(</span><span class="n">family</span><span class="p">):</span>
|
||
<span class="go"> lastname, *members = family.split()</span>
|
||
<span class="go"> return lastname.upper(), *members</span>
|
||
|
||
<span class="gp">>>> </span><span class="n">parse</span><span class="p">(</span><span class="s1">'simpsons homer marge bart lisa maggie'</span><span class="p">)</span>
|
||
<span class="go">('SIMPSONS', 'homer', 'marge', 'bart', 'lisa', 'maggie')</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by David Cuthbert and Jordan Chapman in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32117">bpo-32117</a>.)</p>
|
||
</li>
|
||
<li><p>When a comma is missed in code such as <code class="docutils literal notranslate"><span class="pre">[(10,</span> <span class="pre">20)</span> <span class="pre">(30,</span> <span class="pre">40)]</span></code>, the
|
||
compiler displays a <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a> with a helpful suggestion.
|
||
This improves on just having 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> indicating that the
|
||
first tuple was not callable. (Contributed by Serhiy Storchaka in
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=15248">bpo-15248</a>.)</p></li>
|
||
<li><p>Arithmetic operations between subclasses 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> or
|
||
<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> and <a class="reference internal" href="../library/datetime.html#datetime.timedelta" title="datetime.timedelta"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.timedelta</span></code></a> objects now return
|
||
an instance of the subclass, rather than the base class. This also affects
|
||
the return type of operations whose implementation (directly or indirectly)
|
||
uses <a class="reference internal" href="../library/datetime.html#datetime.timedelta" title="datetime.timedelta"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.timedelta</span></code></a> arithmetic, such as
|
||
<a class="reference internal" href="../library/datetime.html#datetime.datetime.astimezone" title="datetime.datetime.astimezone"><code class="xref py py-meth docutils literal notranslate"><span class="pre">astimezone()</span></code></a>.
|
||
(Contributed by Paul Ganssle in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32417">bpo-32417</a>.)</p></li>
|
||
<li><p>When the Python interpreter is interrupted by Ctrl-C (SIGINT) and the
|
||
resulting <a class="reference internal" href="../library/exceptions.html#KeyboardInterrupt" title="KeyboardInterrupt"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyboardInterrupt</span></code></a> exception is not caught, the Python process
|
||
now exits via a SIGINT signal or with the correct exit code such that the
|
||
calling process can detect that it died due to a Ctrl-C. Shells on POSIX
|
||
and Windows use this to properly terminate scripts in interactive sessions.
|
||
(Contributed by Google via Gregory P. Smith in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=1054041">bpo-1054041</a>.)</p></li>
|
||
<li><p>Some advanced styles of programming require updating the
|
||
<a class="reference internal" href="../library/types.html#types.CodeType" title="types.CodeType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.CodeType</span></code></a> object for an existing function. Since code
|
||
objects are immutable, a new code object needs to be created, one
|
||
that is modeled on the existing code object. With 19 parameters,
|
||
this was somewhat tedious. Now, the new <code class="docutils literal notranslate"><span class="pre">replace()</span></code> method makes
|
||
it possible to create a clone with a few altered parameters.</p>
|
||
<p>Here’s an example that alters the <a class="reference internal" href="../library/statistics.html#statistics.mean" title="statistics.mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.mean()</span></code></a> function to
|
||
prevent the <em>data</em> parameter from being used as a keyword argument:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span><span class="w"> </span><span class="nn">statistics</span><span class="w"> </span><span class="kn">import</span> <span class="n">mean</span>
|
||
<span class="gp">>>> </span><span class="n">mean</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">90</span><span class="p">])</span>
|
||
<span class="go">40</span>
|
||
<span class="gp">>>> </span><span class="n">mean</span><span class="o">.</span><span class="vm">__code__</span> <span class="o">=</span> <span class="n">mean</span><span class="o">.</span><span class="vm">__code__</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">co_posonlyargcount</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="n">mean</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">90</span><span class="p">])</span>
|
||
<span class="gt">Traceback (most recent call last):</span>
|
||
<span class="w"> </span><span class="c">...</span>
|
||
<span class="gr">TypeError</span>: <span class="n">mean() got some positional-only arguments passed as keyword arguments: 'data'</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37032">bpo-37032</a>.)</p>
|
||
</li>
|
||
<li><p>For integers, the three-argument form of the <a class="reference internal" href="../library/functions.html#pow" title="pow"><code class="xref py py-func docutils literal notranslate"><span class="pre">pow()</span></code></a> function now
|
||
permits the exponent to be negative in the case where the base is
|
||
relatively prime to the modulus. It then computes a modular inverse to
|
||
the base when the exponent is <code class="docutils literal notranslate"><span class="pre">-1</span></code>, and a suitable power of that
|
||
inverse for other negative exponents. For example, to compute the
|
||
<a class="reference external" href="https://en.wikipedia.org/wiki/Modular_multiplicative_inverse">modular multiplicative inverse</a> of 38
|
||
modulo 137, write:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">pow</span><span class="p">(</span><span class="mi">38</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">137</span><span class="p">)</span>
|
||
<span class="go">119</span>
|
||
<span class="gp">>>> </span><span class="mi">119</span> <span class="o">*</span> <span class="mi">38</span> <span class="o">%</span> <span class="mi">137</span>
|
||
<span class="go">1</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Modular inverses arise in the solution of <a class="reference external" href="https://en.wikipedia.org/wiki/Diophantine_equation">linear Diophantine
|
||
equations</a>.
|
||
For example, to find integer solutions for <code class="docutils literal notranslate"><span class="pre">4258𝑥</span> <span class="pre">+</span> <span class="pre">147𝑦</span> <span class="pre">=</span> <span class="pre">369</span></code>,
|
||
first rewrite as <code class="docutils literal notranslate"><span class="pre">4258𝑥</span> <span class="pre">≡</span> <span class="pre">369</span> <span class="pre">(mod</span> <span class="pre">147)</span></code> then solve:</p>
|
||
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="mi">369</span> <span class="o">*</span> <span class="nb">pow</span><span class="p">(</span><span class="mi">4258</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">147</span><span class="p">)</span> <span class="o">%</span> <span class="mi">147</span>
|
||
<span class="gp">>>> </span><span class="n">y</span> <span class="o">=</span> <span class="p">(</span><span class="mi">4258</span> <span class="o">*</span> <span class="n">x</span> <span class="o">-</span> <span class="mi">369</span><span class="p">)</span> <span class="o">//</span> <span class="o">-</span><span class="mi">147</span>
|
||
<span class="gp">>>> </span><span class="mi">4258</span> <span class="o">*</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">147</span> <span class="o">*</span> <span class="n">y</span>
|
||
<span class="go">369</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36027">bpo-36027</a>.)</p>
|
||
</li>
|
||
<li><p>Dict comprehensions have been synced-up with dict literals so that the
|
||
key is computed first and the value second:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># Dict comprehension</span>
|
||
<span class="gp">>>> </span><span class="n">cast</span> <span class="o">=</span> <span class="p">{</span><span class="nb">input</span><span class="p">(</span><span class="s1">'role? '</span><span class="p">):</span> <span class="nb">input</span><span class="p">(</span><span class="s1">'actor? '</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">)}</span>
|
||
<span class="go">role? King Arthur</span>
|
||
<span class="go">actor? Chapman</span>
|
||
<span class="go">role? Black Knight</span>
|
||
<span class="go">actor? Cleese</span>
|
||
|
||
<span class="gp">>>> </span><span class="c1"># Dict literal</span>
|
||
<span class="gp">>>> </span><span class="n">cast</span> <span class="o">=</span> <span class="p">{</span><span class="nb">input</span><span class="p">(</span><span class="s1">'role? '</span><span class="p">):</span> <span class="nb">input</span><span class="p">(</span><span class="s1">'actor? '</span><span class="p">)}</span>
|
||
<span class="go">role? Sir Robin</span>
|
||
<span class="go">actor? Eric Idle</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The guaranteed execution order is helpful with assignment expressions
|
||
because variables assigned in the key expression will be available in
|
||
the value expression:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">names</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'Martin von Löwis'</span><span class="p">,</span> <span class="s1">'Łukasz Langa'</span><span class="p">,</span> <span class="s1">'Walter Dörwald'</span><span class="p">]</span>
|
||
<span class="gp">>>> </span><span class="p">{(</span><span class="n">n</span> <span class="o">:=</span> <span class="n">normalize</span><span class="p">(</span><span class="s1">'NFC'</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span><span class="o">.</span><span class="n">casefold</span><span class="p">()</span> <span class="p">:</span> <span class="n">n</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="go">{'martin von löwis': 'Martin von Löwis',</span>
|
||
<span class="go"> 'łukasz langa': 'Łukasz Langa',</span>
|
||
<span class="go"> 'walter dörwald': 'Walter Dörwald'}</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Jörn Heissler in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35224">bpo-35224</a>.)</p>
|
||
</li>
|
||
<li><p>The <a class="reference internal" href="../library/pickle.html#object.__reduce__" title="object.__reduce__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__reduce__()</span></code></a> method can now return a tuple from two to
|
||
six elements long. Formerly, five was the limit. The new, optional sixth
|
||
element is a callable with a <code class="docutils literal notranslate"><span class="pre">(obj,</span> <span class="pre">state)</span></code> signature. This allows the
|
||
direct control over the state-updating behavior of a specific object. If
|
||
not <em>None</em>, this callable will have priority over the object’s
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">__setstate__()</span></code> method.
|
||
(Contributed by Pierre Glaser and Olivier Grisel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35900">bpo-35900</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="new-modules">
|
||
<h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading">¶</a></h2>
|
||
<ul>
|
||
<li><p>The new <a class="reference internal" href="../library/importlib.metadata.html#module-importlib.metadata" title="importlib.metadata: Accessing package metadata"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code></a> module provides (provisional) support for
|
||
reading metadata from third-party packages. For example, it can extract an
|
||
installed package’s version number, list of entry points, and more:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="c1"># Note following example requires that the popular "requests"</span>
|
||
<span class="gp">>>> </span><span class="c1"># package has been installed.</span>
|
||
<span class="gp">>>></span>
|
||
<span class="gp">>>> </span><span class="kn">from</span><span class="w"> </span><span class="nn">importlib.metadata</span><span class="w"> </span><span class="kn">import</span> <span class="n">version</span><span class="p">,</span> <span class="n">requires</span><span class="p">,</span> <span class="n">files</span>
|
||
<span class="gp">>>> </span><span class="n">version</span><span class="p">(</span><span class="s1">'requests'</span><span class="p">)</span>
|
||
<span class="go">'2.22.0'</span>
|
||
<span class="gp">>>> </span><span class="nb">list</span><span class="p">(</span><span class="n">requires</span><span class="p">(</span><span class="s1">'requests'</span><span class="p">))</span>
|
||
<span class="go">['chardet (<3.1.0,>=3.0.2)']</span>
|
||
<span class="gp">>>> </span><span class="nb">list</span><span class="p">(</span><span class="n">files</span><span class="p">(</span><span class="s1">'requests'</span><span class="p">))[:</span><span class="mi">5</span><span class="p">]</span>
|
||
<span class="go">[PackagePath('requests-2.22.0.dist-info/INSTALLER'),</span>
|
||
<span class="go"> PackagePath('requests-2.22.0.dist-info/LICENSE'),</span>
|
||
<span class="go"> PackagePath('requests-2.22.0.dist-info/METADATA'),</span>
|
||
<span class="go"> PackagePath('requests-2.22.0.dist-info/RECORD'),</span>
|
||
<span class="go"> PackagePath('requests-2.22.0.dist-info/WHEEL')]</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Barry Warsaw and Jason R. Coombs in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34632">bpo-34632</a>.)</p>
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
<section id="improved-modules">
|
||
<h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading">¶</a></h2>
|
||
<section id="ast">
|
||
<h3>ast<a class="headerlink" href="#ast" title="Link to this heading">¶</a></h3>
|
||
<p>AST nodes now have <code class="docutils literal notranslate"><span class="pre">end_lineno</span></code> and <code class="docutils literal notranslate"><span class="pre">end_col_offset</span></code> attributes,
|
||
which give the precise location of the end of the node. (This only
|
||
applies to nodes that have <code class="docutils literal notranslate"><span class="pre">lineno</span></code> and <code class="docutils literal notranslate"><span class="pre">col_offset</span></code> attributes.)</p>
|
||
<p>New function <a class="reference internal" href="../library/ast.html#ast.get_source_segment" title="ast.get_source_segment"><code class="xref py py-func docutils literal notranslate"><span class="pre">ast.get_source_segment()</span></code></a> returns the source code
|
||
for a specific AST node.</p>
|
||
<p>(Contributed by Ivan Levkivskyi in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33416">bpo-33416</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/ast.html#ast.parse" title="ast.parse"><code class="xref py py-func docutils literal notranslate"><span class="pre">ast.parse()</span></code></a> function has some new flags:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">type_comments=True</span></code> causes it to return the text of <span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> and
|
||
<span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0526/"><strong>PEP 526</strong></a> type comments associated with certain AST nodes;</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">mode='func_type'</span></code> can be used to parse <span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> “signature type
|
||
comments” (returned for function definition AST nodes);</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">feature_version=(3,</span> <span class="pre">N)</span></code> allows specifying an earlier Python 3
|
||
version. For example, <code class="docutils literal notranslate"><span class="pre">feature_version=(3,</span> <span class="pre">4)</span></code> will treat
|
||
<a class="reference internal" href="../reference/compound_stmts.html#async"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span></code></a> and <a class="reference internal" href="../reference/expressions.html#await"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">await</span></code></a> as non-reserved words.</p></li>
|
||
</ul>
|
||
<p>(Contributed by Guido van Rossum in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35766">bpo-35766</a>.)</p>
|
||
</section>
|
||
<section id="asyncio">
|
||
<h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading">¶</a></h3>
|
||
<p><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 graduated from the provisional to stable API. This
|
||
function can be used to execute a <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> and return the result while
|
||
automatically managing the event loop. For example:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">asyncio</span>
|
||
|
||
<span class="k">async</span> <span class="k">def</span><span class="w"> </span><span class="nf">main</span><span class="p">():</span>
|
||
<span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||
<span class="k">return</span> <span class="mi">42</span>
|
||
|
||
<span class="n">asyncio</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">main</span><span class="p">())</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>This is <em>roughly</em> equivalent to:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">asyncio</span>
|
||
|
||
<span class="k">async</span> <span class="k">def</span><span class="w"> </span><span class="nf">main</span><span class="p">():</span>
|
||
<span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||
<span class="k">return</span> <span class="mi">42</span>
|
||
|
||
<span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">new_event_loop</span><span class="p">()</span>
|
||
<span class="n">asyncio</span><span class="o">.</span><span class="n">set_event_loop</span><span class="p">(</span><span class="n">loop</span><span class="p">)</span>
|
||
<span class="k">try</span><span class="p">:</span>
|
||
<span class="n">loop</span><span class="o">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">main</span><span class="p">())</span>
|
||
<span class="k">finally</span><span class="p">:</span>
|
||
<span class="n">asyncio</span><span class="o">.</span><span class="n">set_event_loop</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
|
||
<span class="n">loop</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The actual implementation is significantly more complex. Thus,
|
||
<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> should be the preferred way of running asyncio programs.</p>
|
||
<p>(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32314">bpo-32314</a>.)</p>
|
||
<p>Running <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">asyncio</span></code> launches a natively async REPL. This allows rapid
|
||
experimentation with code that has a top-level <a class="reference internal" href="../reference/expressions.html#await"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">await</span></code></a>. There is no
|
||
longer a need to directly call <code class="docutils literal notranslate"><span class="pre">asyncio.run()</span></code> which would spawn a new event
|
||
loop on every invocation:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>$ python -m asyncio
|
||
asyncio REPL 3.8.0
|
||
Use "await" directly instead of "asyncio.run()".
|
||
Type "help", "copyright", "credits" or "license" for more information.
|
||
>>> import asyncio
|
||
>>> await asyncio.sleep(10, result='hello')
|
||
hello
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37028">bpo-37028</a>.)</p>
|
||
<p>The exception <a class="reference internal" href="../library/asyncio-exceptions.html#asyncio.CancelledError" title="asyncio.CancelledError"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.CancelledError</span></code></a> now inherits from
|
||
<a class="reference internal" href="../library/exceptions.html#BaseException" title="BaseException"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseException</span></code></a> rather than <a class="reference internal" href="../library/exceptions.html#Exception" title="Exception"><code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></a> and no longer inherits
|
||
from <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.CancelledError" title="concurrent.futures.CancelledError"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.CancelledError</span></code></a>.
|
||
(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32528">bpo-32528</a>.)</p>
|
||
<p>On Windows, the default event loop is now <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.ProactorEventLoop" title="asyncio.ProactorEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProactorEventLoop</span></code></a>.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34687">bpo-34687</a>.)</p>
|
||
<p><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.ProactorEventLoop" title="asyncio.ProactorEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProactorEventLoop</span></code></a> now also supports UDP.
|
||
(Contributed by Adam Meily and Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=29883">bpo-29883</a>.)</p>
|
||
<p><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.ProactorEventLoop" title="asyncio.ProactorEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProactorEventLoop</span></code></a> can now be interrupted by
|
||
<a class="reference internal" href="../library/exceptions.html#KeyboardInterrupt" title="KeyboardInterrupt"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyboardInterrupt</span></code></a> (“CTRL+C”).
|
||
(Contributed by Vladimir Matveev in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23057">bpo-23057</a>.)</p>
|
||
<p>Added <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.get_coro" title="asyncio.Task.get_coro"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.Task.get_coro()</span></code></a> for getting the wrapped coroutine
|
||
within an <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a>.
|
||
(Contributed by Alex Grönholm in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36999">bpo-36999</a>.)</p>
|
||
<p>Asyncio tasks can now be named, either by passing the <code class="docutils literal notranslate"><span class="pre">name</span></code> keyword
|
||
argument to <a class="reference internal" href="../library/asyncio-task.html#asyncio.create_task" title="asyncio.create_task"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.create_task()</span></code></a> or
|
||
the <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_task" title="asyncio.loop.create_task"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_task()</span></code></a> event loop method, or by
|
||
calling the <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.set_name" title="asyncio.Task.set_name"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_name()</span></code></a> method on the task object. The
|
||
task name is visible in the <code class="docutils literal notranslate"><span class="pre">repr()</span></code> output of <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a> and
|
||
can also be retrieved using the <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.get_name" title="asyncio.Task.get_name"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_name()</span></code></a> method.
|
||
(Contributed by Alex Grönholm in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34270">bpo-34270</a>.)</p>
|
||
<p>Added support for
|
||
<a class="reference external" href="https://en.wikipedia.org/wiki/Happy_Eyeballs">Happy Eyeballs</a> to
|
||
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_connection" title="asyncio.loop.create_connection"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.loop.create_connection()</span></code></a>. To specify the behavior, two new
|
||
parameters have been added: <em>happy_eyeballs_delay</em> and <em>interleave</em>. The Happy
|
||
Eyeballs algorithm improves responsiveness in applications that support IPv4
|
||
and IPv6 by attempting to simultaneously connect using both.
|
||
(Contributed by twisteroid ambassador in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33530">bpo-33530</a>.)</p>
|
||
</section>
|
||
<section id="builtins">
|
||
<h3>builtins<a class="headerlink" href="#builtins" title="Link to this heading">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> built-in has been improved to accept the
|
||
<code class="docutils literal notranslate"><span class="pre">ast.PyCF_ALLOW_TOP_LEVEL_AWAIT</span></code> flag. With this new flag passed,
|
||
<a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> will allow top-level <code class="docutils literal notranslate"><span class="pre">await</span></code>, <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">for</span></code> and <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">with</span></code>
|
||
constructs that are usually considered invalid syntax. Asynchronous code object
|
||
marked with the <code class="docutils literal notranslate"><span class="pre">CO_COROUTINE</span></code> flag may then be returned.
|
||
(Contributed by Matthias Bussonnier in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34616">bpo-34616</a>)</p>
|
||
</section>
|
||
<section id="collections">
|
||
<h3>collections<a class="headerlink" href="#collections" title="Link to this heading">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/collections.html#collections.somenamedtuple._asdict" title="collections.somenamedtuple._asdict"><code class="xref py py-meth docutils literal notranslate"><span class="pre">_asdict()</span></code></a> method for
|
||
<a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">collections.namedtuple()</span></code></a> now returns 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> instead of a
|
||
<a class="reference internal" href="../library/collections.html#collections.OrderedDict" title="collections.OrderedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.OrderedDict</span></code></a>. This works because regular dicts have
|
||
guaranteed ordering since Python 3.7. If the extra features of
|
||
<code class="xref py py-class docutils literal notranslate"><span class="pre">OrderedDict</span></code> are required, the suggested remediation is to cast the
|
||
result to the desired type: <code class="docutils literal notranslate"><span class="pre">OrderedDict(nt._asdict())</span></code>.
|
||
(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35864">bpo-35864</a>.)</p>
|
||
</section>
|
||
<section id="cprofile">
|
||
<h3>cProfile<a class="headerlink" href="#cprofile" title="Link to this heading">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/profile.html#profile.Profile" title="profile.Profile"><code class="xref py py-class docutils literal notranslate"><span class="pre">cProfile.Profile</span></code></a> class can now be used as a context manager.
|
||
Profile a block of code by running:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">cProfile</span>
|
||
|
||
<span class="k">with</span> <span class="n">cProfile</span><span class="o">.</span><span class="n">Profile</span><span class="p">()</span> <span class="k">as</span> <span class="n">profiler</span><span class="p">:</span>
|
||
<span class="c1"># code to be profiled</span>
|
||
<span class="o">...</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Scott Sanderson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=29235">bpo-29235</a>.)</p>
|
||
</section>
|
||
<section id="csv">
|
||
<h3>csv<a class="headerlink" href="#csv" title="Link to this heading">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/csv.html#csv.DictReader" title="csv.DictReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">csv.DictReader</span></code></a> now returns instances of <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> instead of
|
||
a <a class="reference internal" href="../library/collections.html#collections.OrderedDict" title="collections.OrderedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.OrderedDict</span></code></a>. The tool is now faster and uses less
|
||
memory while still preserving the field order.
|
||
(Contributed by Michael Selik in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34003">bpo-34003</a>.)</p>
|
||
</section>
|
||
<section id="curses">
|
||
<h3>curses<a class="headerlink" href="#curses" title="Link to this heading">¶</a></h3>
|
||
<p>Added a new variable holding structured version information for the
|
||
underlying ncurses library: <a class="reference internal" href="../library/curses.html#curses.ncurses_version" title="curses.ncurses_version"><code class="xref py py-data docutils literal notranslate"><span class="pre">ncurses_version</span></code></a>.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=31680">bpo-31680</a>.)</p>
|
||
</section>
|
||
<section id="ctypes">
|
||
<h3>ctypes<a class="headerlink" href="#ctypes" title="Link to this heading">¶</a></h3>
|
||
<p>On Windows, <a class="reference internal" href="../library/ctypes.html#ctypes.CDLL" title="ctypes.CDLL"><code class="xref py py-class docutils literal notranslate"><span class="pre">CDLL</span></code></a> and subclasses now accept a <em>winmode</em> parameter
|
||
to specify flags for the underlying <code class="docutils literal notranslate"><span class="pre">LoadLibraryEx</span></code> call. The default flags are
|
||
set to only load DLL dependencies from trusted locations, including the path
|
||
where the DLL is stored (if a full or partial path is used to load the initial
|
||
DLL) and paths added by <a class="reference internal" href="../library/os.html#os.add_dll_directory" title="os.add_dll_directory"><code class="xref py py-func docutils literal notranslate"><span class="pre">add_dll_directory()</span></code></a>.
|
||
(Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36085">bpo-36085</a>.)</p>
|
||
</section>
|
||
<section id="datetime">
|
||
<h3>datetime<a class="headerlink" href="#datetime" title="Link to this heading">¶</a></h3>
|
||
<p>Added new alternate constructors <a class="reference internal" href="../library/datetime.html#datetime.date.fromisocalendar" title="datetime.date.fromisocalendar"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.date.fromisocalendar()</span></code></a> and
|
||
<a class="reference internal" href="../library/datetime.html#datetime.datetime.fromisocalendar" title="datetime.datetime.fromisocalendar"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.fromisocalendar()</span></code></a>, which construct <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">date</span></code></a> and
|
||
<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</span></code></a> objects respectively from ISO year, week number, and weekday;
|
||
these are the inverse of each class’s <code class="docutils literal notranslate"><span class="pre">isocalendar</span></code> method.
|
||
(Contributed by Paul Ganssle in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36004">bpo-36004</a>.)</p>
|
||
</section>
|
||
<section id="functools">
|
||
<h3>functools<a class="headerlink" href="#functools" title="Link to this heading">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/functools.html#functools.lru_cache" title="functools.lru_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.lru_cache()</span></code></a> can now be used as a straight decorator rather
|
||
than as a function returning a decorator. So both of these are now supported:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nd">@lru_cache</span>
|
||
<span class="k">def</span><span class="w"> </span><span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
|
||
<span class="o">...</span>
|
||
|
||
<span class="nd">@lru_cache</span><span class="p">(</span><span class="n">maxsize</span><span class="o">=</span><span class="mi">256</span><span class="p">)</span>
|
||
<span class="k">def</span><span class="w"> </span><span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
|
||
<span class="o">...</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36772">bpo-36772</a>.)</p>
|
||
<p>Added a new <a class="reference internal" href="../library/functools.html#functools.cached_property" title="functools.cached_property"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.cached_property()</span></code></a> decorator, for computed properties
|
||
cached for the life of the instance.</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">functools</span>
|
||
<span class="kn">import</span><span class="w"> </span><span class="nn">statistics</span>
|
||
|
||
<span class="k">class</span><span class="w"> </span><span class="nc">Dataset</span><span class="p">:</span>
|
||
<span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sequence_of_numbers</span><span class="p">):</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">sequence_of_numbers</span>
|
||
|
||
<span class="nd">@functools</span><span class="o">.</span><span class="n">cached_property</span>
|
||
<span class="k">def</span><span class="w"> </span><span class="nf">variance</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="k">return</span> <span class="n">statistics</span><span class="o">.</span><span class="n">variance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Carl Meyer in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=21145">bpo-21145</a>)</p>
|
||
<p>Added a new <a class="reference internal" href="../library/functools.html#functools.singledispatchmethod" title="functools.singledispatchmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.singledispatchmethod()</span></code></a> decorator that converts
|
||
methods into <a class="reference internal" href="../glossary.html#term-generic-function"><span class="xref std std-term">generic functions</span></a> using
|
||
<a class="reference internal" href="../glossary.html#term-single-dispatch"><span class="xref std std-term">single dispatch</span></a>:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">functools</span><span class="w"> </span><span class="kn">import</span> <span class="n">singledispatchmethod</span>
|
||
<span class="kn">from</span><span class="w"> </span><span class="nn">contextlib</span><span class="w"> </span><span class="kn">import</span> <span class="n">suppress</span>
|
||
|
||
<span class="k">class</span><span class="w"> </span><span class="nc">TaskManager</span><span class="p">:</span>
|
||
|
||
<span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tasks</span><span class="p">):</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">tasks</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">tasks</span><span class="p">)</span>
|
||
|
||
<span class="nd">@singledispatchmethod</span>
|
||
<span class="k">def</span><span class="w"> </span><span class="nf">discard</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
|
||
<span class="k">with</span> <span class="n">suppress</span><span class="p">(</span><span class="ne">ValueError</span><span class="p">):</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">tasks</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
|
||
|
||
<span class="nd">@discard</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>
|
||
<span class="k">def</span><span class="w"> </span><span class="nf">_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tasks</span><span class="p">):</span>
|
||
<span class="n">targets</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">tasks</span><span class="p">)</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">tasks</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tasks</span> <span class="k">if</span> <span class="n">x</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">targets</span><span class="p">]</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Ethan Smith in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32380">bpo-32380</a>)</p>
|
||
</section>
|
||
<section id="gc">
|
||
<h3>gc<a class="headerlink" href="#gc" title="Link to this heading">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/gc.html#gc.get_objects" title="gc.get_objects"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_objects()</span></code></a> can now receive an optional <em>generation</em> parameter
|
||
indicating a generation to get objects from.
|
||
(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36016">bpo-36016</a>.)</p>
|
||
</section>
|
||
<section id="gettext">
|
||
<h3>gettext<a class="headerlink" href="#gettext" title="Link to this heading">¶</a></h3>
|
||
<p>Added <a class="reference internal" href="../library/gettext.html#gettext.pgettext" title="gettext.pgettext"><code class="xref py py-func docutils literal notranslate"><span class="pre">pgettext()</span></code></a> and its variants.
|
||
(Contributed by Franz Glasner, Éric Araujo, and Cheryl Sabella in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=2504">bpo-2504</a>.)</p>
|
||
</section>
|
||
<section id="gzip">
|
||
<h3>gzip<a class="headerlink" href="#gzip" title="Link to this heading">¶</a></h3>
|
||
<p>Added the <em>mtime</em> parameter to <a class="reference internal" href="../library/gzip.html#gzip.compress" title="gzip.compress"><code class="xref py py-func docutils literal notranslate"><span class="pre">gzip.compress()</span></code></a> for reproducible output.
|
||
(Contributed by Guo Ci Teo in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34898">bpo-34898</a>.)</p>
|
||
<p>A <a class="reference internal" href="../library/gzip.html#gzip.BadGzipFile" title="gzip.BadGzipFile"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BadGzipFile</span></code></a> exception is now raised instead of <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>
|
||
for certain types of invalid or corrupt gzip files.
|
||
(Contributed by Filip Gruszczyński, Michele Orrù, and Zackery Spytz in
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=6584">bpo-6584</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>Output over N lines (50 by default) is squeezed down to a button.
|
||
N can be changed in the PyShell section of the General page of the
|
||
Settings dialog. Fewer, but possibly extra long, lines can be squeezed by
|
||
right clicking on the output. Squeezed output can be expanded in place
|
||
by double-clicking the button or into the clipboard or a separate window
|
||
by right-clicking the button. (Contributed by Tal Einat in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=1529353">bpo-1529353</a>.)</p>
|
||
<p>Add “Run Customized” to the Run menu to run a module with customized
|
||
settings. Any command line arguments entered are added to sys.argv.
|
||
They also re-appear in the box for the next customized run. One can also
|
||
suppress the normal Shell main module restart. (Contributed by Cheryl
|
||
Sabella, Terry Jan Reedy, and others in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=5680">bpo-5680</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37627">bpo-37627</a>.)</p>
|
||
<p>Added optional line numbers for IDLE editor windows. Windows
|
||
open without line numbers unless set otherwise in the General
|
||
tab of the configuration dialog. Line numbers for an existing
|
||
window are shown and hidden in the Options menu.
|
||
(Contributed by Tal Einat and Saimadhav Heblikar in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=17535">bpo-17535</a>.)</p>
|
||
<p>OS native encoding is now used for converting between Python strings and Tcl
|
||
objects. This allows IDLE to work with emoji and other non-BMP characters.
|
||
These characters can be displayed or copied and pasted to or from the
|
||
clipboard. Converting strings from Tcl to Python and back now never fails.
|
||
(Many people worked on this for eight years but the problem was finally
|
||
solved by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=13153">bpo-13153</a>.)</p>
|
||
<p>New in 3.8.1:</p>
|
||
<p>Add option to toggle cursor blink off. (Contributed by Zackery Spytz
|
||
in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&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?@action=redirect&bpo=38944">bpo-38944</a>.)</p>
|
||
<p>The changes above have been backported to 3.7 maintenance releases.</p>
|
||
<p>Add keywords to module name completion list. (Contributed by Terry J.
|
||
Reedy in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37765">bpo-37765</a>.)</p>
|
||
</section>
|
||
<section id="inspect">
|
||
<h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/inspect.html#inspect.getdoc" title="inspect.getdoc"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getdoc()</span></code></a> function can now find docstrings for <code class="docutils literal notranslate"><span class="pre">__slots__</span></code>
|
||
if that attribute is 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> where the values are docstrings.
|
||
This provides documentation options similar to what we already have
|
||
for <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-func docutils literal notranslate"><span class="pre">property()</span></code></a>, <a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">classmethod()</span></code></a>, and <a class="reference internal" href="../library/functions.html#staticmethod" title="staticmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">staticmethod()</span></code></a>:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span><span class="w"> </span><span class="nc">AudioClip</span><span class="p">:</span>
|
||
<span class="vm">__slots__</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'bit_rate'</span><span class="p">:</span> <span class="s1">'expressed in kilohertz to one decimal place'</span><span class="p">,</span>
|
||
<span class="s1">'duration'</span><span class="p">:</span> <span class="s1">'in seconds, rounded up to an integer'</span><span class="p">}</span>
|
||
<span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bit_rate</span><span class="p">,</span> <span class="n">duration</span><span class="p">):</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">bit_rate</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">bit_rate</span> <span class="o">/</span> <span class="mf">1000.0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">duration</span> <span class="o">=</span> <span class="n">ceil</span><span class="p">(</span><span class="n">duration</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36326">bpo-36326</a>.)</p>
|
||
</section>
|
||
<section id="io">
|
||
<h3>io<a class="headerlink" href="#io" title="Link to this heading">¶</a></h3>
|
||
<p>In development mode (<a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> <code class="docutils literal notranslate"><span class="pre">env</span></code>) and in <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug build</span></a>, the
|
||
<a class="reference internal" href="../library/io.html#io.IOBase" title="io.IOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.IOBase</span></code></a> finalizer now logs the exception if the <code class="docutils literal notranslate"><span class="pre">close()</span></code> method
|
||
fails. The exception is ignored silently by default in release build.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=18748">bpo-18748</a>.)</p>
|
||
</section>
|
||
<section id="itertools">
|
||
<h3>itertools<a class="headerlink" href="#itertools" title="Link to this heading">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/itertools.html#itertools.accumulate" title="itertools.accumulate"><code class="xref py py-func docutils literal notranslate"><span class="pre">itertools.accumulate()</span></code></a> function added an option <em>initial</em> keyword
|
||
argument to specify an initial value:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span><span class="w"> </span><span class="nn">itertools</span><span class="w"> </span><span class="kn">import</span> <span class="n">accumulate</span>
|
||
<span class="gp">>>> </span><span class="nb">list</span><span class="p">(</span><span class="n">accumulate</span><span class="p">([</span><span class="mi">10</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">15</span><span class="p">],</span> <span class="n">initial</span><span class="o">=</span><span class="mi">1000</span><span class="p">))</span>
|
||
<span class="go">[1000, 1010, 1015, 1045, 1060]</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Lisa Roach in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34659">bpo-34659</a>.)</p>
|
||
</section>
|
||
<section id="json-tool">
|
||
<h3>json.tool<a class="headerlink" href="#json-tool" title="Link to this heading">¶</a></h3>
|
||
<p>Add option <code class="docutils literal notranslate"><span class="pre">--json-lines</span></code> to parse every input line as a separate JSON object.
|
||
(Contributed by Weipeng Hong in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=31553">bpo-31553</a>.)</p>
|
||
</section>
|
||
<section id="logging">
|
||
<h3>logging<a class="headerlink" href="#logging" title="Link to this heading">¶</a></h3>
|
||
<p>Added a <em>force</em> keyword argument to <a class="reference internal" href="../library/logging.html#logging.basicConfig" title="logging.basicConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">logging.basicConfig()</span></code></a>.
|
||
When set to true, any existing handlers attached
|
||
to the root logger are removed and closed before carrying out the
|
||
configuration specified by the other arguments.</p>
|
||
<p>This solves a long-standing problem. Once a logger or <em>basicConfig()</em> had
|
||
been called, subsequent calls to <em>basicConfig()</em> were silently ignored.
|
||
This made it difficult to update, experiment with, or teach the various
|
||
logging configuration options using the interactive prompt or a Jupyter
|
||
notebook.</p>
|
||
<p>(Suggested by Raymond Hettinger, implemented by Donghee Na, and
|
||
reviewed by Vinay Sajip in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33897">bpo-33897</a>.)</p>
|
||
</section>
|
||
<section id="math">
|
||
<h3>math<a class="headerlink" href="#math" title="Link to this heading">¶</a></h3>
|
||
<p>Added new function <a class="reference internal" href="../library/math.html#math.dist" title="math.dist"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.dist()</span></code></a> for computing Euclidean distance
|
||
between two points. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33089">bpo-33089</a>.)</p>
|
||
<p>Expanded the <a class="reference internal" href="../library/math.html#math.hypot" title="math.hypot"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.hypot()</span></code></a> function to handle multiple dimensions.
|
||
Formerly, it only supported the 2-D case.
|
||
(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33089">bpo-33089</a>.)</p>
|
||
<p>Added new function, <a class="reference internal" href="../library/math.html#math.prod" title="math.prod"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.prod()</span></code></a>, as analogous function to <a class="reference internal" href="../library/functions.html#sum" title="sum"><code class="xref py py-func docutils literal notranslate"><span class="pre">sum()</span></code></a>
|
||
that returns the product of a ‘start’ value (default: 1) times an iterable of
|
||
numbers:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">prior</span> <span class="o">=</span> <span class="mf">0.8</span>
|
||
<span class="gp">>>> </span><span class="n">likelihoods</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.625</span><span class="p">,</span> <span class="mf">0.84</span><span class="p">,</span> <span class="mf">0.30</span><span class="p">]</span>
|
||
<span class="gp">>>> </span><span class="n">math</span><span class="o">.</span><span class="n">prod</span><span class="p">(</span><span class="n">likelihoods</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="n">prior</span><span class="p">)</span>
|
||
<span class="go">0.126</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35606">bpo-35606</a>.)</p>
|
||
<p>Added two new combinatoric functions <a class="reference internal" href="../library/math.html#math.perm" title="math.perm"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.perm()</span></code></a> and <a class="reference internal" href="../library/math.html#math.comb" title="math.comb"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.comb()</span></code></a>:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">math</span><span class="o">.</span><span class="n">perm</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span> <span class="c1"># Permutations of 10 things taken 3 at a time</span>
|
||
<span class="go">720</span>
|
||
<span class="gp">>>> </span><span class="n">math</span><span class="o">.</span><span class="n">comb</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span> <span class="c1"># Combinations of 10 things taken 3 at a time</span>
|
||
<span class="go">120</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Yash Aggarwal, Keller Fuchs, Serhiy Storchaka, and Raymond
|
||
Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37128">bpo-37128</a>, <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37178">bpo-37178</a>, and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35431">bpo-35431</a>.)</p>
|
||
<p>Added a new function <a class="reference internal" href="../library/math.html#math.isqrt" title="math.isqrt"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.isqrt()</span></code></a> for computing accurate integer square
|
||
roots without conversion to floating point. The new function supports
|
||
arbitrarily large integers. It is faster than <code class="docutils literal notranslate"><span class="pre">floor(sqrt(n))</span></code> but slower
|
||
than <a class="reference internal" href="../library/math.html#math.sqrt" title="math.sqrt"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.sqrt()</span></code></a>:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">r</span> <span class="o">=</span> <span class="mi">650320427</span>
|
||
<span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">r</span> <span class="o">**</span> <span class="mi">2</span>
|
||
<span class="gp">>>> </span><span class="n">isqrt</span><span class="p">(</span><span class="n">s</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="c1"># correct</span>
|
||
<span class="go">650320426</span>
|
||
<span class="gp">>>> </span><span class="n">floor</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">s</span> <span class="o">-</span> <span class="mi">1</span><span class="p">))</span> <span class="c1"># incorrect</span>
|
||
<span class="go">650320427</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36887">bpo-36887</a>.)</p>
|
||
<p>The function <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> no longer accepts arguments that are not
|
||
int-like. (Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33083">bpo-33083</a>.)</p>
|
||
</section>
|
||
<section id="mmap">
|
||
<h3>mmap<a class="headerlink" href="#mmap" title="Link to this heading">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/mmap.html#mmap.mmap" title="mmap.mmap"><code class="xref py py-class docutils literal notranslate"><span class="pre">mmap.mmap</span></code></a> class now has an <a class="reference internal" href="../library/mmap.html#mmap.mmap.madvise" title="mmap.mmap.madvise"><code class="xref py py-meth docutils literal notranslate"><span class="pre">madvise()</span></code></a> method to
|
||
access the <code class="docutils literal notranslate"><span class="pre">madvise()</span></code> system call.
|
||
(Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32941">bpo-32941</a>.)</p>
|
||
</section>
|
||
<section id="multiprocessing">
|
||
<h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Link to this heading">¶</a></h3>
|
||
<p>Added new <a class="reference internal" href="../library/multiprocessing.shared_memory.html#module-multiprocessing.shared_memory" title="multiprocessing.shared_memory: Provides shared memory for direct access across processes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing.shared_memory</span></code></a> module.
|
||
(Contributed by Davin Potts in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35813">bpo-35813</a>.)</p>
|
||
<p>On macOS, the <em>spawn</em> start method is now used by default.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33725">bpo-33725</a>.)</p>
|
||
</section>
|
||
<section id="os">
|
||
<h3>os<a class="headerlink" href="#os" title="Link to this heading">¶</a></h3>
|
||
<p>Added new function <a class="reference internal" href="../library/os.html#os.add_dll_directory" title="os.add_dll_directory"><code class="xref py py-func docutils literal notranslate"><span class="pre">add_dll_directory()</span></code></a> on Windows for providing
|
||
additional search paths for native dependencies when importing extension
|
||
modules or loading DLLs using <a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a>.
|
||
(Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36085">bpo-36085</a>.)</p>
|
||
<p>A new <a class="reference internal" href="../library/os.html#os.memfd_create" title="os.memfd_create"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.memfd_create()</span></code></a> function was added to wrap the
|
||
<code class="docutils literal notranslate"><span class="pre">memfd_create()</span></code> syscall.
|
||
(Contributed by Zackery Spytz and Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26836">bpo-26836</a>.)</p>
|
||
<p>On Windows, much of the manual logic for handling reparse points (including
|
||
symlinks and directory junctions) has been delegated to the operating system.
|
||
Specifically, <a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> will now traverse anything supported by the
|
||
operating system, while <a class="reference internal" href="../library/os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.lstat()</span></code></a> will only open reparse points that
|
||
identify as “name surrogates” while others are opened as for <a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a>.
|
||
In all cases, <code class="xref py py-attr docutils literal notranslate"><span class="pre">stat_result.st_mode</span></code> will only have <code class="docutils literal notranslate"><span class="pre">S_IFLNK</span></code> set for
|
||
symbolic links and not other kinds of reparse points. To identify other kinds
|
||
of reparse point, check the new <code class="xref py py-attr docutils literal notranslate"><span class="pre">stat_result.st_reparse_tag</span></code> attribute.</p>
|
||
<p>On Windows, <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> is now able to read directory junctions. Note
|
||
that <a class="reference internal" href="../library/os.path.html#os.path.islink" title="os.path.islink"><code class="xref py py-func docutils literal notranslate"><span class="pre">islink()</span></code></a> will return <code class="docutils literal notranslate"><span class="pre">False</span></code> for directory junctions,
|
||
and so code that checks <code class="docutils literal notranslate"><span class="pre">islink</span></code> first will continue to treat junctions as
|
||
directories, while code that handles errors from <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> may now
|
||
treat junctions as links.</p>
|
||
<p>(Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37834">bpo-37834</a>.)</p>
|
||
</section>
|
||
<section id="os-path">
|
||
<h3>os.path<a class="headerlink" href="#os-path" title="Link to this heading">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> functions that return a boolean result like
|
||
<a class="reference internal" href="../library/os.path.html#os.path.exists" title="os.path.exists"><code class="xref py py-func docutils literal notranslate"><span class="pre">exists()</span></code></a>, <a class="reference internal" href="../library/os.path.html#os.path.lexists" title="os.path.lexists"><code class="xref py py-func docutils literal notranslate"><span class="pre">lexists()</span></code></a>, <a class="reference internal" href="../library/os.path.html#os.path.isdir" title="os.path.isdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">isdir()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.path.html#os.path.isfile" title="os.path.isfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">isfile()</span></code></a>, <a class="reference internal" href="../library/os.path.html#os.path.islink" title="os.path.islink"><code class="xref py py-func docutils literal notranslate"><span class="pre">islink()</span></code></a>, and <a class="reference internal" href="../library/os.path.html#os.path.ismount" title="os.path.ismount"><code class="xref py py-func docutils literal notranslate"><span class="pre">ismount()</span></code></a>
|
||
now return <code class="docutils literal notranslate"><span class="pre">False</span></code> instead of raising <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> or its subclasses
|
||
<a class="reference internal" href="../library/exceptions.html#UnicodeEncodeError" title="UnicodeEncodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeEncodeError</span></code></a> and <a class="reference internal" href="../library/exceptions.html#UnicodeDecodeError" title="UnicodeDecodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeDecodeError</span></code></a> for paths that contain
|
||
characters or bytes unrepresentable at the OS level.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33721">bpo-33721</a>.)</p>
|
||
<p><a class="reference internal" href="../library/os.path.html#os.path.expanduser" title="os.path.expanduser"><code class="xref py py-func docutils literal notranslate"><span class="pre">expanduser()</span></code></a> on Windows now prefers the <span class="target" id="index-13"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">USERPROFILE</span></code>
|
||
environment variable and does not use <span class="target" id="index-14"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">HOME</span></code>, which is not normally set
|
||
for regular user accounts.
|
||
(Contributed by Anthony Sottile in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36264">bpo-36264</a>.)</p>
|
||
<p><a class="reference internal" href="../library/os.path.html#os.path.isdir" title="os.path.isdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">isdir()</span></code></a> on Windows no longer returns <code class="docutils literal notranslate"><span class="pre">True</span></code> for a link to a
|
||
non-existent directory.</p>
|
||
<p><a class="reference internal" href="../library/os.path.html#os.path.realpath" title="os.path.realpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">realpath()</span></code></a> on Windows now resolves reparse points, including
|
||
symlinks and directory junctions.</p>
|
||
<p>(Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37834">bpo-37834</a>.)</p>
|
||
</section>
|
||
<section id="pathlib">
|
||
<h3>pathlib<a class="headerlink" href="#pathlib" title="Link to this heading">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> methods that return a boolean result like
|
||
<a class="reference internal" href="../library/pathlib.html#pathlib.Path.exists" title="pathlib.Path.exists"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exists()</span></code></a>, <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_dir" title="pathlib.Path.is_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_dir()</span></code></a>,
|
||
<a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_file" title="pathlib.Path.is_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_file()</span></code></a>, <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_mount" title="pathlib.Path.is_mount"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_mount()</span></code></a>,
|
||
<a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_symlink" title="pathlib.Path.is_symlink"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_symlink()</span></code></a>, <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_block_device" title="pathlib.Path.is_block_device"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_block_device()</span></code></a>,
|
||
<a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_char_device" title="pathlib.Path.is_char_device"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_char_device()</span></code></a>, <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_fifo" title="pathlib.Path.is_fifo"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_fifo()</span></code></a>,
|
||
<a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_socket" title="pathlib.Path.is_socket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_socket()</span></code></a> now return <code class="docutils literal notranslate"><span class="pre">False</span></code> instead of raising
|
||
<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> or its subclass <a class="reference internal" href="../library/exceptions.html#UnicodeEncodeError" title="UnicodeEncodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeEncodeError</span></code></a> for paths that
|
||
contain characters unrepresentable at the OS level.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33721">bpo-33721</a>.)</p>
|
||
<p>Added <code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.link_to()</span></code> which creates a hard link pointing
|
||
to a path.
|
||
(Contributed by Joannah Nanjekye in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26978">bpo-26978</a>)
|
||
Note that <code class="docutils literal notranslate"><span class="pre">link_to</span></code> was deprecated in 3.10 and removed in 3.12 in
|
||
favor of a <code class="docutils literal notranslate"><span class="pre">hardlink_to</span></code> method added in 3.10 which matches the
|
||
semantics of the existing <code class="docutils literal notranslate"><span class="pre">symlink_to</span></code> method.</p>
|
||
</section>
|
||
<section id="pickle">
|
||
<h3>pickle<a class="headerlink" href="#pickle" title="Link to this heading">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> extensions subclassing the C-optimized <a class="reference internal" href="../library/pickle.html#pickle.Pickler" title="pickle.Pickler"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pickler</span></code></a>
|
||
can now override the pickling logic of functions and classes by defining the
|
||
special <a class="reference internal" href="../library/pickle.html#pickle.Pickler.reducer_override" title="pickle.Pickler.reducer_override"><code class="xref py py-meth docutils literal notranslate"><span class="pre">reducer_override()</span></code></a> method.
|
||
(Contributed by Pierre Glaser and Olivier Grisel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35900">bpo-35900</a>.)</p>
|
||
</section>
|
||
<section id="plistlib">
|
||
<h3>plistlib<a class="headerlink" href="#plistlib" title="Link to this heading">¶</a></h3>
|
||
<p>Added new <a class="reference internal" href="../library/plistlib.html#plistlib.UID" title="plistlib.UID"><code class="xref py py-class docutils literal notranslate"><span class="pre">plistlib.UID</span></code></a> and enabled support for reading and writing
|
||
NSKeyedArchiver-encoded binary plists.
|
||
(Contributed by Jon Janzen in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26707">bpo-26707</a>.)</p>
|
||
</section>
|
||
<section id="pprint">
|
||
<h3>pprint<a class="headerlink" href="#pprint" title="Link to this heading">¶</a></h3>
|
||
<p>The <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> module added a <em>sort_dicts</em> parameter to several functions.
|
||
By default, those functions continue to sort dictionaries before rendering or
|
||
printing. However, if <em>sort_dicts</em> is set to false, the dictionaries retain
|
||
the order that keys were inserted. This can be useful for comparison to JSON
|
||
inputs during debugging.</p>
|
||
<p>In addition, there is a convenience new function, <a class="reference internal" href="../library/pprint.html#pprint.pp" title="pprint.pp"><code class="xref py py-func docutils literal notranslate"><span class="pre">pprint.pp()</span></code></a> that is
|
||
like <a class="reference internal" href="../library/pprint.html#pprint.pprint" title="pprint.pprint"><code class="xref py py-func docutils literal notranslate"><span class="pre">pprint.pprint()</span></code></a> but with <em>sort_dicts</em> defaulting to <code class="docutils literal notranslate"><span class="pre">False</span></code>:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span><span class="w"> </span><span class="nn">pprint</span><span class="w"> </span><span class="kn">import</span> <span class="n">pprint</span><span class="p">,</span> <span class="n">pp</span>
|
||
<span class="gp">>>> </span><span class="n">d</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">source</span><span class="o">=</span><span class="s1">'input.txt'</span><span class="p">,</span> <span class="n">operation</span><span class="o">=</span><span class="s1">'filter'</span><span class="p">,</span> <span class="n">destination</span><span class="o">=</span><span class="s1">'output.txt'</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="n">pp</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">40</span><span class="p">)</span> <span class="c1"># Original order</span>
|
||
<span class="go">{'source': 'input.txt',</span>
|
||
<span class="go"> 'operation': 'filter',</span>
|
||
<span class="go"> 'destination': 'output.txt'}</span>
|
||
<span class="gp">>>> </span><span class="n">pprint</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">40</span><span class="p">)</span> <span class="c1"># Keys sorted alphabetically</span>
|
||
<span class="go">{'destination': 'output.txt',</span>
|
||
<span class="go"> 'operation': 'filter',</span>
|
||
<span class="go"> 'source': 'input.txt'}</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Rémi Lapeyre in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=30670">bpo-30670</a>.)</p>
|
||
</section>
|
||
<section id="py-compile">
|
||
<h3>py_compile<a class="headerlink" href="#py-compile" title="Link to this heading">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/py_compile.html#py_compile.compile" title="py_compile.compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">py_compile.compile()</span></code></a> now supports silent mode.
|
||
(Contributed by Joannah Nanjekye in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=22640">bpo-22640</a>.)</p>
|
||
</section>
|
||
<section id="shlex">
|
||
<h3>shlex<a class="headerlink" href="#shlex" title="Link to this heading">¶</a></h3>
|
||
<p>The new <a class="reference internal" href="../library/shlex.html#shlex.join" title="shlex.join"><code class="xref py py-func docutils literal notranslate"><span class="pre">shlex.join()</span></code></a> function acts as the inverse of <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>.
|
||
(Contributed by Bo Bayles in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32102">bpo-32102</a>.)</p>
|
||
</section>
|
||
<section id="shutil">
|
||
<h3>shutil<a class="headerlink" href="#shutil" title="Link to this heading">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copytree()</span></code></a> now accepts a new <code class="docutils literal notranslate"><span class="pre">dirs_exist_ok</span></code> keyword argument.
|
||
(Contributed by Josh Bronson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=20849">bpo-20849</a>.)</p>
|
||
<p><a class="reference internal" href="../library/shutil.html#shutil.make_archive" title="shutil.make_archive"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.make_archive()</span></code></a> now defaults to the modern pax (POSIX.1-2001)
|
||
format for new archives to improve portability and standards conformance,
|
||
inherited from the corresponding change to the <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> module.
|
||
(Contributed by C.A.M. Gerlach in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=30661">bpo-30661</a>.)</p>
|
||
<p><a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.rmtree()</span></code></a> on Windows now removes directory junctions without
|
||
recursively removing their contents first.
|
||
(Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37834">bpo-37834</a>.)</p>
|
||
</section>
|
||
<section id="socket">
|
||
<h3>socket<a class="headerlink" href="#socket" title="Link to this heading">¶</a></h3>
|
||
<p>Added <a class="reference internal" href="../library/socket.html#socket.create_server" title="socket.create_server"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_server()</span></code></a> and <a class="reference internal" href="../library/socket.html#socket.has_dualstack_ipv6" title="socket.has_dualstack_ipv6"><code class="xref py py-meth docutils literal notranslate"><span class="pre">has_dualstack_ipv6()</span></code></a>
|
||
convenience functions to automate the necessary tasks usually involved when
|
||
creating a server socket, including accepting both IPv4 and IPv6 connections
|
||
on the same socket. (Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=17561">bpo-17561</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/socket.html#socket.if_nameindex" title="socket.if_nameindex"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.if_nameindex()</span></code></a>, <a class="reference internal" href="../library/socket.html#socket.if_nametoindex" title="socket.if_nametoindex"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.if_nametoindex()</span></code></a>, and
|
||
<a class="reference internal" href="../library/socket.html#socket.if_indextoname" title="socket.if_indextoname"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.if_indextoname()</span></code></a> functions have been implemented on Windows.
|
||
(Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37007">bpo-37007</a>.)</p>
|
||
</section>
|
||
<section id="ssl">
|
||
<h3>ssl<a class="headerlink" href="#ssl" title="Link to this heading">¶</a></h3>
|
||
<p>Added <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.post_handshake_auth" title="ssl.SSLContext.post_handshake_auth"><code class="xref py py-attr docutils literal notranslate"><span class="pre">post_handshake_auth</span></code></a> to enable and
|
||
<a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.verify_client_post_handshake" title="ssl.SSLSocket.verify_client_post_handshake"><code class="xref py py-meth docutils literal notranslate"><span class="pre">verify_client_post_handshake()</span></code></a> to initiate TLS 1.3
|
||
post-handshake authentication.
|
||
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34670">bpo-34670</a>.)</p>
|
||
</section>
|
||
<section id="statistics">
|
||
<h3>statistics<a class="headerlink" href="#statistics" title="Link to this heading">¶</a></h3>
|
||
<p>Added <a class="reference internal" href="../library/statistics.html#statistics.fmean" title="statistics.fmean"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.fmean()</span></code></a> as a faster, floating-point variant of
|
||
<a class="reference internal" href="../library/statistics.html#statistics.mean" title="statistics.mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.mean()</span></code></a>. (Contributed by Raymond Hettinger and
|
||
Steven D’Aprano in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35904">bpo-35904</a>.)</p>
|
||
<p>Added <a class="reference internal" href="../library/statistics.html#statistics.geometric_mean" title="statistics.geometric_mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.geometric_mean()</span></code></a>
|
||
(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27181">bpo-27181</a>.)</p>
|
||
<p>Added <a class="reference internal" href="../library/statistics.html#statistics.multimode" title="statistics.multimode"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.multimode()</span></code></a> that returns a list of the most
|
||
common values. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35892">bpo-35892</a>.)</p>
|
||
<p>Added <a class="reference internal" href="../library/statistics.html#statistics.quantiles" title="statistics.quantiles"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.quantiles()</span></code></a> that divides data or a distribution
|
||
in to equiprobable intervals (e.g. quartiles, deciles, or percentiles).
|
||
(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36546">bpo-36546</a>.)</p>
|
||
<p>Added <a class="reference internal" href="../library/statistics.html#statistics.NormalDist" title="statistics.NormalDist"><code class="xref py py-class docutils literal notranslate"><span class="pre">statistics.NormalDist</span></code></a>, a tool for creating
|
||
and manipulating normal distributions of a random variable.
|
||
(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36018">bpo-36018</a>.)</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">temperature_feb</span> <span class="o">=</span> <span class="n">NormalDist</span><span class="o">.</span><span class="n">from_samples</span><span class="p">([</span><span class="mi">4</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="o">-</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">14</span><span class="p">])</span>
|
||
<span class="gp">>>> </span><span class="n">temperature_feb</span><span class="o">.</span><span class="n">mean</span>
|
||
<span class="go">6.0</span>
|
||
<span class="gp">>>> </span><span class="n">temperature_feb</span><span class="o">.</span><span class="n">stdev</span>
|
||
<span class="go">6.356099432828281</span>
|
||
|
||
<span class="gp">>>> </span><span class="n">temperature_feb</span><span class="o">.</span><span class="n">cdf</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="c1"># Chance of being under 3 degrees</span>
|
||
<span class="go">0.3184678262814532</span>
|
||
<span class="gp">>>> </span><span class="c1"># Relative chance of being 7 degrees versus 10 degrees</span>
|
||
<span class="gp">>>> </span><span class="n">temperature_feb</span><span class="o">.</span><span class="n">pdf</span><span class="p">(</span><span class="mi">7</span><span class="p">)</span> <span class="o">/</span> <span class="n">temperature_feb</span><span class="o">.</span><span class="n">pdf</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
|
||
<span class="go">1.2039930378537762</span>
|
||
|
||
<span class="gp">>>> </span><span class="n">el_niño</span> <span class="o">=</span> <span class="n">NormalDist</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mf">2.5</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="n">temperature_feb</span> <span class="o">+=</span> <span class="n">el_niño</span> <span class="c1"># Add in a climate effect</span>
|
||
<span class="gp">>>> </span><span class="n">temperature_feb</span>
|
||
<span class="go">NormalDist(mu=10.0, sigma=6.830080526611674)</span>
|
||
|
||
<span class="gp">>>> </span><span class="n">temperature_feb</span> <span class="o">*</span> <span class="p">(</span><span class="mi">9</span><span class="o">/</span><span class="mi">5</span><span class="p">)</span> <span class="o">+</span> <span class="mi">32</span> <span class="c1"># Convert to Fahrenheit</span>
|
||
<span class="go">NormalDist(mu=50.0, sigma=12.294144947901014)</span>
|
||
<span class="gp">>>> </span><span class="n">temperature_feb</span><span class="o">.</span><span class="n">samples</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="c1"># Generate random samples</span>
|
||
<span class="go">[7.672102882379219, 12.000027119750287, 4.647488369766392]</span>
|
||
</pre></div>
|
||
</div>
|
||
</section>
|
||
<section id="sys">
|
||
<h3>sys<a class="headerlink" href="#sys" title="Link to this heading">¶</a></h3>
|
||
<p>Add new <a class="reference internal" href="../library/sys.html#sys.unraisablehook" title="sys.unraisablehook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.unraisablehook()</span></code></a> function which can be overridden to control
|
||
how “unraisable exceptions” are handled. It is called when an exception has
|
||
occurred but there is no way for Python to handle it. For example, when a
|
||
destructor raises an exception or during garbage collection
|
||
(<a class="reference internal" href="../library/gc.html#gc.collect" title="gc.collect"><code class="xref py py-func docutils literal notranslate"><span class="pre">gc.collect()</span></code></a>).
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36829">bpo-36829</a>.)</p>
|
||
</section>
|
||
<section id="tarfile">
|
||
<h3>tarfile<a class="headerlink" href="#tarfile" title="Link to this heading">¶</a></h3>
|
||
<p>The <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> module now defaults to the modern pax (POSIX.1-2001)
|
||
format for new archives, instead of the previous GNU-specific one.
|
||
This improves cross-platform portability with a consistent encoding (UTF-8)
|
||
in a standardized and extensible format, and offers several other benefits.
|
||
(Contributed by C.A.M. Gerlach in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36268">bpo-36268</a>.)</p>
|
||
</section>
|
||
<section id="threading">
|
||
<h3>threading<a class="headerlink" href="#threading" title="Link to this heading">¶</a></h3>
|
||
<p>Add a new <a class="reference internal" href="../library/threading.html#threading.excepthook" title="threading.excepthook"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.excepthook()</span></code></a> function which handles uncaught
|
||
<a class="reference internal" href="../library/threading.html#threading.Thread.run" title="threading.Thread.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Thread.run()</span></code></a> exception. It can be overridden to control how
|
||
uncaught <a class="reference internal" href="../library/threading.html#threading.Thread.run" title="threading.Thread.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Thread.run()</span></code></a> exceptions are handled.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=1230540">bpo-1230540</a>.)</p>
|
||
<p>Add a new <a class="reference internal" href="../library/threading.html#threading.get_native_id" title="threading.get_native_id"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.get_native_id()</span></code></a> function and
|
||
a <a class="reference internal" href="../library/threading.html#threading.Thread.native_id" title="threading.Thread.native_id"><code class="xref py py-data docutils literal notranslate"><span class="pre">native_id</span></code></a>
|
||
attribute to the <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> class. These return the native
|
||
integral Thread ID of the current thread assigned by the kernel.
|
||
This feature is only available on certain platforms, see
|
||
<a class="reference internal" href="../library/threading.html#threading.get_native_id" title="threading.get_native_id"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_native_id</span></code></a> for more information.
|
||
(Contributed by Jake Tesler in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36084">bpo-36084</a>.)</p>
|
||
</section>
|
||
<section id="tokenize">
|
||
<h3>tokenize<a class="headerlink" href="#tokenize" title="Link to this heading">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> module now implicitly emits a <code class="docutils literal notranslate"><span class="pre">NEWLINE</span></code> token when
|
||
provided with input that does not have a trailing new line. This behavior
|
||
now matches what the C tokenizer does internally.
|
||
(Contributed by Ammar Askar in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33899">bpo-33899</a>.)</p>
|
||
</section>
|
||
<section id="tkinter">
|
||
<h3>tkinter<a class="headerlink" href="#tkinter" title="Link to this heading">¶</a></h3>
|
||
<p>Added methods <code class="xref py py-meth docutils literal notranslate"><span class="pre">selection_from()</span></code>,
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">selection_present()</span></code>,
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">selection_range()</span></code> and
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">selection_to()</span></code>
|
||
in the <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.Spinbox</span></code> class.
|
||
(Contributed by Juliette Monsel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34829">bpo-34829</a>.)</p>
|
||
<p>Added method <code class="xref py py-meth docutils literal notranslate"><span class="pre">moveto()</span></code>
|
||
in the <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.Canvas</span></code> class.
|
||
(Contributed by Juliette Monsel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23831">bpo-23831</a>.)</p>
|
||
<p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.PhotoImage</span></code> class now has
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">transparency_get()</span></code> and
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">transparency_set()</span></code> methods. (Contributed by
|
||
Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25451">bpo-25451</a>.)</p>
|
||
</section>
|
||
<section id="time">
|
||
<h3>time<a class="headerlink" href="#time" title="Link to this heading">¶</a></h3>
|
||
<p>Added new clock <a class="reference internal" href="../library/time.html#time.CLOCK_UPTIME_RAW" title="time.CLOCK_UPTIME_RAW"><code class="xref py py-const docutils literal notranslate"><span class="pre">CLOCK_UPTIME_RAW</span></code></a> for macOS 10.12.
|
||
(Contributed by Joannah Nanjekye in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35702">bpo-35702</a>.)</p>
|
||
</section>
|
||
<section id="typing">
|
||
<h3>typing<a class="headerlink" href="#typing" title="Link to this heading">¶</a></h3>
|
||
<p>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 incorporates several new features:</p>
|
||
<ul>
|
||
<li><p>A dictionary type with per-key types. See <span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0589/"><strong>PEP 589</strong></a> and
|
||
<a class="reference internal" href="../library/typing.html#typing.TypedDict" title="typing.TypedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.TypedDict</span></code></a>.
|
||
TypedDict uses only string keys. By default, every key is required
|
||
to be present. Specify “total=False” to allow keys to be optional:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span><span class="w"> </span><span class="nc">Location</span><span class="p">(</span><span class="n">TypedDict</span><span class="p">,</span> <span class="n">total</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
|
||
<span class="n">lat_long</span><span class="p">:</span> <span class="nb">tuple</span>
|
||
<span class="n">grid_square</span><span class="p">:</span> <span class="nb">str</span>
|
||
<span class="n">xy_coordinate</span><span class="p">:</span> <span class="nb">tuple</span>
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>Literal types. See <span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0586/"><strong>PEP 586</strong></a> and <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>.
|
||
Literal types indicate that a parameter or return value
|
||
is constrained to one or more specific literal values:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">get_status</span><span class="p">(</span><span class="n">port</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-></span> <span class="n">Literal</span><span class="p">[</span><span class="s1">'connected'</span><span class="p">,</span> <span class="s1">'disconnected'</span><span class="p">]:</span>
|
||
<span class="o">...</span>
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>“Final” variables, functions, methods and classes. See <span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0591/"><strong>PEP 591</strong></a>,
|
||
<a class="reference internal" href="../library/typing.html#typing.Final" title="typing.Final"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Final</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.final" title="typing.final"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.final()</span></code></a>.
|
||
The final qualifier instructs a static type checker to restrict
|
||
subclassing, overriding, or reassignment:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">pi</span><span class="p">:</span> <span class="n">Final</span><span class="p">[</span><span class="nb">float</span><span class="p">]</span> <span class="o">=</span> <span class="mf">3.1415926536</span>
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>Protocol definitions. See <span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0544/"><strong>PEP 544</strong></a>, <a class="reference internal" href="../library/typing.html#typing.Protocol" title="typing.Protocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Protocol</span></code></a> and
|
||
<a class="reference internal" href="../library/typing.html#typing.runtime_checkable" title="typing.runtime_checkable"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.runtime_checkable()</span></code></a>. Simple ABCs like
|
||
<a class="reference internal" href="../library/typing.html#typing.SupportsInt" title="typing.SupportsInt"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.SupportsInt</span></code></a> are now <code class="docutils literal notranslate"><span class="pre">Protocol</span></code> subclasses.</p></li>
|
||
<li><p>New protocol class <a class="reference internal" href="../library/typing.html#typing.SupportsIndex" title="typing.SupportsIndex"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.SupportsIndex</span></code></a>.</p></li>
|
||
<li><p>New functions <a class="reference internal" href="../library/typing.html#typing.get_origin" title="typing.get_origin"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_origin()</span></code></a> and <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>.</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="unicodedata">
|
||
<h3>unicodedata<a class="headerlink" href="#unicodedata" title="Link to this heading">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/unicodedata.html#module-unicodedata" title="unicodedata: Access the Unicode Database."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unicodedata</span></code></a> module has been upgraded to use the <a class="reference external" href="https://blog.unicode.org/2019/05/unicode-12-1-en.html">Unicode 12.1.0</a> release.</p>
|
||
<p>New function <a class="reference internal" href="../library/unicodedata.html#unicodedata.is_normalized" title="unicodedata.is_normalized"><code class="xref py py-func docutils literal notranslate"><span class="pre">is_normalized()</span></code></a> can be used to verify a string
|
||
is in a specific normal form, often much faster than by actually normalizing
|
||
the string. (Contributed by Max Belanger, David Euresti, and Greg Price in
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32285">bpo-32285</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37966">bpo-37966</a>).</p>
|
||
</section>
|
||
<section id="unittest">
|
||
<h3>unittest<a class="headerlink" href="#unittest" title="Link to this heading">¶</a></h3>
|
||
<p>Added <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.AsyncMock" title="unittest.mock.AsyncMock"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncMock</span></code></a> to support an asynchronous version of
|
||
<a class="reference internal" href="../library/unittest.mock.html#unittest.mock.Mock" title="unittest.mock.Mock"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mock</span></code></a>. Appropriate new assert functions for testing
|
||
have been added as well.
|
||
(Contributed by Lisa Roach in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26467">bpo-26467</a>).</p>
|
||
<p>Added <a class="reference internal" href="../library/unittest.html#unittest.addModuleCleanup" title="unittest.addModuleCleanup"><code class="xref py py-func docutils literal notranslate"><span class="pre">addModuleCleanup()</span></code></a> and
|
||
<a class="reference internal" href="../library/unittest.html#unittest.TestCase.addClassCleanup" title="unittest.TestCase.addClassCleanup"><code class="xref py py-meth docutils literal notranslate"><span class="pre">addClassCleanup()</span></code></a> to unittest to support
|
||
cleanups for <code class="xref py py-func docutils literal notranslate"><span class="pre">setUpModule()</span></code> and
|
||
<a class="reference internal" href="../library/unittest.html#unittest.TestCase.setUpClass" title="unittest.TestCase.setUpClass"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setUpClass()</span></code></a>.
|
||
(Contributed by Lisa Roach in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24412">bpo-24412</a>.)</p>
|
||
<p>Several mock assert functions now also print a list of actual calls upon
|
||
failure. (Contributed by Petter Strandmark in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35047">bpo-35047</a>.)</p>
|
||
<p><a class="reference internal" href="../library/unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code></a> module gained support for coroutines to be used as test cases
|
||
with <a class="reference internal" href="../library/unittest.html#unittest.IsolatedAsyncioTestCase" title="unittest.IsolatedAsyncioTestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">unittest.IsolatedAsyncioTestCase</span></code></a>.
|
||
(Contributed by Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32972">bpo-32972</a>.)</p>
|
||
<p>Example:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">unittest</span>
|
||
|
||
|
||
<span class="k">class</span><span class="w"> </span><span class="nc">TestRequest</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">IsolatedAsyncioTestCase</span><span class="p">):</span>
|
||
|
||
<span class="k">async</span> <span class="k">def</span><span class="w"> </span><span class="nf">asyncSetUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">connection</span> <span class="o">=</span> <span class="k">await</span> <span class="n">AsyncConnection</span><span class="p">()</span>
|
||
|
||
<span class="k">async</span> <span class="k">def</span><span class="w"> </span><span class="nf">test_get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="n">response</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"https://example.com"</span><span class="p">)</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span><span class="p">,</span> <span class="mi">200</span><span class="p">)</span>
|
||
|
||
<span class="k">async</span> <span class="k">def</span><span class="w"> </span><span class="nf">asyncTearDown</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
||
|
||
|
||
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
||
<span class="n">unittest</span><span class="o">.</span><span class="n">main</span><span class="p">()</span>
|
||
</pre></div>
|
||
</div>
|
||
</section>
|
||
<section id="venv">
|
||
<h3>venv<a class="headerlink" href="#venv" title="Link to this heading">¶</a></h3>
|
||
<p><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 includes an <code class="docutils literal notranslate"><span class="pre">Activate.ps1</span></code> script on all platforms for
|
||
activating virtual environments under PowerShell Core 6.1.
|
||
(Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32718">bpo-32718</a>.)</p>
|
||
</section>
|
||
<section id="weakref">
|
||
<h3>weakref<a class="headerlink" href="#weakref" title="Link to this heading">¶</a></h3>
|
||
<p>The proxy objects returned by <a class="reference internal" href="../library/weakref.html#weakref.proxy" title="weakref.proxy"><code class="xref py py-func docutils literal notranslate"><span class="pre">weakref.proxy()</span></code></a> now support the matrix
|
||
multiplication operators <code class="docutils literal notranslate"><span class="pre">@</span></code> and <code class="docutils literal notranslate"><span class="pre">@=</span></code> in addition to the other
|
||
numeric operators. (Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36669">bpo-36669</a>.)</p>
|
||
</section>
|
||
<section id="xml">
|
||
<h3>xml<a class="headerlink" href="#xml" title="Link to this heading">¶</a></h3>
|
||
<p>As mitigation against DTD and external entity retrieval, the
|
||
<a class="reference internal" href="../library/xml.dom.minidom.html#module-xml.dom.minidom" title="xml.dom.minidom: Minimal Document Object Model (DOM) implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code></a> and <a class="reference internal" href="../library/xml.sax.html#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code></a> modules no longer process
|
||
external entities by default.
|
||
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=17239">bpo-17239</a>.)</p>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">.find*()</span></code> methods 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">xml.etree.ElementTree</span></code></a> module
|
||
support wildcard searches like <code class="docutils literal notranslate"><span class="pre">{*}tag</span></code> which ignores the namespace
|
||
and <code class="docutils literal notranslate"><span class="pre">{namespace}*</span></code> which returns all tags in the given namespace.
|
||
(Contributed by Stefan Behnel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28238">bpo-28238</a>.)</p>
|
||
<p>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">xml.etree.ElementTree</span></code></a> module provides a new function
|
||
<code class="xref py py-func docutils literal notranslate"><span class="pre">–xml.etree.ElementTree.canonicalize()</span></code> that implements C14N 2.0.
|
||
(Contributed by Stefan Behnel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=13611">bpo-13611</a>.)</p>
|
||
<p>The target object of <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLParser" title="xml.etree.ElementTree.XMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.etree.ElementTree.XMLParser</span></code></a> can
|
||
receive namespace declaration events through the new callback methods
|
||
<code class="docutils literal notranslate"><span class="pre">start_ns()</span></code> and <code class="docutils literal notranslate"><span class="pre">end_ns()</span></code>. Additionally, the
|
||
<a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.TreeBuilder" title="xml.etree.ElementTree.TreeBuilder"><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.etree.ElementTree.TreeBuilder</span></code></a> target can be configured
|
||
to process events about comments and processing instructions to include
|
||
them in the generated tree.
|
||
(Contributed by Stefan Behnel in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36676">bpo-36676</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36673">bpo-36673</a>.)</p>
|
||
</section>
|
||
<section id="xmlrpc">
|
||
<h3>xmlrpc<a class="headerlink" href="#xmlrpc" title="Link to this heading">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/xmlrpc.client.html#xmlrpc.client.ServerProxy" title="xmlrpc.client.ServerProxy"><code class="xref py py-class docutils literal notranslate"><span class="pre">xmlrpc.client.ServerProxy</span></code></a> now supports an optional <em>headers</em> keyword
|
||
argument for a sequence of HTTP headers to be sent with each request. Among
|
||
other things, this makes it possible to upgrade from default basic
|
||
authentication to faster session authentication.
|
||
(Contributed by Cédric Krier in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35153">bpo-35153</a>.)</p>
|
||
</section>
|
||
</section>
|
||
<section id="optimizations">
|
||
<h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading">¶</a></h2>
|
||
<ul>
|
||
<li><p>The <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module can now use the <a class="reference internal" href="../library/os.html#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.posix_spawn()</span></code></a> function
|
||
in some cases for better performance. Currently, it is only used on macOS
|
||
and Linux (using glibc 2.24 or newer) if all these conditions are met:</p>
|
||
<ul class="simple">
|
||
<li><p><em>close_fds</em> is false;</p></li>
|
||
<li><p><em>preexec_fn</em>, <em>pass_fds</em>, <em>cwd</em> and <em>start_new_session</em> parameters
|
||
are not set;</p></li>
|
||
<li><p>the <em>executable</em> path contains a directory.</p></li>
|
||
</ul>
|
||
<p>(Contributed by Joannah Nanjekye and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35537">bpo-35537</a>.)</p>
|
||
</li>
|
||
<li><p><a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copyfile()</span></code></a>, <a class="reference internal" href="../library/shutil.html#shutil.copy" title="shutil.copy"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copy()</span></code></a>, <a class="reference internal" href="../library/shutil.html#shutil.copy2" title="shutil.copy2"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copy2()</span></code></a>,
|
||
<a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copytree()</span></code></a> and <a class="reference internal" href="../library/shutil.html#shutil.move" title="shutil.move"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.move()</span></code></a> use platform-specific
|
||
“fast-copy” syscalls on Linux and macOS in order to copy the file
|
||
more efficiently.
|
||
“fast-copy” means that the copying operation occurs within the kernel,
|
||
avoiding the use of userspace buffers in Python as in
|
||
“<code class="docutils literal notranslate"><span class="pre">outfd.write(infd.read())</span></code>”.
|
||
On Windows <a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copyfile()</span></code></a> uses a bigger default buffer size (1 MiB
|
||
instead of 16 KiB) and a <a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-func docutils literal notranslate"><span class="pre">memoryview()</span></code></a>-based variant of
|
||
<a class="reference internal" href="../library/shutil.html#shutil.copyfileobj" title="shutil.copyfileobj"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copyfileobj()</span></code></a> is used.
|
||
The speedup for copying a 512 MiB file within the same partition is about
|
||
+26% on Linux, +50% on macOS and +40% on Windows. Also, much less CPU cycles
|
||
are consumed.
|
||
See <a class="reference internal" href="../library/shutil.html#shutil-platform-dependent-efficient-copy-operations"><span class="std std-ref">Platform-dependent efficient copy operations</span></a> section.
|
||
(Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33671">bpo-33671</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copytree()</span></code></a> uses <a class="reference internal" href="../library/os.html#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.scandir()</span></code></a> function and all copy
|
||
functions depending from it use cached <a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> values. The speedup
|
||
for copying a directory with 8000 files is around +9% on Linux, +20% on
|
||
Windows and +30% on a Windows SMB share. Also the number of <a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a>
|
||
syscalls is reduced by 38% making <a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copytree()</span></code></a> especially faster
|
||
on network filesystems. (Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33695">bpo-33695</a>.)</p></li>
|
||
<li><p>The default protocol in the <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> module is now Protocol 4,
|
||
first introduced in Python 3.4. It offers better performance and smaller
|
||
size compared to Protocol 3 available since Python 3.0.</p></li>
|
||
<li><p>Removed one <a class="reference internal" href="../c-api/intro.html#c.Py_ssize_t" title="Py_ssize_t"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_ssize_t</span></code></a> member from <code class="docutils literal notranslate"><span class="pre">PyGC_Head</span></code>. All GC tracked
|
||
objects (e.g. tuple, list, dict) size is reduced 4 or 8 bytes.
|
||
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33597">bpo-33597</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/uuid.html#uuid.UUID" title="uuid.UUID"><code class="xref py py-class docutils literal notranslate"><span class="pre">uuid.UUID</span></code></a> now uses <code class="docutils literal notranslate"><span class="pre">__slots__</span></code> to reduce its memory footprint.
|
||
(Contributed by Wouter Bolsterlee and Tal Einat in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=30977">bpo-30977</a>)</p></li>
|
||
<li><p>Improved performance of <a class="reference internal" href="../library/operator.html#operator.itemgetter" title="operator.itemgetter"><code class="xref py py-func docutils literal notranslate"><span class="pre">operator.itemgetter()</span></code></a> by 33%. Optimized
|
||
argument handling and added a fast path for the common case of a single
|
||
non-negative integer index into a tuple (which is the typical use case in
|
||
the standard library). (Contributed by Raymond Hettinger in
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35664">bpo-35664</a>.)</p></li>
|
||
<li><p>Sped-up field lookups in <a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">collections.namedtuple()</span></code></a>. They are now more
|
||
than two times faster, making them the fastest form of instance variable
|
||
lookup in Python. (Contributed by Raymond Hettinger, Pablo Galindo, and
|
||
Joe Jevnik, Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32492">bpo-32492</a>.)</p></li>
|
||
<li><p>The <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> constructor does not overallocate the internal item buffer
|
||
if the input iterable has a known length (the input implements <code class="docutils literal notranslate"><span class="pre">__len__</span></code>).
|
||
This makes the created list 12% smaller on average. (Contributed by
|
||
Raymond Hettinger and Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33234">bpo-33234</a>.)</p></li>
|
||
<li><p>Doubled the speed of class variable writes. When a non-dunder attribute
|
||
was updated, there was an unnecessary call to update slots.
|
||
(Contributed by Stefan Behnel, Pablo Galindo Salgado, Raymond Hettinger,
|
||
Neil Schemenauer, and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36012">bpo-36012</a>.)</p></li>
|
||
<li><p>Reduced an overhead of converting arguments passed to many builtin functions
|
||
and methods. This sped up calling some simple builtin functions and
|
||
methods up to 20–50%. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23867">bpo-23867</a>,
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35582">bpo-35582</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36127">bpo-36127</a>.)</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">LOAD_GLOBAL</span></code> instruction now uses new “per opcode cache” mechanism.
|
||
It is about 40% faster now. (Contributed by Yury Selivanov and Inada Naoki in
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26219">bpo-26219</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="build-and-c-api-changes">
|
||
<h2>Build and C API Changes<a class="headerlink" href="#build-and-c-api-changes" title="Link to this heading">¶</a></h2>
|
||
<ul>
|
||
<li><p>Default <a class="reference internal" href="../library/sys.html#sys.abiflags" title="sys.abiflags"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.abiflags</span></code></a> became an empty string: the <code class="docutils literal notranslate"><span class="pre">m</span></code> flag for
|
||
pymalloc became useless (builds with and without pymalloc are ABI compatible)
|
||
and so has been removed. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36707">bpo-36707</a>.)</p>
|
||
<p>Example of changes:</p>
|
||
<ul class="simple">
|
||
<li><p>Only <code class="docutils literal notranslate"><span class="pre">python3.8</span></code> program is installed, <code class="docutils literal notranslate"><span class="pre">python3.8m</span></code> program is gone.</p></li>
|
||
<li><p>Only <code class="docutils literal notranslate"><span class="pre">python3.8-config</span></code> script is installed, <code class="docutils literal notranslate"><span class="pre">python3.8m-config</span></code> script
|
||
is gone.</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">m</span></code> flag has been removed from the suffix of dynamic library
|
||
filenames: extension modules in the standard library as well as those
|
||
produced and installed by third-party packages, like those downloaded from
|
||
PyPI. On Linux, for example, the Python 3.7 suffix
|
||
<code class="docutils literal notranslate"><span class="pre">.cpython-37m-x86_64-linux-gnu.so</span></code> became
|
||
<code class="docutils literal notranslate"><span class="pre">.cpython-38-x86_64-linux-gnu.so</span></code> in Python 3.8.</p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p>The header files have been reorganized to better separate the different kinds
|
||
of APIs:</p>
|
||
<ul class="simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">Include/*.h</span></code> should be the portable public stable C API.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">Include/cpython/*.h</span></code> should be the unstable C API specific to CPython;
|
||
public API, with some private API prefixed by <code class="docutils literal notranslate"><span class="pre">_Py</span></code> or <code class="docutils literal notranslate"><span class="pre">_PY</span></code>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">Include/internal/*.h</span></code> is the private internal C API very specific to
|
||
CPython. This API comes with no backward compatibility warranty and should
|
||
not be used outside CPython. It is only exposed for very specific needs
|
||
like debuggers and profiles which has to access to CPython internals
|
||
without calling functions. This API is now installed by <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">install</span></code>.</p></li>
|
||
</ul>
|
||
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35134">bpo-35134</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35081">bpo-35081</a>,
|
||
work initiated by Eric Snow in Python 3.7.)</p>
|
||
</li>
|
||
<li><p>Some macros have been converted to static inline functions: parameter types
|
||
and return type are well defined, they don’t have issues specific to macros,
|
||
variables have a local scopes. Examples:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../c-api/refcounting.html#c.Py_INCREF" title="Py_INCREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_INCREF()</span></code></a>, <a class="reference internal" href="../c-api/refcounting.html#c.Py_DECREF" title="Py_DECREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DECREF()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../c-api/refcounting.html#c.Py_XINCREF" title="Py_XINCREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_XINCREF()</span></code></a>, <a class="reference internal" href="../c-api/refcounting.html#c.Py_XDECREF" title="Py_XDECREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_XDECREF()</span></code></a></p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_INIT()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_INIT_VAR()</span></code></p></li>
|
||
<li><p>Private functions: <code class="xref c c-func docutils literal notranslate"><span class="pre">_PyObject_GC_TRACK()</span></code>,
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">_PyObject_GC_UNTRACK()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">_Py_Dealloc()</span></code></p></li>
|
||
</ul>
|
||
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35059">bpo-35059</a>.)</p>
|
||
</li>
|
||
<li><p>The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyByteArray_Init()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyByteArray_Fini()</span></code> functions have
|
||
been removed. They did nothing since Python 2.7.4 and Python 3.2.0, were
|
||
excluded from the limited API (stable ABI), and were not documented.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35713">bpo-35713</a>.)</p></li>
|
||
<li><p>The result of <code class="xref c c-func docutils literal notranslate"><span class="pre">PyExceptionClass_Name()</span></code> is now of type
|
||
<code class="docutils literal notranslate"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></code> rather of <code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*</span></code>.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33818">bpo-33818</a>.)</p></li>
|
||
<li><p>The duality of <code class="docutils literal notranslate"><span class="pre">Modules/Setup.dist</span></code> and <code class="docutils literal notranslate"><span class="pre">Modules/Setup</span></code> has been
|
||
removed. Previously, when updating the CPython source tree, one had
|
||
to manually copy <code class="docutils literal notranslate"><span class="pre">Modules/Setup.dist</span></code> (inside the source tree) to
|
||
<code class="docutils literal notranslate"><span class="pre">Modules/Setup</span></code> (inside the build tree) in order to reflect any changes
|
||
upstream. This was of a small benefit to packagers at the expense of
|
||
a frequent annoyance to developers following CPython development, as
|
||
forgetting to copy the file could produce build failures.</p>
|
||
<p>Now the build system always reads from <code class="docutils literal notranslate"><span class="pre">Modules/Setup</span></code> inside the source
|
||
tree. People who want to customize that file are encouraged to maintain
|
||
their changes in a git fork of CPython or as patch files, as they would do
|
||
for any other change to the source tree.</p>
|
||
<p>(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32430">bpo-32430</a>.)</p>
|
||
</li>
|
||
<li><p>Functions that convert Python number to C integer like
|
||
<a class="reference internal" href="../c-api/long.html#c.PyLong_AsLong" title="PyLong_AsLong"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyLong_AsLong()</span></code></a> and argument parsing functions like
|
||
<a class="reference internal" href="../c-api/arg.html#c.PyArg_ParseTuple" title="PyArg_ParseTuple"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTuple()</span></code></a> with integer converting format units like <code class="docutils literal notranslate"><span class="pre">'i'</span></code>
|
||
will now use the <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> special method instead of
|
||
<a class="reference internal" href="../reference/datamodel.html#object.__int__" title="object.__int__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__int__()</span></code></a>, if available. The deprecation warning will be
|
||
emitted for objects with the <code class="docutils literal notranslate"><span class="pre">__int__()</span></code> method but without the
|
||
<code class="docutils literal notranslate"><span class="pre">__index__()</span></code> method (like <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">Decimal</span></code></a> and
|
||
<a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a>). <a class="reference internal" href="../c-api/number.html#c.PyNumber_Check" title="PyNumber_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_Check()</span></code></a> will now return
|
||
<code class="docutils literal notranslate"><span class="pre">1</span></code> for objects implementing <code class="docutils literal notranslate"><span class="pre">__index__()</span></code>.
|
||
<a class="reference internal" href="../c-api/number.html#c.PyNumber_Long" title="PyNumber_Long"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_Long()</span></code></a>, <a class="reference internal" href="../c-api/number.html#c.PyNumber_Float" title="PyNumber_Float"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_Float()</span></code></a> and
|
||
<a class="reference internal" href="../c-api/float.html#c.PyFloat_AsDouble" title="PyFloat_AsDouble"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_AsDouble()</span></code></a> also now use the <code class="docutils literal notranslate"><span class="pre">__index__()</span></code> method if
|
||
available.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36048">bpo-36048</a> and <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=20092">bpo-20092</a>.)</p></li>
|
||
<li><p>Heap-allocated type objects will now increase their reference count
|
||
in <a class="reference internal" href="../c-api/allocation.html#c.PyObject_Init" title="PyObject_Init"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Init()</span></code></a> (and its parallel macro <code class="docutils literal notranslate"><span class="pre">PyObject_INIT</span></code>)
|
||
instead of in <a class="reference internal" href="../c-api/type.html#c.PyType_GenericAlloc" title="PyType_GenericAlloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GenericAlloc()</span></code></a>. Types that modify instance
|
||
allocation or deallocation may need to be adjusted.
|
||
(Contributed by Eddie Elizondo in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35810">bpo-35810</a>.)</p></li>
|
||
<li><p>The new function <code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_NewWithPosOnlyArgs()</span></code> allows to create
|
||
code objects like <code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_New()</span></code>, but with an extra <em>posonlyargcount</em>
|
||
parameter for indicating the number of positional-only arguments.
|
||
(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37221">bpo-37221</a>.)</p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetPath()</span></code> now sets <a class="reference internal" href="../library/sys.html#sys.executable" title="sys.executable"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.executable</span></code></a> to the program full
|
||
path (<a class="reference internal" href="../c-api/init.html#c.Py_GetProgramFullPath" title="Py_GetProgramFullPath"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetProgramFullPath()</span></code></a>) rather than to the program name
|
||
(<a class="reference internal" href="../c-api/init.html#c.Py_GetProgramName" title="Py_GetProgramName"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetProgramName()</span></code></a>).
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=38234">bpo-38234</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="deprecated">
|
||
<h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading">¶</a></h2>
|
||
<ul>
|
||
<li><p>The distutils <code class="docutils literal notranslate"><span class="pre">bdist_wininst</span></code> command is now deprecated, use
|
||
<code class="docutils literal notranslate"><span class="pre">bdist_wheel</span></code> (wheel packages) instead.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37481">bpo-37481</a>.)</p></li>
|
||
<li><p>Deprecated methods <code class="docutils literal notranslate"><span class="pre">getchildren()</span></code> and <code class="docutils literal notranslate"><span class="pre">getiterator()</span></code> 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 now emit a
|
||
<a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> instead of <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>.
|
||
They will be removed in Python 3.9.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=29209">bpo-29209</a>.)</p></li>
|
||
<li><p>Passing an object that is not an instance of
|
||
<a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.ThreadPoolExecutor</span></code></a> to
|
||
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.set_default_executor" title="asyncio.loop.set_default_executor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.set_default_executor()</span></code></a> is
|
||
deprecated and will be prohibited in Python 3.9.
|
||
(Contributed by Elvis Pranskevichus in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34075">bpo-34075</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a> methods of <a class="reference internal" href="../library/xml.dom.pulldom.html#xml.dom.pulldom.DOMEventStream" title="xml.dom.pulldom.DOMEventStream"><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.dom.pulldom.DOMEventStream</span></code></a>,
|
||
<a class="reference internal" href="../library/wsgiref.html#wsgiref.util.FileWrapper" title="wsgiref.util.FileWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">wsgiref.util.FileWrapper</span></code></a> and <a class="reference internal" href="../library/fileinput.html#fileinput.FileInput" title="fileinput.FileInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">fileinput.FileInput</span></code></a> have been
|
||
deprecated.</p>
|
||
<p>Implementations of these methods have been ignoring their <em>index</em> parameter,
|
||
and returning the next item instead.
|
||
(Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=9372">bpo-9372</a>.)</p>
|
||
</li>
|
||
<li><p>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 deprecated the <code class="docutils literal notranslate"><span class="pre">_field_types</span></code>
|
||
attribute in favor of the <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code> attribute which has the same
|
||
information. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36320">bpo-36320</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">Num</span></code>, <code class="docutils literal notranslate"><span class="pre">Str</span></code>, <code class="docutils literal notranslate"><span class="pre">Bytes</span></code>, <code class="docutils literal notranslate"><span class="pre">NameConstant</span></code> and
|
||
<code class="docutils literal notranslate"><span class="pre">Ellipsis</span></code> are considered deprecated and will be removed in future Python
|
||
versions. <a class="reference internal" href="../library/ast.html#ast.Constant" title="ast.Constant"><code class="xref py py-class docutils literal notranslate"><span class="pre">Constant</span></code></a> should be used instead.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32892">bpo-32892</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/ast.html#ast.NodeVisitor" title="ast.NodeVisitor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.NodeVisitor</span></code></a> methods <code class="docutils literal notranslate"><span class="pre">visit_Num()</span></code>, <code class="docutils literal notranslate"><span class="pre">visit_Str()</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">visit_Bytes()</span></code>, <code class="docutils literal notranslate"><span class="pre">visit_NameConstant()</span></code> and <code class="docutils literal notranslate"><span class="pre">visit_Ellipsis()</span></code> are
|
||
deprecated now and will not be called in future Python versions.
|
||
Add the <a class="reference internal" href="../library/ast.html#ast.NodeVisitor.visit_Constant" title="ast.NodeVisitor.visit_Constant"><code class="xref py py-meth docutils literal notranslate"><span class="pre">visit_Constant()</span></code></a> method to handle all
|
||
constant nodes.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36917">bpo-36917</a>.)</p></li>
|
||
<li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.coroutine()</span></code> <a class="reference internal" href="../glossary.html#term-decorator"><span class="xref std std-term">decorator</span></a> is deprecated and will be
|
||
removed in version 3.10. Instead of <code class="docutils literal notranslate"><span class="pre">@asyncio.coroutine</span></code>, use
|
||
<a class="reference internal" href="../reference/compound_stmts.html#async-def"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">def</span></code></a> instead.
|
||
(Contributed by Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36921">bpo-36921</a>.)</p></li>
|
||
<li><p>In <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a>, the explicit passing of a <em>loop</em> argument has been
|
||
deprecated and will be removed in version 3.10 for the following:
|
||
<a class="reference internal" href="../library/asyncio-task.html#asyncio.sleep" title="asyncio.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.sleep()</span></code></a>, <a class="reference internal" href="../library/asyncio-task.html#asyncio.gather" title="asyncio.gather"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.gather()</span></code></a>, <a class="reference internal" href="../library/asyncio-task.html#asyncio.shield" title="asyncio.shield"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.shield()</span></code></a>,
|
||
<a class="reference internal" href="../library/asyncio-task.html#asyncio.wait_for" title="asyncio.wait_for"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.wait_for()</span></code></a>, <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>, <a class="reference internal" href="../library/asyncio-task.html#asyncio.as_completed" title="asyncio.as_completed"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.as_completed()</span></code></a>,
|
||
<a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a>, <a class="reference internal" href="../library/asyncio-sync.html#asyncio.Lock" title="asyncio.Lock"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Lock</span></code></a>, <a class="reference internal" href="../library/asyncio-sync.html#asyncio.Event" title="asyncio.Event"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Event</span></code></a>,
|
||
<a class="reference internal" href="../library/asyncio-sync.html#asyncio.Condition" title="asyncio.Condition"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Condition</span></code></a>, <a class="reference internal" href="../library/asyncio-sync.html#asyncio.Semaphore" title="asyncio.Semaphore"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Semaphore</span></code></a>,
|
||
<a class="reference internal" href="../library/asyncio-sync.html#asyncio.BoundedSemaphore" title="asyncio.BoundedSemaphore"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.BoundedSemaphore</span></code></a>, <a class="reference internal" href="../library/asyncio-queue.html#asyncio.Queue" title="asyncio.Queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Queue</span></code></a>,
|
||
<a class="reference internal" href="../library/asyncio-subprocess.html#asyncio.create_subprocess_exec" title="asyncio.create_subprocess_exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.create_subprocess_exec()</span></code></a>, and
|
||
<a class="reference internal" href="../library/asyncio-subprocess.html#asyncio.create_subprocess_shell" title="asyncio.create_subprocess_shell"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.create_subprocess_shell()</span></code></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 in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34790">bpo-34790</a>.)</p></li>
|
||
<li><p>The following functions and methods are deprecated in the <a class="reference internal" href="../library/gettext.html#module-gettext" title="gettext: Multilingual internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gettext</span></code></a>
|
||
module: <code class="xref py py-func docutils literal notranslate"><span class="pre">lgettext()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">ldgettext()</span></code>,
|
||
<code class="xref py py-func docutils literal notranslate"><span class="pre">lngettext()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">ldngettext()</span></code>.
|
||
They return encoded bytes, and it’s possible that you will get unexpected
|
||
Unicode-related exceptions if there are encoding problems with the
|
||
translated strings. It’s much better to use alternatives which return
|
||
Unicode strings in Python 3. These functions have been broken for a long time.</p>
|
||
<p>Function <code class="xref py py-func docutils literal notranslate"><span class="pre">bind_textdomain_codeset()</span></code>, methods
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">output_charset()</span></code> and
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">set_output_charset()</span></code>, and the <em>codeset</em>
|
||
parameter of functions <a class="reference internal" href="../library/gettext.html#gettext.translation" title="gettext.translation"><code class="xref py py-func docutils literal notranslate"><span class="pre">translation()</span></code></a> and
|
||
<a class="reference internal" href="../library/gettext.html#gettext.install" title="gettext.install"><code class="xref py py-func docutils literal notranslate"><span class="pre">install()</span></code></a> are also deprecated, since they are only used for
|
||
the <code class="docutils literal notranslate"><span class="pre">l*gettext()</span></code> functions.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33710">bpo-33710</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 deprecated.
|
||
(Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35283">bpo-35283</a>.)</p></li>
|
||
<li><p>Many builtin and extension functions that take integer arguments will
|
||
now emit a deprecation warning for <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">Decimal</span></code></a>s,
|
||
<a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a>s and any other objects that can be converted
|
||
to integers only with a loss (e.g. that have the <a class="reference internal" href="../reference/datamodel.html#object.__int__" title="object.__int__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__int__()</span></code></a>
|
||
method but do not have the <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> method). In future
|
||
version they will be errors.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36048">bpo-36048</a>.)</p></li>
|
||
<li><p>Deprecated passing the following arguments as keyword arguments:</p>
|
||
<ul class="simple">
|
||
<li><p><em>func</em> in <a class="reference internal" href="../library/functools.html#functools.partialmethod" title="functools.partialmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.partialmethod()</span></code></a>, <a class="reference internal" href="../library/weakref.html#weakref.finalize" title="weakref.finalize"><code class="xref py py-func docutils literal notranslate"><span class="pre">weakref.finalize()</span></code></a>,
|
||
<a class="reference internal" href="../library/profile.html#profile.Profile.runcall" title="profile.Profile.runcall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">profile.Profile.runcall()</span></code></a>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">cProfile.Profile.runcall()</span></code>,
|
||
<a class="reference internal" href="../library/bdb.html#bdb.Bdb.runcall" title="bdb.Bdb.runcall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bdb.Bdb.runcall()</span></code></a>, <a class="reference internal" href="../library/trace.html#trace.Trace.runfunc" title="trace.Trace.runfunc"><code class="xref py py-meth docutils literal notranslate"><span class="pre">trace.Trace.runfunc()</span></code></a> and
|
||
<a class="reference internal" href="../library/curses.html#curses.wrapper" title="curses.wrapper"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.wrapper()</span></code></a>.</p></li>
|
||
<li><p><em>function</em> in <a class="reference internal" href="../library/unittest.html#unittest.TestCase.addCleanup" title="unittest.TestCase.addCleanup"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestCase.addCleanup()</span></code></a>.</p></li>
|
||
<li><p><em>fn</em> in the <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.Executor.submit" title="concurrent.futures.Executor.submit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">submit()</span></code></a> method of
|
||
<a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.ThreadPoolExecutor</span></code></a> 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">concurrent.futures.ProcessPoolExecutor</span></code></a>.</p></li>
|
||
<li><p><em>callback</em> in <a class="reference internal" href="../library/contextlib.html#contextlib.ExitStack.callback" title="contextlib.ExitStack.callback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">contextlib.ExitStack.callback()</span></code></a>,
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">contextlib.AsyncExitStack.callback()</span></code> and
|
||
<a class="reference internal" href="../library/contextlib.html#contextlib.AsyncExitStack.push_async_callback" title="contextlib.AsyncExitStack.push_async_callback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">contextlib.AsyncExitStack.push_async_callback()</span></code></a>.</p></li>
|
||
<li><p><em>c</em> and <em>typeid</em> in the <code class="xref py py-meth docutils literal notranslate"><span class="pre">create()</span></code>
|
||
method of <code class="xref py py-class docutils literal notranslate"><span class="pre">multiprocessing.managers.Server</span></code> and
|
||
<code class="xref py py-class docutils literal notranslate"><span class="pre">multiprocessing.managers.SharedMemoryServer</span></code>.</p></li>
|
||
<li><p><em>obj</em> in <a class="reference internal" href="../library/weakref.html#weakref.finalize" title="weakref.finalize"><code class="xref py py-func docutils literal notranslate"><span class="pre">weakref.finalize()</span></code></a>.</p></li>
|
||
</ul>
|
||
<p>In future releases of Python, they will be <a class="reference internal" href="../glossary.html#positional-only-parameter"><span class="std std-ref">positional-only</span></a>.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36492">bpo-36492</a>.)</p>
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
<section id="api-and-feature-removals">
|
||
<h2>API and Feature Removals<a class="headerlink" href="#api-and-feature-removals" title="Link to this heading">¶</a></h2>
|
||
<p>The following features and APIs have been removed from Python 3.8:</p>
|
||
<ul class="simple">
|
||
<li><p>Starting with Python 3.3, importing ABCs from <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> was
|
||
deprecated, and importing should be done from <a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a>. Being
|
||
able to import from collections was marked for removal in 3.8, but has been
|
||
delayed to 3.9. (See <a class="reference external" href="https://github.com/python/cpython/issues/81134">gh-81134</a>.)</p></li>
|
||
<li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">macpath</span></code> module, deprecated in Python 3.7, has been removed.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35471">bpo-35471</a>.)</p></li>
|
||
<li><p>The function <code class="xref py py-func docutils literal notranslate"><span class="pre">platform.popen()</span></code> has been removed, after having been
|
||
deprecated since Python 3.3: use <a class="reference internal" href="../library/os.html#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.popen()</span></code></a> instead.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35345">bpo-35345</a>.)</p></li>
|
||
<li><p>The function <code class="xref py py-func docutils literal notranslate"><span class="pre">time.clock()</span></code> has been removed, after having been
|
||
deprecated since Python 3.3: use <a class="reference internal" href="../library/time.html#time.perf_counter" title="time.perf_counter"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.perf_counter()</span></code></a> or
|
||
<a class="reference internal" href="../library/time.html#time.process_time" title="time.process_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.process_time()</span></code></a> instead, depending
|
||
on your requirements, to have well-defined behavior.
|
||
(Contributed by Matthias Bussonnier in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36895">bpo-36895</a>.)</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> script has been removed in favor of <code class="docutils literal notranslate"><span class="pre">python3.8</span> <span class="pre">-m</span> <span class="pre">venv</span></code>
|
||
to help eliminate confusion as to what Python interpreter the <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code>
|
||
script is tied to. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25427">bpo-25427</a>.)</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">parse_qs</span></code>, <code class="docutils literal notranslate"><span class="pre">parse_qsl</span></code>, and <code class="docutils literal notranslate"><span class="pre">escape</span></code> are removed from the <code class="xref py py-mod docutils literal notranslate"><span class="pre">cgi</span></code>
|
||
module. They are deprecated in Python 3.2 or older. They should be imported
|
||
from the <code class="docutils literal notranslate"><span class="pre">urllib.parse</span></code> and <code class="docutils literal notranslate"><span class="pre">html</span></code> modules instead.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">filemode</span></code> function is removed from the <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> module.
|
||
It is not documented and deprecated since Python 3.3.</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLParser" title="xml.etree.ElementTree.XMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLParser</span></code></a> constructor no longer accepts
|
||
the <em>html</em> argument. It never had an effect and was deprecated in Python 3.4.
|
||
All other parameters are now <a class="reference internal" href="../glossary.html#keyword-only-parameter"><span class="std std-ref">keyword-only</span></a>.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=29209">bpo-29209</a>.)</p></li>
|
||
<li><p>Removed the <code class="docutils literal notranslate"><span class="pre">doctype()</span></code> method of <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLParser" title="xml.etree.ElementTree.XMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLParser</span></code></a>.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=29209">bpo-29209</a>.)</p></li>
|
||
<li><p>“unicode_internal” codec is removed.
|
||
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36297">bpo-36297</a>.)</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">Cache</span></code> and <code class="docutils literal notranslate"><span class="pre">Statement</span></code> objects of the <a class="reference internal" href="../library/sqlite3.html#module-sqlite3" title="sqlite3: A DB-API 2.0 implementation using SQLite 3.x."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlite3</span></code></a> module are not
|
||
exposed to the user.
|
||
(Contributed by Aviv Palivoda in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=30262">bpo-30262</a>.)</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">bufsize</span></code> keyword argument of <a class="reference internal" href="../library/fileinput.html#fileinput.input" title="fileinput.input"><code class="xref py py-func docutils literal notranslate"><span class="pre">fileinput.input()</span></code></a> and
|
||
<a class="reference internal" href="../library/fileinput.html#fileinput.FileInput" title="fileinput.FileInput"><code class="xref py py-func docutils literal notranslate"><span class="pre">fileinput.FileInput()</span></code></a> which was ignored and deprecated since Python 3.6
|
||
has been removed. <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36952">bpo-36952</a> (Contributed by Matthias Bussonnier.)</p></li>
|
||
<li><p>The functions <code class="xref py py-func docutils literal notranslate"><span class="pre">sys.set_coroutine_wrapper()</span></code> and
|
||
<code class="xref py py-func docutils literal notranslate"><span class="pre">sys.get_coroutine_wrapper()</span></code> deprecated in Python 3.7 have been removed;
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36933">bpo-36933</a> (Contributed by Matthias Bussonnier.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="porting-to-python-3-8">
|
||
<h2>Porting to Python 3.8<a class="headerlink" href="#porting-to-python-3-8" 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-python-behavior">
|
||
<h3>Changes in Python behavior<a class="headerlink" href="#changes-in-python-behavior" title="Link to this heading">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Yield expressions (both <code class="docutils literal notranslate"><span class="pre">yield</span></code> and <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> clauses) are now disallowed
|
||
in comprehensions and generator expressions (aside from the iterable expression
|
||
in the leftmost <code class="xref std std-keyword docutils literal notranslate"><span class="pre">for</span></code> clause).
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=10544">bpo-10544</a>.)</p></li>
|
||
<li><p>The compiler now produces a <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a> when identity checks
|
||
(<code class="docutils literal notranslate"><span class="pre">is</span></code> and <code class="docutils literal notranslate"><span class="pre">is</span> <span class="pre">not</span></code>) are used with certain types of literals
|
||
(e.g. strings, numbers). These can often work by accident in CPython,
|
||
but are not guaranteed by the language spec. The warning advises users
|
||
to use equality tests (<code class="docutils literal notranslate"><span class="pre">==</span></code> and <code class="docutils literal notranslate"><span class="pre">!=</span></code>) instead.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34850">bpo-34850</a>.)</p></li>
|
||
<li><p>The CPython interpreter can swallow exceptions in some circumstances.
|
||
In Python 3.8 this happens in fewer cases. In particular, exceptions
|
||
raised when getting the attribute from the type dictionary are no longer
|
||
ignored. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35459">bpo-35459</a>.)</p></li>
|
||
<li><p>Removed <code class="docutils literal notranslate"><span class="pre">__str__</span></code> implementations from builtin types <a class="reference internal" href="../library/functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a>,
|
||
<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/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a> and few classes from
|
||
the standard library. They now inherit <code class="docutils literal notranslate"><span class="pre">__str__()</span></code> from <a class="reference internal" href="../library/functions.html#object" title="object"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a>.
|
||
As result, defining the <code class="docutils literal notranslate"><span class="pre">__repr__()</span></code> method in the subclass of these
|
||
classes will affect their string representation.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36793">bpo-36793</a>.)</p></li>
|
||
<li><p>On AIX, <a class="reference internal" href="../library/sys.html#sys.platform" title="sys.platform"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platform</span></code></a> doesn’t contain the major version anymore.
|
||
It is always <code class="docutils literal notranslate"><span class="pre">'aix'</span></code>, instead of <code class="docutils literal notranslate"><span class="pre">'aix3'</span></code> .. <code class="docutils literal notranslate"><span class="pre">'aix7'</span></code>. Since
|
||
older Python versions include the version number, so it is recommended to
|
||
always use <code class="docutils literal notranslate"><span class="pre">sys.platform.startswith('aix')</span></code>.
|
||
(Contributed by M. Felt in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36588">bpo-36588</a>.)</p></li>
|
||
<li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_AcquireLock()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_AcquireThread()</span></code> now
|
||
terminate the current thread if called while the interpreter is
|
||
finalizing, making them consistent with <a class="reference internal" href="../c-api/init.html#c.PyEval_RestoreThread" title="PyEval_RestoreThread"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_RestoreThread()</span></code></a>,
|
||
<a class="reference internal" href="../c-api/init.html#c.Py_END_ALLOW_THREADS" title="Py_END_ALLOW_THREADS"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_END_ALLOW_THREADS()</span></code></a>, and <a class="reference internal" href="../c-api/init.html#c.PyGILState_Ensure" title="PyGILState_Ensure"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyGILState_Ensure()</span></code></a>. If this
|
||
behavior is not desired, guard the call by checking <code class="xref c c-func docutils literal notranslate"><span class="pre">_Py_IsFinalizing()</span></code>
|
||
or <a class="reference internal" href="../library/sys.html#sys.is_finalizing" title="sys.is_finalizing"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.is_finalizing()</span></code></a>.
|
||
(Contributed by Joannah Nanjekye in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36475">bpo-36475</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<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>The <a class="reference internal" href="../library/os.html#os.getcwdb" title="os.getcwdb"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.getcwdb()</span></code></a> function now uses the UTF-8 encoding on Windows,
|
||
rather than the ANSI code page: see <span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0529/"><strong>PEP 529</strong></a> for the rationale. The
|
||
function is no longer deprecated on Windows.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37412">bpo-37412</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a> can now use <a class="reference internal" href="../library/os.html#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.posix_spawn()</span></code></a> in some cases
|
||
for better performance. On Windows Subsystem for Linux and QEMU User
|
||
Emulation, the <code class="xref py py-class docutils literal notranslate"><span class="pre">Popen</span></code> constructor using <a class="reference internal" href="../library/os.html#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.posix_spawn()</span></code></a> no longer raises an
|
||
exception on errors like “missing program”. Instead the child process fails with a
|
||
non-zero <code class="xref py py-attr docutils literal notranslate"><span class="pre">returncode</span></code>.
|
||
(Contributed by Joannah Nanjekye and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35537">bpo-35537</a>.)</p></li>
|
||
<li><p>The <em>preexec_fn</em> argument of * <a class="reference internal" href="../library/subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a> is no longer
|
||
compatible with subinterpreters. The use of the parameter in a
|
||
subinterpreter now raises <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>.
|
||
(Contributed by Eric Snow in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34651">bpo-34651</a>, modified by Christian Heimes
|
||
in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37951">bpo-37951</a>.)</p></li>
|
||
<li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">imap.IMAP4.logout()</span></code> method no longer silently ignores arbitrary
|
||
exceptions.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36348">bpo-36348</a>.)</p></li>
|
||
<li><p>The function <code class="xref py py-func docutils literal notranslate"><span class="pre">platform.popen()</span></code> has been removed, after having been deprecated since
|
||
Python 3.3: use <a class="reference internal" href="../library/os.html#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.popen()</span></code></a> instead.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35345">bpo-35345</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/statistics.html#statistics.mode" title="statistics.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.mode()</span></code></a> function no longer raises an exception
|
||
when given multimodal data. Instead, it returns the first mode
|
||
encountered in the input data. (Contributed by Raymond Hettinger
|
||
in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35892">bpo-35892</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/tkinter.ttk.html#tkinter.ttk.Treeview.selection" title="tkinter.ttk.Treeview.selection"><code class="xref py py-meth docutils literal notranslate"><span class="pre">selection()</span></code></a> method of the
|
||
<a class="reference internal" href="../library/tkinter.ttk.html#tkinter.ttk.Treeview" title="tkinter.ttk.Treeview"><code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.ttk.Treeview</span></code></a> class no longer takes arguments. Using it with
|
||
arguments for changing the selection was deprecated in Python 3.6. Use
|
||
specialized methods like <a class="reference internal" href="../library/tkinter.ttk.html#tkinter.ttk.Treeview.selection_set" title="tkinter.ttk.Treeview.selection_set"><code class="xref py py-meth docutils literal notranslate"><span class="pre">selection_set()</span></code></a> for
|
||
changing the selection. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=31508">bpo-31508</a>.)</p></li>
|
||
<li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">writexml()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">toxml()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">toprettyxml()</span></code> methods of
|
||
<a class="reference internal" href="../library/xml.dom.minidom.html#module-xml.dom.minidom" title="xml.dom.minidom: Minimal Document Object Model (DOM) implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code></a>, and the <code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code> method of <code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree</span></code>,
|
||
now preserve the attribute order specified by the user.
|
||
(Contributed by Diego Rojas and Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=34160">bpo-34160</a>.)</p></li>
|
||
<li><p>A <a class="reference internal" href="../library/dbm.html#module-dbm.dumb" title="dbm.dumb: Portable implementation of the simple DBM interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.dumb</span></code></a> database opened with flags <code class="docutils literal notranslate"><span class="pre">'r'</span></code> is now read-only.
|
||
<a class="reference internal" href="../library/dbm.html#dbm.dumb.open" title="dbm.dumb.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">dbm.dumb.open()</span></code></a> with flags <code class="docutils literal notranslate"><span class="pre">'r'</span></code> and <code class="docutils literal notranslate"><span class="pre">'w'</span></code> no longer creates
|
||
a database if it does not exist.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32749">bpo-32749</a>.)</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">doctype()</span></code> method defined in a subclass of
|
||
<a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLParser" title="xml.etree.ElementTree.XMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLParser</span></code></a> will no longer be called and will
|
||
emit a <a class="reference internal" href="../library/exceptions.html#RuntimeWarning" title="RuntimeWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeWarning</span></code></a> instead of 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>.
|
||
Define the <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.TreeBuilder.doctype" title="xml.etree.ElementTree.TreeBuilder.doctype"><code class="xref py py-meth docutils literal notranslate"><span class="pre">doctype()</span></code></a>
|
||
method on a target for handling an XML doctype declaration.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=29209">bpo-29209</a>.)</p></li>
|
||
<li><p>A <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> is now raised when the custom metaclass doesn’t
|
||
provide the <code class="docutils literal notranslate"><span class="pre">__classcell__</span></code> entry in the namespace passed to
|
||
<code class="docutils literal notranslate"><span class="pre">type.__new__</span></code>. A <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> was emitted in Python
|
||
3.6–3.7. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23722">bpo-23722</a>.)</p></li>
|
||
<li><p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">cProfile.Profile</span></code> class can now be used as a context
|
||
manager. (Contributed by Scott Sanderson in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=29235">bpo-29235</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copyfile()</span></code></a>, <a class="reference internal" href="../library/shutil.html#shutil.copy" title="shutil.copy"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copy()</span></code></a>, <a class="reference internal" href="../library/shutil.html#shutil.copy2" title="shutil.copy2"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copy2()</span></code></a>,
|
||
<a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copytree()</span></code></a> and <a class="reference internal" href="../library/shutil.html#shutil.move" title="shutil.move"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.move()</span></code></a> use platform-specific
|
||
“fast-copy” syscalls (see
|
||
<a class="reference internal" href="../library/shutil.html#shutil-platform-dependent-efficient-copy-operations"><span class="std std-ref">Platform-dependent efficient copy operations</span></a> section).</p></li>
|
||
<li><p><a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copyfile()</span></code></a> default buffer size on Windows was changed from
|
||
16 KiB to 1 MiB.</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">PyGC_Head</span></code> struct has changed completely. All code that touched the
|
||
struct member should be rewritten. (See <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33597">bpo-33597</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../c-api/init.html#c.PyInterpreterState" title="PyInterpreterState"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyInterpreterState</span></code></a> struct has been moved into the “internal”
|
||
header files (specifically Include/internal/pycore_pystate.h). An
|
||
opaque <code class="docutils literal notranslate"><span class="pre">PyInterpreterState</span></code> is still available as part of the public
|
||
API (and stable ABI). The docs indicate that none of the struct’s
|
||
fields are public, so we hope no one has been using them. However,
|
||
if you do rely on one or more of those private fields and have no
|
||
alternative then please open a BPO issue. We’ll work on helping
|
||
you adjust (possibly including adding accessor functions to the
|
||
public API). (See <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35886">bpo-35886</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/mmap.html#mmap.mmap.flush" title="mmap.mmap.flush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">mmap.flush()</span></code></a> method now returns <code class="docutils literal notranslate"><span class="pre">None</span></code> on
|
||
success and raises an exception on error under all platforms. Previously,
|
||
its behavior was platform-dependent: a nonzero value was returned on success;
|
||
zero was returned on error under Windows. A zero value was returned on
|
||
success; an exception was raised on error under Unix.
|
||
(Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=2122">bpo-2122</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/xml.dom.minidom.html#module-xml.dom.minidom" title="xml.dom.minidom: Minimal Document Object Model (DOM) implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code></a> and <a class="reference internal" href="../library/xml.sax.html#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code></a> modules no longer process
|
||
external entities by default.
|
||
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=17239">bpo-17239</a>.)</p></li>
|
||
<li><p>Deleting a key from a read-only <a class="reference internal" href="../library/dbm.html#module-dbm" title="dbm: Interfaces to various Unix "database" formats."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm</span></code></a> database (<a class="reference internal" href="../library/dbm.html#module-dbm.dumb" title="dbm.dumb: Portable implementation of the simple DBM interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.dumb</span></code></a>,
|
||
<a class="reference internal" href="../library/dbm.html#module-dbm.gnu" title="dbm.gnu: GNU database manager (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.gnu</span></code></a> or <a class="reference internal" href="../library/dbm.html#module-dbm.ndbm" title="dbm.ndbm: The New Database Manager (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.ndbm</span></code></a>) raises <code class="xref py py-attr docutils literal notranslate"><span class="pre">error</span></code> (<a class="reference internal" href="../library/dbm.html#dbm.dumb.error" title="dbm.dumb.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">dbm.dumb.error</span></code></a>,
|
||
<a class="reference internal" href="../library/dbm.html#dbm.gnu.error" title="dbm.gnu.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">dbm.gnu.error</span></code></a> or <a class="reference internal" href="../library/dbm.html#dbm.ndbm.error" title="dbm.ndbm.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">dbm.ndbm.error</span></code></a>) instead of <a class="reference internal" href="../library/exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a>.
|
||
(Contributed by Xiang Zhang in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33106">bpo-33106</a>.)</p></li>
|
||
<li><p>Simplified AST for literals. All constants will be represented as
|
||
<a class="reference internal" href="../library/ast.html#ast.Constant" title="ast.Constant"><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Constant</span></code></a> instances. Instantiating old classes <code class="docutils literal notranslate"><span class="pre">Num</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">Str</span></code>, <code class="docutils literal notranslate"><span class="pre">Bytes</span></code>, <code class="docutils literal notranslate"><span class="pre">NameConstant</span></code> and <code class="docutils literal notranslate"><span class="pre">Ellipsis</span></code> will return
|
||
an instance of <code class="docutils literal notranslate"><span class="pre">Constant</span></code>.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32892">bpo-32892</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/os.path.html#os.path.expanduser" title="os.path.expanduser"><code class="xref py py-func docutils literal notranslate"><span class="pre">expanduser()</span></code></a> on Windows now prefers the <span class="target" id="index-20"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">USERPROFILE</span></code>
|
||
environment variable and does not use <span class="target" id="index-21"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">HOME</span></code>, which is not normally
|
||
set for regular user accounts.
|
||
(Contributed by Anthony Sottile in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36264">bpo-36264</a>.)</p></li>
|
||
<li><p>The exception <a class="reference internal" href="../library/asyncio-exceptions.html#asyncio.CancelledError" title="asyncio.CancelledError"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.CancelledError</span></code></a> now inherits from
|
||
<a class="reference internal" href="../library/exceptions.html#BaseException" title="BaseException"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseException</span></code></a> rather than <a class="reference internal" href="../library/exceptions.html#Exception" title="Exception"><code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></a> and no longer inherits
|
||
from <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.CancelledError" title="concurrent.futures.CancelledError"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.CancelledError</span></code></a>.
|
||
(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32528">bpo-32528</a>.)</p></li>
|
||
<li><p>The function <a class="reference internal" href="../library/asyncio-task.html#asyncio.wait_for" title="asyncio.wait_for"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.wait_for()</span></code></a> now correctly waits for cancellation
|
||
when using an instance of <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a>. Previously, upon reaching
|
||
<em>timeout</em>, it was cancelled and immediately returned.
|
||
(Contributed by Elvis Pranskevichus in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32751">bpo-32751</a>.)</p></li>
|
||
<li><p>The function <a class="reference internal" href="../library/asyncio-protocol.html#asyncio.BaseTransport.get_extra_info" title="asyncio.BaseTransport.get_extra_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.BaseTransport.get_extra_info()</span></code></a> now returns a safe
|
||
to use socket object when ‘socket’ is passed to the <em>name</em> parameter.
|
||
(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37027">bpo-37027</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/asyncio-protocol.html#asyncio.BufferedProtocol" title="asyncio.BufferedProtocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.BufferedProtocol</span></code></a> has graduated to the stable API.</p></li>
|
||
</ul>
|
||
<ul class="simple" id="bpo-36085-whatsnew">
|
||
<li><p>DLL dependencies for extension modules and DLLs loaded with <a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a> on
|
||
Windows are now resolved more securely. Only the system paths, the directory
|
||
containing the DLL or PYD file, and directories added with
|
||
<a class="reference internal" href="../library/os.html#os.add_dll_directory" title="os.add_dll_directory"><code class="xref py py-func docutils literal notranslate"><span class="pre">add_dll_directory()</span></code></a> are searched for load-time dependencies.
|
||
Specifically, <span class="target" id="index-22"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> and the current working directory are no longer
|
||
used, and modifications to these will no longer have any effect on normal DLL
|
||
resolution. If your application relies on these mechanisms, you should check
|
||
for <a class="reference internal" href="../library/os.html#os.add_dll_directory" title="os.add_dll_directory"><code class="xref py py-func docutils literal notranslate"><span class="pre">add_dll_directory()</span></code></a> and if it exists, use it to add your DLLs
|
||
directory while loading your library. Note that Windows 7 users will need to
|
||
ensure that Windows Update KB2533623 has been installed (this is also verified
|
||
by the installer).
|
||
(Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36085">bpo-36085</a>.)</p></li>
|
||
<li><p>The header files and functions related to pgen have been removed after its
|
||
replacement by a pure Python implementation. (Contributed by Pablo Galindo
|
||
in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36623">bpo-36623</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/types.html#types.CodeType" title="types.CodeType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.CodeType</span></code></a> has a new parameter in the second position of the
|
||
constructor (<em>posonlyargcount</em>) to support positional-only arguments defined
|
||
in <span class="target" id="index-23"></span><a class="pep reference external" href="https://peps.python.org/pep-0570/"><strong>PEP 570</strong></a>. The first argument (<em>argcount</em>) now represents the total
|
||
number of positional arguments (including positional-only arguments). The new
|
||
<code class="docutils literal notranslate"><span class="pre">replace()</span></code> method of <a class="reference internal" href="../library/types.html#types.CodeType" title="types.CodeType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.CodeType</span></code></a> can be used to make the code
|
||
future-proof.</p></li>
|
||
<li><p>The parameter <code class="docutils literal notranslate"><span class="pre">digestmod</span></code> for <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">hmac.new()</span></code></a> no longer uses the MD5 digest
|
||
by default.</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>The <a class="reference internal" href="../c-api/veryhigh.html#c.PyCompilerFlags" title="PyCompilerFlags"><code class="xref c c-struct docutils literal notranslate"><span class="pre">PyCompilerFlags</span></code></a> structure got a new <em>cf_feature_version</em>
|
||
field. It should be initialized to <code class="docutils literal notranslate"><span class="pre">PY_MINOR_VERSION</span></code>. The field is ignored
|
||
by default, and is used if and only if <code class="docutils literal notranslate"><span class="pre">PyCF_ONLY_AST</span></code> flag is set in
|
||
<em>cf_flags</em>.
|
||
(Contributed by Guido van Rossum in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35766">bpo-35766</a>.)</p></li>
|
||
<li><p>The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_ReInitThreads()</span></code> function has been removed from the C API.
|
||
It should not be called explicitly: use <a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork_Child" title="PyOS_AfterFork_Child"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Child()</span></code></a>
|
||
instead.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36728">bpo-36728</a>.)</p></li>
|
||
<li><p>On Unix, C extensions are no longer linked to libpython except on Android
|
||
and Cygwin. When Python is embedded, <code class="docutils literal notranslate"><span class="pre">libpython</span></code> must not be loaded with
|
||
<code class="docutils literal notranslate"><span class="pre">RTLD_LOCAL</span></code>, but <code class="docutils literal notranslate"><span class="pre">RTLD_GLOBAL</span></code> instead. Previously, using
|
||
<code class="docutils literal notranslate"><span class="pre">RTLD_LOCAL</span></code>, it was already not possible to load C extensions which
|
||
were not linked to <code class="docutils literal notranslate"><span class="pre">libpython</span></code>, like C extensions of the standard
|
||
library built by the <code class="docutils literal notranslate"><span class="pre">*shared*</span></code> section of <code class="docutils literal notranslate"><span class="pre">Modules/Setup</span></code>.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=21536">bpo-21536</a>.)</p></li>
|
||
<li><p>Use of <code class="docutils literal notranslate"><span class="pre">#</span></code> variants of formats in parsing or building value (e.g.
|
||
<a class="reference internal" href="../c-api/arg.html#c.PyArg_ParseTuple" title="PyArg_ParseTuple"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTuple()</span></code></a>, <a class="reference internal" href="../c-api/arg.html#c.Py_BuildValue" title="Py_BuildValue"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_BuildValue()</span></code></a>, <a class="reference internal" href="../c-api/call.html#c.PyObject_CallFunction" title="PyObject_CallFunction"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CallFunction()</span></code></a>,
|
||
etc.) without <code class="docutils literal notranslate"><span class="pre">PY_SSIZE_T_CLEAN</span></code> defined raises <code class="docutils literal notranslate"><span class="pre">DeprecationWarning</span></code> now.
|
||
It will be removed in 3.10 or 4.0. Read <a class="reference internal" href="../c-api/arg.html#arg-parsing"><span class="std std-ref">Parsing arguments and building values</span></a> for detail.
|
||
(Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36381">bpo-36381</a>.)</p></li>
|
||
<li><p>Instances of heap-allocated types (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>) hold a reference to their type object.
|
||
Increasing the reference count of these type objects has been moved from
|
||
<a class="reference internal" href="../c-api/type.html#c.PyType_GenericAlloc" title="PyType_GenericAlloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GenericAlloc()</span></code></a> to the more low-level functions,
|
||
<a class="reference internal" href="../c-api/allocation.html#c.PyObject_Init" title="PyObject_Init"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Init()</span></code></a> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_INIT()</span></code>.
|
||
This makes types created through <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> behave like
|
||
other classes in managed code.</p>
|
||
<p><a class="reference internal" href="../c-api/typeobj.html#static-types"><span class="std std-ref">Statically allocated types</span></a> are not affected.</p>
|
||
<p>For the vast majority of cases, there should be no side effect.
|
||
However, types that manually increase the reference count after allocating
|
||
an instance (perhaps to work around the bug) may now become immortal.
|
||
To avoid this, these classes need to call Py_DECREF on the type object
|
||
during instance deallocation.</p>
|
||
<p>To correctly port these types into 3.8, please apply the following
|
||
changes:</p>
|
||
<ul>
|
||
<li><p>Remove <a class="reference internal" href="../c-api/refcounting.html#c.Py_INCREF" title="Py_INCREF"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_INCREF</span></code></a> on the type object after allocating an
|
||
instance - if any.
|
||
This may happen after calling <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>,
|
||
<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>, <a class="reference internal" href="../c-api/gcsupport.html#c.PyObject_GC_New" title="PyObject_GC_New"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GC_New()</span></code></a>,
|
||
<a class="reference internal" href="../c-api/gcsupport.html#c.PyObject_GC_NewVar" title="PyObject_GC_NewVar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GC_NewVar()</span></code></a>, or any other custom allocator that uses
|
||
<a class="reference internal" href="../c-api/allocation.html#c.PyObject_Init" title="PyObject_Init"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Init()</span></code></a> or <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_INIT()</span></code>.</p>
|
||
<p>Example:</p>
|
||
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">static</span><span class="w"> </span><span class="n">foo_struct</span><span class="w"> </span><span class="o">*</span>
|
||
<span class="nf">foo_new</span><span class="p">(</span><span class="n">PyObject</span><span class="w"> </span><span class="o">*</span><span class="n">type</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||
<span class="w"> </span><span class="n">foo_struct</span><span class="w"> </span><span class="o">*</span><span class="n">foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyObject_GC_New</span><span class="p">(</span><span class="n">foo_struct</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">PyTypeObject</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="w"> </span><span class="n">type</span><span class="p">);</span>
|
||
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">foo</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span>
|
||
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span>
|
||
<span class="cp">#if PY_VERSION_HEX < 0x03080000</span>
|
||
<span class="w"> </span><span class="c1">// Workaround for Python issue 35810; no longer necessary in Python 3.8</span>
|
||
<span class="w"> </span><span class="n">PY_INCREF</span><span class="p">(</span><span class="n">type</span><span class="p">)</span>
|
||
<span class="cp">#endif</span>
|
||
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">foo</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>Ensure that all custom <code class="docutils literal notranslate"><span class="pre">tp_dealloc</span></code> functions of heap-allocated types
|
||
decrease the type’s reference count.</p>
|
||
<p>Example:</p>
|
||
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">static</span><span class="w"> </span><span class="kt">void</span>
|
||
<span class="nf">foo_dealloc</span><span class="p">(</span><span class="n">foo_struct</span><span class="w"> </span><span class="o">*</span><span class="n">instance</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
|
||
<span class="w"> </span><span class="n">PyObject</span><span class="w"> </span><span class="o">*</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Py_TYPE</span><span class="p">(</span><span class="n">instance</span><span class="p">);</span>
|
||
<span class="w"> </span><span class="n">PyObject_GC_Del</span><span class="p">(</span><span class="n">instance</span><span class="p">);</span>
|
||
<span class="cp">#if PY_VERSION_HEX >= 0x03080000</span>
|
||
<span class="w"> </span><span class="c1">// This was not needed before Python 3.8 (Python issue 35810)</span>
|
||
<span class="w"> </span><span class="n">Py_DECREF</span><span class="p">(</span><span class="n">type</span><span class="p">);</span>
|
||
<span class="cp">#endif</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
<p>(Contributed by Eddie Elizondo in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35810">bpo-35810</a>.)</p>
|
||
</li>
|
||
<li><p>The <a class="reference internal" href="../c-api/intro.html#c.Py_DEPRECATED" title="Py_DEPRECATED"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_DEPRECATED()</span></code></a> macro has been implemented for MSVC.
|
||
The macro now must be placed before the symbol name.</p>
|
||
<p>Example:</p>
|
||
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">Py_DEPRECATED</span><span class="p">(</span><span class="mf">3.8</span><span class="p">)</span><span class="w"> </span><span class="n">PyAPI_FUNC</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="n">Py_OldFunction</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33407">bpo-33407</a>.)</p>
|
||
</li>
|
||
<li><p>The interpreter does not pretend to support binary compatibility of
|
||
extension types across feature releases, anymore. A <a class="reference internal" href="../c-api/type.html#c.PyTypeObject" title="PyTypeObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyTypeObject</span></code></a>
|
||
exported by a third-party extension module is supposed to have all the
|
||
slots expected in the current Python version, including
|
||
<a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_finalize" title="PyTypeObject.tp_finalize"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_finalize</span></code></a> (<a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_HAVE_FINALIZE" title="Py_TPFLAGS_HAVE_FINALIZE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_HAVE_FINALIZE</span></code></a>
|
||
is not checked anymore before reading <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_finalize" title="PyTypeObject.tp_finalize"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_finalize</span></code></a>).</p>
|
||
<p>(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=32388">bpo-32388</a>.)</p>
|
||
</li>
|
||
<li><p>The functions <code class="xref c c-func docutils literal notranslate"><span class="pre">PyNode_AddChild()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyParser_AddToken()</span></code> now accept
|
||
two additional <code class="docutils literal notranslate"><span class="pre">int</span></code> arguments <em>end_lineno</em> and <em>end_col_offset</em>.</p></li>
|
||
<li><p>The <code class="file docutils literal notranslate"><span class="pre">libpython38.a</span></code> file to allow MinGW tools to link directly against
|
||
<code class="file docutils literal notranslate"><span class="pre">python38.dll</span></code> is no longer included in the regular Windows distribution.
|
||
If you require this file, it may be generated with the <code class="docutils literal notranslate"><span class="pre">gendef</span></code> and
|
||
<code class="docutils literal notranslate"><span class="pre">dlltool</span></code> tools, which are part of the MinGW binutils package:</p>
|
||
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>gendef<span class="w"> </span>-<span class="w"> </span>python38.dll<span class="w"> </span>><span class="w"> </span>tmp.def
|
||
dlltool<span class="w"> </span>--dllname<span class="w"> </span>python38.dll<span class="w"> </span>--def<span class="w"> </span>tmp.def<span class="w"> </span>--output-lib<span class="w"> </span>libpython38.a
|
||
</pre></div>
|
||
</div>
|
||
<p>The location of an installed <code class="file docutils literal notranslate"><span class="pre">pythonXY.dll</span></code> will depend on the
|
||
installation options and the version and language of Windows. See
|
||
<a class="reference internal" href="../using/windows.html#using-on-windows"><span class="std std-ref">Using Python on Windows</span></a> for more information. The resulting library should be
|
||
placed in the same directory as <code class="file docutils literal notranslate"><span class="pre">pythonXY.lib</span></code>, which is generally the
|
||
<code class="file docutils literal notranslate"><span class="pre">libs</span></code> directory under your Python installation.</p>
|
||
<p>(Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=37351">bpo-37351</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 interpreter loop has been simplified by moving the logic of unrolling
|
||
the stack of blocks into the compiler. The compiler emits now explicit
|
||
instructions for adjusting the stack of values and calling the
|
||
cleaning-up code for <a class="reference internal" href="../reference/simple_stmts.html#break"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">break</span></code></a>, <a class="reference internal" href="../reference/simple_stmts.html#continue"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">continue</span></code></a> and
|
||
<a class="reference internal" href="../reference/simple_stmts.html#return"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">return</span></code></a>.</p>
|
||
<p>Removed opcodes <code class="xref std std-opcode docutils literal notranslate"><span class="pre">BREAK_LOOP</span></code>, <code class="xref std std-opcode docutils literal notranslate"><span class="pre">CONTINUE_LOOP</span></code>,
|
||
<code class="xref std std-opcode docutils literal notranslate"><span class="pre">SETUP_LOOP</span></code> and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">SETUP_EXCEPT</span></code>. Added new opcodes
|
||
<code class="xref std std-opcode docutils literal notranslate"><span class="pre">ROT_FOUR</span></code>, <code class="xref std std-opcode docutils literal notranslate"><span class="pre">BEGIN_FINALLY</span></code>, <code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FINALLY</span></code> and
|
||
<code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_FINALLY</span></code>. Changed the behavior of <code class="xref std std-opcode docutils literal notranslate"><span class="pre">END_FINALLY</span></code>
|
||
and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">WITH_CLEANUP_START</span></code>.</p>
|
||
<p>(Contributed by Mark Shannon, Antoine Pitrou and Serhiy Storchaka in
|
||
<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=17611">bpo-17611</a>.)</p>
|
||
</li>
|
||
<li><p>Added new opcode <a class="reference internal" href="../library/dis.html#opcode-END_ASYNC_FOR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">END_ASYNC_FOR</span></code></a> for handling exceptions raised
|
||
when awaiting a next item in an <a class="reference internal" href="../reference/compound_stmts.html#async-for"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">for</span></code></a> loop.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33041">bpo-33041</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/dis.html#opcode-MAP_ADD"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">MAP_ADD</span></code></a> now expects the value as the first element in the
|
||
stack and the key as the second element. This change was made so the key
|
||
is always evaluated before the value in dictionary comprehensions, as
|
||
proposed by <span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0572/"><strong>PEP 572</strong></a>. (Contributed by Jörn Heissler in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35224">bpo-35224</a>.)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="demos-and-tools">
|
||
<h3>Demos and Tools<a class="headerlink" href="#demos-and-tools" title="Link to this heading">¶</a></h3>
|
||
<p>Added a benchmark script for timing various ways to access variables:
|
||
<code class="docutils literal notranslate"><span class="pre">Tools/scripts/var_access_benchmark.py</span></code>.
|
||
(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=35884">bpo-35884</a>.)</p>
|
||
<p>Here’s a summary of performance improvements since Python 3.3:</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Python version 3.3 3.4 3.5 3.6 3.7 3.8
|
||
-------------- --- --- --- --- --- ---
|
||
|
||
Variable and attribute read access:
|
||
read_local 4.0 7.1 7.1 5.4 5.1 3.9
|
||
read_nonlocal 5.3 7.1 8.1 5.8 5.4 4.4
|
||
read_global 13.3 15.5 19.0 14.3 13.6 7.6
|
||
read_builtin 20.0 21.1 21.6 18.5 19.0 7.5
|
||
read_classvar_from_class 20.5 25.6 26.5 20.7 19.5 18.4
|
||
read_classvar_from_instance 18.5 22.8 23.5 18.8 17.1 16.4
|
||
read_instancevar 26.8 32.4 33.1 28.0 26.3 25.4
|
||
read_instancevar_slots 23.7 27.8 31.3 20.8 20.8 20.2
|
||
read_namedtuple 68.5 73.8 57.5 45.0 46.8 18.4
|
||
read_boundmethod 29.8 37.6 37.9 29.6 26.9 27.7
|
||
|
||
Variable and attribute write access:
|
||
write_local 4.6 8.7 9.3 5.5 5.3 4.3
|
||
write_nonlocal 7.3 10.5 11.1 5.6 5.5 4.7
|
||
write_global 15.9 19.7 21.2 18.0 18.0 15.8
|
||
write_classvar 81.9 92.9 96.0 104.6 102.1 39.2
|
||
write_instancevar 36.4 44.6 45.8 40.0 38.9 35.5
|
||
write_instancevar_slots 28.7 35.6 36.1 27.3 26.6 25.7
|
||
|
||
Data structure read access:
|
||
read_list 19.2 24.2 24.5 20.8 20.8 19.0
|
||
read_deque 19.9 24.7 25.5 20.2 20.6 19.8
|
||
read_dict 19.7 24.3 25.7 22.3 23.0 21.0
|
||
read_strdict 17.9 22.6 24.3 19.5 21.2 18.9
|
||
|
||
Data structure write access:
|
||
write_list 21.2 27.1 28.5 22.5 21.6 20.0
|
||
write_deque 23.8 28.7 30.1 22.7 21.8 23.5
|
||
write_dict 25.9 31.4 33.3 29.3 29.2 24.7
|
||
write_strdict 22.9 28.4 29.9 27.5 25.2 23.1
|
||
|
||
Stack (or queue) operations:
|
||
list_append_pop 144.2 93.4 112.7 75.4 74.2 50.8
|
||
deque_append_pop 30.4 43.5 57.0 49.4 49.2 42.5
|
||
deque_append_popleft 30.8 43.7 57.3 49.7 49.7 42.8
|
||
|
||
Timing loop:
|
||
loop_overhead 0.3 0.5 0.6 0.4 0.3 0.3
|
||
</pre></div>
|
||
</div>
|
||
<p>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>.
|
||
The benchmark script displays timings in nanoseconds.</p>
|
||
</section>
|
||
</section>
|
||
<section id="notable-changes-in-python-3-8-1">
|
||
<h2>Notable changes in Python 3.8.1<a class="headerlink" href="#notable-changes-in-python-3-8-1" title="Link to this heading">¶</a></h2>
|
||
<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?@action=redirect&bpo=37228">bpo-37228</a>.)</p>
|
||
</section>
|
||
<section id="notable-changes-in-python-3-8-2">
|
||
<h2>Notable changes in Python 3.8.2<a class="headerlink" href="#notable-changes-in-python-3-8-2" title="Link to this heading">¶</a></h2>
|
||
<p>Fixed a regression with the <code class="docutils literal notranslate"><span class="pre">ignore</span></code> callback of <a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copytree()</span></code></a>.
|
||
The argument types are now str and List[str] again.
|
||
(Contributed by Manuel Barkhau and Giampaolo Rodola in <a class="reference external" href="https://github.com/python/cpython/issues/83571">gh-83571</a>.)</p>
|
||
</section>
|
||
<section id="notable-changes-in-python-3-8-3">
|
||
<h2>Notable changes in Python 3.8.3<a class="headerlink" href="#notable-changes-in-python-3-8-3" title="Link to this heading">¶</a></h2>
|
||
<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
|
||
are 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://github.com/python/cpython/issues/83743">gh-83743</a>)</p>
|
||
</section>
|
||
<section id="notable-changes-in-python-3-8-8">
|
||
<h2>Notable changes in Python 3.8.8<a class="headerlink" href="#notable-changes-in-python-3-8-8" title="Link to this heading">¶</a></h2>
|
||
<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">&</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">&</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?@action=redirect&bpo=42967">bpo-42967</a>.)</p>
|
||
</section>
|
||
<section id="notable-changes-in-python-3-8-9">
|
||
<h2>Notable changes in Python 3.8.9<a class="headerlink" href="#notable-changes-in-python-3-8-9" 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-8-10">
|
||
<h2>Notable changes in Python 3.8.10<a class="headerlink" href="#notable-changes-in-python-3-8-10" title="Link to this heading">¶</a></h2>
|
||
<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.8.10, Python now supports building and running on macOS 11
|
||
(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.
|
||
Note that support for “weaklinking”, building binaries targeted for newer
|
||
versions of macOS that will also run correctly on older versions by
|
||
testing at runtime for missing features, is not included in this backport
|
||
from Python 3.9; to support a range of macOS versions, continue to target
|
||
for and build on the oldest version in the range.</p>
|
||
<p>(Originally contributed by Ronald Oussoren and Lawrence D’Anna in <a class="reference external" href="https://github.com/python/cpython/issues/85272">gh-85272</a>,
|
||
with fixes by FX Coudert and Eli Rykoff, and backported to 3.8 by Maxime Bélanger
|
||
and Ned Deily)</p>
|
||
</section>
|
||
</section>
|
||
<section id="id1">
|
||
<h2>Notable changes in Python 3.8.10<a class="headerlink" href="#id1" title="Link to this heading">¶</a></h2>
|
||
<section id="urllib-parse">
|
||
<h3>urllib.parse<a class="headerlink" href="#urllib-parse" 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-25"></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://bugs.python.org/issue?@action=redirect&bpo=43882">bpo-43882</a>)</p>
|
||
</section>
|
||
</section>
|
||
<section id="notable-changes-in-python-3-8-12">
|
||
<h2>Notable changes in Python 3.8.12<a class="headerlink" href="#notable-changes-in-python-3-8-12" title="Link to this heading">¶</a></h2>
|
||
<section id="id2">
|
||
<h3>Changes in the Python API<a class="headerlink" href="#id2" title="Link to this heading">¶</a></h3>
|
||
<p>Starting with Python 3.8.12 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 notation.
|
||
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.</p>
|
||
<p>(Originally contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=36384">bpo-36384</a>, and backported
|
||
to 3.8 by Achraf Merzouki.)</p>
|
||
</section>
|
||
</section>
|
||
<section id="notable-security-feature-in-3-8-14">
|
||
<h2>Notable security feature in 3.8.14<a class="headerlink" href="#notable-security-feature-in-3-8-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-26"></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-8-17">
|
||
<h2>Notable changes in 3.8.17<a class="headerlink" href="#notable-changes-in-3-8-17" title="Link to this heading">¶</a></h2>
|
||
<section id="id3">
|
||
<h3>tarfile<a class="headerlink" href="#id3" 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-27"></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="#">What’s New In Python 3.8</a><ul>
|
||
<li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
|
||
<li><a class="reference internal" href="#new-features">New Features</a><ul>
|
||
<li><a class="reference internal" href="#assignment-expressions">Assignment expressions</a></li>
|
||
<li><a class="reference internal" href="#positional-only-parameters">Positional-only parameters</a></li>
|
||
<li><a class="reference internal" href="#parallel-filesystem-cache-for-compiled-bytecode-files">Parallel filesystem cache for compiled bytecode files</a></li>
|
||
<li><a class="reference internal" href="#debug-build-uses-the-same-abi-as-release-build">Debug build uses the same ABI as release build</a></li>
|
||
<li><a class="reference internal" href="#f-strings-support-for-self-documenting-expressions-and-debugging">f-strings support <code class="docutils literal notranslate"><span class="pre">=</span></code> for self-documenting expressions and debugging</a></li>
|
||
<li><a class="reference internal" href="#pep-578-python-runtime-audit-hooks">PEP 578: Python Runtime Audit Hooks</a></li>
|
||
<li><a class="reference internal" href="#pep-587-python-initialization-configuration">PEP 587: Python Initialization Configuration</a></li>
|
||
<li><a class="reference internal" href="#pep-590-vectorcall-a-fast-calling-protocol-for-cpython">PEP 590: Vectorcall: a fast calling protocol for CPython</a></li>
|
||
<li><a class="reference internal" href="#pickle-protocol-5-with-out-of-band-data-buffers">Pickle protocol 5 with out-of-band data buffers</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
|
||
<li><a class="reference internal" href="#new-modules">New Modules</a></li>
|
||
<li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
|
||
<li><a class="reference internal" href="#ast">ast</a></li>
|
||
<li><a class="reference internal" href="#asyncio">asyncio</a></li>
|
||
<li><a class="reference internal" href="#builtins">builtins</a></li>
|
||
<li><a class="reference internal" href="#collections">collections</a></li>
|
||
<li><a class="reference internal" href="#cprofile">cProfile</a></li>
|
||
<li><a class="reference internal" href="#csv">csv</a></li>
|
||
<li><a class="reference internal" href="#curses">curses</a></li>
|
||
<li><a class="reference internal" href="#ctypes">ctypes</a></li>
|
||
<li><a class="reference internal" href="#datetime">datetime</a></li>
|
||
<li><a class="reference internal" href="#functools">functools</a></li>
|
||
<li><a class="reference internal" href="#gc">gc</a></li>
|
||
<li><a class="reference internal" href="#gettext">gettext</a></li>
|
||
<li><a class="reference internal" href="#gzip">gzip</a></li>
|
||
<li><a class="reference internal" href="#idle-and-idlelib">IDLE and idlelib</a></li>
|
||
<li><a class="reference internal" href="#inspect">inspect</a></li>
|
||
<li><a class="reference internal" href="#io">io</a></li>
|
||
<li><a class="reference internal" href="#itertools">itertools</a></li>
|
||
<li><a class="reference internal" href="#json-tool">json.tool</a></li>
|
||
<li><a class="reference internal" href="#logging">logging</a></li>
|
||
<li><a class="reference internal" href="#math">math</a></li>
|
||
<li><a class="reference internal" href="#mmap">mmap</a></li>
|
||
<li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
|
||
<li><a class="reference internal" href="#os">os</a></li>
|
||
<li><a class="reference internal" href="#os-path">os.path</a></li>
|
||
<li><a class="reference internal" href="#pathlib">pathlib</a></li>
|
||
<li><a class="reference internal" href="#pickle">pickle</a></li>
|
||
<li><a class="reference internal" href="#plistlib">plistlib</a></li>
|
||
<li><a class="reference internal" href="#pprint">pprint</a></li>
|
||
<li><a class="reference internal" href="#py-compile">py_compile</a></li>
|
||
<li><a class="reference internal" href="#shlex">shlex</a></li>
|
||
<li><a class="reference internal" href="#shutil">shutil</a></li>
|
||
<li><a class="reference internal" href="#socket">socket</a></li>
|
||
<li><a class="reference internal" href="#ssl">ssl</a></li>
|
||
<li><a class="reference internal" href="#statistics">statistics</a></li>
|
||
<li><a class="reference internal" href="#sys">sys</a></li>
|
||
<li><a class="reference internal" href="#tarfile">tarfile</a></li>
|
||
<li><a class="reference internal" href="#threading">threading</a></li>
|
||
<li><a class="reference internal" href="#tokenize">tokenize</a></li>
|
||
<li><a class="reference internal" href="#tkinter">tkinter</a></li>
|
||
<li><a class="reference internal" href="#time">time</a></li>
|
||
<li><a class="reference internal" href="#typing">typing</a></li>
|
||
<li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
|
||
<li><a class="reference internal" href="#unittest">unittest</a></li>
|
||
<li><a class="reference internal" href="#venv">venv</a></li>
|
||
<li><a class="reference internal" href="#weakref">weakref</a></li>
|
||
<li><a class="reference internal" href="#xml">xml</a></li>
|
||
<li><a class="reference internal" href="#xmlrpc">xmlrpc</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#optimizations">Optimizations</a></li>
|
||
<li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
|
||
<li><a class="reference internal" href="#deprecated">Deprecated</a></li>
|
||
<li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
|
||
<li><a class="reference internal" href="#porting-to-python-3-8">Porting to Python 3.8</a><ul>
|
||
<li><a class="reference internal" href="#changes-in-python-behavior">Changes in Python behavior</a></li>
|
||
<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>
|
||
<li><a class="reference internal" href="#demos-and-tools">Demos and Tools</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-8-1">Notable changes in Python 3.8.1</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-8-2">Notable changes in Python 3.8.2</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-8-3">Notable changes in Python 3.8.3</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-8-8">Notable changes in Python 3.8.8</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-8-9">Notable changes in Python 3.8.9</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-8-10">Notable changes in Python 3.8.10</a><ul>
|
||
<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="#id1">Notable changes in Python 3.8.10</a><ul>
|
||
<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-8-12">Notable changes in Python 3.8.12</a><ul>
|
||
<li><a class="reference internal" href="#id2">Changes in the Python API</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#notable-security-feature-in-3-8-14">Notable security feature in 3.8.14</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-3-8-17">Notable changes in 3.8.17</a><ul>
|
||
<li><a class="reference internal" href="#id3">tarfile</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
</div>
|
||
<div>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="3.9.html"
|
||
title="previous chapter">What’s New In Python 3.9</a></p>
|
||
</div>
|
||
<div>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="3.7.html"
|
||
title="next chapter">What’s New In Python 3.7</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.8.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.7.html" title="What’s New In Python 3.7"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.9.html" title="What’s New In Python 3.9"
|
||
>previous</a> |</li>
|
||
|
||
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
|
||
<li><a href="https://www.python.org/">Python</a> »</li>
|
||
<li class="switchers">
|
||
<div class="language_switcher_placeholder"></div>
|
||
<div class="version_switcher_placeholder"></div>
|
||
</li>
|
||
<li>
|
||
|
||
</li>
|
||
<li id="cpython-language-and-version">
|
||
<a href="../index.html">3.13.3 Documentation</a> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">What’s New In Python 3.8</a></li>
|
||
<li class="right">
|
||
|
||
|
||
<div class="inline-search" role="search">
|
||
<form class="inline-search" action="../search.html" method="get">
|
||
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
|
|
||
</li>
|
||
<li class="right">
|
||
<label class="theme-selector-label">
|
||
Theme
|
||
<select class="theme-selector" oninput="activateTheme(this.value)">
|
||
<option value="auto" selected>Auto</option>
|
||
<option value="light">Light</option>
|
||
<option value="dark">Dark</option>
|
||
</select>
|
||
</label> |</li>
|
||
|
||
</ul>
|
||
</div>
|
||
<div class="footer">
|
||
©
|
||
<a href="../copyright.html">
|
||
|
||
Copyright
|
||
|
||
</a>
|
||
2001-2025, Python Software Foundation.
|
||
<br />
|
||
This page is licensed under the Python Software Foundation License Version 2.
|
||
<br />
|
||
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
|
||
<br />
|
||
|
||
See <a href="/license.html">History and License</a> for more information.<br />
|
||
|
||
|
||
<br />
|
||
|
||
The Python Software Foundation is a non-profit corporation.
|
||
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
||
<br />
|
||
<br />
|
||
Last updated on Apr 08, 2025 (14:33 UTC).
|
||
|
||
<a href="/bugs.html">Found a bug</a>?
|
||
|
||
<br />
|
||
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
|
||
</div>
|
||
|
||
</body>
|
||
</html> |