2421 lines
304 KiB
HTML
2421 lines
304 KiB
HTML
|
|
|||
|
<!DOCTYPE html>
|
|||
|
|
|||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|||
|
<head>
|
|||
|
<meta charset="utf-8" />
|
|||
|
<title>What’s New In Python 3.5 — Python 3.7.4 documentation</title>
|
|||
|
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
|||
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|||
|
|
|||
|
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/jquery.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/underscore.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/doctools.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/language_data.js"></script>
|
|||
|
|
|||
|
<script type="text/javascript" src="../_static/sidebar.js"></script>
|
|||
|
|
|||
|
<link rel="search" type="application/opensearchdescription+xml"
|
|||
|
title="Search within Python 3.7.4 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.4" href="3.4.html" />
|
|||
|
<link rel="prev" title="What’s New In Python 3.6" href="3.6.html" />
|
|||
|
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
|
|||
|
<link rel="canonical" href="https://docs.python.org/3/whatsnew/3.5.html" />
|
|||
|
|
|||
|
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/switchers.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<style>
|
|||
|
@media only screen {
|
|||
|
table.full-width-table {
|
|||
|
width: 100%;
|
|||
|
}
|
|||
|
}
|
|||
|
</style>
|
|||
|
|
|||
|
|
|||
|
</head><body>
|
|||
|
|
|||
|
<div class="related" role="navigation" aria-label="related navigation">
|
|||
|
<h3>Navigation</h3>
|
|||
|
<ul>
|
|||
|
<li class="right" style="margin-right: 10px">
|
|||
|
<a href="../genindex.html" title="General Index"
|
|||
|
accesskey="I">index</a></li>
|
|||
|
<li class="right" >
|
|||
|
<a href="../py-modindex.html" title="Python Module Index"
|
|||
|
>modules</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="3.4.html" title="What’s New In Python 3.4"
|
|||
|
accesskey="N">next</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="3.6.html" title="What’s New In Python 3.6"
|
|||
|
accesskey="P">previous</a> |</li>
|
|||
|
<li><img src="../_static/py.png" alt=""
|
|||
|
style="vertical-align: middle; margin-top: -1px"/></li>
|
|||
|
<li><a href="https://www.python.org/">Python</a> »</li>
|
|||
|
<li>
|
|||
|
<span class="language_switcher_placeholder">en</span>
|
|||
|
<span class="version_switcher_placeholder">3.7.4</span>
|
|||
|
<a href="../index.html">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="right">
|
|||
|
|
|||
|
|
|||
|
<div class="inline-search" style="display: none" role="search">
|
|||
|
<form class="inline-search" action="../search.html" method="get">
|
|||
|
<input placeholder="Quick search" type="text" name="q" />
|
|||
|
<input type="submit" value="Go" />
|
|||
|
<input type="hidden" name="check_keywords" value="yes" />
|
|||
|
<input type="hidden" name="area" value="default" />
|
|||
|
</form>
|
|||
|
</div>
|
|||
|
<script type="text/javascript">$('.inline-search').show(0);</script>
|
|||
|
|
|
|||
|
</li>
|
|||
|
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="document">
|
|||
|
<div class="documentwrapper">
|
|||
|
<div class="bodywrapper">
|
|||
|
<div class="body" role="main">
|
|||
|
|
|||
|
<div class="section" id="what-s-new-in-python-3-5">
|
|||
|
<h1>What’s New In Python 3.5<a class="headerlink" href="#what-s-new-in-python-3-5" title="Permalink to this headline">¶</a></h1>
|
|||
|
<dl class="field-list simple">
|
|||
|
<dt class="field-odd">Editors</dt>
|
|||
|
<dd class="field-odd"><p>Elvis Pranskevichus <<a class="reference external" href="mailto:elvis%40magic.io">elvis<span>@</span>magic<span>.</span>io</a>>, Yury Selivanov <<a class="reference external" href="mailto:yury%40magic.io">yury<span>@</span>magic<span>.</span>io</a>></p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
<p>This article explains the new features in Python 3.5, compared to 3.4.
|
|||
|
Python 3.5 was released on September 13, 2015. See the
|
|||
|
<a class="reference external" href="https://docs.python.org/3.5/whatsnew/changelog.html">changelog</a> for a full
|
|||
|
list of changes.</p>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<p><span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0478"><strong>PEP 478</strong></a> - Python 3.5 Release Schedule</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="summary-release-highlights">
|
|||
|
<h2>Summary – Release highlights<a class="headerlink" href="#summary-release-highlights" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>New syntax features:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p><a class="reference internal" href="#whatsnew-pep-492"><span class="std std-ref">PEP 492</span></a>, coroutines with async and await syntax.</p></li>
|
|||
|
<li><p><a class="reference internal" href="#whatsnew-pep-465"><span class="std std-ref">PEP 465</span></a>, a new matrix multiplication operator: <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">@</span> <span class="pre">b</span></code>.</p></li>
|
|||
|
<li><p><a class="reference internal" href="#whatsnew-pep-448"><span class="std std-ref">PEP 448</span></a>, additional unpacking generalizations.</p></li>
|
|||
|
</ul>
|
|||
|
<p>New library modules:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p><a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see PEP 484)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a>: <a class="reference internal" href="#whatsnew-pep-484"><span class="std std-ref">PEP 484 – Type Hints</span></a>.</p></li>
|
|||
|
<li><p><a class="reference internal" href="../library/zipapp.html#module-zipapp" title="zipapp: Manage executable Python zip archives"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipapp</span></code></a>: <a class="reference internal" href="#whatsnew-zipapp"><span class="std std-ref">PEP 441 Improving Python ZIP Application Support</span></a>.</p></li>
|
|||
|
</ul>
|
|||
|
<p>New built-in features:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">bytes</span> <span class="pre">%</span> <span class="pre">args</span></code>, <code class="docutils literal notranslate"><span class="pre">bytearray</span> <span class="pre">%</span> <span class="pre">args</span></code>: <a class="reference internal" href="#whatsnew-pep-461"><span class="std std-ref">PEP 461</span></a> –
|
|||
|
Adding <code class="docutils literal notranslate"><span class="pre">%</span></code> formatting to bytes and bytearray.</p></li>
|
|||
|
<li><p>New <a class="reference internal" href="../library/stdtypes.html#bytes.hex" title="bytes.hex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytes.hex()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#bytearray.hex" title="bytearray.hex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytearray.hex()</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#memoryview.hex" title="memoryview.hex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">memoryview.hex()</span></code></a>
|
|||
|
methods. (Contributed by Arnon Yaari in <a class="reference external" href="https://bugs.python.org/issue9951">bpo-9951</a>.)</p></li>
|
|||
|
<li><p><a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-class docutils literal notranslate"><span class="pre">memoryview</span></code></a> now supports tuple indexing (including multi-dimensional).
|
|||
|
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue23632">bpo-23632</a>.)</p></li>
|
|||
|
<li><p>Generators have a new <code class="docutils literal notranslate"><span class="pre">gi_yieldfrom</span></code> attribute, which returns the
|
|||
|
object being iterated by <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> expressions. (Contributed
|
|||
|
by Benno Leslie and Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue24450">bpo-24450</a>.)</p></li>
|
|||
|
<li><p>A new <a class="reference internal" href="../library/exceptions.html#RecursionError" title="RecursionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RecursionError</span></code></a> exception is now raised when maximum
|
|||
|
recursion depth is reached. (Contributed by Georg Brandl
|
|||
|
in <a class="reference external" href="https://bugs.python.org/issue19235">bpo-19235</a>.)</p></li>
|
|||
|
</ul>
|
|||
|
<p>CPython implementation improvements:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>When the <code class="docutils literal notranslate"><span class="pre">LC_TYPE</span></code> locale is the POSIX locale (<code class="docutils literal notranslate"><span class="pre">C</span></code> locale),
|
|||
|
<a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a> now use the
|
|||
|
<code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code> error handler, instead of the <code class="docutils literal notranslate"><span class="pre">strict</span></code> error handler.
|
|||
|
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue19977">bpo-19977</a>.)</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files are no longer used and have been replaced by a more flexible
|
|||
|
scheme that includes the optimization level explicitly in <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> name.
|
|||
|
(See <a class="reference internal" href="#whatsnew-pep-488"><span class="std std-ref">PEP 488 overview</span></a>.)</p></li>
|
|||
|
<li><p>Builtin and extension modules are now initialized in a multi-phase process,
|
|||
|
which is similar to how Python modules are loaded.
|
|||
|
(See <a class="reference internal" href="#whatsnew-pep-489"><span class="std std-ref">PEP 489 overview</span></a>.)</p></li>
|
|||
|
</ul>
|
|||
|
<p>Significant improvements in the standard library:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p><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> is now
|
|||
|
<a class="reference internal" href="#whatsnew-ordereddict"><span class="std std-ref">implemented in C</span></a>, which makes it
|
|||
|
4 to 100 times faster.</p></li>
|
|||
|
<li><p>The <a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a> module gained
|
|||
|
<a class="reference internal" href="#whatsnew-sslmemorybio"><span class="std std-ref">support for Memory BIO</span></a>, which decouples SSL
|
|||
|
protocol handling from network IO.</p></li>
|
|||
|
<li><p>The new <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 provides a
|
|||
|
<a class="reference internal" href="#whatsnew-pep-471"><span class="std std-ref">better and significantly faster way</span></a>
|
|||
|
of directory traversal.</p></li>
|
|||
|
<li><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> has been mostly
|
|||
|
<a class="reference internal" href="#whatsnew-lrucache"><span class="std std-ref">reimplemented in C</span></a>, yielding much better
|
|||
|
performance.</p></li>
|
|||
|
<li><p>The new <a class="reference internal" href="../library/subprocess.html#subprocess.run" title="subprocess.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">subprocess.run()</span></code></a> function provides a
|
|||
|
<a class="reference internal" href="#whatsnew-subprocess"><span class="std std-ref">streamlined way to run subprocesses</span></a>.</p></li>
|
|||
|
<li><p>The <a class="reference internal" href="../library/traceback.html#module-traceback" title="traceback: Print or retrieve a stack traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">traceback</span></code></a> module has been significantly
|
|||
|
<a class="reference internal" href="#whatsnew-traceback"><span class="std std-ref">enhanced</span></a> for improved
|
|||
|
performance and developer convenience.</p></li>
|
|||
|
</ul>
|
|||
|
<p>Security improvements:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>SSLv3 is now disabled throughout the standard library.
|
|||
|
It can still be enabled by instantiating a <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a>
|
|||
|
manually. (See <a class="reference external" href="https://bugs.python.org/issue22638">bpo-22638</a> for more details; this change was
|
|||
|
backported to CPython 3.4 and 2.7.)</p></li>
|
|||
|
<li><p>HTTP cookie parsing is now stricter, in order to protect
|
|||
|
against potential injection attacks. (Contributed by Antoine Pitrou
|
|||
|
in <a class="reference external" href="https://bugs.python.org/issue22796">bpo-22796</a>.)</p></li>
|
|||
|
</ul>
|
|||
|
<p>Windows improvements:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>A new installer for Windows has replaced the old MSI.
|
|||
|
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.</p></li>
|
|||
|
<li><p>Windows builds now use Microsoft Visual C++ 14.0, and extension modules
|
|||
|
should use the same.</p></li>
|
|||
|
</ul>
|
|||
|
<p>Please read on for a comprehensive list of user-facing changes, including many
|
|||
|
other smaller improvements, CPython optimizations, deprecations, and potential
|
|||
|
porting issues.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="new-features">
|
|||
|
<h2>New Features<a class="headerlink" href="#new-features" title="Permalink to this headline">¶</a></h2>
|
|||
|
<div class="section" id="pep-492-coroutines-with-async-and-await-syntax">
|
|||
|
<span id="whatsnew-pep-492"></span><h3>PEP 492 - Coroutines with async and await syntax<a class="headerlink" href="#pep-492-coroutines-with-async-and-await-syntax" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><span class="target" id="index-1"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0492"><strong>PEP 492</strong></a> greatly improves support for asynchronous programming in Python
|
|||
|
by adding <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitable objects</span></a>,
|
|||
|
<a class="reference internal" href="../glossary.html#term-coroutine-function"><span class="xref std std-term">coroutine functions</span></a>,
|
|||
|
<a class="reference internal" href="../glossary.html#term-asynchronous-iterable"><span class="xref std std-term">asynchronous iteration</span></a>,
|
|||
|
and <a class="reference internal" href="../glossary.html#term-asynchronous-context-manager"><span class="xref std std-term">asynchronous context managers</span></a>.</p>
|
|||
|
<p>Coroutine functions are declared using the new <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> syntax:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">async</span> <span class="k">def</span> <span class="nf">coro</span><span class="p">():</span>
|
|||
|
<span class="gp">... </span> <span class="k">return</span> <span class="s1">'spam'</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Inside a coroutine function, the new <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> expression can be used
|
|||
|
to suspend coroutine execution until the result is available. Any object
|
|||
|
can be <em>awaited</em>, as long as it implements the <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitable</span></a> protocol by
|
|||
|
defining the <a class="reference internal" href="../reference/datamodel.html#object.__await__" title="object.__await__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__await__()</span></code></a> method.</p>
|
|||
|
<p>PEP 492 also adds <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> statement for convenient iteration
|
|||
|
over asynchronous iterables.</p>
|
|||
|
<p>An example of a rudimentary HTTP client written using the new syntax:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">asyncio</span>
|
|||
|
|
|||
|
<span class="k">async</span> <span class="k">def</span> <span class="nf">http_get</span><span class="p">(</span><span class="n">domain</span><span class="p">):</span>
|
|||
|
<span class="n">reader</span><span class="p">,</span> <span class="n">writer</span> <span class="o">=</span> <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">open_connection</span><span class="p">(</span><span class="n">domain</span><span class="p">,</span> <span class="mi">80</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="n">writer</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="sa">b</span><span class="s1">'</span><span class="se">\r\n</span><span class="s1">'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span>
|
|||
|
<span class="sa">b</span><span class="s1">'GET / HTTP/1.1'</span><span class="p">,</span>
|
|||
|
<span class="sa">b</span><span class="s1">'Host: %b'</span> <span class="o">%</span> <span class="n">domain</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">'latin-1'</span><span class="p">),</span>
|
|||
|
<span class="sa">b</span><span class="s1">'Connection: close'</span><span class="p">,</span>
|
|||
|
<span class="sa">b</span><span class="s1">''</span><span class="p">,</span> <span class="sa">b</span><span class="s1">''</span>
|
|||
|
<span class="p">]))</span>
|
|||
|
|
|||
|
<span class="k">async</span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">reader</span><span class="p">:</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'>>>'</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="n">writer</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
|||
|
|
|||
|
<span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_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">http_get</span><span class="p">(</span><span class="s1">'example.com'</span><span class="p">))</span>
|
|||
|
<span class="k">finally</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>Similarly to asynchronous iteration, there is a new syntax for asynchronous
|
|||
|
context managers. The following script:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">asyncio</span>
|
|||
|
|
|||
|
<span class="k">async</span> <span class="k">def</span> <span class="nf">coro</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">lock</span><span class="p">):</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'coro </span><span class="si">{}</span><span class="s1">: waiting for lock'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
|
|||
|
<span class="k">async</span> <span class="k">with</span> <span class="n">lock</span><span class="p">:</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'coro </span><span class="si">{}</span><span class="s1">: holding the lock'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</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">1</span><span class="p">)</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'coro </span><span class="si">{}</span><span class="s1">: releasing the lock'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
|
|||
|
|
|||
|
<span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>
|
|||
|
<span class="n">lock</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">Lock</span><span class="p">()</span>
|
|||
|
<span class="n">coros</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">gather</span><span class="p">(</span><span class="n">coro</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">lock</span><span class="p">),</span> <span class="n">coro</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">lock</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">coros</span><span class="p">)</span>
|
|||
|
<span class="k">finally</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>will output:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">coro</span> <span class="mi">2</span><span class="p">:</span> <span class="n">waiting</span> <span class="k">for</span> <span class="n">lock</span>
|
|||
|
<span class="n">coro</span> <span class="mi">2</span><span class="p">:</span> <span class="n">holding</span> <span class="n">the</span> <span class="n">lock</span>
|
|||
|
<span class="n">coro</span> <span class="mi">1</span><span class="p">:</span> <span class="n">waiting</span> <span class="k">for</span> <span class="n">lock</span>
|
|||
|
<span class="n">coro</span> <span class="mi">2</span><span class="p">:</span> <span class="n">releasing</span> <span class="n">the</span> <span class="n">lock</span>
|
|||
|
<span class="n">coro</span> <span class="mi">1</span><span class="p">:</span> <span class="n">holding</span> <span class="n">the</span> <span class="n">lock</span>
|
|||
|
<span class="n">coro</span> <span class="mi">1</span><span class="p">:</span> <span class="n">releasing</span> <span class="n">the</span> <span class="n">lock</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Note that both <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> and <a class="reference internal" href="../reference/compound_stmts.html#async-with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">with</span></code></a> can only
|
|||
|
be used inside a coroutine function declared with <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>.</p>
|
|||
|
<p>Coroutine functions are intended to be run inside a compatible event loop,
|
|||
|
such as the <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio-event-loop"><span class="std std-ref">asyncio loop</span></a>.</p>
|
|||
|
<div class="admonition note">
|
|||
|
<p class="admonition-title">Note</p>
|
|||
|
<div class="versionchanged">
|
|||
|
<p><span class="versionmodified changed">Changed in version 3.5.2: </span>Starting with CPython 3.5.2, <code class="docutils literal notranslate"><span class="pre">__aiter__</span></code> can directly return
|
|||
|
<a class="reference internal" href="../glossary.html#term-asynchronous-iterator"><span class="xref std std-term">asynchronous iterators</span></a>. Returning
|
|||
|
an <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitable</span></a> object will result in a
|
|||
|
<a class="reference internal" href="../library/exceptions.html#PendingDeprecationWarning" title="PendingDeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PendingDeprecationWarning</span></code></a>.</p>
|
|||
|
<p>See more details in the <a class="reference internal" href="../reference/datamodel.html#async-iterators"><span class="std std-ref">Asynchronous Iterators</span></a> documentation
|
|||
|
section.</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<dl class="simple">
|
|||
|
<dt><span class="target" id="index-2"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0492"><strong>PEP 492</strong></a> – Coroutines with async and await syntax</dt><dd><p>PEP written and implemented by Yury Selivanov.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="pep-465-a-dedicated-infix-operator-for-matrix-multiplication">
|
|||
|
<span id="whatsnew-pep-465"></span><h3>PEP 465 - A dedicated infix operator for matrix multiplication<a class="headerlink" href="#pep-465-a-dedicated-infix-operator-for-matrix-multiplication" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><span class="target" id="index-3"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0465"><strong>PEP 465</strong></a> adds the <code class="docutils literal notranslate"><span class="pre">@</span></code> infix operator for matrix multiplication.
|
|||
|
Currently, no builtin Python types implement the new operator, however, it
|
|||
|
can be implemented by defining <a class="reference internal" href="../reference/datamodel.html#object.__matmul__" title="object.__matmul__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__matmul__()</span></code></a>, <a class="reference internal" href="../reference/datamodel.html#object.__rmatmul__" title="object.__rmatmul__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__rmatmul__()</span></code></a>,
|
|||
|
and <a class="reference internal" href="../reference/datamodel.html#object.__imatmul__" title="object.__imatmul__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__imatmul__()</span></code></a> for regular, reflected, and in-place matrix
|
|||
|
multiplication. The semantics of these methods is similar to that of
|
|||
|
methods defining other infix arithmetic operators.</p>
|
|||
|
<p>Matrix multiplication is a notably common operation in many fields of
|
|||
|
mathematics, science, engineering, and the addition of <code class="docutils literal notranslate"><span class="pre">@</span></code> allows writing
|
|||
|
cleaner code:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">S</span> <span class="o">=</span> <span class="p">(</span><span class="n">H</span> <span class="o">@</span> <span class="n">beta</span> <span class="o">-</span> <span class="n">r</span><span class="p">)</span><span class="o">.</span><span class="n">T</span> <span class="o">@</span> <span class="n">inv</span><span class="p">(</span><span class="n">H</span> <span class="o">@</span> <span class="n">V</span> <span class="o">@</span> <span class="n">H</span><span class="o">.</span><span class="n">T</span><span class="p">)</span> <span class="o">@</span> <span class="p">(</span><span class="n">H</span> <span class="o">@</span> <span class="n">beta</span> <span class="o">-</span> <span class="n">r</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>instead of:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">S</span> <span class="o">=</span> <span class="n">dot</span><span class="p">((</span><span class="n">dot</span><span class="p">(</span><span class="n">H</span><span class="p">,</span> <span class="n">beta</span><span class="p">)</span> <span class="o">-</span> <span class="n">r</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="p">,</span>
|
|||
|
<span class="n">dot</span><span class="p">(</span><span class="n">inv</span><span class="p">(</span><span class="n">dot</span><span class="p">(</span><span class="n">dot</span><span class="p">(</span><span class="n">H</span><span class="p">,</span> <span class="n">V</span><span class="p">),</span> <span class="n">H</span><span class="o">.</span><span class="n">T</span><span class="p">)),</span> <span class="n">dot</span><span class="p">(</span><span class="n">H</span><span class="p">,</span> <span class="n">beta</span><span class="p">)</span> <span class="o">-</span> <span class="n">r</span><span class="p">))</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>NumPy 1.10 has support for the new operator:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">numpy</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="n">x</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">x</span>
|
|||
|
<span class="go">array([ 1., 1., 1.])</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="n">m</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">m</span>
|
|||
|
<span class="go">array([[ 1., 0., 0.],</span>
|
|||
|
<span class="go"> [ 0., 1., 0.],</span>
|
|||
|
<span class="go"> [ 0., 0., 1.]])</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="n">x</span> <span class="o">@</span> <span class="n">m</span>
|
|||
|
<span class="go">array([ 1., 1., 1.])</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<dl class="simple">
|
|||
|
<dt><span class="target" id="index-4"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0465"><strong>PEP 465</strong></a> – A dedicated infix operator for matrix multiplication</dt><dd><p>PEP written by Nathaniel J. Smith; implemented by Benjamin Peterson.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="pep-448-additional-unpacking-generalizations">
|
|||
|
<span id="whatsnew-pep-448"></span><h3>PEP 448 - Additional Unpacking Generalizations<a class="headerlink" href="#pep-448-additional-unpacking-generalizations" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><span class="target" id="index-5"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0448"><strong>PEP 448</strong></a> extends the allowed uses of the <code class="docutils literal notranslate"><span class="pre">*</span></code> iterable unpacking
|
|||
|
operator and <code class="docutils literal notranslate"><span class="pre">**</span></code> dictionary unpacking operator. It is now possible
|
|||
|
to use an arbitrary number of unpackings in <a class="reference internal" href="../reference/expressions.html#calls"><span class="std std-ref">function calls</span></a>:</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="o">*</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="o">*</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="mi">3</span><span class="p">,</span> <span class="o">*</span><span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span>
|
|||
|
<span class="go">1 2 3 4 5</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="k">def</span> <span class="nf">fn</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="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">c</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span>
|
|||
|
<span class="gp">...</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="n">fn</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="s1">'a'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'c'</span><span class="p">:</span> <span class="mi">3</span><span class="p">},</span> <span class="o">**</span><span class="p">{</span><span class="s1">'b'</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">'d'</span><span class="p">:</span> <span class="mi">4</span><span class="p">})</span>
|
|||
|
<span class="go">1 2 3 4</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Similarly, tuple, list, set, and dictionary displays allow multiple
|
|||
|
unpackings (see <a class="reference internal" href="../reference/expressions.html#exprlists"><span class="std std-ref">Expression lists</span></a> and <a class="reference internal" href="../reference/expressions.html#dict"><span class="std std-ref">Dictionary displays</span></a>):</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="o">*</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span> <span class="mi">4</span>
|
|||
|
<span class="go">(0, 1, 2, 3, 4)</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="p">[</span><span class="o">*</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span> <span class="mi">4</span><span class="p">]</span>
|
|||
|
<span class="go">[0, 1, 2, 3, 4]</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="p">{</span><span class="o">*</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span> <span class="mi">4</span><span class="p">,</span> <span class="o">*</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">7</span><span class="p">)}</span>
|
|||
|
<span class="go">{0, 1, 2, 3, 4, 5, 6, 7}</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="p">{</span><span class="s1">'x'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="s1">'y'</span><span class="p">:</span> <span class="mi">2</span><span class="p">}}</span>
|
|||
|
<span class="go">{'x': 1, 'y': 2}</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<dl class="simple">
|
|||
|
<dt><span class="target" id="index-6"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0448"><strong>PEP 448</strong></a> – Additional Unpacking Generalizations</dt><dd><p>PEP written by Joshua Landau; implemented by Neil Girdhar,
|
|||
|
Thomas Wouters, and Joshua Landau.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="pep-461-percent-formatting-support-for-bytes-and-bytearray">
|
|||
|
<span id="whatsnew-pep-461"></span><h3>PEP 461 - percent formatting support for bytes and bytearray<a class="headerlink" href="#pep-461-percent-formatting-support-for-bytes-and-bytearray" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><span class="target" id="index-7"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0461"><strong>PEP 461</strong></a> adds support for the <code class="docutils literal notranslate"><span class="pre">%</span></code>
|
|||
|
<a class="reference internal" href="../library/stdtypes.html#bytes-formatting"><span class="std std-ref">interpolation operator</span></a> to <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>
|
|||
|
and <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a>.</p>
|
|||
|
<p>While interpolation is usually thought of as a string operation, there are
|
|||
|
cases where interpolation on <code class="docutils literal notranslate"><span class="pre">bytes</span></code> or <code class="docutils literal notranslate"><span class="pre">bytearrays</span></code> makes sense, and the
|
|||
|
work needed to make up for this missing functionality detracts from the
|
|||
|
overall readability of the code. This issue is particularly important when
|
|||
|
dealing with wire format protocols, which are often a mixture of binary
|
|||
|
and ASCII compatible text.</p>
|
|||
|
<p>Examples:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="sa">b</span><span class="s1">'Hello %b!'</span> <span class="o">%</span> <span class="sa">b</span><span class="s1">'World'</span>
|
|||
|
<span class="go">b'Hello World!'</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="sa">b</span><span class="s1">'x=</span><span class="si">%i</span><span class="s1"> y=</span><span class="si">%f</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mf">2.5</span><span class="p">)</span>
|
|||
|
<span class="go">b'x=1 y=2.500000'</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Unicode is not allowed for <code class="docutils literal notranslate"><span class="pre">%b</span></code>, but it is accepted by <code class="docutils literal notranslate"><span class="pre">%a</span></code> (equivalent of
|
|||
|
<code class="docutils literal notranslate"><span class="pre">repr(obj).encode('ascii',</span> <span class="pre">'backslashreplace')</span></code>):</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="sa">b</span><span class="s1">'Hello %b!'</span> <span class="o">%</span> <span class="s1">'World'</span>
|
|||
|
<span class="gt">Traceback (most recent call last):</span>
|
|||
|
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
|
|||
|
<span class="gr">TypeError</span>: <span class="n">%b requires bytes, or an object that implements __bytes__, not 'str'</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="sa">b</span><span class="s1">'price: </span><span class="si">%a</span><span class="s1">'</span> <span class="o">%</span> <span class="s1">'10€'</span>
|
|||
|
<span class="go">b"price: '10\\u20ac'"</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Note that <code class="docutils literal notranslate"><span class="pre">%s</span></code> and <code class="docutils literal notranslate"><span class="pre">%r</span></code> conversion types, although supported, should
|
|||
|
only be used in codebases that need compatibility with Python 2.</p>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<dl class="simple">
|
|||
|
<dt><span class="target" id="index-8"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0461"><strong>PEP 461</strong></a> – Adding % formatting to bytes and bytearray</dt><dd><p>PEP written by Ethan Furman; implemented by Neil Schemenauer and
|
|||
|
Ethan Furman.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="pep-484-type-hints">
|
|||
|
<span id="whatsnew-pep-484"></span><h3>PEP 484 - Type Hints<a class="headerlink" href="#pep-484-type-hints" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Function annotation syntax has been a Python feature since version 3.0
|
|||
|
(<span class="target" id="index-9"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3107"><strong>PEP 3107</strong></a>), however the semantics of annotations has been left undefined.</p>
|
|||
|
<p>Experience has shown that the majority of function annotation
|
|||
|
uses were to provide type hints to function parameters and return values. It
|
|||
|
became evident that it would be beneficial for Python users, if the
|
|||
|
standard library included the base definitions and tools for type annotations.</p>
|
|||
|
<p><span class="target" id="index-10"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0484"><strong>PEP 484</strong></a> introduces a <a class="reference internal" href="../glossary.html#term-provisional-api"><span class="xref std std-term">provisional module</span></a> to
|
|||
|
provide these standard definitions and tools, along with some conventions
|
|||
|
for situations where annotations are not available.</p>
|
|||
|
<p>For example, here is a simple function whose argument and return type
|
|||
|
are declared in the annotations:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">greeting</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="nb">str</span><span class="p">:</span>
|
|||
|
<span class="k">return</span> <span class="s1">'Hello '</span> <span class="o">+</span> <span class="n">name</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>While these annotations are available at runtime through the usual
|
|||
|
<code class="xref py py-attr docutils literal notranslate"><span class="pre">__annotations__</span></code> attribute, <em>no automatic type checking happens at
|
|||
|
runtime</em>. Instead, it is assumed that a separate off-line type checker
|
|||
|
(e.g. <a class="reference external" href="http://mypy-lang.org">mypy</a>) will be used for on-demand
|
|||
|
source code analysis.</p>
|
|||
|
<p>The type system supports unions, generic types, and a special type
|
|||
|
named <a class="reference internal" href="../library/typing.html#typing.Any" title="typing.Any"><code class="xref py py-class docutils literal notranslate"><span class="pre">Any</span></code></a> which is consistent with (i.e. assignable to
|
|||
|
and from) all types.</p>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p><a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see PEP 484)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module documentation</p></li>
|
|||
|
<li><dl class="simple">
|
|||
|
<dt><span class="target" id="index-11"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0484"><strong>PEP 484</strong></a> – Type Hints</dt><dd><p>PEP written by Guido van Rossum, Jukka Lehtosalo, and Łukasz Langa;
|
|||
|
implemented by Guido van Rossum.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</li>
|
|||
|
<li><dl class="simple">
|
|||
|
<dt><span class="target" id="index-12"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0483"><strong>PEP 483</strong></a> – The Theory of Type Hints</dt><dd><p>PEP written by Guido van Rossum</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="pep-471-os-scandir-function-a-better-and-faster-directory-iterator">
|
|||
|
<span id="whatsnew-pep-471"></span><h3>PEP 471 - os.scandir() function – a better and faster directory iterator<a class="headerlink" href="#pep-471-os-scandir-function-a-better-and-faster-directory-iterator" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><span class="target" id="index-13"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0471"><strong>PEP 471</strong></a> adds a new directory iteration function, <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>,
|
|||
|
to the standard library. Additionally, <a class="reference internal" href="../library/os.html#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.walk()</span></code></a> is now
|
|||
|
implemented using <code class="docutils literal notranslate"><span class="pre">scandir</span></code>, which makes it 3 to 5 times faster
|
|||
|
on POSIX systems and 7 to 20 times faster on Windows systems. This is
|
|||
|
largely achieved by greatly reducing the number of calls to <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>
|
|||
|
required to walk a directory tree.</p>
|
|||
|
<p>Additionally, <code class="docutils literal notranslate"><span class="pre">scandir</span></code> returns an iterator, as opposed to returning
|
|||
|
a list of file names, which improves memory efficiency when iterating
|
|||
|
over very large directories.</p>
|
|||
|
<p>The following example shows a simple use of <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> to display all
|
|||
|
the files (excluding directories) in the given <em>path</em> that don’t start with
|
|||
|
<code class="docutils literal notranslate"><span class="pre">'.'</span></code>. The <a class="reference internal" href="../library/os.html#os.DirEntry.is_file" title="os.DirEntry.is_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">entry.is_file()</span></code></a> call will generally
|
|||
|
not make an additional system call:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">scandir</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
|
|||
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">entry</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">'.'</span><span class="p">)</span> <span class="ow">and</span> <span class="n">entry</span><span class="o">.</span><span class="n">is_file</span><span class="p">():</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="n">entry</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<dl class="simple">
|
|||
|
<dt><span class="target" id="index-14"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0471"><strong>PEP 471</strong></a> – os.scandir() function – a better and faster directory iterator</dt><dd><p>PEP written and implemented by Ben Hoyt with the help of Victor Stinner.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="pep-475-retry-system-calls-failing-with-eintr">
|
|||
|
<span id="whatsnew-pep-475"></span><h3>PEP 475: Retry system calls failing with EINTR<a class="headerlink" href="#pep-475-retry-system-calls-failing-with-eintr" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>An <a class="reference internal" href="../library/errno.html#errno.EINTR" title="errno.EINTR"><code class="xref py py-data docutils literal notranslate"><span class="pre">errno.EINTR</span></code></a> error code is returned whenever a system call, that
|
|||
|
is waiting for I/O, is interrupted by a signal. Previously, Python would
|
|||
|
raise <a class="reference internal" href="../library/exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a> in such cases. This meant that, when writing a
|
|||
|
Python application, the developer had two choices:</p>
|
|||
|
<ol class="arabic simple">
|
|||
|
<li><p>Ignore the <code class="docutils literal notranslate"><span class="pre">InterruptedError</span></code>.</p></li>
|
|||
|
<li><p>Handle the <code class="docutils literal notranslate"><span class="pre">InterruptedError</span></code> and attempt to restart the interrupted
|
|||
|
system call at every call site.</p></li>
|
|||
|
</ol>
|
|||
|
<p>The first option makes an application fail intermittently.
|
|||
|
The second option adds a large amount of boilerplate that makes the
|
|||
|
code nearly unreadable. Compare:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="s2">"Hello World"</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>and:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
|
|||
|
<span class="k">try</span><span class="p">:</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s2">"Hello World"</span><span class="p">)</span>
|
|||
|
<span class="k">break</span>
|
|||
|
<span class="k">except</span> <span class="ne">InterruptedError</span><span class="p">:</span>
|
|||
|
<span class="k">continue</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p><span class="target" id="index-15"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0475"><strong>PEP 475</strong></a> implements automatic retry of system calls on
|
|||
|
<code class="docutils literal notranslate"><span class="pre">EINTR</span></code>. This removes the burden of dealing with <code class="docutils literal notranslate"><span class="pre">EINTR</span></code>
|
|||
|
or <a class="reference internal" href="../library/exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a> in user code in most situations and makes
|
|||
|
Python programs, including the standard library, more robust. Note that
|
|||
|
the system call is only retried if the signal handler does not raise an
|
|||
|
exception.</p>
|
|||
|
<p>Below is a list of functions which are now retried when interrupted
|
|||
|
by a signal:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p><a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> and <a class="reference internal" href="../library/io.html#io.open" title="io.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">io.open()</span></code></a>;</p></li>
|
|||
|
<li><p>functions of the <a class="reference internal" href="../library/faulthandler.html#module-faulthandler" title="faulthandler: Dump the Python traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code></a> module;</p></li>
|
|||
|
<li><p><a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> functions: <a class="reference internal" href="../library/os.html#os.fchdir" title="os.fchdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">fchdir()</span></code></a>, <a class="reference internal" href="../library/os.html#os.fchmod" title="os.fchmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">fchmod()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/os.html#os.fchown" title="os.fchown"><code class="xref py py-func docutils literal notranslate"><span class="pre">fchown()</span></code></a>, <a class="reference internal" href="../library/os.html#os.fdatasync" title="os.fdatasync"><code class="xref py py-func docutils literal notranslate"><span class="pre">fdatasync()</span></code></a>, <a class="reference internal" href="../library/os.html#os.fstat" title="os.fstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstat()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/os.html#os.fstatvfs" title="os.fstatvfs"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstatvfs()</span></code></a>, <a class="reference internal" href="../library/os.html#os.fsync" title="os.fsync"><code class="xref py py-func docutils literal notranslate"><span class="pre">fsync()</span></code></a>, <a class="reference internal" href="../library/os.html#os.ftruncate" title="os.ftruncate"><code class="xref py py-func docutils literal notranslate"><span class="pre">ftruncate()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/os.html#os.mkfifo" title="os.mkfifo"><code class="xref py py-func docutils literal notranslate"><span class="pre">mkfifo()</span></code></a>, <a class="reference internal" href="../library/os.html#os.mknod" title="os.mknod"><code class="xref py py-func docutils literal notranslate"><span class="pre">mknod()</span></code></a>, <a class="reference internal" href="../library/os.html#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/os.html#os.posix_fadvise" title="os.posix_fadvise"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_fadvise()</span></code></a>, <a class="reference internal" href="../library/os.html#os.posix_fallocate" title="os.posix_fallocate"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_fallocate()</span></code></a>, <a class="reference internal" href="../library/os.html#os.pread" title="os.pread"><code class="xref py py-func docutils literal notranslate"><span class="pre">pread()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/os.html#os.pwrite" title="os.pwrite"><code class="xref py py-func docutils literal notranslate"><span class="pre">pwrite()</span></code></a>, <a class="reference internal" href="../library/os.html#os.read" title="os.read"><code class="xref py py-func docutils literal notranslate"><span class="pre">read()</span></code></a>, <a class="reference internal" href="../library/os.html#os.readv" title="os.readv"><code class="xref py py-func docutils literal notranslate"><span class="pre">readv()</span></code></a>, <a class="reference internal" href="../library/os.html#os.sendfile" title="os.sendfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">sendfile()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/os.html#os.wait3" title="os.wait3"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait3()</span></code></a>, <a class="reference internal" href="../library/os.html#os.wait4" title="os.wait4"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait4()</span></code></a>, <a class="reference internal" href="../library/os.html#os.wait" title="os.wait"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/os.html#os.waitid" title="os.waitid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitid()</span></code></a>, <a class="reference internal" href="../library/os.html#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a>, <a class="reference internal" href="../library/os.html#os.write" title="os.write"><code class="xref py py-func docutils literal notranslate"><span class="pre">write()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/os.html#os.writev" title="os.writev"><code class="xref py py-func docutils literal notranslate"><span class="pre">writev()</span></code></a>;</p></li>
|
|||
|
<li><p>special cases: <a class="reference internal" href="../library/os.html#os.close" title="os.close"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.close()</span></code></a> and <a class="reference internal" href="../library/os.html#os.dup2" title="os.dup2"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.dup2()</span></code></a> now ignore
|
|||
|
<a class="reference internal" href="../library/errno.html#errno.EINTR" title="errno.EINTR"><code class="xref py py-data docutils literal notranslate"><span class="pre">EINTR</span></code></a> errors; the syscall is not retried (see the PEP
|
|||
|
for the rationale);</p></li>
|
|||
|
<li><p><a class="reference internal" href="../library/select.html#module-select" title="select: Wait for I/O completion on multiple streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code></a> functions: <a class="reference internal" href="../library/select.html#select.devpoll.poll" title="select.devpoll.poll"><code class="xref py py-func docutils literal notranslate"><span class="pre">devpoll.poll()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/select.html#select.epoll.poll" title="select.epoll.poll"><code class="xref py py-func docutils literal notranslate"><span class="pre">epoll.poll()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/select.html#select.kqueue.control" title="select.kqueue.control"><code class="xref py py-func docutils literal notranslate"><span class="pre">kqueue.control()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/select.html#select.poll.poll" title="select.poll.poll"><code class="xref py py-func docutils literal notranslate"><span class="pre">poll.poll()</span></code></a>, <a class="reference internal" href="../library/select.html#select.select" title="select.select"><code class="xref py py-func docutils literal notranslate"><span class="pre">select()</span></code></a>;</p></li>
|
|||
|
<li><p>methods of the <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket</span></code></a> class: <a class="reference internal" href="../library/socket.html#socket.socket.accept" title="socket.socket.accept"><code class="xref py py-meth docutils literal notranslate"><span class="pre">accept()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/socket.html#socket.socket.connect" title="socket.socket.connect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">connect()</span></code></a> (except for non-blocking sockets),
|
|||
|
<a class="reference internal" href="../library/socket.html#socket.socket.recv" title="socket.socket.recv"><code class="xref py py-meth docutils literal notranslate"><span class="pre">recv()</span></code></a>, <a class="reference internal" href="../library/socket.html#socket.socket.recvfrom" title="socket.socket.recvfrom"><code class="xref py py-meth docutils literal notranslate"><span class="pre">recvfrom()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/socket.html#socket.socket.recvmsg" title="socket.socket.recvmsg"><code class="xref py py-meth docutils literal notranslate"><span class="pre">recvmsg()</span></code></a>, <a class="reference internal" href="../library/socket.html#socket.socket.send" title="socket.socket.send"><code class="xref py py-meth docutils literal notranslate"><span class="pre">send()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/socket.html#socket.socket.sendall" title="socket.socket.sendall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sendall()</span></code></a>, <a class="reference internal" href="../library/socket.html#socket.socket.sendmsg" title="socket.socket.sendmsg"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sendmsg()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/socket.html#socket.socket.sendto" title="socket.socket.sendto"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sendto()</span></code></a>;</p></li>
|
|||
|
<li><p><a class="reference internal" href="../library/signal.html#signal.sigtimedwait" title="signal.sigtimedwait"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.sigtimedwait()</span></code></a> and <a class="reference internal" href="../library/signal.html#signal.sigwaitinfo" title="signal.sigwaitinfo"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.sigwaitinfo()</span></code></a>;</p></li>
|
|||
|
<li><p><a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.sleep()</span></code></a>.</p></li>
|
|||
|
</ul>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<dl class="simple">
|
|||
|
<dt><span class="target" id="index-16"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0475"><strong>PEP 475</strong></a> – Retry system calls failing with EINTR</dt><dd><p>PEP and implementation written by Charles-François Natali and
|
|||
|
Victor Stinner, with the help of Antoine Pitrou (the French connection).</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="pep-479-change-stopiteration-handling-inside-generators">
|
|||
|
<span id="whatsnew-pep-479"></span><h3>PEP 479: Change StopIteration handling inside generators<a class="headerlink" href="#pep-479-change-stopiteration-handling-inside-generators" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The interaction of generators and <a class="reference internal" href="../library/exceptions.html#StopIteration" title="StopIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code></a> in Python 3.4 and
|
|||
|
earlier was sometimes surprising, and could conceal obscure bugs. Previously,
|
|||
|
<code class="docutils literal notranslate"><span class="pre">StopIteration</span></code> raised accidentally inside a generator function was
|
|||
|
interpreted as the end of the iteration by the loop construct driving the
|
|||
|
generator.</p>
|
|||
|
<p><span class="target" id="index-17"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0479"><strong>PEP 479</strong></a> changes the behavior of generators: when a <code class="docutils literal notranslate"><span class="pre">StopIteration</span></code>
|
|||
|
exception is raised inside a generator, it is replaced with 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> before it exits the generator frame. The main goal of
|
|||
|
this change is to ease debugging in the situation where an unguarded
|
|||
|
<a class="reference internal" href="../library/functions.html#next" title="next"><code class="xref py py-func docutils literal notranslate"><span class="pre">next()</span></code></a> call raises <code class="docutils literal notranslate"><span class="pre">StopIteration</span></code> and causes the iteration controlled
|
|||
|
by the generator to terminate silently. This is particularly pernicious in
|
|||
|
combination with the <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> construct.</p>
|
|||
|
<p>This is a backwards incompatible change, so to enable the new behavior,
|
|||
|
a <a class="reference internal" href="../glossary.html#term-future"><span class="xref std std-term">__future__</span></a> import is necessary:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">generator_stop</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="k">def</span> <span class="nf">gen</span><span class="p">():</span>
|
|||
|
<span class="gp">... </span> <span class="nb">next</span><span class="p">(</span><span class="nb">iter</span><span class="p">([]))</span>
|
|||
|
<span class="gp">... </span> <span class="k">yield</span>
|
|||
|
<span class="gp">...</span>
|
|||
|
<span class="gp">>>> </span><span class="nb">next</span><span class="p">(</span><span class="n">gen</span><span class="p">())</span>
|
|||
|
<span class="gt">Traceback (most recent call last):</span>
|
|||
|
File <span class="nb">"<stdin>"</span>, line <span class="m">2</span>, in <span class="n">gen</span>
|
|||
|
<span class="gr">StopIteration</span>
|
|||
|
|
|||
|
<span class="go">The above exception was the direct cause of the following exception:</span>
|
|||
|
|
|||
|
<span class="gt">Traceback (most recent call last):</span>
|
|||
|
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
|
|||
|
<span class="gr">RuntimeError</span>: <span class="n">generator raised StopIteration</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Without a <code class="docutils literal notranslate"><span class="pre">__future__</span></code> import, a <a class="reference internal" href="../library/exceptions.html#PendingDeprecationWarning" title="PendingDeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PendingDeprecationWarning</span></code></a> will be
|
|||
|
raised whenever a <a class="reference internal" href="../library/exceptions.html#StopIteration" title="StopIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code></a> exception is raised inside a generator.</p>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<dl class="simple">
|
|||
|
<dt><span class="target" id="index-18"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0479"><strong>PEP 479</strong></a> – Change StopIteration handling inside generators</dt><dd><p>PEP written by Chris Angelico and Guido van Rossum. Implemented by
|
|||
|
Chris Angelico, Yury Selivanov and Nick Coghlan.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="pep-485-a-function-for-testing-approximate-equality">
|
|||
|
<span id="whatsnew-pep-485"></span><h3>PEP 485: A function for testing approximate equality<a class="headerlink" href="#pep-485-a-function-for-testing-approximate-equality" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><span class="target" id="index-19"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0485"><strong>PEP 485</strong></a> adds the <a class="reference internal" href="../library/math.html#math.isclose" title="math.isclose"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.isclose()</span></code></a> and <a class="reference internal" href="../library/cmath.html#cmath.isclose" title="cmath.isclose"><code class="xref py py-func docutils literal notranslate"><span class="pre">cmath.isclose()</span></code></a>
|
|||
|
functions which tell whether two values are approximately equal or
|
|||
|
“close” to each other. Whether or not two values are considered
|
|||
|
close is determined according to given absolute and relative tolerances.
|
|||
|
Relative tolerance is the maximum allowed difference between <code class="docutils literal notranslate"><span class="pre">isclose</span></code>
|
|||
|
arguments, relative to the larger absolute value:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">math</span>
|
|||
|
<span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="mf">5.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="mf">4.99998</span>
|
|||
|
<span class="gp">>>> </span><span class="n">math</span><span class="o">.</span><span class="n">isclose</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">rel_tol</span><span class="o">=</span><span class="mf">1e-5</span><span class="p">)</span>
|
|||
|
<span class="go">True</span>
|
|||
|
<span class="gp">>>> </span><span class="n">math</span><span class="o">.</span><span class="n">isclose</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">rel_tol</span><span class="o">=</span><span class="mf">1e-6</span><span class="p">)</span>
|
|||
|
<span class="go">False</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>It is also possible to compare two values using absolute tolerance, which
|
|||
|
must be a non-negative value:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">math</span>
|
|||
|
<span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="mf">5.0</span>
|
|||
|
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="mf">4.99998</span>
|
|||
|
<span class="gp">>>> </span><span class="n">math</span><span class="o">.</span><span class="n">isclose</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">abs_tol</span><span class="o">=</span><span class="mf">0.00003</span><span class="p">)</span>
|
|||
|
<span class="go">True</span>
|
|||
|
<span class="gp">>>> </span><span class="n">math</span><span class="o">.</span><span class="n">isclose</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">abs_tol</span><span class="o">=</span><span class="mf">0.00001</span><span class="p">)</span>
|
|||
|
<span class="go">False</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<dl class="simple">
|
|||
|
<dt><span class="target" id="index-20"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0485"><strong>PEP 485</strong></a> – A function for testing approximate equality</dt><dd><p>PEP written by Christopher Barker; implemented by Chris Barker and
|
|||
|
Tal Einat.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="pep-486-make-the-python-launcher-aware-of-virtual-environments">
|
|||
|
<span id="whatsnew-pep-486"></span><h3>PEP 486: Make the Python Launcher aware of virtual environments<a class="headerlink" href="#pep-486-make-the-python-launcher-aware-of-virtual-environments" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><span class="target" id="index-21"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0486"><strong>PEP 486</strong></a> makes the Windows launcher (see <span class="target" id="index-22"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0397"><strong>PEP 397</strong></a>) aware of an active
|
|||
|
virtual environment. When the default interpreter would be used and the
|
|||
|
<code class="docutils literal notranslate"><span class="pre">VIRTUAL_ENV</span></code> environment variable is set, the interpreter in the virtual
|
|||
|
environment will be used.</p>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<dl class="simple">
|
|||
|
<dt><span class="target" id="index-23"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0486"><strong>PEP 486</strong></a> – Make the Python Launcher aware of virtual environments</dt><dd><p>PEP written and implemented by Paul Moore.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="pep-488-elimination-of-pyo-files">
|
|||
|
<span id="whatsnew-pep-488"></span><h3>PEP 488: Elimination of PYO files<a class="headerlink" href="#pep-488-elimination-of-pyo-files" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><span class="target" id="index-24"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0488"><strong>PEP 488</strong></a> does away with the concept of <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files. This means that
|
|||
|
<code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files represent both unoptimized and optimized bytecode. To prevent the
|
|||
|
need to constantly regenerate bytecode files, <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files now have an
|
|||
|
optional <code class="docutils literal notranslate"><span class="pre">opt-</span></code> tag in their name when the bytecode is optimized. This has the
|
|||
|
side-effect of no more bytecode file name clashes when running under either
|
|||
|
<a class="reference internal" href="../using/cmdline.html#cmdoption-o"><code class="xref std std-option docutils literal notranslate"><span class="pre">-O</span></code></a> or <a class="reference internal" href="../using/cmdline.html#cmdoption-oo"><code class="xref std std-option docutils literal notranslate"><span class="pre">-OO</span></code></a>. Consequently, bytecode files generated from
|
|||
|
<a class="reference internal" href="../using/cmdline.html#cmdoption-o"><code class="xref std std-option docutils literal notranslate"><span class="pre">-O</span></code></a>, and <a class="reference internal" href="../using/cmdline.html#cmdoption-oo"><code class="xref std std-option docutils literal notranslate"><span class="pre">-OO</span></code></a> may now exist simultaneously.
|
|||
|
<a class="reference internal" href="../library/importlib.html#importlib.util.cache_from_source" title="importlib.util.cache_from_source"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.cache_from_source()</span></code></a> has an updated API to help with
|
|||
|
this change.</p>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<dl class="simple">
|
|||
|
<dt><span class="target" id="index-25"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0488"><strong>PEP 488</strong></a> – Elimination of PYO files</dt><dd><p>PEP written and implemented by Brett Cannon.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="pep-489-multi-phase-extension-module-initialization">
|
|||
|
<span id="whatsnew-pep-489"></span><h3>PEP 489: Multi-phase extension module initialization<a class="headerlink" href="#pep-489-multi-phase-extension-module-initialization" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><span class="target" id="index-26"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0489"><strong>PEP 489</strong></a> updates extension module initialization to take advantage of the
|
|||
|
two step module loading mechanism introduced by <span class="target" id="index-27"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0451"><strong>PEP 451</strong></a> in Python 3.4.</p>
|
|||
|
<p>This change brings the import semantics of extension modules that opt-in to
|
|||
|
using the new mechanism much closer to those of Python source and bytecode
|
|||
|
modules, including the ability to use any valid identifier as a module name,
|
|||
|
rather than being restricted to ASCII.</p>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<dl class="simple">
|
|||
|
<dt><span class="target" id="index-28"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0489"><strong>PEP 489</strong></a> – Multi-phase extension module initialization</dt><dd><p>PEP written by Petr Viktorin, Stefan Behnel, and Nick Coghlan;
|
|||
|
implemented by Petr Viktorin.</p>
|
|||
|
</dd>
|
|||
|
</dl>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="other-language-changes">
|
|||
|
<h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>Some smaller changes made to the core Python language are:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>Added the <code class="docutils literal notranslate"><span class="pre">"namereplace"</span></code> error handlers. The <code class="docutils literal notranslate"><span class="pre">"backslashreplace"</span></code>
|
|||
|
error handlers now work with decoding and translating.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue19676">bpo-19676</a> and <a class="reference external" href="https://bugs.python.org/issue22286">bpo-22286</a>.)</p></li>
|
|||
|
<li><p>The <a class="reference internal" href="../using/cmdline.html#cmdoption-b"><code class="xref std std-option docutils literal notranslate"><span class="pre">-b</span></code></a> option now affects comparisons of <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> with
|
|||
|
<a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue23681">bpo-23681</a>.)</p></li>
|
|||
|
<li><p>New Kazakh <code class="docutils literal notranslate"><span class="pre">kz1048</span></code> and Tajik <code class="docutils literal notranslate"><span class="pre">koi8_t</span></code> <a class="reference internal" href="../library/codecs.html#standard-encodings"><span class="std std-ref">codecs</span></a>.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue22682">bpo-22682</a> and <a class="reference external" href="https://bugs.python.org/issue22681">bpo-22681</a>.)</p></li>
|
|||
|
<li><p>Property docstrings are now writable. This is especially useful 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> docstrings.
|
|||
|
(Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue24064">bpo-24064</a>.)</p></li>
|
|||
|
<li><p>Circular imports involving relative imports are now supported.
|
|||
|
(Contributed by Brett Cannon and Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue17636">bpo-17636</a>.)</p></li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
<div class="section" id="new-modules">
|
|||
|
<h2>New Modules<a class="headerlink" href="#new-modules" title="Permalink to this headline">¶</a></h2>
|
|||
|
<div class="section" id="typing">
|
|||
|
<h3>typing<a class="headerlink" href="#typing" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The new <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see PEP 484)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> <a class="reference internal" href="../glossary.html#term-provisional-api"><span class="xref std std-term">provisional</span></a> module
|
|||
|
provides standard definitions and tools for function type annotations.
|
|||
|
See <a class="reference internal" href="#whatsnew-pep-484"><span class="std std-ref">Type Hints</span></a> for more information.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="zipapp">
|
|||
|
<span id="whatsnew-zipapp"></span><h3>zipapp<a class="headerlink" href="#zipapp" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The new <a class="reference internal" href="../library/zipapp.html#module-zipapp" title="zipapp: Manage executable Python zip archives"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipapp</span></code></a> module (specified in <span class="target" id="index-29"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0441"><strong>PEP 441</strong></a>) provides an API and
|
|||
|
command line tool for creating executable Python Zip Applications, which
|
|||
|
were introduced in Python 2.6 in <a class="reference external" href="https://bugs.python.org/issue1739468">bpo-1739468</a>, but which were not well
|
|||
|
publicized, either at the time or since.</p>
|
|||
|
<p>With the new module, bundling your application is as simple as putting all
|
|||
|
the files, including a <code class="docutils literal notranslate"><span class="pre">__main__.py</span></code> file, into a directory <code class="docutils literal notranslate"><span class="pre">myapp</span></code>
|
|||
|
and running:</p>
|
|||
|
<div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> python -m zipapp myapp
|
|||
|
<span class="gp">$</span> python myapp.pyz
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>The module implementation has been contributed by Paul Moore in
|
|||
|
<a class="reference external" href="https://bugs.python.org/issue23491">bpo-23491</a>.</p>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<p><span class="target" id="index-30"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0441"><strong>PEP 441</strong></a> – Improving Python ZIP Application Support</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="improved-modules">
|
|||
|
<h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Permalink to this headline">¶</a></h2>
|
|||
|
<div class="section" id="argparse">
|
|||
|
<h3>argparse<a class="headerlink" href="#argparse" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/argparse.html#argparse.ArgumentParser" title="argparse.ArgumentParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">ArgumentParser</span></code></a> class now allows disabling
|
|||
|
<a class="reference internal" href="../library/argparse.html#prefix-matching"><span class="std std-ref">abbreviated usage</span></a> of long options by setting
|
|||
|
<a class="reference internal" href="../library/argparse.html#allow-abbrev"><span class="std std-ref">allow_abbrev</span></a> to <code class="docutils literal notranslate"><span class="pre">False</span></code>. (Contributed by Jonathan Paugh,
|
|||
|
Steven Bethard, paul j3 and Daniel Eriksson in <a class="reference external" href="https://bugs.python.org/issue14910">bpo-14910</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="asyncio">
|
|||
|
<h3>asyncio<a class="headerlink" href="#asyncio" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Since the <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> module is <a class="reference internal" href="../glossary.html#term-provisional-api"><span class="xref std std-term">provisional</span></a>,
|
|||
|
all changes introduced in Python 3.5 have also been backported to Python 3.4.x.</p>
|
|||
|
<p>Notable changes in the <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> module since Python 3.4.0:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>New debugging APIs: <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.set_debug" title="asyncio.loop.set_debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.set_debug()</span></code></a>
|
|||
|
and <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.get_debug" title="asyncio.loop.get_debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.get_debug()</span></code></a> methods.
|
|||
|
(Contributed by Victor Stinner.)</p></li>
|
|||
|
<li><p>The proactor event loop now supports SSL.
|
|||
|
(Contributed by Antoine Pitrou and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue22560">bpo-22560</a>.)</p></li>
|
|||
|
<li><p>A new <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.is_closed" title="asyncio.loop.is_closed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.is_closed()</span></code></a> method to
|
|||
|
check if the event loop is closed.
|
|||
|
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue21326">bpo-21326</a>.)</p></li>
|
|||
|
<li><p>A new <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">loop.create_task()</span></code></a>
|
|||
|
to conveniently create and schedule a new <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">Task</span></code></a>
|
|||
|
for a coroutine. The <code class="docutils literal notranslate"><span class="pre">create_task</span></code> method is also used by all
|
|||
|
asyncio functions that wrap coroutines into tasks, such as
|
|||
|
<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.gather" title="asyncio.gather"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.gather()</span></code></a>, etc.
|
|||
|
(Contributed by Victor Stinner.)</p></li>
|
|||
|
<li><p>A new <a class="reference internal" href="../library/asyncio-protocol.html#asyncio.WriteTransport.get_write_buffer_limits" title="asyncio.WriteTransport.get_write_buffer_limits"><code class="xref py py-meth docutils literal notranslate"><span class="pre">transport.get_write_buffer_limits()</span></code></a>
|
|||
|
method to inquire for <em>high-</em> and <em>low-</em> water limits of the flow
|
|||
|
control.
|
|||
|
(Contributed by Victor Stinner.)</p></li>
|
|||
|
<li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">async()</span></code> function is deprecated in favor of
|
|||
|
<a class="reference internal" href="../library/asyncio-future.html#asyncio.ensure_future" title="asyncio.ensure_future"><code class="xref py py-func docutils literal notranslate"><span class="pre">ensure_future()</span></code></a>.
|
|||
|
(Contributed by Yury Selivanov.)</p></li>
|
|||
|
<li><p>New <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.set_task_factory" title="asyncio.loop.set_task_factory"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.set_task_factory()</span></code></a> and
|
|||
|
<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.get_task_factory" title="asyncio.loop.get_task_factory"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.get_task_factory()</span></code></a>
|
|||
|
methods to customize the task factory that <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">loop.create_task()</span></code></a> method uses. (Contributed by Yury
|
|||
|
Selivanov.)</p></li>
|
|||
|
<li><p>New <a class="reference internal" href="../library/asyncio-queue.html#asyncio.Queue.join" title="asyncio.Queue.join"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Queue.join()</span></code></a> and
|
|||
|
<a class="reference internal" href="../library/asyncio-queue.html#asyncio.Queue.task_done" title="asyncio.Queue.task_done"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Queue.task_done()</span></code></a> queue methods.
|
|||
|
(Contributed by Victor Stinner.)</p></li>
|
|||
|
<li><p>The <code class="docutils literal notranslate"><span class="pre">JoinableQueue</span></code> class was removed, in favor of the
|
|||
|
<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> class.
|
|||
|
(Contributed by Victor Stinner.)</p></li>
|
|||
|
</ul>
|
|||
|
<p>Updates in 3.5.1:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>The <a class="reference internal" href="../library/asyncio-future.html#asyncio.ensure_future" title="asyncio.ensure_future"><code class="xref py py-func docutils literal notranslate"><span class="pre">ensure_future()</span></code></a> function and all functions that
|
|||
|
use it, such as <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.run_until_complete" title="asyncio.loop.run_until_complete"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.run_until_complete()</span></code></a>,
|
|||
|
now accept all kinds of <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitable objects</span></a>.
|
|||
|
(Contributed by Yury Selivanov.)</p></li>
|
|||
|
<li><p>New <a class="reference internal" href="../library/asyncio-task.html#asyncio.run_coroutine_threadsafe" title="asyncio.run_coroutine_threadsafe"><code class="xref py py-func docutils literal notranslate"><span class="pre">run_coroutine_threadsafe()</span></code></a> function to submit
|
|||
|
coroutines to event loops from other threads.
|
|||
|
(Contributed by Vincent Michel.)</p></li>
|
|||
|
<li><p>New <a class="reference internal" href="../library/asyncio-protocol.html#asyncio.BaseTransport.is_closing" title="asyncio.BaseTransport.is_closing"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Transport.is_closing()</span></code></a>
|
|||
|
method to check if the transport is closing or closed.
|
|||
|
(Contributed by Yury Selivanov.)</p></li>
|
|||
|
<li><p>The <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_server" title="asyncio.loop.create_server"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_server()</span></code></a>
|
|||
|
method can now accept a list of hosts.
|
|||
|
(Contributed by Yann Sionneau.)</p></li>
|
|||
|
</ul>
|
|||
|
<p>Updates in 3.5.2:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>New <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_future" title="asyncio.loop.create_future"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_future()</span></code></a>
|
|||
|
method to create Future objects. This allows alternative event
|
|||
|
loop implementations, such as
|
|||
|
<a class="reference external" href="https://github.com/MagicStack/uvloop">uvloop</a>, to provide a faster
|
|||
|
<a class="reference internal" href="../library/asyncio-future.html#asyncio.Future" title="asyncio.Future"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Future</span></code></a> implementation.
|
|||
|
(Contributed by Yury Selivanov.)</p></li>
|
|||
|
<li><p>New <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.get_exception_handler" title="asyncio.loop.get_exception_handler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.get_exception_handler()</span></code></a>
|
|||
|
method to get the current exception handler.
|
|||
|
(Contributed by Yury Selivanov.)</p></li>
|
|||
|
<li><p>New <a class="reference internal" href="../library/asyncio-stream.html#asyncio.StreamReader.readuntil" title="asyncio.StreamReader.readuntil"><code class="xref py py-meth docutils literal notranslate"><span class="pre">StreamReader.readuntil()</span></code></a>
|
|||
|
method to read data from the stream until a separator bytes
|
|||
|
sequence appears.
|
|||
|
(Contributed by Mark Korenberg.)</p></li>
|
|||
|
<li><p>The <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_connection" title="asyncio.loop.create_connection"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_connection()</span></code></a>
|
|||
|
and <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_server" title="asyncio.loop.create_server"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_server()</span></code></a>
|
|||
|
methods are optimized to avoid calling the system <code class="docutils literal notranslate"><span class="pre">getaddrinfo</span></code>
|
|||
|
function if the address is already resolved.
|
|||
|
(Contributed by A. Jesse Jiryu Davis.)</p></li>
|
|||
|
<li><p>The <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_connect" title="asyncio.loop.sock_connect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.sock_connect(sock,</span> <span class="pre">address)</span></code></a>
|
|||
|
no longer requires the <em>address</em> to be resolved prior to the call.
|
|||
|
(Contributed by A. Jesse Jiryu Davis.)</p></li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
<div class="section" id="bz2">
|
|||
|
<h3>bz2<a class="headerlink" href="#bz2" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/bz2.html#bz2.BZ2Decompressor.decompress" title="bz2.BZ2Decompressor.decompress"><code class="xref py py-meth docutils literal notranslate"><span class="pre">BZ2Decompressor.decompress</span></code></a>
|
|||
|
method now accepts an optional <em>max_length</em> argument to limit the maximum
|
|||
|
size of decompressed data. (Contributed by Nikolaus Rath in <a class="reference external" href="https://bugs.python.org/issue15955">bpo-15955</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="cgi">
|
|||
|
<h3>cgi<a class="headerlink" href="#cgi" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">FieldStorage</span></code> class now supports the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a>
|
|||
|
protocol. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue20289">bpo-20289</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="cmath">
|
|||
|
<h3>cmath<a class="headerlink" href="#cmath" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new function <a class="reference internal" href="../library/cmath.html#cmath.isclose" title="cmath.isclose"><code class="xref py py-func docutils literal notranslate"><span class="pre">isclose()</span></code></a> provides a way to test for approximate
|
|||
|
equality. (Contributed by Chris Barker and Tal Einat in <a class="reference external" href="https://bugs.python.org/issue24270">bpo-24270</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="code">
|
|||
|
<h3>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/code.html#code.InteractiveInterpreter.showtraceback" title="code.InteractiveInterpreter.showtraceback"><code class="xref py py-func docutils literal notranslate"><span class="pre">InteractiveInterpreter.showtraceback()</span></code></a>
|
|||
|
method now prints the full chained traceback, just like the interactive
|
|||
|
interpreter. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue17442">bpo-17442</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="collections">
|
|||
|
<h3>collections<a class="headerlink" href="#collections" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p id="whatsnew-ordereddict">The <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">OrderedDict</span></code></a> class is now implemented in C, which
|
|||
|
makes it 4 to 100 times faster. (Contributed by Eric Snow in <a class="reference external" href="https://bugs.python.org/issue16991">bpo-16991</a>.)</p>
|
|||
|
<p><code class="xref py py-meth docutils literal notranslate"><span class="pre">OrderedDict.items()</span></code>,
|
|||
|
<code class="xref py py-meth docutils literal notranslate"><span class="pre">OrderedDict.keys()</span></code>,
|
|||
|
<code class="xref py py-meth docutils literal notranslate"><span class="pre">OrderedDict.values()</span></code> views now support
|
|||
|
<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> iteration.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue19505">bpo-19505</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/collections.html#collections.deque" title="collections.deque"><code class="xref py py-class docutils literal notranslate"><span class="pre">deque</span></code></a> class now defines
|
|||
|
<a class="reference internal" href="../library/collections.html#collections.deque.index" title="collections.deque.index"><code class="xref py py-meth docutils literal notranslate"><span class="pre">index()</span></code></a>, <a class="reference internal" href="../library/collections.html#collections.deque.insert" title="collections.deque.insert"><code class="xref py py-meth docutils literal notranslate"><span class="pre">insert()</span></code></a>, and
|
|||
|
<a class="reference internal" href="../library/collections.html#collections.deque.copy" title="collections.deque.copy"><code class="xref py py-meth docutils literal notranslate"><span class="pre">copy()</span></code></a>, and supports the <code class="docutils literal notranslate"><span class="pre">+</span></code> and <code class="docutils literal notranslate"><span class="pre">*</span></code> operators.
|
|||
|
This allows deques to be recognized as a <a class="reference internal" href="../library/collections.abc.html#collections.abc.MutableSequence" title="collections.abc.MutableSequence"><code class="xref py py-class docutils literal notranslate"><span class="pre">MutableSequence</span></code></a>
|
|||
|
and improves their substitutability for lists.
|
|||
|
(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue23704">bpo-23704</a>.)</p>
|
|||
|
<p>Docstrings produced by <a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a> can now be updated:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Point</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s1">'Point'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'x'</span><span class="p">,</span> <span class="s1">'y'</span><span class="p">])</span>
|
|||
|
<span class="n">Point</span><span class="o">.</span><span class="vm">__doc__</span> <span class="o">+=</span> <span class="s1">': Cartesian coodinate'</span>
|
|||
|
<span class="n">Point</span><span class="o">.</span><span class="n">x</span><span class="o">.</span><span class="vm">__doc__</span> <span class="o">=</span> <span class="s1">'abscissa'</span>
|
|||
|
<span class="n">Point</span><span class="o">.</span><span class="n">y</span><span class="o">.</span><span class="vm">__doc__</span> <span class="o">=</span> <span class="s1">'ordinate'</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue24064">bpo-24064</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/collections.html#collections.UserString" title="collections.UserString"><code class="xref py py-class docutils literal notranslate"><span class="pre">UserString</span></code></a> class now implements the
|
|||
|
<a class="reference internal" href="../library/pickle.html#object.__getnewargs__" title="object.__getnewargs__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getnewargs__()</span></code></a>, <a class="reference internal" href="../reference/datamodel.html#object.__rmod__" title="object.__rmod__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__rmod__()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#str.casefold" title="str.casefold"><code class="xref py py-meth docutils literal notranslate"><span class="pre">casefold()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/stdtypes.html#str.format_map" title="str.format_map"><code class="xref py py-meth docutils literal notranslate"><span class="pre">format_map()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#str.isprintable" title="str.isprintable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">isprintable()</span></code></a>, and <a class="reference internal" href="../library/stdtypes.html#str.maketrans" title="str.maketrans"><code class="xref py py-meth docutils literal notranslate"><span class="pre">maketrans()</span></code></a>
|
|||
|
methods to match the corresponding methods of <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>.
|
|||
|
(Contributed by Joe Jevnik in <a class="reference external" href="https://bugs.python.org/issue22189">bpo-22189</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="collections-abc">
|
|||
|
<h3>collections.abc<a class="headerlink" href="#collections-abc" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">Sequence.index()</span></code> method now
|
|||
|
accepts <em>start</em> and <em>stop</em> arguments to match the corresponding methods
|
|||
|
of <a class="reference internal" href="../library/stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>, etc.
|
|||
|
(Contributed by Devin Jeanpierre in <a class="reference external" href="https://bugs.python.org/issue23086">bpo-23086</a>.)</p>
|
|||
|
<p>A new <a class="reference internal" href="../library/collections.abc.html#collections.abc.Generator" title="collections.abc.Generator"><code class="xref py py-class docutils literal notranslate"><span class="pre">Generator</span></code></a> abstract base class. (Contributed
|
|||
|
by Stefan Behnel in <a class="reference external" href="https://bugs.python.org/issue24018">bpo-24018</a>.)</p>
|
|||
|
<p>New <a class="reference internal" href="../library/collections.abc.html#collections.abc.Awaitable" title="collections.abc.Awaitable"><code class="xref py py-class docutils literal notranslate"><span class="pre">Awaitable</span></code></a>, <a class="reference internal" href="../library/collections.abc.html#collections.abc.Coroutine" title="collections.abc.Coroutine"><code class="xref py py-class docutils literal notranslate"><span class="pre">Coroutine</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/collections.abc.html#collections.abc.AsyncIterator" title="collections.abc.AsyncIterator"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncIterator</span></code></a>, and
|
|||
|
<a class="reference internal" href="../library/collections.abc.html#collections.abc.AsyncIterable" title="collections.abc.AsyncIterable"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncIterable</span></code></a> abstract base classes.
|
|||
|
(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue24184">bpo-24184</a>.)</p>
|
|||
|
<p>For earlier Python versions, a backport of the new ABCs is available in an
|
|||
|
external <a class="reference external" href="https://pypi.org/project/backports_abc">PyPI package</a>.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="compileall">
|
|||
|
<h3>compileall<a class="headerlink" href="#compileall" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new <a class="reference internal" href="../library/compileall.html#module-compileall" title="compileall: Tools for byte-compiling all Python source files in a directory tree."><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code></a> option, <code class="samp docutils literal notranslate"><span class="pre">-j</span> <em><span class="pre">N</span></em></code>, allows running <em>N</em> workers
|
|||
|
simultaneously to perform parallel bytecode compilation.
|
|||
|
The <a class="reference internal" href="../library/compileall.html#compileall.compile_dir" title="compileall.compile_dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile_dir()</span></code></a> function has a corresponding <code class="docutils literal notranslate"><span class="pre">workers</span></code>
|
|||
|
parameter. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue16104">bpo-16104</a>.)</p>
|
|||
|
<p>Another new option, <code class="docutils literal notranslate"><span class="pre">-r</span></code>, allows controlling the maximum recursion
|
|||
|
level for subdirectories. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue19628">bpo-19628</a>.)</p>
|
|||
|
<p>The <code class="docutils literal notranslate"><span class="pre">-q</span></code> command line option can now be specified more than once, in
|
|||
|
which case all output, including errors, will be suppressed. The corresponding
|
|||
|
<code class="docutils literal notranslate"><span class="pre">quiet</span></code> parameter in <a class="reference internal" href="../library/compileall.html#compileall.compile_dir" title="compileall.compile_dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile_dir()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/compileall.html#compileall.compile_file" title="compileall.compile_file"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile_file()</span></code></a>, and <a class="reference internal" href="../library/compileall.html#compileall.compile_path" title="compileall.compile_path"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile_path()</span></code></a> can now
|
|||
|
accept an integer value indicating the level of output suppression.
|
|||
|
(Contributed by Thomas Kluyver in <a class="reference external" href="https://bugs.python.org/issue21338">bpo-21338</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="concurrent-futures">
|
|||
|
<h3>concurrent.futures<a class="headerlink" href="#concurrent-futures" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.Executor.map" title="concurrent.futures.Executor.map"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Executor.map()</span></code></a> method now accepts a
|
|||
|
<em>chunksize</em> argument to allow batching of tasks to improve performance when
|
|||
|
<a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor" title="concurrent.futures.ProcessPoolExecutor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ProcessPoolExecutor()</span></code></a> is used.
|
|||
|
(Contributed by Dan O’Reilly in <a class="reference external" href="https://bugs.python.org/issue11271">bpo-11271</a>.)</p>
|
|||
|
<p>The number of workers in the <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ThreadPoolExecutor</span></code></a>
|
|||
|
constructor is optional now. The default value is 5 times the number of CPUs.
|
|||
|
(Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue21527">bpo-21527</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="configparser">
|
|||
|
<h3>configparser<a class="headerlink" href="#configparser" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><a class="reference internal" href="../library/configparser.html#module-configparser" title="configparser: Configuration file parser."><code class="xref py py-mod docutils literal notranslate"><span class="pre">configparser</span></code></a> now provides a way to customize the conversion
|
|||
|
of values by specifying a dictionary of converters in the
|
|||
|
<a class="reference internal" href="../library/configparser.html#configparser.ConfigParser" title="configparser.ConfigParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">ConfigParser</span></code></a> constructor, or by defining them
|
|||
|
as methods in <code class="docutils literal notranslate"><span class="pre">ConfigParser</span></code> subclasses. Converters defined in
|
|||
|
a parser instance are inherited by its section proxies.</p>
|
|||
|
<p>Example:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">configparser</span>
|
|||
|
<span class="gp">>>> </span><span class="n">conv</span> <span class="o">=</span> <span class="p">{}</span>
|
|||
|
<span class="gp">>>> </span><span class="n">conv</span><span class="p">[</span><span class="s1">'list'</span><span class="p">]</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">v</span><span class="p">:</span> <span class="p">[</span><span class="n">e</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">v</span><span class="o">.</span><span class="n">split</span><span class="p">()</span> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">strip</span><span class="p">()]</span>
|
|||
|
<span class="gp">>>> </span><span class="n">cfg</span> <span class="o">=</span> <span class="n">configparser</span><span class="o">.</span><span class="n">ConfigParser</span><span class="p">(</span><span class="n">converters</span><span class="o">=</span><span class="n">conv</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">cfg</span><span class="o">.</span><span class="n">read_string</span><span class="p">(</span><span class="s2">"""</span>
|
|||
|
<span class="gp">... </span><span class="s2">[s]</span>
|
|||
|
<span class="gp">... </span><span class="s2">list = a b c d e f g</span>
|
|||
|
<span class="gp">... </span><span class="s2">"""</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">cfg</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'s'</span><span class="p">,</span> <span class="s1">'list'</span><span class="p">)</span>
|
|||
|
<span class="go">'a b c d e f g'</span>
|
|||
|
<span class="gp">>>> </span><span class="n">cfg</span><span class="o">.</span><span class="n">getlist</span><span class="p">(</span><span class="s1">'s'</span><span class="p">,</span> <span class="s1">'list'</span><span class="p">)</span>
|
|||
|
<span class="go">['a', 'b', 'c', 'd', 'e', 'f', 'g']</span>
|
|||
|
<span class="gp">>>> </span><span class="n">section</span> <span class="o">=</span> <span class="n">cfg</span><span class="p">[</span><span class="s1">'s'</span><span class="p">]</span>
|
|||
|
<span class="gp">>>> </span><span class="n">section</span><span class="o">.</span><span class="n">getlist</span><span class="p">(</span><span class="s1">'list'</span><span class="p">)</span>
|
|||
|
<span class="go">['a', 'b', 'c', 'd', 'e', 'f', 'g']</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Łukasz Langa in <a class="reference external" href="https://bugs.python.org/issue18159">bpo-18159</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="contextlib">
|
|||
|
<h3>contextlib<a class="headerlink" href="#contextlib" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The new <a class="reference internal" href="../library/contextlib.html#contextlib.redirect_stderr" title="contextlib.redirect_stderr"><code class="xref py py-func docutils literal notranslate"><span class="pre">redirect_stderr()</span></code></a> <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> (similar to
|
|||
|
<a class="reference internal" href="../library/contextlib.html#contextlib.redirect_stdout" title="contextlib.redirect_stdout"><code class="xref py py-func docutils literal notranslate"><span class="pre">redirect_stdout()</span></code></a>) makes it easier for utility scripts to
|
|||
|
handle inflexible APIs that write their output to <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> and
|
|||
|
don’t provide any options to redirect it:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">contextlib</span><span class="o">,</span> <span class="nn">io</span><span class="o">,</span> <span class="nn">logging</span>
|
|||
|
<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">io</span><span class="o">.</span><span class="n">StringIO</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="k">with</span> <span class="n">contextlib</span><span class="o">.</span><span class="n">redirect_stderr</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
|
|||
|
<span class="gp">... </span> <span class="n">logging</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">'warning'</span><span class="p">)</span>
|
|||
|
<span class="gp">...</span>
|
|||
|
<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
|
|||
|
<span class="go">'WARNING:root:warning\n'</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue22389">bpo-22389</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="csv">
|
|||
|
<h3>csv<a class="headerlink" href="#csv" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/csv.html#csv.csvwriter.writerow" title="csv.csvwriter.writerow"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writerow()</span></code></a> method now supports arbitrary iterables,
|
|||
|
not just sequences. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue23171">bpo-23171</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="curses">
|
|||
|
<h3>curses<a class="headerlink" href="#curses" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The new <a class="reference internal" href="../library/curses.html#curses.update_lines_cols" title="curses.update_lines_cols"><code class="xref py py-func docutils literal notranslate"><span class="pre">update_lines_cols()</span></code></a> function updates the <span class="target" id="index-31"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">LINES</span></code>
|
|||
|
and <span class="target" id="index-32"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">COLS</span></code> environment variables. This is useful for detecting
|
|||
|
manual screen resizing. (Contributed by Arnon Yaari in <a class="reference external" href="https://bugs.python.org/issue4254">bpo-4254</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="dbm">
|
|||
|
<h3>dbm<a class="headerlink" href="#dbm" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><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">dumb.open</span></code></a> always creates a new database when the flag
|
|||
|
has the value <code class="docutils literal notranslate"><span class="pre">"n"</span></code>. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue18039">bpo-18039</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="difflib">
|
|||
|
<h3>difflib<a class="headerlink" href="#difflib" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The charset of HTML documents generated by
|
|||
|
<a class="reference internal" href="../library/difflib.html#difflib.HtmlDiff.make_file" title="difflib.HtmlDiff.make_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HtmlDiff.make_file()</span></code></a>
|
|||
|
can now be customized by using a new <em>charset</em> keyword-only argument.
|
|||
|
The default charset of HTML document changed from <code class="docutils literal notranslate"><span class="pre">"ISO-8859-1"</span></code>
|
|||
|
to <code class="docutils literal notranslate"><span class="pre">"utf-8"</span></code>.
|
|||
|
(Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue2052">bpo-2052</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/difflib.html#difflib.diff_bytes" title="difflib.diff_bytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">diff_bytes()</span></code></a> function can now compare lists of byte
|
|||
|
strings. This fixes a regression from Python 2.
|
|||
|
(Contributed by Terry J. Reedy and Greg Ward in <a class="reference external" href="https://bugs.python.org/issue17445">bpo-17445</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="distutils">
|
|||
|
<h3>distutils<a class="headerlink" href="#distutils" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Both the <code class="docutils literal notranslate"><span class="pre">build</span></code> and <code class="docutils literal notranslate"><span class="pre">build_ext</span></code> commands now accept a <code class="docutils literal notranslate"><span class="pre">-j</span></code> option to
|
|||
|
enable parallel building of extension modules.
|
|||
|
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue5309">bpo-5309</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/distutils.html#module-distutils" title="distutils: Support for building and installing Python modules into an existing Python installation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code></a> module now supports <code class="docutils literal notranslate"><span class="pre">xz</span></code> compression, and can be
|
|||
|
enabled by passing <code class="docutils literal notranslate"><span class="pre">xztar</span></code> as an argument to <code class="docutils literal notranslate"><span class="pre">bdist</span> <span class="pre">--format</span></code>.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue16314">bpo-16314</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="doctest">
|
|||
|
<h3>doctest<a class="headerlink" href="#doctest" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/doctest.html#doctest.DocTestSuite" title="doctest.DocTestSuite"><code class="xref py py-func docutils literal notranslate"><span class="pre">DocTestSuite()</span></code></a> function returns an empty
|
|||
|
<a class="reference internal" href="../library/unittest.html#unittest.TestSuite" title="unittest.TestSuite"><code class="xref py py-class docutils literal notranslate"><span class="pre">unittest.TestSuite</span></code></a> if <em>module</em> contains no docstrings, 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>. (Contributed by Glenn Jones in <a class="reference external" href="https://bugs.python.org/issue15916">bpo-15916</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="email">
|
|||
|
<h3>email<a class="headerlink" href="#email" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new policy option <a class="reference internal" href="../library/email.policy.html#email.policy.Policy.mangle_from_" title="email.policy.Policy.mangle_from_"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Policy.mangle_from_</span></code></a>
|
|||
|
controls whether or not lines that start with <code class="docutils literal notranslate"><span class="pre">"From</span> <span class="pre">"</span></code> in email bodies are
|
|||
|
prefixed with a <code class="docutils literal notranslate"><span class="pre">">"</span></code> character by generators. The default is <code class="docutils literal notranslate"><span class="pre">True</span></code> for
|
|||
|
<a class="reference internal" href="../library/email.policy.html#email.policy.compat32" title="email.policy.compat32"><code class="xref py py-attr docutils literal notranslate"><span class="pre">compat32</span></code></a> and <code class="docutils literal notranslate"><span class="pre">False</span></code> for all other policies.
|
|||
|
(Contributed by Milan Oberkirch in <a class="reference external" href="https://bugs.python.org/issue20098">bpo-20098</a>.)</p>
|
|||
|
<p>A new
|
|||
|
<a class="reference internal" href="../library/email.compat32-message.html#email.message.Message.get_content_disposition" title="email.message.Message.get_content_disposition"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Message.get_content_disposition()</span></code></a>
|
|||
|
method provides easy access to a canonical value for the
|
|||
|
<em class="mailheader">Content-Disposition</em> header.
|
|||
|
(Contributed by Abhilash Raj in <a class="reference external" href="https://bugs.python.org/issue21083">bpo-21083</a>.)</p>
|
|||
|
<p>A new policy option <a class="reference internal" href="../library/email.policy.html#email.policy.EmailPolicy.utf8" title="email.policy.EmailPolicy.utf8"><code class="xref py py-attr docutils literal notranslate"><span class="pre">EmailPolicy.utf8</span></code></a>
|
|||
|
can be set to <code class="docutils literal notranslate"><span class="pre">True</span></code> to encode email headers using the UTF-8 charset instead
|
|||
|
of using encoded words. This allows <code class="docutils literal notranslate"><span class="pre">Messages</span></code> to be formatted according to
|
|||
|
<span class="target" id="index-33"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc6532.html"><strong>RFC 6532</strong></a> and used with an SMTP server that supports the <span class="target" id="index-34"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc6531.html"><strong>RFC 6531</strong></a>
|
|||
|
<code class="docutils literal notranslate"><span class="pre">SMTPUTF8</span></code> extension. (Contributed by R. David Murray in
|
|||
|
<a class="reference external" href="https://bugs.python.org/issue24211">bpo-24211</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/email.mime.html#email.mime.text.MIMEText" title="email.mime.text.MIMEText"><code class="xref py py-class docutils literal notranslate"><span class="pre">mime.text.MIMEText</span></code></a> constructor now
|
|||
|
accepts a <a class="reference internal" href="../library/email.charset.html#email.charset.Charset" title="email.charset.Charset"><code class="xref py py-class docutils literal notranslate"><span class="pre">charset.Charset</span></code></a> instance.
|
|||
|
(Contributed by Claude Paroz and Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue16324">bpo-16324</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="enum">
|
|||
|
<h3>enum<a class="headerlink" href="#enum" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/enum.html#enum.Enum" title="enum.Enum"><code class="xref py py-class docutils literal notranslate"><span class="pre">Enum</span></code></a> callable has a new parameter <em>start</em> to
|
|||
|
specify the initial number of enum values if only <em>names</em> are provided:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Animal</span> <span class="o">=</span> <span class="n">enum</span><span class="o">.</span><span class="n">Enum</span><span class="p">(</span><span class="s1">'Animal'</span><span class="p">,</span> <span class="s1">'cat dog'</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">Animal</span><span class="o">.</span><span class="n">cat</span>
|
|||
|
<span class="go"><Animal.cat: 10></span>
|
|||
|
<span class="gp">>>> </span><span class="n">Animal</span><span class="o">.</span><span class="n">dog</span>
|
|||
|
<span class="go"><Animal.dog: 11></span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Ethan Furman in <a class="reference external" href="https://bugs.python.org/issue21706">bpo-21706</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="faulthandler">
|
|||
|
<h3>faulthandler<a class="headerlink" href="#faulthandler" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/faulthandler.html#faulthandler.enable" title="faulthandler.enable"><code class="xref py py-func docutils literal notranslate"><span class="pre">enable()</span></code></a>, <a class="reference internal" href="../library/faulthandler.html#faulthandler.register" title="faulthandler.register"><code class="xref py py-func docutils literal notranslate"><span class="pre">register()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/faulthandler.html#faulthandler.dump_traceback" title="faulthandler.dump_traceback"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump_traceback()</span></code></a> and
|
|||
|
<a class="reference internal" href="../library/faulthandler.html#faulthandler.dump_traceback_later" title="faulthandler.dump_traceback_later"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump_traceback_later()</span></code></a> functions now accept file
|
|||
|
descriptors in addition to file-like objects.
|
|||
|
(Contributed by Wei Wu in <a class="reference external" href="https://bugs.python.org/issue23566">bpo-23566</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="functools">
|
|||
|
<h3>functools<a class="headerlink" href="#functools" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p id="whatsnew-lrucache">Most of the <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">lru_cache()</span></code></a> machinery is now implemented in C, making
|
|||
|
it significantly faster. (Contributed by Matt Joiner, Alexey Kachayev, and
|
|||
|
Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue14373">bpo-14373</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="glob">
|
|||
|
<h3>glob<a class="headerlink" href="#glob" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/glob.html#glob.iglob" title="glob.iglob"><code class="xref py py-func docutils literal notranslate"><span class="pre">iglob()</span></code></a> and <a class="reference internal" href="../library/glob.html#glob.glob" title="glob.glob"><code class="xref py py-func docutils literal notranslate"><span class="pre">glob()</span></code></a> functions now support recursive
|
|||
|
search in subdirectories, using the <code class="docutils literal notranslate"><span class="pre">"**"</span></code> pattern.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue13968">bpo-13968</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="gzip">
|
|||
|
<h3>gzip<a class="headerlink" href="#gzip" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <em>mode</em> argument of the <a class="reference internal" href="../library/gzip.html#gzip.GzipFile" title="gzip.GzipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">GzipFile</span></code></a> constructor now
|
|||
|
accepts <code class="docutils literal notranslate"><span class="pre">"x"</span></code> to request exclusive creation.
|
|||
|
(Contributed by Tim Heaney in <a class="reference external" href="https://bugs.python.org/issue19222">bpo-19222</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="heapq">
|
|||
|
<h3>heapq<a class="headerlink" href="#heapq" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Element comparison in <a class="reference internal" href="../library/heapq.html#heapq.merge" title="heapq.merge"><code class="xref py py-func docutils literal notranslate"><span class="pre">merge()</span></code></a> can now be customized by
|
|||
|
passing a <a class="reference internal" href="../glossary.html#term-key-function"><span class="xref std std-term">key function</span></a> in a new optional <em>key</em> keyword argument,
|
|||
|
and a new optional <em>reverse</em> keyword argument can be used to reverse element
|
|||
|
comparison:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">heapq</span>
|
|||
|
<span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'9'</span><span class="p">,</span> <span class="s1">'777'</span><span class="p">,</span> <span class="s1">'55555'</span><span class="p">]</span>
|
|||
|
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'88'</span><span class="p">,</span> <span class="s1">'6666'</span><span class="p">]</span>
|
|||
|
<span class="gp">>>> </span><span class="nb">list</span><span class="p">(</span><span class="n">heapq</span><span class="o">.</span><span class="n">merge</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">key</span><span class="o">=</span><span class="nb">len</span><span class="p">))</span>
|
|||
|
<span class="go">['9', '88', '777', '6666', '55555']</span>
|
|||
|
<span class="gp">>>> </span><span class="nb">list</span><span class="p">(</span><span class="n">heapq</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="nb">reversed</span><span class="p">(</span><span class="n">b</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="nb">len</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
|
|||
|
<span class="go">['55555', '6666', '777', '88', '9']</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue13742">bpo-13742</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="http">
|
|||
|
<h3>http<a class="headerlink" href="#http" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new <a class="reference internal" href="../library/http.html#http.HTTPStatus" title="http.HTTPStatus"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPStatus</span></code></a> enum that defines a set of
|
|||
|
HTTP status codes, reason phrases and long descriptions written in English.
|
|||
|
(Contributed by Demian Brecht in <a class="reference external" href="https://bugs.python.org/issue21793">bpo-21793</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="http-client">
|
|||
|
<h3>http.client<a class="headerlink" href="#http-client" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><a class="reference internal" href="../library/http.client.html#http.client.HTTPConnection.getresponse" title="http.client.HTTPConnection.getresponse"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HTTPConnection.getresponse()</span></code></a>
|
|||
|
now raises a <a class="reference internal" href="../library/http.client.html#http.client.RemoteDisconnected" title="http.client.RemoteDisconnected"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RemoteDisconnected</span></code></a> exception when a
|
|||
|
remote server connection is closed unexpectedly. Additionally, if a
|
|||
|
<a class="reference internal" href="../library/exceptions.html#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a> (of which <code class="docutils literal notranslate"><span class="pre">RemoteDisconnected</span></code>
|
|||
|
is a subclass) is raised, the client socket is now closed automatically,
|
|||
|
and will reconnect on the next request:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">http.client</span>
|
|||
|
<span class="n">conn</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">(</span><span class="s1">'www.python.org'</span><span class="p">)</span>
|
|||
|
<span class="k">for</span> <span class="n">retries</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
|
|||
|
<span class="k">try</span><span class="p">:</span>
|
|||
|
<span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s1">'GET'</span><span class="p">,</span> <span class="s1">'/'</span><span class="p">)</span>
|
|||
|
<span class="n">resp</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span>
|
|||
|
<span class="k">except</span> <span class="n">http</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">RemoteDisconnected</span><span class="p">:</span>
|
|||
|
<span class="k">pass</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Martin Panter in <a class="reference external" href="https://bugs.python.org/issue3566">bpo-3566</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="idlelib-and-idle">
|
|||
|
<h3>idlelib and IDLE<a class="headerlink" href="#idlelib-and-idle" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Since idlelib implements the IDLE shell and editor and is not intended for
|
|||
|
import by other programs, it gets improvements with every release. See
|
|||
|
<code class="file docutils literal notranslate"><span class="pre">Lib/idlelib/NEWS.txt</span></code> for a cumulative list of changes since 3.4.0,
|
|||
|
as well as changes made in future 3.5.x releases. This file is also available
|
|||
|
from the IDLE <span class="menuselection">Help ‣ About IDLE</span> dialog.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="imaplib">
|
|||
|
<h3>imaplib<a class="headerlink" href="#imaplib" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4</span></code></a> class now supports the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> protocol.
|
|||
|
When used in a <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement, the IMAP4 <code class="docutils literal notranslate"><span class="pre">LOGOUT</span></code>
|
|||
|
command will be called automatically at the end of the block.
|
|||
|
(Contributed by Tarek Ziadé and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue4972">bpo-4972</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/imaplib.html#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a> module now supports <span class="target" id="index-35"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5161.html"><strong>RFC 5161</strong></a> (ENABLE Extension)
|
|||
|
and <span class="target" id="index-36"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc6855.html"><strong>RFC 6855</strong></a> (UTF-8 Support) via the <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4.enable" title="imaplib.IMAP4.enable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">IMAP4.enable()</span></code></a>
|
|||
|
method. A new <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4.utf8_enabled" title="imaplib.IMAP4.utf8_enabled"><code class="xref py py-attr docutils literal notranslate"><span class="pre">IMAP4.utf8_enabled</span></code></a>
|
|||
|
attribute tracks whether or not <span class="target" id="index-37"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc6855.html"><strong>RFC 6855</strong></a> support is enabled.
|
|||
|
(Contributed by Milan Oberkirch, R. David Murray, and Maciej Szulik in
|
|||
|
<a class="reference external" href="https://bugs.python.org/issue21800">bpo-21800</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/imaplib.html#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a> module now automatically encodes non-ASCII string usernames
|
|||
|
and passwords using UTF-8, as recommended by the RFCs. (Contributed by Milan
|
|||
|
Oberkirch in <a class="reference external" href="https://bugs.python.org/issue21800">bpo-21800</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="imghdr">
|
|||
|
<h3>imghdr<a class="headerlink" href="#imghdr" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/imghdr.html#imghdr.what" title="imghdr.what"><code class="xref py py-func docutils literal notranslate"><span class="pre">what()</span></code></a> function now recognizes the
|
|||
|
<a class="reference external" href="http://www.openexr.com">OpenEXR</a> format
|
|||
|
(contributed by Martin Vignali and Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue20295">bpo-20295</a>),
|
|||
|
and the <a class="reference external" href="https://en.wikipedia.org/wiki/WebP">WebP</a> format
|
|||
|
(contributed by Fabrice Aneche and Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue20197">bpo-20197</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="importlib">
|
|||
|
<h3>importlib<a class="headerlink" href="#importlib" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/importlib.html#importlib.util.LazyLoader" title="importlib.util.LazyLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">util.LazyLoader</span></code></a> class allows for
|
|||
|
lazy loading of modules in applications where startup time is important.
|
|||
|
(Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue17621">bpo-17621</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader.source_to_code" title="importlib.abc.InspectLoader.source_to_code"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.InspectLoader.source_to_code()</span></code></a>
|
|||
|
method is now a static method. This makes it easier to initialize a module
|
|||
|
object with code compiled from a string by running
|
|||
|
<code class="docutils literal notranslate"><span class="pre">exec(code,</span> <span class="pre">module.__dict__)</span></code>.
|
|||
|
(Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue21156">bpo-21156</a>.)</p>
|
|||
|
<p>The new <a class="reference internal" href="../library/importlib.html#importlib.util.module_from_spec" title="importlib.util.module_from_spec"><code class="xref py py-func docutils literal notranslate"><span class="pre">util.module_from_spec()</span></code></a>
|
|||
|
function is now the preferred way to create a new module. As opposed to
|
|||
|
creating a <a class="reference internal" href="../library/types.html#types.ModuleType" title="types.ModuleType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.ModuleType</span></code></a> instance directly, this new function
|
|||
|
will set the various import-controlled attributes based on the passed-in
|
|||
|
spec object. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue20383">bpo-20383</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="inspect">
|
|||
|
<h3>inspect<a class="headerlink" href="#inspect" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Both the <a class="reference internal" href="../library/inspect.html#inspect.Signature" title="inspect.Signature"><code class="xref py py-class docutils literal notranslate"><span class="pre">Signature</span></code></a> and <a class="reference internal" href="../library/inspect.html#inspect.Parameter" title="inspect.Parameter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Parameter</span></code></a> classes are
|
|||
|
now picklable and hashable. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue20726">bpo-20726</a>
|
|||
|
and <a class="reference external" href="https://bugs.python.org/issue20334">bpo-20334</a>.)</p>
|
|||
|
<p>A new
|
|||
|
<a class="reference internal" href="../library/inspect.html#inspect.BoundArguments.apply_defaults" title="inspect.BoundArguments.apply_defaults"><code class="xref py py-meth docutils literal notranslate"><span class="pre">BoundArguments.apply_defaults()</span></code></a>
|
|||
|
method provides a way to set default values for missing arguments:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="s1">'ham'</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span> <span class="k">pass</span>
|
|||
|
<span class="gp">>>> </span><span class="n">ba</span> <span class="o">=</span> <span class="n">inspect</span><span class="o">.</span><span class="n">signature</span><span class="p">(</span><span class="n">foo</span><span class="p">)</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s1">'spam'</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">ba</span><span class="o">.</span><span class="n">apply_defaults</span><span class="p">()</span>
|
|||
|
<span class="gp">>>> </span><span class="n">ba</span><span class="o">.</span><span class="n">arguments</span>
|
|||
|
<span class="go">OrderedDict([('a', 'spam'), ('b', 'ham'), ('args', ())])</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue24190">bpo-24190</a>.)</p>
|
|||
|
<p>A new class method
|
|||
|
<a class="reference internal" href="../library/inspect.html#inspect.Signature.from_callable" title="inspect.Signature.from_callable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Signature.from_callable()</span></code></a> makes
|
|||
|
subclassing of <a class="reference internal" href="../library/inspect.html#inspect.Signature" title="inspect.Signature"><code class="xref py py-class docutils literal notranslate"><span class="pre">Signature</span></code></a> easier. (Contributed
|
|||
|
by Yury Selivanov and Eric Snow in <a class="reference external" href="https://bugs.python.org/issue17373">bpo-17373</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">signature()</span></code></a> function now accepts a <em>follow_wrapped</em>
|
|||
|
optional keyword argument, which, when set to <code class="docutils literal notranslate"><span class="pre">False</span></code>, disables automatic
|
|||
|
following of <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> links.
|
|||
|
(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue20691">bpo-20691</a>.)</p>
|
|||
|
<p>A set of new functions to inspect
|
|||
|
<a class="reference internal" href="../glossary.html#term-coroutine-function"><span class="xref std std-term">coroutine functions</span></a> and
|
|||
|
<a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine objects</span></a> has been added:
|
|||
|
<a class="reference internal" href="../library/inspect.html#inspect.iscoroutine" title="inspect.iscoroutine"><code class="xref py py-func docutils literal notranslate"><span class="pre">iscoroutine()</span></code></a>, <a class="reference internal" href="../library/inspect.html#inspect.iscoroutinefunction" title="inspect.iscoroutinefunction"><code class="xref py py-func docutils literal notranslate"><span class="pre">iscoroutinefunction()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/inspect.html#inspect.isawaitable" title="inspect.isawaitable"><code class="xref py py-func docutils literal notranslate"><span class="pre">isawaitable()</span></code></a>, <a class="reference internal" href="../library/inspect.html#inspect.getcoroutinelocals" title="inspect.getcoroutinelocals"><code class="xref py py-func docutils literal notranslate"><span class="pre">getcoroutinelocals()</span></code></a>,
|
|||
|
and <a class="reference internal" href="../library/inspect.html#inspect.getcoroutinestate" title="inspect.getcoroutinestate"><code class="xref py py-func docutils literal notranslate"><span class="pre">getcoroutinestate()</span></code></a>.
|
|||
|
(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue24017">bpo-24017</a> and <a class="reference external" href="https://bugs.python.org/issue24400">bpo-24400</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/inspect.html#inspect.stack" title="inspect.stack"><code class="xref py py-func docutils literal notranslate"><span class="pre">stack()</span></code></a>, <a class="reference internal" href="../library/inspect.html#inspect.trace" title="inspect.trace"><code class="xref py py-func docutils literal notranslate"><span class="pre">trace()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/inspect.html#inspect.getouterframes" title="inspect.getouterframes"><code class="xref py py-func docutils literal notranslate"><span class="pre">getouterframes()</span></code></a>, and <a class="reference internal" href="../library/inspect.html#inspect.getinnerframes" title="inspect.getinnerframes"><code class="xref py py-func docutils literal notranslate"><span class="pre">getinnerframes()</span></code></a>
|
|||
|
functions now return a list of named tuples.
|
|||
|
(Contributed by Daniel Shahaf in <a class="reference external" href="https://bugs.python.org/issue16808">bpo-16808</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="io">
|
|||
|
<h3>io<a class="headerlink" href="#io" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new <a class="reference internal" href="../library/io.html#io.BufferedIOBase.readinto1" title="io.BufferedIOBase.readinto1"><code class="xref py py-meth docutils literal notranslate"><span class="pre">BufferedIOBase.readinto1()</span></code></a>
|
|||
|
method, that uses at most one call to the underlying raw stream’s
|
|||
|
<a class="reference internal" href="../library/io.html#io.RawIOBase.read" title="io.RawIOBase.read"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RawIOBase.read()</span></code></a> or
|
|||
|
<a class="reference internal" href="../library/io.html#io.RawIOBase.readinto" title="io.RawIOBase.readinto"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RawIOBase.readinto()</span></code></a> methods.
|
|||
|
(Contributed by Nikolaus Rath in <a class="reference external" href="https://bugs.python.org/issue20578">bpo-20578</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="ipaddress">
|
|||
|
<h3>ipaddress<a class="headerlink" href="#ipaddress" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Both the <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv4Network</span></code></a> and <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv6Network</span></code></a> classes
|
|||
|
now accept an <code class="docutils literal notranslate"><span class="pre">(address,</span> <span class="pre">netmask)</span></code> tuple argument, so as to easily construct
|
|||
|
network objects from existing addresses:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">ipaddress</span>
|
|||
|
<span class="gp">>>> </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Network</span><span class="p">((</span><span class="s1">'127.0.0.0'</span><span class="p">,</span> <span class="mi">8</span><span class="p">))</span>
|
|||
|
<span class="go">IPv4Network('127.0.0.0/8')</span>
|
|||
|
<span class="gp">>>> </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Network</span><span class="p">((</span><span class="s1">'127.0.0.0'</span><span class="p">,</span> <span class="s1">'255.0.0.0'</span><span class="p">))</span>
|
|||
|
<span class="go">IPv4Network('127.0.0.0/8')</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Peter Moody and Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue16531">bpo-16531</a>.)</p>
|
|||
|
<p>A new <code class="xref py py-attr docutils literal notranslate"><span class="pre">reverse_pointer</span></code> attribute for the
|
|||
|
<a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv4Network</span></code></a> and <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv6Network</span></code></a> classes
|
|||
|
returns the name of the reverse DNS PTR record:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">ipaddress</span>
|
|||
|
<span class="gp">>>> </span><span class="n">addr</span> <span class="o">=</span> <span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Address</span><span class="p">(</span><span class="s1">'127.0.0.1'</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">addr</span><span class="o">.</span><span class="n">reverse_pointer</span>
|
|||
|
<span class="go">'1.0.0.127.in-addr.arpa'</span>
|
|||
|
<span class="gp">>>> </span><span class="n">addr6</span> <span class="o">=</span> <span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv6Address</span><span class="p">(</span><span class="s1">'::1'</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">addr6</span><span class="o">.</span><span class="n">reverse_pointer</span>
|
|||
|
<span class="go">'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa'</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Leon Weber in <a class="reference external" href="https://bugs.python.org/issue20480">bpo-20480</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="json">
|
|||
|
<h3>json<a class="headerlink" href="#json" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/json.html#module-json.tool" title="json.tool: A command line to validate and pretty-print JSON."><code class="xref py py-mod docutils literal notranslate"><span class="pre">json.tool</span></code></a> command line interface now preserves the order of keys in
|
|||
|
JSON objects passed in input. The new <code class="docutils literal notranslate"><span class="pre">--sort-keys</span></code> option can be used
|
|||
|
to sort the keys alphabetically. (Contributed by Berker Peksag
|
|||
|
in <a class="reference external" href="https://bugs.python.org/issue21650">bpo-21650</a>.)</p>
|
|||
|
<p>JSON decoder now raises <a class="reference internal" href="../library/json.html#json.JSONDecodeError" title="json.JSONDecodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">JSONDecodeError</span></code></a> instead of
|
|||
|
<a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> to provide better context information about the error.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue19361">bpo-19361</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="linecache">
|
|||
|
<h3>linecache<a class="headerlink" href="#linecache" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new <a class="reference internal" href="../library/linecache.html#linecache.lazycache" title="linecache.lazycache"><code class="xref py py-func docutils literal notranslate"><span class="pre">lazycache()</span></code></a> function can be used to capture information
|
|||
|
about a non-file-based module to permit getting its lines later via
|
|||
|
<a class="reference internal" href="../library/linecache.html#linecache.getline" title="linecache.getline"><code class="xref py py-func docutils literal notranslate"><span class="pre">getline()</span></code></a>. This avoids doing I/O until a line is actually
|
|||
|
needed, without having to carry the module globals around indefinitely.
|
|||
|
(Contributed by Robert Collins in <a class="reference external" href="https://bugs.python.org/issue17911">bpo-17911</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="locale">
|
|||
|
<h3>locale<a class="headerlink" href="#locale" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new <a class="reference internal" href="../library/locale.html#locale.delocalize" title="locale.delocalize"><code class="xref py py-func docutils literal notranslate"><span class="pre">delocalize()</span></code></a> function can be used to convert a string into
|
|||
|
a normalized number string, taking the <code class="docutils literal notranslate"><span class="pre">LC_NUMERIC</span></code> settings into account:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">locale</span>
|
|||
|
<span class="gp">>>> </span><span class="n">locale</span><span class="o">.</span><span class="n">setlocale</span><span class="p">(</span><span class="n">locale</span><span class="o">.</span><span class="n">LC_NUMERIC</span><span class="p">,</span> <span class="s1">'de_DE.UTF-8'</span><span class="p">)</span>
|
|||
|
<span class="go">'de_DE.UTF-8'</span>
|
|||
|
<span class="gp">>>> </span><span class="n">locale</span><span class="o">.</span><span class="n">delocalize</span><span class="p">(</span><span class="s1">'1.234,56'</span><span class="p">)</span>
|
|||
|
<span class="go">'1234.56'</span>
|
|||
|
<span class="gp">>>> </span><span class="n">locale</span><span class="o">.</span><span class="n">setlocale</span><span class="p">(</span><span class="n">locale</span><span class="o">.</span><span class="n">LC_NUMERIC</span><span class="p">,</span> <span class="s1">'en_US.UTF-8'</span><span class="p">)</span>
|
|||
|
<span class="go">'en_US.UTF-8'</span>
|
|||
|
<span class="gp">>>> </span><span class="n">locale</span><span class="o">.</span><span class="n">delocalize</span><span class="p">(</span><span class="s1">'1,234.56'</span><span class="p">)</span>
|
|||
|
<span class="go">'1234.56'</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Cédric Krier in <a class="reference external" href="https://bugs.python.org/issue13918">bpo-13918</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="logging">
|
|||
|
<h3>logging<a class="headerlink" href="#logging" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>All logging methods (<a class="reference internal" href="../library/logging.html#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> <a class="reference internal" href="../library/logging.html#logging.Logger.log" title="logging.Logger.log"><code class="xref py py-meth docutils literal notranslate"><span class="pre">log()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/logging.html#logging.Logger.exception" title="logging.Logger.exception"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exception()</span></code></a>, <a class="reference internal" href="../library/logging.html#logging.Logger.critical" title="logging.Logger.critical"><code class="xref py py-meth docutils literal notranslate"><span class="pre">critical()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/logging.html#logging.Logger.debug" title="logging.Logger.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>, etc.), now accept exception instances
|
|||
|
as an <em>exc_info</em> argument, in addition to boolean values and exception
|
|||
|
tuples:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">logging</span>
|
|||
|
<span class="gp">>>> </span><span class="k">try</span><span class="p">:</span>
|
|||
|
<span class="gp">... </span> <span class="mi">1</span><span class="o">/</span><span class="mi">0</span>
|
|||
|
<span class="gp">... </span><span class="k">except</span> <span class="ne">ZeroDivisionError</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
|
|||
|
<span class="gp">... </span> <span class="n">logging</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">'exception'</span><span class="p">,</span> <span class="n">exc_info</span><span class="o">=</span><span class="n">ex</span><span class="p">)</span>
|
|||
|
<span class="go">ERROR:root:exception</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue20537">bpo-20537</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.HTTPHandler" title="logging.handlers.HTTPHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">handlers.HTTPHandler</span></code></a> class now
|
|||
|
accepts an optional <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> instance to configure SSL
|
|||
|
settings used in an HTTP connection.
|
|||
|
(Contributed by Alex Gaynor in <a class="reference external" href="https://bugs.python.org/issue22788">bpo-22788</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.QueueListener" title="logging.handlers.QueueListener"><code class="xref py py-class docutils literal notranslate"><span class="pre">handlers.QueueListener</span></code></a> class now
|
|||
|
takes a <em>respect_handler_level</em> keyword argument which, if set to <code class="docutils literal notranslate"><span class="pre">True</span></code>,
|
|||
|
will pass messages to handlers taking handler levels into account.
|
|||
|
(Contributed by Vinay Sajip.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="lzma">
|
|||
|
<h3>lzma<a class="headerlink" href="#lzma" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/lzma.html#lzma.LZMADecompressor.decompress" title="lzma.LZMADecompressor.decompress"><code class="xref py py-meth docutils literal notranslate"><span class="pre">LZMADecompressor.decompress()</span></code></a>
|
|||
|
method now accepts an optional <em>max_length</em> argument to limit the maximum
|
|||
|
size of decompressed data.
|
|||
|
(Contributed by Martin Panter in <a class="reference external" href="https://bugs.python.org/issue15955">bpo-15955</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="math">
|
|||
|
<h3>math<a class="headerlink" href="#math" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Two new constants have been added to the <a class="reference internal" href="../library/math.html#module-math" title="math: Mathematical functions (sin() etc.)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">math</span></code></a> module: <a class="reference internal" href="../library/math.html#math.inf" title="math.inf"><code class="xref py py-data docutils literal notranslate"><span class="pre">inf</span></code></a>
|
|||
|
and <a class="reference internal" href="../library/math.html#math.nan" title="math.nan"><code class="xref py py-data docutils literal notranslate"><span class="pre">nan</span></code></a>. (Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue23185">bpo-23185</a>.)</p>
|
|||
|
<p>A new function <a class="reference internal" href="../library/math.html#math.isclose" title="math.isclose"><code class="xref py py-func docutils literal notranslate"><span class="pre">isclose()</span></code></a> provides a way to test for approximate
|
|||
|
equality. (Contributed by Chris Barker and Tal Einat in <a class="reference external" href="https://bugs.python.org/issue24270">bpo-24270</a>.)</p>
|
|||
|
<p>A new <a class="reference internal" href="../library/math.html#math.gcd" title="math.gcd"><code class="xref py py-func docutils literal notranslate"><span class="pre">gcd()</span></code></a> function has been added. The <a class="reference internal" href="../library/fractions.html#fractions.gcd" title="fractions.gcd"><code class="xref py py-func docutils literal notranslate"><span class="pre">fractions.gcd()</span></code></a>
|
|||
|
function is now deprecated. (Contributed by Mark Dickinson and Serhiy
|
|||
|
Storchaka in <a class="reference external" href="https://bugs.python.org/issue22486">bpo-22486</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="multiprocessing">
|
|||
|
<h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><a class="reference internal" href="../library/multiprocessing.html#multiprocessing.sharedctypes.synchronized" title="multiprocessing.sharedctypes.synchronized"><code class="xref py py-func docutils literal notranslate"><span class="pre">sharedctypes.synchronized()</span></code></a>
|
|||
|
objects now support the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> protocol.
|
|||
|
(Contributed by Charles-François Natali in <a class="reference external" href="https://bugs.python.org/issue21565">bpo-21565</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="operator">
|
|||
|
<h3>operator<a class="headerlink" href="#operator" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><a class="reference internal" href="../library/operator.html#operator.attrgetter" title="operator.attrgetter"><code class="xref py py-func docutils literal notranslate"><span class="pre">attrgetter()</span></code></a>, <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">itemgetter()</span></code></a>,
|
|||
|
and <a class="reference internal" href="../library/operator.html#operator.methodcaller" title="operator.methodcaller"><code class="xref py py-func docutils literal notranslate"><span class="pre">methodcaller()</span></code></a> objects now support pickling.
|
|||
|
(Contributed by Josh Rosenberg and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue22955">bpo-22955</a>.)</p>
|
|||
|
<p>New <a class="reference internal" href="../library/operator.html#operator.matmul" title="operator.matmul"><code class="xref py py-func docutils literal notranslate"><span class="pre">matmul()</span></code></a> and <a class="reference internal" href="../library/operator.html#operator.imatmul" title="operator.imatmul"><code class="xref py py-func docutils literal notranslate"><span class="pre">imatmul()</span></code></a> functions
|
|||
|
to perform matrix multiplication.
|
|||
|
(Contributed by Benjamin Peterson in <a class="reference external" href="https://bugs.python.org/issue21176">bpo-21176</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="os">
|
|||
|
<h3>os<a class="headerlink" href="#os" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The new <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">scandir()</span></code></a> function returning an iterator of
|
|||
|
<a class="reference internal" href="../library/os.html#os.DirEntry" title="os.DirEntry"><code class="xref py py-class docutils literal notranslate"><span class="pre">DirEntry</span></code></a> objects has been added. If possible, <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">scandir()</span></code></a>
|
|||
|
extracts file attributes while scanning a directory, removing the need to
|
|||
|
perform subsequent system calls to determine file type or attributes, which may
|
|||
|
significantly improve performance. (Contributed by Ben Hoyt with the help
|
|||
|
of Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue22524">bpo-22524</a>.)</p>
|
|||
|
<p>On Windows, a new
|
|||
|
<a class="reference internal" href="../library/os.html#os.stat_result.st_file_attributes" title="os.stat_result.st_file_attributes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">stat_result.st_file_attributes</span></code></a>
|
|||
|
attribute is now available. It corresponds to the <code class="docutils literal notranslate"><span class="pre">dwFileAttributes</span></code> member
|
|||
|
of the <code class="docutils literal notranslate"><span class="pre">BY_HANDLE_FILE_INFORMATION</span></code> structure returned by
|
|||
|
<code class="docutils literal notranslate"><span class="pre">GetFileInformationByHandle()</span></code>. (Contributed by Ben Hoyt in <a class="reference external" href="https://bugs.python.org/issue21719">bpo-21719</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">urandom()</span></code></a> function now uses the <code class="docutils literal notranslate"><span class="pre">getrandom()</span></code> syscall on Linux 3.17
|
|||
|
or newer, and <code class="docutils literal notranslate"><span class="pre">getentropy()</span></code> on OpenBSD 5.6 and newer, removing the need to
|
|||
|
use <code class="docutils literal notranslate"><span class="pre">/dev/urandom</span></code> and avoiding failures due to potential file descriptor
|
|||
|
exhaustion. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue22181">bpo-22181</a>.)</p>
|
|||
|
<p>New <a class="reference internal" href="../library/os.html#os.get_blocking" title="os.get_blocking"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_blocking()</span></code></a> and <a class="reference internal" href="../library/os.html#os.set_blocking" title="os.set_blocking"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_blocking()</span></code></a> functions allow
|
|||
|
getting and setting a file descriptor’s blocking mode (<a class="reference internal" href="../library/os.html#os.O_NONBLOCK" title="os.O_NONBLOCK"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_NONBLOCK</span></code></a>.)
|
|||
|
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue22054">bpo-22054</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/os.html#os.truncate" title="os.truncate"><code class="xref py py-func docutils literal notranslate"><span class="pre">truncate()</span></code></a> and <a class="reference internal" href="../library/os.html#os.ftruncate" title="os.ftruncate"><code class="xref py py-func docutils literal notranslate"><span class="pre">ftruncate()</span></code></a> functions are now supported
|
|||
|
on Windows. (Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue23668">bpo-23668</a>.)</p>
|
|||
|
<p>There is a new <a class="reference internal" href="../library/os.path.html#os.path.commonpath" title="os.path.commonpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.commonpath()</span></code></a> function returning the longest
|
|||
|
common sub-path of each passed pathname. Unlike the
|
|||
|
<a class="reference internal" href="../library/os.path.html#os.path.commonprefix" title="os.path.commonprefix"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.commonprefix()</span></code></a> function, it always returns a valid
|
|||
|
path:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">commonprefix</span><span class="p">([</span><span class="s1">'/usr/lib'</span><span class="p">,</span> <span class="s1">'/usr/local/lib'</span><span class="p">])</span>
|
|||
|
<span class="go">'/usr/l'</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">commonpath</span><span class="p">([</span><span class="s1">'/usr/lib'</span><span class="p">,</span> <span class="s1">'/usr/local/lib'</span><span class="p">])</span>
|
|||
|
<span class="go">'/usr'</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Rafik Draoui and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue10395">bpo-10395</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="pathlib">
|
|||
|
<h3>pathlib<a class="headerlink" href="#pathlib" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The new <a class="reference internal" href="../library/pathlib.html#pathlib.Path.samefile" title="pathlib.Path.samefile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.samefile()</span></code></a> method can be used
|
|||
|
to check whether the path points to the same file as another path, which can
|
|||
|
be either another <a class="reference internal" href="../library/pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">Path</span></code></a> object, or a string:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">pathlib</span>
|
|||
|
<span class="gp">>>> </span><span class="n">p1</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s1">'/etc/hosts'</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">p2</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s1">'/etc/../etc/hosts'</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">p1</span><span class="o">.</span><span class="n">samefile</span><span class="p">(</span><span class="n">p2</span><span class="p">)</span>
|
|||
|
<span class="go">True</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Vajrasky Kok and Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue19775">bpo-19775</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/pathlib.html#pathlib.Path.mkdir" title="pathlib.Path.mkdir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.mkdir()</span></code></a> method now accepts a new optional
|
|||
|
<em>exist_ok</em> argument to match <code class="docutils literal notranslate"><span class="pre">mkdir</span> <span class="pre">-p</span></code> and <a class="reference internal" href="../library/os.html#os.makedirs" title="os.makedirs"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.makedirs()</span></code></a>
|
|||
|
functionality. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue21539">bpo-21539</a>.)</p>
|
|||
|
<p>There is a new <a class="reference internal" href="../library/pathlib.html#pathlib.Path.expanduser" title="pathlib.Path.expanduser"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.expanduser()</span></code></a> method to
|
|||
|
expand <code class="docutils literal notranslate"><span class="pre">~</span></code> and <code class="docutils literal notranslate"><span class="pre">~user</span></code> prefixes. (Contributed by Serhiy Storchaka and
|
|||
|
Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue19776">bpo-19776</a>.)</p>
|
|||
|
<p>A new <a class="reference internal" href="../library/pathlib.html#pathlib.Path.home" title="pathlib.Path.home"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.home()</span></code></a> class method can be used to get
|
|||
|
a <a class="reference internal" href="../library/pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">Path</span></code></a> instance representing the user’s home
|
|||
|
directory.
|
|||
|
(Contributed by Victor Salgado and Mayank Tripathi in <a class="reference external" href="https://bugs.python.org/issue19777">bpo-19777</a>.)</p>
|
|||
|
<p>New <a class="reference internal" href="../library/pathlib.html#pathlib.Path.write_text" title="pathlib.Path.write_text"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.write_text()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/pathlib.html#pathlib.Path.read_text" title="pathlib.Path.read_text"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.read_text()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/pathlib.html#pathlib.Path.write_bytes" title="pathlib.Path.write_bytes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.write_bytes()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/pathlib.html#pathlib.Path.read_bytes" title="pathlib.Path.read_bytes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.read_bytes()</span></code></a> methods to simplify
|
|||
|
read/write operations on files.</p>
|
|||
|
<p>The following code snippet will create or rewrite existing file
|
|||
|
<code class="docutils literal notranslate"><span class="pre">~/spam42</span></code>:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">pathlib</span>
|
|||
|
<span class="gp">>>> </span><span class="n">p</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s1">'~/spam42'</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">p</span><span class="o">.</span><span class="n">expanduser</span><span class="p">()</span><span class="o">.</span><span class="n">write_text</span><span class="p">(</span><span class="s1">'ham'</span><span class="p">)</span>
|
|||
|
<span class="go">3</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Christopher Welborn in <a class="reference external" href="https://bugs.python.org/issue20218">bpo-20218</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="pickle">
|
|||
|
<h3>pickle<a class="headerlink" href="#pickle" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Nested objects, such as unbound methods or nested classes, can now be pickled
|
|||
|
using <a class="reference internal" href="../library/pickle.html#pickle-protocols"><span class="std std-ref">pickle protocols</span></a> older than protocol version 4.
|
|||
|
Protocol version 4 already supports these cases. (Contributed by Serhiy
|
|||
|
Storchaka in <a class="reference external" href="https://bugs.python.org/issue23611">bpo-23611</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="poplib">
|
|||
|
<h3>poplib<a class="headerlink" href="#poplib" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new <a class="reference internal" href="../library/poplib.html#poplib.POP3.utf8" title="poplib.POP3.utf8"><code class="xref py py-meth docutils literal notranslate"><span class="pre">POP3.utf8()</span></code></a> command enables <span class="target" id="index-38"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc6856.html"><strong>RFC 6856</strong></a>
|
|||
|
(Internationalized Email) support, if a POP server supports it.
|
|||
|
(Contributed by Milan OberKirch in <a class="reference external" href="https://bugs.python.org/issue21804">bpo-21804</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="re">
|
|||
|
<h3>re<a class="headerlink" href="#re" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>References and conditional references to groups with fixed length are now
|
|||
|
allowed in lookbehind assertions:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">re</span>
|
|||
|
<span class="gp">>>> </span><span class="n">pat</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">'(a|b).(?<=\1)c'</span><span class="p">)</span>
|
|||
|
<span class="gp">>>> </span><span class="n">pat</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">'aac'</span><span class="p">)</span>
|
|||
|
<span class="go"><_sre.SRE_Match object; span=(0, 3), match='aac'></span>
|
|||
|
<span class="gp">>>> </span><span class="n">pat</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">'bbc'</span><span class="p">)</span>
|
|||
|
<span class="go"><_sre.SRE_Match object; span=(0, 3), match='bbc'></span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue9179">bpo-9179</a>.)</p>
|
|||
|
<p>The number of capturing groups in regular expressions is no longer limited to
|
|||
|
100. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue22437">bpo-22437</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/re.html#re.sub" title="re.sub"><code class="xref py py-func docutils literal notranslate"><span class="pre">sub()</span></code></a> and <a class="reference internal" href="../library/re.html#re.subn" title="re.subn"><code class="xref py py-func docutils literal notranslate"><span class="pre">subn()</span></code></a> functions now replace unmatched
|
|||
|
groups with empty strings instead of raising an exception.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue1519638">bpo-1519638</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/re.html#re.error" title="re.error"><code class="xref py py-class docutils literal notranslate"><span class="pre">re.error</span></code></a> exceptions have new attributes,
|
|||
|
<a class="reference internal" href="../library/re.html#re.error.msg" title="re.error.msg"><code class="xref py py-attr docutils literal notranslate"><span class="pre">msg</span></code></a>, <a class="reference internal" href="../library/re.html#re.error.pattern" title="re.error.pattern"><code class="xref py py-attr docutils literal notranslate"><span class="pre">pattern</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/re.html#re.error.pos" title="re.error.pos"><code class="xref py py-attr docutils literal notranslate"><span class="pre">pos</span></code></a>, <a class="reference internal" href="../library/re.html#re.error.lineno" title="re.error.lineno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">lineno</span></code></a>,
|
|||
|
and <a class="reference internal" href="../library/re.html#re.error.colno" title="re.error.colno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">colno</span></code></a>, that provide better context
|
|||
|
information about the error:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s2">"""</span>
|
|||
|
<span class="gp">... </span><span class="s2"> (?x)</span>
|
|||
|
<span class="gp">... </span><span class="s2"> .++</span>
|
|||
|
<span class="gp">... </span><span class="s2">"""</span><span class="p">)</span>
|
|||
|
<span class="gt">Traceback (most recent call last):</span>
|
|||
|
<span class="c">...</span>
|
|||
|
<span class="gr">sre_constants.error</span>: <span class="n">multiple repeat at position 16 (line 3, column 7)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue22578">bpo-22578</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="readline">
|
|||
|
<h3>readline<a class="headerlink" href="#readline" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new <a class="reference internal" href="../library/readline.html#readline.append_history_file" title="readline.append_history_file"><code class="xref py py-func docutils literal notranslate"><span class="pre">append_history_file()</span></code></a> function can be used to append
|
|||
|
the specified number of trailing elements in history to the given file.
|
|||
|
(Contributed by Bruno Cauet in <a class="reference external" href="https://bugs.python.org/issue22940">bpo-22940</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="selectors">
|
|||
|
<h3>selectors<a class="headerlink" href="#selectors" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The new <a class="reference internal" href="../library/selectors.html#selectors.DevpollSelector" title="selectors.DevpollSelector"><code class="xref py py-class docutils literal notranslate"><span class="pre">DevpollSelector</span></code></a> supports efficient
|
|||
|
<code class="docutils literal notranslate"><span class="pre">/dev/poll</span></code> polling on Solaris.
|
|||
|
(Contributed by Giampaolo Rodola’ in <a class="reference external" href="https://bugs.python.org/issue18931">bpo-18931</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="shutil">
|
|||
|
<h3>shutil<a class="headerlink" href="#shutil" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <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">move()</span></code></a> function now accepts a <em>copy_function</em> argument,
|
|||
|
allowing, for example, the <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">copy()</span></code></a> function to be used instead of
|
|||
|
the default <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">copy2()</span></code></a> if there is a need to ignore file metadata
|
|||
|
when moving.
|
|||
|
(Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue19840">bpo-19840</a>.)</p>
|
|||
|
<p>The <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">make_archive()</span></code></a> function now supports the <em>xztar</em> format.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue5411">bpo-5411</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="signal">
|
|||
|
<h3>signal<a class="headerlink" href="#signal" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>On Windows, the <a class="reference internal" href="../library/signal.html#signal.set_wakeup_fd" title="signal.set_wakeup_fd"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_wakeup_fd()</span></code></a> function now also supports
|
|||
|
socket handles. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue22018">bpo-22018</a>.)</p>
|
|||
|
<p>Various <code class="docutils literal notranslate"><span class="pre">SIG*</span></code> constants in the <a class="reference internal" href="../library/signal.html#module-signal" title="signal: Set handlers for asynchronous events."><code class="xref py py-mod docutils literal notranslate"><span class="pre">signal</span></code></a> module have been converted into
|
|||
|
<a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">Enums</span></code></a>. This allows meaningful names to be printed
|
|||
|
during debugging, instead of integer “magic numbers”.
|
|||
|
(Contributed by Giampaolo Rodola’ in <a class="reference external" href="https://bugs.python.org/issue21076">bpo-21076</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="smtpd">
|
|||
|
<h3>smtpd<a class="headerlink" href="#smtpd" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Both the <a class="reference internal" href="../library/smtpd.html#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code></a> and <a class="reference internal" href="../library/smtpd.html#smtpd.SMTPChannel" title="smtpd.SMTPChannel"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPChannel</span></code></a> classes now
|
|||
|
accept a <em>decode_data</em> keyword argument to determine if the <code class="docutils literal notranslate"><span class="pre">DATA</span></code> portion of
|
|||
|
the SMTP transaction is decoded using the <code class="docutils literal notranslate"><span class="pre">"utf-8"</span></code> codec or is instead
|
|||
|
provided to the
|
|||
|
<a class="reference internal" href="../library/smtpd.html#smtpd.SMTPServer.process_message" title="smtpd.SMTPServer.process_message"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTPServer.process_message()</span></code></a>
|
|||
|
method as a byte string. The default is <code class="docutils literal notranslate"><span class="pre">True</span></code> for backward compatibility
|
|||
|
reasons, but will change to <code class="docutils literal notranslate"><span class="pre">False</span></code> in Python 3.6. If <em>decode_data</em> is set
|
|||
|
to <code class="docutils literal notranslate"><span class="pre">False</span></code>, the <code class="docutils literal notranslate"><span class="pre">process_message</span></code> method must be prepared to accept keyword
|
|||
|
arguments.
|
|||
|
(Contributed by Maciej Szulik in <a class="reference external" href="https://bugs.python.org/issue19662">bpo-19662</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/smtpd.html#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code></a> class now advertises the <code class="docutils literal notranslate"><span class="pre">8BITMIME</span></code> extension
|
|||
|
(<span class="target" id="index-39"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc6152.html"><strong>RFC 6152</strong></a>) if <em>decode_data</em> has been set <code class="docutils literal notranslate"><span class="pre">True</span></code>. If the client
|
|||
|
specifies <code class="docutils literal notranslate"><span class="pre">BODY=8BITMIME</span></code> on the <code class="docutils literal notranslate"><span class="pre">MAIL</span></code> command, it is passed to
|
|||
|
<a class="reference internal" href="../library/smtpd.html#smtpd.SMTPServer.process_message" title="smtpd.SMTPServer.process_message"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTPServer.process_message()</span></code></a>
|
|||
|
via the <em>mail_options</em> keyword.
|
|||
|
(Contributed by Milan Oberkirch and R. David Murray in <a class="reference external" href="https://bugs.python.org/issue21795">bpo-21795</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/smtpd.html#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code></a> class now also supports the <code class="docutils literal notranslate"><span class="pre">SMTPUTF8</span></code>
|
|||
|
extension (<span class="target" id="index-40"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc6531.html"><strong>RFC 6531</strong></a>: Internationalized Email). If the client specified
|
|||
|
<code class="docutils literal notranslate"><span class="pre">SMTPUTF8</span> <span class="pre">BODY=8BITMIME</span></code> on the <code class="docutils literal notranslate"><span class="pre">MAIL</span></code> command, they are passed to
|
|||
|
<a class="reference internal" href="../library/smtpd.html#smtpd.SMTPServer.process_message" title="smtpd.SMTPServer.process_message"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTPServer.process_message()</span></code></a>
|
|||
|
via the <em>mail_options</em> keyword. It is the responsibility of the
|
|||
|
<code class="docutils literal notranslate"><span class="pre">process_message</span></code> method to correctly handle the <code class="docutils literal notranslate"><span class="pre">SMTPUTF8</span></code> data.
|
|||
|
(Contributed by Milan Oberkirch in <a class="reference external" href="https://bugs.python.org/issue21725">bpo-21725</a>.)</p>
|
|||
|
<p>It is now possible to provide, directly or via name resolution, IPv6
|
|||
|
addresses in the <a class="reference internal" href="../library/smtpd.html#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code></a> constructor, and have it
|
|||
|
successfully connect. (Contributed by Milan Oberkirch in <a class="reference external" href="https://bugs.python.org/issue14758">bpo-14758</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="smtplib">
|
|||
|
<h3>smtplib<a class="headerlink" href="#smtplib" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP.auth" title="smtplib.SMTP.auth"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTP.auth()</span></code></a> method provides a convenient way to
|
|||
|
implement custom authentication mechanisms. (Contributed by Milan
|
|||
|
Oberkirch in <a class="reference external" href="https://bugs.python.org/issue15014">bpo-15014</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP.set_debuglevel" title="smtplib.SMTP.set_debuglevel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTP.set_debuglevel()</span></code></a> method now
|
|||
|
accepts an additional debuglevel (2), which enables timestamps in debug
|
|||
|
messages. (Contributed by Gavin Chappell and Maciej Szulik in <a class="reference external" href="https://bugs.python.org/issue16914">bpo-16914</a>.)</p>
|
|||
|
<p>Both the <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP.sendmail" title="smtplib.SMTP.sendmail"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTP.sendmail()</span></code></a> and
|
|||
|
<a class="reference internal" href="../library/smtplib.html#smtplib.SMTP.send_message" title="smtplib.SMTP.send_message"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTP.send_message()</span></code></a> methods now
|
|||
|
support <span class="target" id="index-41"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc6531.html"><strong>RFC 6531</strong></a> (SMTPUTF8).
|
|||
|
(Contributed by Milan Oberkirch and R. David Murray in <a class="reference external" href="https://bugs.python.org/issue22027">bpo-22027</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="sndhdr">
|
|||
|
<h3>sndhdr<a class="headerlink" href="#sndhdr" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/sndhdr.html#sndhdr.what" title="sndhdr.what"><code class="xref py py-func docutils literal notranslate"><span class="pre">what()</span></code></a> and <a class="reference internal" href="../library/sndhdr.html#sndhdr.whathdr" title="sndhdr.whathdr"><code class="xref py py-func docutils literal notranslate"><span class="pre">whathdr()</span></code></a> functions now return
|
|||
|
a <a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a>. (Contributed by Claudiu Popa in
|
|||
|
<a class="reference external" href="https://bugs.python.org/issue18615">bpo-18615</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="socket">
|
|||
|
<h3>socket<a class="headerlink" href="#socket" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Functions with timeouts now use a monotonic clock, instead of a system clock.
|
|||
|
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue22043">bpo-22043</a>.)</p>
|
|||
|
<p>A new <a class="reference internal" href="../library/socket.html#socket.socket.sendfile" title="socket.socket.sendfile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.sendfile()</span></code></a> method allows
|
|||
|
sending a file over a socket by using the high-performance <a class="reference internal" href="../library/os.html#os.sendfile" title="os.sendfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.sendfile()</span></code></a>
|
|||
|
function on UNIX, resulting in uploads being from 2 to 3 times faster than when
|
|||
|
using plain <a class="reference internal" href="../library/socket.html#socket.socket.send" title="socket.socket.send"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.send()</span></code></a>.
|
|||
|
(Contributed by Giampaolo Rodola’ in <a class="reference external" href="https://bugs.python.org/issue17552">bpo-17552</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/socket.html#socket.socket.sendall" title="socket.socket.sendall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.sendall()</span></code></a> method no longer resets the
|
|||
|
socket timeout every time bytes are received or sent. The socket timeout is
|
|||
|
now the maximum total duration to send all data.
|
|||
|
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue23853">bpo-23853</a>.)</p>
|
|||
|
<p>The <em>backlog</em> argument of the <a class="reference internal" href="../library/socket.html#socket.socket.listen" title="socket.socket.listen"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.listen()</span></code></a>
|
|||
|
method is now optional. By default it is set to
|
|||
|
<a class="reference internal" href="../library/socket.html#socket.SOMAXCONN" title="socket.SOMAXCONN"><code class="xref py py-data docutils literal notranslate"><span class="pre">SOMAXCONN</span></code></a> or to <code class="docutils literal notranslate"><span class="pre">128</span></code>, whichever is less.
|
|||
|
(Contributed by Charles-François Natali in <a class="reference external" href="https://bugs.python.org/issue21455">bpo-21455</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="ssl">
|
|||
|
<h3>ssl<a class="headerlink" href="#ssl" title="Permalink to this headline">¶</a></h3>
|
|||
|
<div class="section" id="memory-bio-support">
|
|||
|
<span id="whatsnew-sslmemorybio"></span><h4>Memory BIO Support<a class="headerlink" href="#memory-bio-support" title="Permalink to this headline">¶</a></h4>
|
|||
|
<p>(Contributed by Geert Jansen in <a class="reference external" href="https://bugs.python.org/issue21965">bpo-21965</a>.)</p>
|
|||
|
<p>The new <a class="reference internal" href="../library/ssl.html#ssl.SSLObject" title="ssl.SSLObject"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLObject</span></code></a> class has been added to provide SSL protocol
|
|||
|
support for cases when the network I/O capabilities of <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket" title="ssl.SSLSocket"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLSocket</span></code></a>
|
|||
|
are not necessary or are suboptimal. <code class="docutils literal notranslate"><span class="pre">SSLObject</span></code> represents
|
|||
|
an SSL protocol instance, but does not implement any network I/O methods, and
|
|||
|
instead provides a memory buffer interface. The new <a class="reference internal" href="../library/ssl.html#ssl.MemoryBIO" title="ssl.MemoryBIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">MemoryBIO</span></code></a>
|
|||
|
class can be used to pass data between Python and an SSL protocol instance.</p>
|
|||
|
<p>The memory BIO SSL support is primarily intended to be used in frameworks
|
|||
|
implementing asynchronous I/O for which <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket" title="ssl.SSLSocket"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLSocket</span></code></a>’s readiness
|
|||
|
model (“select/poll”) is inefficient.</p>
|
|||
|
<p>A new <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.wrap_bio" title="ssl.SSLContext.wrap_bio"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLContext.wrap_bio()</span></code></a> method can be used
|
|||
|
to create a new <code class="docutils literal notranslate"><span class="pre">SSLObject</span></code> instance.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="application-layer-protocol-negotiation-support">
|
|||
|
<h4>Application-Layer Protocol Negotiation Support<a class="headerlink" href="#application-layer-protocol-negotiation-support" title="Permalink to this headline">¶</a></h4>
|
|||
|
<p>(Contributed by Benjamin Peterson in <a class="reference external" href="https://bugs.python.org/issue20188">bpo-20188</a>.)</p>
|
|||
|
<p>Where OpenSSL support is present, the <a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a> module now implements
|
|||
|
the <em>Application-Layer Protocol Negotiation</em> TLS extension as described
|
|||
|
in <span class="target" id="index-42"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc7301.html"><strong>RFC 7301</strong></a>.</p>
|
|||
|
<p>The new <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_alpn_protocols" title="ssl.SSLContext.set_alpn_protocols"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLContext.set_alpn_protocols()</span></code></a>
|
|||
|
can be used to specify which protocols a socket should advertise during
|
|||
|
the TLS handshake.</p>
|
|||
|
<p>The new
|
|||
|
<a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.selected_alpn_protocol" title="ssl.SSLSocket.selected_alpn_protocol"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.selected_alpn_protocol()</span></code></a>
|
|||
|
returns the protocol that was selected during the TLS handshake.
|
|||
|
The <a class="reference internal" href="../library/ssl.html#ssl.HAS_ALPN" title="ssl.HAS_ALPN"><code class="xref py py-data docutils literal notranslate"><span class="pre">HAS_ALPN</span></code></a> flag indicates whether ALPN support is present.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="other-changes">
|
|||
|
<h4>Other Changes<a class="headerlink" href="#other-changes" title="Permalink to this headline">¶</a></h4>
|
|||
|
<p>There is a new <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.version" title="ssl.SSLSocket.version"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.version()</span></code></a> method to
|
|||
|
query the actual protocol version in use.
|
|||
|
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue20421">bpo-20421</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket" title="ssl.SSLSocket"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLSocket</span></code></a> class now implements
|
|||
|
a <code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.sendfile()</span></code> method.
|
|||
|
(Contributed by Giampaolo Rodola’ in <a class="reference external" href="https://bugs.python.org/issue17552">bpo-17552</a>.)</p>
|
|||
|
<p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.send()</span></code> method now raises either
|
|||
|
the <a class="reference internal" href="../library/ssl.html#ssl.SSLWantReadError" title="ssl.SSLWantReadError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ssl.SSLWantReadError</span></code></a> or <a class="reference internal" href="../library/ssl.html#ssl.SSLWantWriteError" title="ssl.SSLWantWriteError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ssl.SSLWantWriteError</span></code></a> exception on a
|
|||
|
non-blocking socket if the operation would block. Previously, it would return
|
|||
|
<code class="docutils literal notranslate"><span class="pre">0</span></code>. (Contributed by Nikolaus Rath in <a class="reference external" href="https://bugs.python.org/issue20951">bpo-20951</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/ssl.html#ssl.cert_time_to_seconds" title="ssl.cert_time_to_seconds"><code class="xref py py-func docutils literal notranslate"><span class="pre">cert_time_to_seconds()</span></code></a> function now interprets the input time
|
|||
|
as UTC and not as local time, per <span class="target" id="index-43"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5280.html"><strong>RFC 5280</strong></a>. Additionally, the return
|
|||
|
value is always an <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>. (Contributed by Akira Li in <a class="reference external" href="https://bugs.python.org/issue19940">bpo-19940</a>.)</p>
|
|||
|
<p>New <code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLObject.shared_ciphers()</span></code> and
|
|||
|
<a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.shared_ciphers" title="ssl.SSLSocket.shared_ciphers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.shared_ciphers()</span></code></a> methods return
|
|||
|
the list of ciphers sent by the client during the handshake.
|
|||
|
(Contributed by Benjamin Peterson in <a class="reference external" href="https://bugs.python.org/issue23186">bpo-23186</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.do_handshake" title="ssl.SSLSocket.do_handshake"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.do_handshake()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.read" title="ssl.SSLSocket.read"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.read()</span></code></a>,
|
|||
|
<code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.shutdown()</span></code>, and
|
|||
|
<a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.write" title="ssl.SSLSocket.write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.write()</span></code></a> methods of the <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket" title="ssl.SSLSocket"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLSocket</span></code></a>
|
|||
|
class no longer reset the socket timeout every time bytes are received or sent.
|
|||
|
The socket timeout is now the maximum total duration of the method.
|
|||
|
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue23853">bpo-23853</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/ssl.html#ssl.match_hostname" title="ssl.match_hostname"><code class="xref py py-func docutils literal notranslate"><span class="pre">match_hostname()</span></code></a> function now supports matching of IP addresses.
|
|||
|
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue23239">bpo-23239</a>.)</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="sqlite3">
|
|||
|
<h3>sqlite3<a class="headerlink" href="#sqlite3" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/sqlite3.html#sqlite3.Row" title="sqlite3.Row"><code class="xref py py-class docutils literal notranslate"><span class="pre">Row</span></code></a> class now fully supports the sequence protocol,
|
|||
|
in particular <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> iteration and slice indexing.
|
|||
|
(Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue10203">bpo-10203</a>; by Lucas Sinclair,
|
|||
|
Jessica McKellar, and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue13583">bpo-13583</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="subprocess">
|
|||
|
<span id="whatsnew-subprocess"></span><h3>subprocess<a class="headerlink" href="#subprocess" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The new <a class="reference internal" href="../library/subprocess.html#subprocess.run" title="subprocess.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">run()</span></code></a> function has been added.
|
|||
|
It runs the specified command and returns a
|
|||
|
<a class="reference internal" href="../library/subprocess.html#subprocess.CompletedProcess" title="subprocess.CompletedProcess"><code class="xref py py-class docutils literal notranslate"><span class="pre">CompletedProcess</span></code></a> object, which describes a finished
|
|||
|
process. The new API is more consistent and is the recommended approach
|
|||
|
to invoking subprocesses in Python code that does not need to maintain
|
|||
|
compatibility with earlier Python versions.
|
|||
|
(Contributed by Thomas Kluyver in <a class="reference external" href="https://bugs.python.org/issue23342">bpo-23342</a>.)</p>
|
|||
|
<p>Examples:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">subprocess</span><span class="o">.</span><span class="n">run</span><span class="p">([</span><span class="s2">"ls"</span><span class="p">,</span> <span class="s2">"-l"</span><span class="p">])</span> <span class="c1"># doesn't capture output</span>
|
|||
|
<span class="go">CompletedProcess(args=['ls', '-l'], returncode=0)</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="n">subprocess</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="s2">"exit 1"</span><span class="p">,</span> <span class="n">shell</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">check</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
|||
|
<span class="gt">Traceback (most recent call last):</span>
|
|||
|
<span class="c">...</span>
|
|||
|
<span class="gr">subprocess.CalledProcessError</span>: <span class="n">Command 'exit 1' returned non-zero exit status 1</span>
|
|||
|
|
|||
|
<span class="gp">>>> </span><span class="n">subprocess</span><span class="o">.</span><span class="n">run</span><span class="p">([</span><span class="s2">"ls"</span><span class="p">,</span> <span class="s2">"-l"</span><span class="p">,</span> <span class="s2">"/dev/null"</span><span class="p">],</span> <span class="n">stdout</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">)</span>
|
|||
|
<span class="go">CompletedProcess(args=['ls', '-l', '/dev/null'], returncode=0,</span>
|
|||
|
<span class="go">stdout=b'crw-rw-rw- 1 root root 1, 3 Jan 23 16:23 /dev/null\n')</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="sys">
|
|||
|
<h3>sys<a class="headerlink" href="#sys" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new <a class="reference internal" href="../library/sys.html#sys.set_coroutine_wrapper" title="sys.set_coroutine_wrapper"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_coroutine_wrapper()</span></code></a> function allows setting a global
|
|||
|
hook that will be called whenever a <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine object</span></a>
|
|||
|
is created by an <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> function. A corresponding
|
|||
|
<a class="reference internal" href="../library/sys.html#sys.get_coroutine_wrapper" title="sys.get_coroutine_wrapper"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_coroutine_wrapper()</span></code></a> can be used to obtain a currently set
|
|||
|
wrapper. Both functions are <a class="reference internal" href="../glossary.html#term-provisional-api"><span class="xref std std-term">provisional</span></a>,
|
|||
|
and are intended for debugging purposes only. (Contributed by Yury Selivanov
|
|||
|
in <a class="reference external" href="https://bugs.python.org/issue24017">bpo-24017</a>.)</p>
|
|||
|
<p>A new <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">is_finalizing()</span></code></a> function can be used to check if the Python
|
|||
|
interpreter is <a class="reference internal" href="../glossary.html#term-interpreter-shutdown"><span class="xref std std-term">shutting down</span></a>.
|
|||
|
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue22696">bpo-22696</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="sysconfig">
|
|||
|
<h3>sysconfig<a class="headerlink" href="#sysconfig" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The name of the user scripts directory on Windows now includes the first
|
|||
|
two components of the Python version. (Contributed by Paul Moore
|
|||
|
in <a class="reference external" href="https://bugs.python.org/issue23437">bpo-23437</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="tarfile">
|
|||
|
<h3>tarfile<a class="headerlink" href="#tarfile" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <em>mode</em> argument of the <a class="reference internal" href="../library/tarfile.html#tarfile.open" title="tarfile.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function now accepts <code class="docutils literal notranslate"><span class="pre">"x"</span></code>
|
|||
|
to request exclusive creation. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue21717">bpo-21717</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/tarfile.html#tarfile.TarFile.extractall" title="tarfile.TarFile.extractall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TarFile.extractall()</span></code></a> and
|
|||
|
<a class="reference internal" href="../library/tarfile.html#tarfile.TarFile.extract" title="tarfile.TarFile.extract"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TarFile.extract()</span></code></a> methods now take a keyword
|
|||
|
argument <em>numeric_owner</em>. If set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, the extracted files and
|
|||
|
directories will be owned by the numeric <code class="docutils literal notranslate"><span class="pre">uid</span></code> and <code class="docutils literal notranslate"><span class="pre">gid</span></code> from the tarfile.
|
|||
|
If set to <code class="docutils literal notranslate"><span class="pre">False</span></code> (the default, and the behavior in versions prior to 3.5),
|
|||
|
they will be owned by the named user and group in the tarfile.
|
|||
|
(Contributed by Michael Vogt and Eric Smith in <a class="reference external" href="https://bugs.python.org/issue23193">bpo-23193</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/tarfile.html#tarfile.TarFile.list" title="tarfile.TarFile.list"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TarFile.list()</span></code></a> now accepts an optional
|
|||
|
<em>members</em> keyword argument that can be set to a subset of the list returned
|
|||
|
by <a class="reference internal" href="../library/tarfile.html#tarfile.TarFile.getmembers" title="tarfile.TarFile.getmembers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TarFile.getmembers()</span></code></a>.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue21549">bpo-21549</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="threading">
|
|||
|
<h3>threading<a class="headerlink" href="#threading" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Both the <a class="reference internal" href="../library/threading.html#threading.Lock.acquire" title="threading.Lock.acquire"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Lock.acquire()</span></code></a> and
|
|||
|
<a class="reference internal" href="../library/threading.html#threading.RLock.acquire" title="threading.RLock.acquire"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RLock.acquire()</span></code></a> methods
|
|||
|
now use a monotonic clock for timeout management.
|
|||
|
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue22043">bpo-22043</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="time">
|
|||
|
<h3>time<a class="headerlink" href="#time" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/time.html#time.monotonic" title="time.monotonic"><code class="xref py py-func docutils literal notranslate"><span class="pre">monotonic()</span></code></a> function is now always available.
|
|||
|
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue22043">bpo-22043</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="timeit">
|
|||
|
<h3>timeit<a class="headerlink" href="#timeit" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new command line option <code class="docutils literal notranslate"><span class="pre">-u</span></code> or <code class="samp docutils literal notranslate"><span class="pre">--unit=</span><em><span class="pre">U</span></em></code> can be used to specify the time
|
|||
|
unit for the timer output. Supported options are <code class="docutils literal notranslate"><span class="pre">usec</span></code>, <code class="docutils literal notranslate"><span class="pre">msec</span></code>,
|
|||
|
or <code class="docutils literal notranslate"><span class="pre">sec</span></code>. (Contributed by Julian Gindi in <a class="reference external" href="https://bugs.python.org/issue18983">bpo-18983</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/timeit.html#timeit.timeit" title="timeit.timeit"><code class="xref py py-func docutils literal notranslate"><span class="pre">timeit()</span></code></a> function has a new <em>globals</em> parameter for
|
|||
|
specifying the namespace in which the code will be running.
|
|||
|
(Contributed by Ben Roberts in <a class="reference external" href="https://bugs.python.org/issue2527">bpo-2527</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="tkinter">
|
|||
|
<h3>tkinter<a class="headerlink" href="#tkinter" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter._fix</span></code> module used for setting up the Tcl/Tk environment
|
|||
|
on Windows has been replaced by a private function in the <code class="xref py py-mod docutils literal notranslate"><span class="pre">_tkinter</span></code>
|
|||
|
module which makes no permanent changes to environment variables.
|
|||
|
(Contributed by Zachary Ware in <a class="reference external" href="https://bugs.python.org/issue20035">bpo-20035</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="traceback">
|
|||
|
<span id="whatsnew-traceback"></span><h3>traceback<a class="headerlink" href="#traceback" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>New <a class="reference internal" href="../library/traceback.html#traceback.walk_stack" title="traceback.walk_stack"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk_stack()</span></code></a> and <a class="reference internal" href="../library/traceback.html#traceback.walk_tb" title="traceback.walk_tb"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk_tb()</span></code></a>
|
|||
|
functions to conveniently traverse frame and traceback objects.
|
|||
|
(Contributed by Robert Collins in <a class="reference external" href="https://bugs.python.org/issue17911">bpo-17911</a>.)</p>
|
|||
|
<p>New lightweight classes: <a class="reference internal" href="../library/traceback.html#traceback.TracebackException" title="traceback.TracebackException"><code class="xref py py-class docutils literal notranslate"><span class="pre">TracebackException</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/traceback.html#traceback.StackSummary" title="traceback.StackSummary"><code class="xref py py-class docutils literal notranslate"><span class="pre">StackSummary</span></code></a>, and <a class="reference internal" href="../library/traceback.html#traceback.FrameSummary" title="traceback.FrameSummary"><code class="xref py py-class docutils literal notranslate"><span class="pre">FrameSummary</span></code></a>.
|
|||
|
(Contributed by Robert Collins in <a class="reference external" href="https://bugs.python.org/issue17911">bpo-17911</a>.)</p>
|
|||
|
<p>Both the <a class="reference internal" href="../library/traceback.html#traceback.print_tb" title="traceback.print_tb"><code class="xref py py-func docutils literal notranslate"><span class="pre">print_tb()</span></code></a> and <a class="reference internal" href="../library/traceback.html#traceback.print_stack" title="traceback.print_stack"><code class="xref py py-func docutils literal notranslate"><span class="pre">print_stack()</span></code></a> functions
|
|||
|
now support negative values for the <em>limit</em> argument.
|
|||
|
(Contributed by Dmitry Kazakov in <a class="reference external" href="https://bugs.python.org/issue22619">bpo-22619</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="types">
|
|||
|
<h3>types<a class="headerlink" href="#types" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new <a class="reference internal" href="../library/types.html#types.coroutine" title="types.coroutine"><code class="xref py py-func docutils literal notranslate"><span class="pre">coroutine()</span></code></a> function to transform
|
|||
|
<a class="reference internal" href="../glossary.html#term-generator-iterator"><span class="xref std std-term">generator</span></a> and
|
|||
|
<a class="reference internal" href="../library/collections.abc.html#collections.abc.Generator" title="collections.abc.Generator"><code class="xref py py-class docutils literal notranslate"><span class="pre">generator-like</span></code></a> objects into
|
|||
|
<a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitables</span></a>.
|
|||
|
(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue24017">bpo-24017</a>.)</p>
|
|||
|
<p>A new type called <a class="reference internal" href="../library/types.html#types.CoroutineType" title="types.CoroutineType"><code class="xref py py-class docutils literal notranslate"><span class="pre">CoroutineType</span></code></a>, which is used for
|
|||
|
<a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> objects created by <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> functions.
|
|||
|
(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue24400">bpo-24400</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="unicodedata">
|
|||
|
<h3>unicodedata<a class="headerlink" href="#unicodedata" title="Permalink to this headline">¶</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 now uses data from <a class="reference external" href="http://unicode.org/versions/Unicode8.0.0/">Unicode 8.0.0</a>.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="unittest">
|
|||
|
<h3>unittest<a class="headerlink" href="#unittest" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/unittest.html#unittest.TestLoader.loadTestsFromModule" title="unittest.TestLoader.loadTestsFromModule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TestLoader.loadTestsFromModule()</span></code></a>
|
|||
|
method now accepts a keyword-only argument <em>pattern</em> which is passed to
|
|||
|
<code class="docutils literal notranslate"><span class="pre">load_tests</span></code> as the third argument. Found packages are now checked for
|
|||
|
<code class="docutils literal notranslate"><span class="pre">load_tests</span></code> regardless of whether their path matches <em>pattern</em>, because it
|
|||
|
is impossible for a package name to match the default pattern.
|
|||
|
(Contributed by Robert Collins and Barry A. Warsaw in <a class="reference external" href="https://bugs.python.org/issue16662">bpo-16662</a>.)</p>
|
|||
|
<p>Unittest discovery errors now are exposed in the
|
|||
|
<a class="reference internal" href="../library/unittest.html#unittest.TestLoader.errors" title="unittest.TestLoader.errors"><code class="xref py py-data docutils literal notranslate"><span class="pre">TestLoader.errors</span></code></a> attribute of the
|
|||
|
<a class="reference internal" href="../library/unittest.html#unittest.TestLoader" title="unittest.TestLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestLoader</span></code></a> instance.
|
|||
|
(Contributed by Robert Collins in <a class="reference external" href="https://bugs.python.org/issue19746">bpo-19746</a>.)</p>
|
|||
|
<p>A new command line option <code class="docutils literal notranslate"><span class="pre">--locals</span></code> to show local variables in
|
|||
|
tracebacks. (Contributed by Robert Collins in <a class="reference external" href="https://bugs.python.org/issue22936">bpo-22936</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="unittest-mock">
|
|||
|
<h3>unittest.mock<a class="headerlink" href="#unittest-mock" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <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> class has the following improvements:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>The class constructor has a new <em>unsafe</em> parameter, which causes mock
|
|||
|
objects to raise <a class="reference internal" href="../library/exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a> on attribute names starting
|
|||
|
with <code class="docutils literal notranslate"><span class="pre">"assert"</span></code>.
|
|||
|
(Contributed by Kushal Das in <a class="reference external" href="https://bugs.python.org/issue21238">bpo-21238</a>.)</p></li>
|
|||
|
<li><p>A new <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.Mock.assert_not_called" title="unittest.mock.Mock.assert_not_called"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Mock.assert_not_called()</span></code></a>
|
|||
|
method to check if the mock object was called.
|
|||
|
(Contributed by Kushal Das in <a class="reference external" href="https://bugs.python.org/issue21262">bpo-21262</a>.)</p></li>
|
|||
|
</ul>
|
|||
|
<p>The <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.MagicMock" title="unittest.mock.MagicMock"><code class="xref py py-class docutils literal notranslate"><span class="pre">MagicMock</span></code></a> class now supports <a class="reference internal" href="../reference/datamodel.html#object.__truediv__" title="object.__truediv__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__truediv__()</span></code></a>,
|
|||
|
<a class="reference internal" href="../reference/datamodel.html#object.__divmod__" title="object.__divmod__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__divmod__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__matmul__" title="object.__matmul__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__matmul__()</span></code></a> operators.
|
|||
|
(Contributed by Johannes Baiter in <a class="reference external" href="https://bugs.python.org/issue20968">bpo-20968</a>, and Håkan Lövdahl
|
|||
|
in <a class="reference external" href="https://bugs.python.org/issue23581">bpo-23581</a> and <a class="reference external" href="https://bugs.python.org/issue23568">bpo-23568</a>.)</p>
|
|||
|
<p>It is no longer necessary to explicitly pass <code class="docutils literal notranslate"><span class="pre">create=True</span></code> to the
|
|||
|
<a class="reference internal" href="../library/unittest.mock.html#unittest.mock.patch" title="unittest.mock.patch"><code class="xref py py-func docutils literal notranslate"><span class="pre">patch()</span></code></a> function when patching builtin names.
|
|||
|
(Contributed by Kushal Das in <a class="reference external" href="https://bugs.python.org/issue17660">bpo-17660</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="urllib">
|
|||
|
<h3>urllib<a class="headerlink" href="#urllib" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>A new
|
|||
|
<a class="reference internal" href="../library/urllib.request.html#urllib.request.HTTPPasswordMgrWithPriorAuth" title="urllib.request.HTTPPasswordMgrWithPriorAuth"><code class="xref py py-class docutils literal notranslate"><span class="pre">request.HTTPPasswordMgrWithPriorAuth</span></code></a>
|
|||
|
class allows HTTP Basic Authentication credentials to be managed so as to
|
|||
|
eliminate unnecessary <code class="docutils literal notranslate"><span class="pre">401</span></code> response handling, or to unconditionally send
|
|||
|
credentials on the first request in order to communicate with servers that
|
|||
|
return a <code class="docutils literal notranslate"><span class="pre">404</span></code> response instead of a <code class="docutils literal notranslate"><span class="pre">401</span></code> if the <code class="docutils literal notranslate"><span class="pre">Authorization</span></code> header
|
|||
|
is not sent. (Contributed by Matej Cepl in <a class="reference external" href="https://bugs.python.org/issue19494">bpo-19494</a> and Akshit Khurana in
|
|||
|
<a class="reference external" href="https://bugs.python.org/issue7159">bpo-7159</a>.)</p>
|
|||
|
<p>A new <em>quote_via</em> argument for the
|
|||
|
<a class="reference internal" href="../library/urllib.parse.html#urllib.parse.urlencode" title="urllib.parse.urlencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse.urlencode()</span></code></a>
|
|||
|
function provides a way to control the encoding of query parts if needed.
|
|||
|
(Contributed by Samwyse and Arnon Yaari in <a class="reference external" href="https://bugs.python.org/issue13866">bpo-13866</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/urllib.request.html#urllib.request.urlopen" title="urllib.request.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">request.urlopen()</span></code></a> function accepts an
|
|||
|
<a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> object as a <em>context</em> argument, which will be used for
|
|||
|
the HTTPS connection. (Contributed by Alex Gaynor in <a class="reference external" href="https://bugs.python.org/issue22366">bpo-22366</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.urljoin" title="urllib.parse.urljoin"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse.urljoin()</span></code></a> was updated to use the
|
|||
|
<span class="target" id="index-44"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc3986.html"><strong>RFC 3986</strong></a> semantics for the resolution of relative URLs, rather than
|
|||
|
<span class="target" id="index-45"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc1808.html"><strong>RFC 1808</strong></a> and <span class="target" id="index-46"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2396.html"><strong>RFC 2396</strong></a>.
|
|||
|
(Contributed by Demian Brecht and Senthil Kumaran in <a class="reference external" href="https://bugs.python.org/issue22118">bpo-22118</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="wsgiref">
|
|||
|
<h3>wsgiref<a class="headerlink" href="#wsgiref" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <em>headers</em> argument of the <a class="reference internal" href="../library/wsgiref.html#wsgiref.headers.Headers" title="wsgiref.headers.Headers"><code class="xref py py-class docutils literal notranslate"><span class="pre">headers.Headers</span></code></a>
|
|||
|
class constructor is now optional.
|
|||
|
(Contributed by Pablo Torres Navarrete and SilentGhost in <a class="reference external" href="https://bugs.python.org/issue5800">bpo-5800</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="xmlrpc">
|
|||
|
<h3>xmlrpc<a class="headerlink" href="#xmlrpc" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <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">client.ServerProxy</span></code></a> class now supports
|
|||
|
the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> protocol.
|
|||
|
(Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue20627">bpo-20627</a>.)</p>
|
|||
|
<p>The <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">client.ServerProxy</span></code></a> constructor now accepts
|
|||
|
an optional <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> instance.
|
|||
|
(Contributed by Alex Gaynor in <a class="reference external" href="https://bugs.python.org/issue22960">bpo-22960</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="xml-sax">
|
|||
|
<h3>xml.sax<a class="headerlink" href="#xml-sax" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>SAX parsers now support a character stream of the
|
|||
|
<a class="reference internal" href="../library/xml.sax.reader.html#xml.sax.xmlreader.InputSource" title="xml.sax.xmlreader.InputSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">xmlreader.InputSource</span></code></a> object.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue2175">bpo-2175</a>.)</p>
|
|||
|
<p><a class="reference internal" href="../library/xml.sax.html#xml.sax.parseString" title="xml.sax.parseString"><code class="xref py py-func docutils literal notranslate"><span class="pre">parseString()</span></code></a> now accepts a <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> instance.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue10590">bpo-10590</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="zipfile">
|
|||
|
<h3>zipfile<a class="headerlink" href="#zipfile" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>ZIP output can now be written to unseekable streams.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue23252">bpo-23252</a>.)</p>
|
|||
|
<p>The <em>mode</em> argument of <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile.open" title="zipfile.ZipFile.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ZipFile.open()</span></code></a> method now
|
|||
|
accepts <code class="docutils literal notranslate"><span class="pre">"x"</span></code> to request exclusive creation.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue21717">bpo-21717</a>.)</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="other-module-level-changes">
|
|||
|
<h2>Other module-level changes<a class="headerlink" href="#other-module-level-changes" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>Many functions in the <a class="reference internal" href="../library/mmap.html#module-mmap" title="mmap: Interface to memory-mapped files for Unix and Windows."><code class="xref py py-mod docutils literal notranslate"><span class="pre">mmap</span></code></a>, <a class="reference internal" href="../library/ossaudiodev.html#module-ossaudiodev" title="ossaudiodev: Access to OSS-compatible audio devices. (Linux, FreeBSD)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code></a>, <a class="reference internal" href="../library/socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socket</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a>, and <a class="reference internal" href="../library/codecs.html#module-codecs" title="codecs: Encode and decode data and streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">codecs</span></code></a> modules now accept writable
|
|||
|
<a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like objects</span></a>.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue23001">bpo-23001</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="optimizations">
|
|||
|
<h2>Optimizations<a class="headerlink" href="#optimizations" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>The <a class="reference internal" href="../library/os.html#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.walk()</span></code></a> function has been sped up by 3 to 5 times on POSIX systems,
|
|||
|
and by 7 to 20 times on Windows. This was done using the new <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, which exposes file information from the underlying <code class="docutils literal notranslate"><span class="pre">readdir</span></code> or
|
|||
|
<code class="docutils literal notranslate"><span class="pre">FindFirstFile</span></code>/<code class="docutils literal notranslate"><span class="pre">FindNextFile</span></code> system calls. (Contributed by
|
|||
|
Ben Hoyt with help from Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue23605">bpo-23605</a>.)</p>
|
|||
|
<p>Construction of <code class="docutils literal notranslate"><span class="pre">bytes(int)</span></code> (filled by zero bytes) is faster and uses less
|
|||
|
memory for large objects. <code class="docutils literal notranslate"><span class="pre">calloc()</span></code> is used instead of <code class="docutils literal notranslate"><span class="pre">malloc()</span></code> to
|
|||
|
allocate memory for these objects.
|
|||
|
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue21233">bpo-21233</a>.)</p>
|
|||
|
<p>Some operations on <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> <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv4Network</span></code></a> and
|
|||
|
<a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv6Network</span></code></a> have been massively sped up, such as
|
|||
|
<a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Network.subnets" title="ipaddress.IPv4Network.subnets"><code class="xref py py-meth docutils literal notranslate"><span class="pre">subnets()</span></code></a>, <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Network.supernet" title="ipaddress.IPv4Network.supernet"><code class="xref py py-meth docutils literal notranslate"><span class="pre">supernet()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/ipaddress.html#ipaddress.summarize_address_range" title="ipaddress.summarize_address_range"><code class="xref py py-func docutils literal notranslate"><span class="pre">summarize_address_range()</span></code></a>, <a class="reference internal" href="../library/ipaddress.html#ipaddress.collapse_addresses" title="ipaddress.collapse_addresses"><code class="xref py py-func docutils literal notranslate"><span class="pre">collapse_addresses()</span></code></a>.
|
|||
|
The speed up can range from 3 to 15 times.
|
|||
|
(Contributed by Antoine Pitrou, Michel Albert, and Markus in
|
|||
|
<a class="reference external" href="https://bugs.python.org/issue21486">bpo-21486</a>, <a class="reference external" href="https://bugs.python.org/issue21487">bpo-21487</a>, <a class="reference external" href="https://bugs.python.org/issue20826">bpo-20826</a>, <a class="reference external" href="https://bugs.python.org/issue23266">bpo-23266</a>.)</p>
|
|||
|
<p>Pickling of <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> objects was optimized to produce significantly
|
|||
|
smaller output. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue23133">bpo-23133</a>.)</p>
|
|||
|
<p>Many operations on <a class="reference internal" href="../library/io.html#io.BytesIO" title="io.BytesIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.BytesIO</span></code></a> are now 50% to 100% faster.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue15381">bpo-15381</a> and David Wilson in
|
|||
|
<a class="reference external" href="https://bugs.python.org/issue22003">bpo-22003</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/marshal.html#marshal.dumps" title="marshal.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">marshal.dumps()</span></code></a> function is now faster: 65–85% with versions 3
|
|||
|
and 4, 20–25% with versions 0 to 2 on typical data, and up to 5 times in
|
|||
|
best cases.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue20416">bpo-20416</a> and <a class="reference external" href="https://bugs.python.org/issue23344">bpo-23344</a>.)</p>
|
|||
|
<p>The UTF-32 encoder is now 3 to 7 times faster.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue15027">bpo-15027</a>.)</p>
|
|||
|
<p>Regular expressions are now parsed up to 10% faster.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue19380">bpo-19380</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/json.html#json.dumps" title="json.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.dumps()</span></code></a> function was optimized to run with
|
|||
|
<code class="docutils literal notranslate"><span class="pre">ensure_ascii=False</span></code> as fast as with <code class="docutils literal notranslate"><span class="pre">ensure_ascii=True</span></code>.
|
|||
|
(Contributed by Naoki Inada in <a class="reference external" href="https://bugs.python.org/issue23206">bpo-23206</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../c-api/object.html#c.PyObject_IsInstance" title="PyObject_IsInstance"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_IsInstance()</span></code></a> and <a class="reference internal" href="../c-api/object.html#c.PyObject_IsSubclass" title="PyObject_IsSubclass"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_IsSubclass()</span></code></a>
|
|||
|
functions have been sped up in the common case that the second argument
|
|||
|
has <a class="reference internal" href="../library/functions.html#type" title="type"><code class="xref py py-class docutils literal notranslate"><span class="pre">type</span></code></a> as its metaclass.
|
|||
|
(Contributed Georg Brandl by in <a class="reference external" href="https://bugs.python.org/issue22540">bpo-22540</a>.)</p>
|
|||
|
<p>Method caching was slightly improved, yielding up to 5% performance
|
|||
|
improvement in some benchmarks.
|
|||
|
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue22847">bpo-22847</a>.)</p>
|
|||
|
<p>Objects from the <a class="reference internal" href="../library/random.html#module-random" title="random: Generate pseudo-random numbers with various common distributions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">random</span></code></a> module now use 50% less memory on 64-bit
|
|||
|
builds. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue23488">bpo-23488</a>.)</p>
|
|||
|
<p>The <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> getter calls are up to 25% faster.
|
|||
|
(Contributed by Joe Jevnik in <a class="reference external" href="https://bugs.python.org/issue23910">bpo-23910</a>.)</p>
|
|||
|
<p>Instantiation of <a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">fractions.Fraction</span></code></a> is now up to 30% faster.
|
|||
|
(Contributed by Stefan Behnel in <a class="reference external" href="https://bugs.python.org/issue22464">bpo-22464</a>.)</p>
|
|||
|
<p>String methods <a class="reference internal" href="../library/stdtypes.html#str.find" title="str.find"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#str.rfind" title="str.rfind"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rfind()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#str.split" title="str.split"><code class="xref py py-meth docutils literal notranslate"><span class="pre">split()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/stdtypes.html#str.partition" title="str.partition"><code class="xref py py-meth docutils literal notranslate"><span class="pre">partition()</span></code></a> and the <a class="reference internal" href="../reference/expressions.html#in"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">in</span></code></a> string operator are now significantly
|
|||
|
faster for searching 1-character substrings.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue23573">bpo-23573</a>.)</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="build-and-c-api-changes">
|
|||
|
<h2>Build and C API Changes<a class="headerlink" href="#build-and-c-api-changes" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>New <code class="docutils literal notranslate"><span class="pre">calloc</span></code> functions were added:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p><a class="reference internal" href="../c-api/memory.html#c.PyMem_RawCalloc" title="PyMem_RawCalloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawCalloc()</span></code></a>,</p></li>
|
|||
|
<li><p><a class="reference internal" href="../c-api/memory.html#c.PyMem_Calloc" title="PyMem_Calloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Calloc()</span></code></a>,</p></li>
|
|||
|
<li><p><a class="reference internal" href="../c-api/memory.html#c.PyObject_Calloc" title="PyObject_Calloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Calloc()</span></code></a>.</p></li>
|
|||
|
</ul>
|
|||
|
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue21233">bpo-21233</a>.)</p>
|
|||
|
<p>New encoding/decoding helper functions:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p><a class="reference internal" href="../c-api/sys.html#c.Py_DecodeLocale" title="Py_DecodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DecodeLocale()</span></code></a> (replaced <code class="docutils literal notranslate"><span class="pre">_Py_char2wchar()</span></code>),</p></li>
|
|||
|
<li><p><a class="reference internal" href="../c-api/sys.html#c.Py_EncodeLocale" title="Py_EncodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_EncodeLocale()</span></code></a> (replaced <code class="docutils literal notranslate"><span class="pre">_Py_wchar2char()</span></code>).</p></li>
|
|||
|
</ul>
|
|||
|
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue18395">bpo-18395</a>.)</p>
|
|||
|
<p>A new <a class="reference internal" href="../c-api/codec.html#c.PyCodec_NameReplaceErrors" title="PyCodec_NameReplaceErrors"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCodec_NameReplaceErrors()</span></code></a> function to replace the unicode
|
|||
|
encode error with <code class="docutils literal notranslate"><span class="pre">\N{...}</span></code> escapes.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue19676">bpo-19676</a>.)</p>
|
|||
|
<p>A new <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_FormatV" title="PyErr_FormatV"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_FormatV()</span></code></a> function similar to <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Format" title="PyErr_Format"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Format()</span></code></a>,
|
|||
|
but accepts a <code class="docutils literal notranslate"><span class="pre">va_list</span></code> argument.
|
|||
|
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue18711">bpo-18711</a>.)</p>
|
|||
|
<p>A new <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_RecursionError</span></code> exception.
|
|||
|
(Contributed by Georg Brandl in <a class="reference external" href="https://bugs.python.org/issue19235">bpo-19235</a>.)</p>
|
|||
|
<p>New <a class="reference internal" href="../c-api/module.html#c.PyModule_FromDefAndSpec" title="PyModule_FromDefAndSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_FromDefAndSpec()</span></code></a>, <a class="reference internal" href="../c-api/module.html#c.PyModule_FromDefAndSpec2" title="PyModule_FromDefAndSpec2"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_FromDefAndSpec2()</span></code></a>,
|
|||
|
and <a class="reference internal" href="../c-api/module.html#c.PyModule_ExecDef" title="PyModule_ExecDef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_ExecDef()</span></code></a> functions introduced by <span class="target" id="index-47"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0489"><strong>PEP 489</strong></a> –
|
|||
|
multi-phase extension module initialization.
|
|||
|
(Contributed by Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue24268">bpo-24268</a>.)</p>
|
|||
|
<p>New <a class="reference internal" href="../c-api/number.html#c.PyNumber_MatrixMultiply" title="PyNumber_MatrixMultiply"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_MatrixMultiply()</span></code></a> and
|
|||
|
<a class="reference internal" href="../c-api/number.html#c.PyNumber_InPlaceMatrixMultiply" title="PyNumber_InPlaceMatrixMultiply"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_InPlaceMatrixMultiply()</span></code></a> functions to perform matrix
|
|||
|
multiplication.
|
|||
|
(Contributed by Benjamin Peterson in <a class="reference external" href="https://bugs.python.org/issue21176">bpo-21176</a>. See also <span class="target" id="index-48"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0465"><strong>PEP 465</strong></a>
|
|||
|
for details.)</p>
|
|||
|
<p>The <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">PyTypeObject.tp_finalize</span></code></a> slot is now part of the stable ABI.</p>
|
|||
|
<p>Windows builds now require Microsoft Visual C++ 14.0, which
|
|||
|
is available as part of <a class="reference external" href="https://www.visualstudio.com/">Visual Studio 2015</a>.</p>
|
|||
|
<p>Extension modules now include a platform information tag in their filename on
|
|||
|
some platforms (the tag is optional, and CPython will import extensions without
|
|||
|
it, although if the tag is present and mismatched, the extension won’t be
|
|||
|
loaded):</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>On Linux, extension module filenames end with
|
|||
|
<code class="docutils literal notranslate"><span class="pre">.cpython-<major><minor>m-<architecture>-<os>.pyd</span></code>:</p>
|
|||
|
<ul>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre"><major></span></code> is the major number of the Python version;
|
|||
|
for Python 3.5 this is <code class="docutils literal notranslate"><span class="pre">3</span></code>.</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre"><minor></span></code> is the minor number of the Python version;
|
|||
|
for Python 3.5 this is <code class="docutils literal notranslate"><span class="pre">5</span></code>.</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre"><architecture></span></code> is the hardware architecture the extension module
|
|||
|
was built to run on. It’s most commonly either <code class="docutils literal notranslate"><span class="pre">i386</span></code> for 32-bit Intel
|
|||
|
platforms or <code class="docutils literal notranslate"><span class="pre">x86_64</span></code> for 64-bit Intel (and AMD) platforms.</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre"><os></span></code> is always <code class="docutils literal notranslate"><span class="pre">linux-gnu</span></code>, except for extensions built to
|
|||
|
talk to the 32-bit ABI on 64-bit platforms, in which case it is
|
|||
|
<code class="docutils literal notranslate"><span class="pre">linux-gnu32</span></code> (and <code class="docutils literal notranslate"><span class="pre"><architecture></span></code> will be <code class="docutils literal notranslate"><span class="pre">x86_64</span></code>).</p></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><p>On Windows, extension module filenames end with
|
|||
|
<code class="docutils literal notranslate"><span class="pre"><debug>.cp<major><minor>-<platform>.pyd</span></code>:</p>
|
|||
|
<ul>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre"><major></span></code> is the major number of the Python version;
|
|||
|
for Python 3.5 this is <code class="docutils literal notranslate"><span class="pre">3</span></code>.</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre"><minor></span></code> is the minor number of the Python version;
|
|||
|
for Python 3.5 this is <code class="docutils literal notranslate"><span class="pre">5</span></code>.</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre"><platform></span></code> is the platform the extension module was built for,
|
|||
|
either <code class="docutils literal notranslate"><span class="pre">win32</span></code> for Win32, <code class="docutils literal notranslate"><span class="pre">win_amd64</span></code> for Win64, <code class="docutils literal notranslate"><span class="pre">win_ia64</span></code> for
|
|||
|
Windows Itanium 64, and <code class="docutils literal notranslate"><span class="pre">win_arm</span></code> for Windows on ARM.</p></li>
|
|||
|
<li><p>If built in debug mode, <code class="docutils literal notranslate"><span class="pre"><debug></span></code> will be <code class="docutils literal notranslate"><span class="pre">_d</span></code>,
|
|||
|
otherwise it will be blank.</p></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><p>On OS X platforms, extension module filenames now end with <code class="docutils literal notranslate"><span class="pre">-darwin.so</span></code>.</p></li>
|
|||
|
<li><p>On all other platforms, extension module filenames are the same as they were
|
|||
|
with Python 3.4.</p></li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
<div class="section" id="deprecated">
|
|||
|
<h2>Deprecated<a class="headerlink" href="#deprecated" title="Permalink to this headline">¶</a></h2>
|
|||
|
<div class="section" id="new-keywords">
|
|||
|
<h3>New Keywords<a class="headerlink" href="#new-keywords" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p><code class="docutils literal notranslate"><span class="pre">async</span></code> and <code class="docutils literal notranslate"><span class="pre">await</span></code> are not recommended to be used as variable, class,
|
|||
|
function or module names. Introduced by <span class="target" id="index-49"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0492"><strong>PEP 492</strong></a> in Python 3.5, they will
|
|||
|
become proper keywords in Python 3.7.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="deprecated-python-behavior">
|
|||
|
<h3>Deprecated Python Behavior<a class="headerlink" href="#deprecated-python-behavior" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Raising the <a class="reference internal" href="../library/exceptions.html#StopIteration" title="StopIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code></a> exception inside a generator will now generate a silent
|
|||
|
<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>, which will become a non-silent deprecation
|
|||
|
warning in Python 3.6 and will trigger 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> in Python 3.7.
|
|||
|
See <a class="reference internal" href="#whatsnew-pep-479"><span class="std std-ref">PEP 479: Change StopIteration handling inside generators</span></a>
|
|||
|
for details.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="unsupported-operating-systems">
|
|||
|
<h3>Unsupported Operating Systems<a class="headerlink" href="#unsupported-operating-systems" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>Windows XP is no longer supported by Microsoft, thus, per <span class="target" id="index-50"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0011"><strong>PEP 11</strong></a>, CPython
|
|||
|
3.5 is no longer officially supported on this OS.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="deprecated-python-modules-functions-and-methods">
|
|||
|
<h3>Deprecated Python modules, functions and methods<a class="headerlink" href="#deprecated-python-modules-functions-and-methods" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <a class="reference internal" href="../library/formatter.html#module-formatter" title="formatter: Generic output formatter and device interface. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">formatter</span></code></a> module has now graduated to full deprecation and is still
|
|||
|
slated for removal in Python 3.6.</p>
|
|||
|
<p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.async()</span></code> function is deprecated in favor of
|
|||
|
<a class="reference internal" href="../library/asyncio-future.html#asyncio.ensure_future" title="asyncio.ensure_future"><code class="xref py py-func docutils literal notranslate"><span class="pre">ensure_future()</span></code></a>.</p>
|
|||
|
<p>The <a class="reference internal" href="../library/smtpd.html#module-smtpd" title="smtpd: A SMTP server implementation in Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code></a> module has in the past always decoded the DATA portion of
|
|||
|
email messages using the <code class="docutils literal notranslate"><span class="pre">utf-8</span></code> codec. This can now be controlled by the
|
|||
|
new <em>decode_data</em> keyword to <a class="reference internal" href="../library/smtpd.html#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code></a>. The default value is
|
|||
|
<code class="docutils literal notranslate"><span class="pre">True</span></code>, but this default is deprecated. Specify the <em>decode_data</em> keyword
|
|||
|
with an appropriate value to avoid the deprecation warning.</p>
|
|||
|
<p>Directly assigning values to the <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.key" title="http.cookies.Morsel.key"><code class="xref py py-attr docutils literal notranslate"><span class="pre">key</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.value" title="http.cookies.Morsel.value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">value</span></code></a> and
|
|||
|
<a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.coded_value" title="http.cookies.Morsel.coded_value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">coded_value</span></code></a> of <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel" title="http.cookies.Morsel"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.cookies.Morsel</span></code></a>
|
|||
|
objects is deprecated. Use the <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.set" title="http.cookies.Morsel.set"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set()</span></code></a> method
|
|||
|
instead. In addition, the undocumented <em>LegalChars</em> parameter of
|
|||
|
<a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.set" title="http.cookies.Morsel.set"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set()</span></code></a> is deprecated, and is now ignored.</p>
|
|||
|
<p>Passing a format string as keyword argument <em>format_string</em> to the
|
|||
|
<a class="reference internal" href="../library/string.html#string.Formatter.format" title="string.Formatter.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">format()</span></code></a> method of the <a class="reference internal" href="../library/string.html#string.Formatter" title="string.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">string.Formatter</span></code></a>
|
|||
|
class has been deprecated.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue23671">bpo-23671</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/platform.html#platform.dist" title="platform.dist"><code class="xref py py-func docutils literal notranslate"><span class="pre">platform.dist()</span></code></a> and <a class="reference internal" href="../library/platform.html#platform.linux_distribution" title="platform.linux_distribution"><code class="xref py py-func docutils literal notranslate"><span class="pre">platform.linux_distribution()</span></code></a> functions
|
|||
|
are now deprecated. Linux distributions use too many different ways of
|
|||
|
describing themselves, so the functionality is left to a package.
|
|||
|
(Contributed by Vajrasky Kok and Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue1322">bpo-1322</a>.)</p>
|
|||
|
<p>The previously undocumented <code class="docutils literal notranslate"><span class="pre">from_function</span></code> and <code class="docutils literal notranslate"><span class="pre">from_builtin</span></code> methods of
|
|||
|
<a class="reference internal" href="../library/inspect.html#inspect.Signature" title="inspect.Signature"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.Signature</span></code></a> are deprecated. Use the new
|
|||
|
<a class="reference internal" href="../library/inspect.html#inspect.Signature.from_callable" title="inspect.Signature.from_callable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Signature.from_callable()</span></code></a>
|
|||
|
method instead. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue24248">bpo-24248</a>.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/inspect.html#inspect.getargspec" title="inspect.getargspec"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getargspec()</span></code></a> function is deprecated and scheduled to be
|
|||
|
removed in Python 3.6. (See <a class="reference external" href="https://bugs.python.org/issue20438">bpo-20438</a> for details.)</p>
|
|||
|
<p>The <a class="reference internal" href="../library/inspect.html#module-inspect" title="inspect: Extract information and source code from live objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">inspect</span></code></a> <a class="reference internal" href="../library/inspect.html#inspect.getfullargspec" title="inspect.getfullargspec"><code class="xref py py-func docutils literal notranslate"><span class="pre">getfullargspec()</span></code></a>,
|
|||
|
<a class="reference internal" href="../library/inspect.html#inspect.getcallargs" title="inspect.getcallargs"><code class="xref py py-func docutils literal notranslate"><span class="pre">getcallargs()</span></code></a>, and <a class="reference internal" href="../library/inspect.html#inspect.formatargspec" title="inspect.formatargspec"><code class="xref py py-func docutils literal notranslate"><span class="pre">formatargspec()</span></code></a> functions are
|
|||
|
deprecated in favor of the <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.signature()</span></code></a> API. (Contributed by Yury
|
|||
|
Selivanov in <a class="reference external" href="https://bugs.python.org/issue20438">bpo-20438</a>.)</p>
|
|||
|
<p><a class="reference internal" href="../library/inspect.html#inspect.getargvalues" title="inspect.getargvalues"><code class="xref py py-func docutils literal notranslate"><span class="pre">getargvalues()</span></code></a> and <a class="reference internal" href="../library/inspect.html#inspect.formatargvalues" title="inspect.formatargvalues"><code class="xref py py-func docutils literal notranslate"><span class="pre">formatargvalues()</span></code></a> functions
|
|||
|
were inadvertently marked as deprecated with the release of Python 3.5.0.</p>
|
|||
|
<p>Use of <a class="reference internal" href="../library/re.html#re.LOCALE" title="re.LOCALE"><code class="xref py py-const docutils literal notranslate"><span class="pre">re.LOCALE</span></code></a> flag with str patterns or <a class="reference internal" href="../library/re.html#re.ASCII" title="re.ASCII"><code class="xref py py-const docutils literal notranslate"><span class="pre">re.ASCII</span></code></a> is now
|
|||
|
deprecated. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue22407">bpo-22407</a>.)</p>
|
|||
|
<p>Use of unrecognized special sequences consisting of <code class="docutils literal notranslate"><span class="pre">'\'</span></code> and an ASCII letter
|
|||
|
in regular expression patterns and replacement patterns now raises a
|
|||
|
deprecation warning and will be forbidden in Python 3.6.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue23622">bpo-23622</a>.)</p>
|
|||
|
<p>The undocumented and unofficial <em>use_load_tests</em> default argument of the
|
|||
|
<a class="reference internal" href="../library/unittest.html#unittest.TestLoader.loadTestsFromModule" title="unittest.TestLoader.loadTestsFromModule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestLoader.loadTestsFromModule()</span></code></a> method now is
|
|||
|
deprecated and ignored.
|
|||
|
(Contributed by Robert Collins and Barry A. Warsaw in <a class="reference external" href="https://bugs.python.org/issue16662">bpo-16662</a>.)</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="removed">
|
|||
|
<h2>Removed<a class="headerlink" href="#removed" title="Permalink to this headline">¶</a></h2>
|
|||
|
<div class="section" id="api-and-feature-removals">
|
|||
|
<h3>API and Feature Removals<a class="headerlink" href="#api-and-feature-removals" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The following obsolete and previously deprecated APIs and features have been
|
|||
|
removed:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>The <code class="docutils literal notranslate"><span class="pre">__version__</span></code> attribute has been dropped from the email package. The
|
|||
|
email code hasn’t been shipped separately from the stdlib for a long time,
|
|||
|
and the <code class="docutils literal notranslate"><span class="pre">__version__</span></code> string was not updated in the last few releases.</p></li>
|
|||
|
<li><p>The internal <code class="docutils literal notranslate"><span class="pre">Netrc</span></code> class in the <a class="reference internal" href="../library/ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a> module was deprecated in
|
|||
|
3.4, and has now been removed.
|
|||
|
(Contributed by Matt Chaput in <a class="reference external" href="https://bugs.python.org/issue6623">bpo-6623</a>.)</p></li>
|
|||
|
<li><p>The concept of <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files has been removed.</p></li>
|
|||
|
<li><p>The JoinableQueue class in the provisional <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> module was
|
|||
|
deprecated in 3.4.4 and is now removed.
|
|||
|
(Contributed by A. Jesse Jiryu Davis in <a class="reference external" href="https://bugs.python.org/issue23464">bpo-23464</a>.)</p></li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="porting-to-python-3-5">
|
|||
|
<h2>Porting to Python 3.5<a class="headerlink" href="#porting-to-python-3-5" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>This section lists previously described changes and other bugfixes
|
|||
|
that may require changes to your code.</p>
|
|||
|
<div class="section" id="changes-in-python-behavior">
|
|||
|
<h3>Changes in Python behavior<a class="headerlink" href="#changes-in-python-behavior" title="Permalink to this headline">¶</a></h3>
|
|||
|
<ul>
|
|||
|
<li><p>Due to an oversight, earlier Python versions erroneously accepted the
|
|||
|
following syntax:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">f</span><span class="p">(</span><span class="mi">1</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span>
|
|||
|
<span class="n">f</span><span class="p">(</span><span class="mi">1</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Python 3.5 now correctly raises a <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>, as generator
|
|||
|
expressions must be put in parentheses if not a sole argument to a function.</p>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
<div class="section" id="changes-in-the-python-api">
|
|||
|
<h3>Changes in the Python API<a class="headerlink" href="#changes-in-the-python-api" title="Permalink to this headline">¶</a></h3>
|
|||
|
<ul class="simple">
|
|||
|
<li><p><span class="target" id="index-51"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0475"><strong>PEP 475</strong></a>: System calls are now retried when interrupted by a signal instead
|
|||
|
of raising <a class="reference internal" href="../library/exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a> if the Python signal handler does not
|
|||
|
raise an exception.</p></li>
|
|||
|
<li><p>Before Python 3.5, a <a class="reference internal" href="../library/datetime.html#datetime.time" title="datetime.time"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.time</span></code></a> object was considered to be false
|
|||
|
if it represented midnight in UTC. This behavior was considered obscure and
|
|||
|
error-prone and has been removed in Python 3.5. See <a class="reference external" href="https://bugs.python.org/issue13936">bpo-13936</a> for full
|
|||
|
details.</p></li>
|
|||
|
<li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLSocket.send()</span></code> method now raises either
|
|||
|
<a class="reference internal" href="../library/ssl.html#ssl.SSLWantReadError" title="ssl.SSLWantReadError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ssl.SSLWantReadError</span></code></a> or <a class="reference internal" href="../library/ssl.html#ssl.SSLWantWriteError" title="ssl.SSLWantWriteError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ssl.SSLWantWriteError</span></code></a>
|
|||
|
on a non-blocking socket if the operation would block. Previously,
|
|||
|
it would return <code class="docutils literal notranslate"><span class="pre">0</span></code>. (Contributed by Nikolaus Rath in <a class="reference external" href="https://bugs.python.org/issue20951">bpo-20951</a>.)</p></li>
|
|||
|
<li><p>The <code class="docutils literal notranslate"><span class="pre">__name__</span></code> attribute of generators is now set from the function name,
|
|||
|
instead of being set from the code name. Use <code class="docutils literal notranslate"><span class="pre">gen.gi_code.co_name</span></code> to
|
|||
|
retrieve the code name. Generators also have a new <code class="docutils literal notranslate"><span class="pre">__qualname__</span></code>
|
|||
|
attribute, the qualified name, which is now used for the representation
|
|||
|
of a generator (<code class="docutils literal notranslate"><span class="pre">repr(gen)</span></code>).
|
|||
|
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue21205">bpo-21205</a>.)</p></li>
|
|||
|
<li><p>The deprecated “strict” mode and argument of <a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a>,
|
|||
|
<code class="xref py py-meth docutils literal notranslate"><span class="pre">HTMLParser.error()</span></code>, and the <code class="xref py py-exc docutils literal notranslate"><span class="pre">HTMLParserError</span></code> exception have been
|
|||
|
removed. (Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue15114">bpo-15114</a>.)
|
|||
|
The <em>convert_charrefs</em> argument of <a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> is
|
|||
|
now <code class="docutils literal notranslate"><span class="pre">True</span></code> by default. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue21047">bpo-21047</a>.)</p></li>
|
|||
|
<li><p>Although it is not formally part of the API, it is worth noting for porting
|
|||
|
purposes (ie: fixing tests) that error messages that were previously of the
|
|||
|
form “‘sometype’ does not support the buffer protocol” are now of the form “a
|
|||
|
<a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a> is required, not ‘sometype’”.
|
|||
|
(Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue16518">bpo-16518</a>.)</p></li>
|
|||
|
<li><p>If the current directory is set to a directory that no longer exists then
|
|||
|
<a class="reference internal" href="../library/exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> will no longer be raised and instead
|
|||
|
<a class="reference internal" href="../library/importlib.html#importlib.machinery.FileFinder.find_spec" title="importlib.machinery.FileFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find_spec()</span></code></a> will return <code class="docutils literal notranslate"><span class="pre">None</span></code>
|
|||
|
<strong>without</strong> caching <code class="docutils literal notranslate"><span class="pre">None</span></code> in <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a>, which is
|
|||
|
different than the typical case (<a class="reference external" href="https://bugs.python.org/issue22834">bpo-22834</a>).</p></li>
|
|||
|
<li><p>HTTP status code and messages from <a class="reference internal" href="../library/http.client.html#module-http.client" title="http.client: HTTP and HTTPS protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.client</span></code></a> and <a class="reference internal" href="../library/http.server.html#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a>
|
|||
|
were refactored into a common <a class="reference internal" href="../library/http.html#http.HTTPStatus" title="http.HTTPStatus"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPStatus</span></code></a> enum. The values in
|
|||
|
<a class="reference internal" href="../library/http.client.html#module-http.client" title="http.client: HTTP and HTTPS protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.client</span></code></a> and <a class="reference internal" href="../library/http.server.html#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a> remain available for backwards
|
|||
|
compatibility. (Contributed by Demian Brecht in <a class="reference external" href="https://bugs.python.org/issue21793">bpo-21793</a>.)</p></li>
|
|||
|
<li><p>When an import loader defines <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.Loader.exec_module()</span></code>
|
|||
|
it is now expected to also define
|
|||
|
<code class="xref py py-meth docutils literal notranslate"><span class="pre">create_module()</span></code> (raises a
|
|||
|
<a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> now, will be an error in Python 3.6). If the loader
|
|||
|
inherits from <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader" title="importlib.abc.Loader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.Loader</span></code></a> then there is nothing to do, else
|
|||
|
simply define <code class="xref py py-meth docutils literal notranslate"><span class="pre">create_module()</span></code> to return
|
|||
|
<code class="docutils literal notranslate"><span class="pre">None</span></code>. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue23014">bpo-23014</a>.)</p></li>
|
|||
|
<li><p>The <a class="reference internal" href="../library/re.html#re.split" title="re.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.split()</span></code></a> function always ignored empty pattern matches, so the
|
|||
|
<code class="docutils literal notranslate"><span class="pre">"x*"</span></code> pattern worked the same as <code class="docutils literal notranslate"><span class="pre">"x+"</span></code>, and the <code class="docutils literal notranslate"><span class="pre">"\b"</span></code> pattern never
|
|||
|
worked. Now <a class="reference internal" href="../library/re.html#re.split" title="re.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.split()</span></code></a> raises a warning if the pattern could match
|
|||
|
an empty string. For compatibility, use patterns that never match an empty
|
|||
|
string (e.g. <code class="docutils literal notranslate"><span class="pre">"x+"</span></code> instead of <code class="docutils literal notranslate"><span class="pre">"x*"</span></code>). Patterns that could only match
|
|||
|
an empty string (such as <code class="docutils literal notranslate"><span class="pre">"\b"</span></code>) now raise an error.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue22818">bpo-22818</a>.)</p></li>
|
|||
|
<li><p>The <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel" title="http.cookies.Morsel"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.cookies.Morsel</span></code></a> dict-like interface has been made self
|
|||
|
consistent: morsel comparison now takes the <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.key" title="http.cookies.Morsel.key"><code class="xref py py-attr docutils literal notranslate"><span class="pre">key</span></code></a>
|
|||
|
and <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.value" title="http.cookies.Morsel.value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">value</span></code></a> into account,
|
|||
|
<a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.copy" title="http.cookies.Morsel.copy"><code class="xref py py-meth docutils literal notranslate"><span class="pre">copy()</span></code></a> now results in a
|
|||
|
<a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel" title="http.cookies.Morsel"><code class="xref py py-class docutils literal notranslate"><span class="pre">Morsel</span></code></a> instance rather than 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>, and
|
|||
|
<a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.update" title="http.cookies.Morsel.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> will now raise an exception if any of the
|
|||
|
keys in the update dictionary are invalid. In addition, the undocumented
|
|||
|
<em>LegalChars</em> parameter of <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.set" title="http.cookies.Morsel.set"><code class="xref py py-func docutils literal notranslate"><span class="pre">set()</span></code></a> is deprecated and
|
|||
|
is now ignored. (Contributed by Demian Brecht in <a class="reference external" href="https://bugs.python.org/issue2211">bpo-2211</a>.)</p></li>
|
|||
|
<li><p><span class="target" id="index-52"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0488"><strong>PEP 488</strong></a> has removed <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files from Python and introduced the optional
|
|||
|
<code class="docutils literal notranslate"><span class="pre">opt-</span></code> tag in <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file names. The
|
|||
|
<a class="reference internal" href="../library/importlib.html#importlib.util.cache_from_source" title="importlib.util.cache_from_source"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.cache_from_source()</span></code></a> has gained an <em>optimization</em>
|
|||
|
parameter to help control the <code class="docutils literal notranslate"><span class="pre">opt-</span></code> tag. Because of this, the
|
|||
|
<em>debug_override</em> parameter of the function is now deprecated. <cite>.pyo</cite> files
|
|||
|
are also no longer supported as a file argument to the Python interpreter and
|
|||
|
thus serve no purpose when distributed on their own (i.e. sourceless code
|
|||
|
distribution). Due to the fact that the magic number for bytecode has changed
|
|||
|
in Python 3.5, all old <cite>.pyo</cite> files from previous versions of Python are
|
|||
|
invalid regardless of this PEP.</p></li>
|
|||
|
<li><p>The <a class="reference internal" href="../library/socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socket</span></code></a> module now exports the <a class="reference internal" href="../library/socket.html#socket.CAN_RAW_FD_FRAMES" title="socket.CAN_RAW_FD_FRAMES"><code class="xref py py-data docutils literal notranslate"><span class="pre">CAN_RAW_FD_FRAMES</span></code></a>
|
|||
|
constant on linux 3.6 and greater.</p></li>
|
|||
|
<li><p>The <a class="reference internal" href="../library/ssl.html#ssl.cert_time_to_seconds" title="ssl.cert_time_to_seconds"><code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.cert_time_to_seconds()</span></code></a> function now interprets the input time
|
|||
|
as UTC and not as local time, per <span class="target" id="index-53"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc5280.html"><strong>RFC 5280</strong></a>. Additionally, the return
|
|||
|
value is always an <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>. (Contributed by Akira Li in <a class="reference external" href="https://bugs.python.org/issue19940">bpo-19940</a>.)</p></li>
|
|||
|
<li><p>The <code class="docutils literal notranslate"><span class="pre">pygettext.py</span></code> Tool now uses the standard +NNNN format for timezones in
|
|||
|
the POT-Creation-Date header.</p></li>
|
|||
|
<li><p>The <a class="reference internal" href="../library/smtplib.html#module-smtplib" title="smtplib: SMTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtplib</span></code></a> module now uses <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> instead of the previous
|
|||
|
module-level <code class="xref py py-data docutils literal notranslate"><span class="pre">stderr</span></code> variable for debug output. If your (test)
|
|||
|
program depends on patching the module-level variable to capture the debug
|
|||
|
output, you will need to update it to capture sys.stderr instead.</p></li>
|
|||
|
<li><p>The <a class="reference internal" href="../library/stdtypes.html#str.startswith" title="str.startswith"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.startswith()</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#str.endswith" title="str.endswith"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.endswith()</span></code></a> methods no longer return
|
|||
|
<code class="docutils literal notranslate"><span class="pre">True</span></code> when finding the empty string and the indexes are completely out of
|
|||
|
range. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue24284">bpo-24284</a>.)</p></li>
|
|||
|
<li><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 now returns documentation strings
|
|||
|
inherited from base classes. Documentation strings no longer need to be
|
|||
|
duplicated if the inherited documentation is appropriate. To suppress an
|
|||
|
inherited string, an empty string must be specified (or the documentation
|
|||
|
may be filled in). This change affects the output of the <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a>
|
|||
|
module and the <a class="reference internal" href="../library/functions.html#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a> function.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue15582">bpo-15582</a>.)</p></li>
|
|||
|
<li><p>Nested <a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.partial()</span></code></a> calls are now flattened. If you were
|
|||
|
relying on the previous behavior, you can now either add an attribute to a
|
|||
|
<a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.partial()</span></code></a> object or you can create a subclass of
|
|||
|
<a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.partial()</span></code></a>.
|
|||
|
(Contributed by Alexander Belopolsky in <a class="reference external" href="https://bugs.python.org/issue7830">bpo-7830</a>.)</p></li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
<div class="section" id="changes-in-the-c-api">
|
|||
|
<h3>Changes in the C API<a class="headerlink" href="#changes-in-the-c-api" title="Permalink to this headline">¶</a></h3>
|
|||
|
<ul class="simple">
|
|||
|
<li><p>The undocumented <code class="xref c c-member docutils literal notranslate"><span class="pre">format</span></code> member of the
|
|||
|
(non-public) <code class="xref c c-type docutils literal notranslate"><span class="pre">PyMemoryViewObject</span></code> structure has been removed.
|
|||
|
All extensions relying on the relevant parts in <code class="docutils literal notranslate"><span class="pre">memoryobject.h</span></code>
|
|||
|
must be rebuilt.</p></li>
|
|||
|
<li><p>The <code class="xref c c-type docutils literal notranslate"><span class="pre">PyMemAllocator</span></code> structure was renamed to
|
|||
|
<a class="reference internal" href="../c-api/memory.html#c.PyMemAllocatorEx" title="PyMemAllocatorEx"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyMemAllocatorEx</span></code></a> and a new <code class="docutils literal notranslate"><span class="pre">calloc</span></code> field was added.</p></li>
|
|||
|
<li><p>Removed non-documented macro <code class="xref c c-macro docutils literal notranslate"><span class="pre">PyObject_REPR</span></code> which leaked references.
|
|||
|
Use format character <code class="docutils literal notranslate"><span class="pre">%R</span></code> in <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a>-like functions
|
|||
|
to format the <a class="reference internal" href="../library/functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a> of the object.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue22453">bpo-22453</a>.)</p></li>
|
|||
|
<li><p>Because the lack of the <code class="xref py py-attr docutils literal notranslate"><span class="pre">__module__</span></code> attribute breaks pickling and
|
|||
|
introspection, a deprecation warning is now raised for builtin types without
|
|||
|
the <code class="xref py py-attr docutils literal notranslate"><span class="pre">__module__</span></code> attribute. This would be an AttributeError in
|
|||
|
the future.
|
|||
|
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue20204">bpo-20204</a>.)</p></li>
|
|||
|
<li><p>As part of the <span class="target" id="index-54"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0492"><strong>PEP 492</strong></a> implementation, the <code class="docutils literal notranslate"><span class="pre">tp_reserved</span></code> slot of
|
|||
|
<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> was replaced with a
|
|||
|
<a class="reference internal" href="../c-api/typeobj.html#c.tp_as_async" title="tp_as_async"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_as_async</span></code></a> slot. Refer to <a class="reference internal" href="../c-api/coro.html#coro-objects"><span class="std std-ref">Coroutine Objects</span></a> for
|
|||
|
new types, structures and functions.</p></li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="notable-changes-in-python-3-5-4">
|
|||
|
<h2>Notable changes in Python 3.5.4<a class="headerlink" href="#notable-changes-in-python-3-5-4" title="Permalink to this headline">¶</a></h2>
|
|||
|
<div class="section" id="new-make-regen-all-build-target">
|
|||
|
<h3>New <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> build target<a class="headerlink" href="#new-make-regen-all-build-target" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>To simplify cross-compilation, and to ensure that CPython can reliably be
|
|||
|
compiled without requiring an existing version of Python to already be
|
|||
|
available, the autotools-based build system no longer attempts to implicitly
|
|||
|
recompile generated files based on file modification times.</p>
|
|||
|
<p>Instead, a new <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> command has been added to force regeneration
|
|||
|
of these files when desired (e.g. after an initial version of Python has
|
|||
|
already been built based on the pregenerated versions).</p>
|
|||
|
<p>More selective regeneration targets are also defined - see
|
|||
|
<a class="reference external" href="https://github.com/python/cpython/tree/3.7/Makefile.pre.in">Makefile.pre.in</a> for details.</p>
|
|||
|
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue23404">bpo-23404</a>.)</p>
|
|||
|
<div class="versionadded">
|
|||
|
<p><span class="versionmodified added">New in version 3.5.4.</span></p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="removal-of-make-touch-build-target">
|
|||
|
<h3>Removal of <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> build target<a class="headerlink" href="#removal-of-make-touch-build-target" title="Permalink to this headline">¶</a></h3>
|
|||
|
<p>The <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> build target previously used to request implicit regeneration
|
|||
|
of generated files by updating their modification times has been removed.</p>
|
|||
|
<p>It has been replaced by the new <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> target.</p>
|
|||
|
<p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue23404">bpo-23404</a>.)</p>
|
|||
|
<div class="versionchanged">
|
|||
|
<p><span class="versionmodified changed">Changed in version 3.5.4.</span></p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
|||
|
<div class="sphinxsidebarwrapper">
|
|||
|
<h3><a href="../contents.html">Table of Contents</a></h3>
|
|||
|
<ul>
|
|||
|
<li><a class="reference internal" href="#">What’s New In Python 3.5</a><ul>
|
|||
|
<li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
|
|||
|
<li><a class="reference internal" href="#new-features">New Features</a><ul>
|
|||
|
<li><a class="reference internal" href="#pep-492-coroutines-with-async-and-await-syntax">PEP 492 - Coroutines with async and await syntax</a></li>
|
|||
|
<li><a class="reference internal" href="#pep-465-a-dedicated-infix-operator-for-matrix-multiplication">PEP 465 - A dedicated infix operator for matrix multiplication</a></li>
|
|||
|
<li><a class="reference internal" href="#pep-448-additional-unpacking-generalizations">PEP 448 - Additional Unpacking Generalizations</a></li>
|
|||
|
<li><a class="reference internal" href="#pep-461-percent-formatting-support-for-bytes-and-bytearray">PEP 461 - percent formatting support for bytes and bytearray</a></li>
|
|||
|
<li><a class="reference internal" href="#pep-484-type-hints">PEP 484 - Type Hints</a></li>
|
|||
|
<li><a class="reference internal" href="#pep-471-os-scandir-function-a-better-and-faster-directory-iterator">PEP 471 - os.scandir() function – a better and faster directory iterator</a></li>
|
|||
|
<li><a class="reference internal" href="#pep-475-retry-system-calls-failing-with-eintr">PEP 475: Retry system calls failing with EINTR</a></li>
|
|||
|
<li><a class="reference internal" href="#pep-479-change-stopiteration-handling-inside-generators">PEP 479: Change StopIteration handling inside generators</a></li>
|
|||
|
<li><a class="reference internal" href="#pep-485-a-function-for-testing-approximate-equality">PEP 485: A function for testing approximate equality</a></li>
|
|||
|
<li><a class="reference internal" href="#pep-486-make-the-python-launcher-aware-of-virtual-environments">PEP 486: Make the Python Launcher aware of virtual environments</a></li>
|
|||
|
<li><a class="reference internal" href="#pep-488-elimination-of-pyo-files">PEP 488: Elimination of PYO files</a></li>
|
|||
|
<li><a class="reference internal" href="#pep-489-multi-phase-extension-module-initialization">PEP 489: Multi-phase extension module initialization</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
|
|||
|
<li><a class="reference internal" href="#new-modules">New Modules</a><ul>
|
|||
|
<li><a class="reference internal" href="#typing">typing</a></li>
|
|||
|
<li><a class="reference internal" href="#zipapp">zipapp</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
|
|||
|
<li><a class="reference internal" href="#argparse">argparse</a></li>
|
|||
|
<li><a class="reference internal" href="#asyncio">asyncio</a></li>
|
|||
|
<li><a class="reference internal" href="#bz2">bz2</a></li>
|
|||
|
<li><a class="reference internal" href="#cgi">cgi</a></li>
|
|||
|
<li><a class="reference internal" href="#cmath">cmath</a></li>
|
|||
|
<li><a class="reference internal" href="#code">code</a></li>
|
|||
|
<li><a class="reference internal" href="#collections">collections</a></li>
|
|||
|
<li><a class="reference internal" href="#collections-abc">collections.abc</a></li>
|
|||
|
<li><a class="reference internal" href="#compileall">compileall</a></li>
|
|||
|
<li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li>
|
|||
|
<li><a class="reference internal" href="#configparser">configparser</a></li>
|
|||
|
<li><a class="reference internal" href="#contextlib">contextlib</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="#dbm">dbm</a></li>
|
|||
|
<li><a class="reference internal" href="#difflib">difflib</a></li>
|
|||
|
<li><a class="reference internal" href="#distutils">distutils</a></li>
|
|||
|
<li><a class="reference internal" href="#doctest">doctest</a></li>
|
|||
|
<li><a class="reference internal" href="#email">email</a></li>
|
|||
|
<li><a class="reference internal" href="#enum">enum</a></li>
|
|||
|
<li><a class="reference internal" href="#faulthandler">faulthandler</a></li>
|
|||
|
<li><a class="reference internal" href="#functools">functools</a></li>
|
|||
|
<li><a class="reference internal" href="#glob">glob</a></li>
|
|||
|
<li><a class="reference internal" href="#gzip">gzip</a></li>
|
|||
|
<li><a class="reference internal" href="#heapq">heapq</a></li>
|
|||
|
<li><a class="reference internal" href="#http">http</a></li>
|
|||
|
<li><a class="reference internal" href="#http-client">http.client</a></li>
|
|||
|
<li><a class="reference internal" href="#idlelib-and-idle">idlelib and IDLE</a></li>
|
|||
|
<li><a class="reference internal" href="#imaplib">imaplib</a></li>
|
|||
|
<li><a class="reference internal" href="#imghdr">imghdr</a></li>
|
|||
|
<li><a class="reference internal" href="#importlib">importlib</a></li>
|
|||
|
<li><a class="reference internal" href="#inspect">inspect</a></li>
|
|||
|
<li><a class="reference internal" href="#io">io</a></li>
|
|||
|
<li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
|
|||
|
<li><a class="reference internal" href="#json">json</a></li>
|
|||
|
<li><a class="reference internal" href="#linecache">linecache</a></li>
|
|||
|
<li><a class="reference internal" href="#locale">locale</a></li>
|
|||
|
<li><a class="reference internal" href="#logging">logging</a></li>
|
|||
|
<li><a class="reference internal" href="#lzma">lzma</a></li>
|
|||
|
<li><a class="reference internal" href="#math">math</a></li>
|
|||
|
<li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
|
|||
|
<li><a class="reference internal" href="#operator">operator</a></li>
|
|||
|
<li><a class="reference internal" href="#os">os</a></li>
|
|||
|
<li><a class="reference internal" href="#pathlib">pathlib</a></li>
|
|||
|
<li><a class="reference internal" href="#pickle">pickle</a></li>
|
|||
|
<li><a class="reference internal" href="#poplib">poplib</a></li>
|
|||
|
<li><a class="reference internal" href="#re">re</a></li>
|
|||
|
<li><a class="reference internal" href="#readline">readline</a></li>
|
|||
|
<li><a class="reference internal" href="#selectors">selectors</a></li>
|
|||
|
<li><a class="reference internal" href="#shutil">shutil</a></li>
|
|||
|
<li><a class="reference internal" href="#signal">signal</a></li>
|
|||
|
<li><a class="reference internal" href="#smtpd">smtpd</a></li>
|
|||
|
<li><a class="reference internal" href="#smtplib">smtplib</a></li>
|
|||
|
<li><a class="reference internal" href="#sndhdr">sndhdr</a></li>
|
|||
|
<li><a class="reference internal" href="#socket">socket</a></li>
|
|||
|
<li><a class="reference internal" href="#ssl">ssl</a><ul>
|
|||
|
<li><a class="reference internal" href="#memory-bio-support">Memory BIO Support</a></li>
|
|||
|
<li><a class="reference internal" href="#application-layer-protocol-negotiation-support">Application-Layer Protocol Negotiation Support</a></li>
|
|||
|
<li><a class="reference internal" href="#other-changes">Other Changes</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
|
|||
|
<li><a class="reference internal" href="#subprocess">subprocess</a></li>
|
|||
|
<li><a class="reference internal" href="#sys">sys</a></li>
|
|||
|
<li><a class="reference internal" href="#sysconfig">sysconfig</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="#time">time</a></li>
|
|||
|
<li><a class="reference internal" href="#timeit">timeit</a></li>
|
|||
|
<li><a class="reference internal" href="#tkinter">tkinter</a></li>
|
|||
|
<li><a class="reference internal" href="#traceback">traceback</a></li>
|
|||
|
<li><a class="reference internal" href="#types">types</a></li>
|
|||
|
<li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
|
|||
|
<li><a class="reference internal" href="#unittest">unittest</a></li>
|
|||
|
<li><a class="reference internal" href="#unittest-mock">unittest.mock</a></li>
|
|||
|
<li><a class="reference internal" href="#urllib">urllib</a></li>
|
|||
|
<li><a class="reference internal" href="#wsgiref">wsgiref</a></li>
|
|||
|
<li><a class="reference internal" href="#xmlrpc">xmlrpc</a></li>
|
|||
|
<li><a class="reference internal" href="#xml-sax">xml.sax</a></li>
|
|||
|
<li><a class="reference internal" href="#zipfile">zipfile</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#other-module-level-changes">Other module-level changes</a></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><ul>
|
|||
|
<li><a class="reference internal" href="#new-keywords">New Keywords</a></li>
|
|||
|
<li><a class="reference internal" href="#deprecated-python-behavior">Deprecated Python Behavior</a></li>
|
|||
|
<li><a class="reference internal" href="#unsupported-operating-systems">Unsupported Operating Systems</a></li>
|
|||
|
<li><a class="reference internal" href="#deprecated-python-modules-functions-and-methods">Deprecated Python modules, functions and methods</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#removed">Removed</a><ul>
|
|||
|
<li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#porting-to-python-3-5">Porting to Python 3.5</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>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#notable-changes-in-python-3-5-4">Notable changes in Python 3.5.4</a><ul>
|
|||
|
<li><a class="reference internal" href="#new-make-regen-all-build-target">New <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> build target</a></li>
|
|||
|
<li><a class="reference internal" href="#removal-of-make-touch-build-target">Removal of <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> build target</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<h4>Previous topic</h4>
|
|||
|
<p class="topless"><a href="3.6.html"
|
|||
|
title="previous chapter">What’s New In Python 3.6</a></p>
|
|||
|
<h4>Next topic</h4>
|
|||
|
<p class="topless"><a href="3.4.html"
|
|||
|
title="next chapter">What’s New In Python 3.4</a></p>
|
|||
|
<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/3.7/Doc/whatsnew/3.5.rst"
|
|||
|
rel="nofollow">Show Source
|
|||
|
</a>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="clearer"></div>
|
|||
|
</div>
|
|||
|
<div class="related" role="navigation" aria-label="related navigation">
|
|||
|
<h3>Navigation</h3>
|
|||
|
<ul>
|
|||
|
<li class="right" style="margin-right: 10px">
|
|||
|
<a href="../genindex.html" title="General Index"
|
|||
|
>index</a></li>
|
|||
|
<li class="right" >
|
|||
|
<a href="../py-modindex.html" title="Python Module Index"
|
|||
|
>modules</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="3.4.html" title="What’s New In Python 3.4"
|
|||
|
>next</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="3.6.html" title="What’s New In Python 3.6"
|
|||
|
>previous</a> |</li>
|
|||
|
<li><img src="../_static/py.png" alt=""
|
|||
|
style="vertical-align: middle; margin-top: -1px"/></li>
|
|||
|
<li><a href="https://www.python.org/">Python</a> »</li>
|
|||
|
<li>
|
|||
|
<span class="language_switcher_placeholder">en</span>
|
|||
|
<span class="version_switcher_placeholder">3.7.4</span>
|
|||
|
<a href="../index.html">Documentation </a> »
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> »</li>
|
|||
|
<li class="right">
|
|||
|
|
|||
|
|
|||
|
<div class="inline-search" style="display: none" role="search">
|
|||
|
<form class="inline-search" action="../search.html" method="get">
|
|||
|
<input placeholder="Quick search" type="text" name="q" />
|
|||
|
<input type="submit" value="Go" />
|
|||
|
<input type="hidden" name="check_keywords" value="yes" />
|
|||
|
<input type="hidden" name="area" value="default" />
|
|||
|
</form>
|
|||
|
</div>
|
|||
|
<script type="text/javascript">$('.inline-search').show(0);</script>
|
|||
|
|
|
|||
|
</li>
|
|||
|
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
<div class="footer">
|
|||
|
© <a href="../copyright.html">Copyright</a> 2001-2019, Python Software Foundation.
|
|||
|
<br />
|
|||
|
The Python Software Foundation is a non-profit corporation.
|
|||
|
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
|||
|
<br />
|
|||
|
Last updated on Jul 13, 2019.
|
|||
|
<a href="../bugs.html">Found a bug</a>?
|
|||
|
<br />
|
|||
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1.
|
|||
|
</div>
|
|||
|
|
|||
|
</body>
|
|||
|
</html>
|