2332 lines
320 KiB
HTML
2332 lines
320 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<title>What’s New In Python 3.4 — 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.3" href="3.3.html" />
|
||
<link rel="prev" title="What’s New In Python 3.5" href="3.5.html" />
|
||
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
|
||
<link rel="canonical" href="https://docs.python.org/3/whatsnew/3.4.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.3.html" title="What’s New In Python 3.3"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.5.html" title="What’s New In Python 3.5"
|
||
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-4">
|
||
<h1>What’s New In Python 3.4<a class="headerlink" href="#what-s-new-in-python-3-4" title="Permalink to this headline">¶</a></h1>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Author</dt>
|
||
<dd class="field-odd"><p>R. David Murray <<a class="reference external" href="mailto:rdmurray%40bitdance.com">rdmurray<span>@</span>bitdance<span>.</span>com</a>> (Editor)</p>
|
||
</dd>
|
||
</dl>
|
||
<p>This article explains the new features in Python 3.4, compared to 3.3.
|
||
Python 3.4 was released on March 16, 2014. For full details, see the
|
||
<a class="reference external" href="https://docs.python.org/3.4/whatsnew/changelog.html">changelog</a>.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<p><span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0429"><strong>PEP 429</strong></a> – Python 3.4 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>No new syntax features were added in Python 3.4.</p></li>
|
||
</ul>
|
||
<p>Other new features:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#whatsnew-pep-453"><span class="std std-ref">pip should always be available</span></a> (<span class="target" id="index-1"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0453"><strong>PEP 453</strong></a>).</p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew-pep-446"><span class="std std-ref">Newly created file descriptors are non-inheritable</span></a>
|
||
(<span class="target" id="index-2"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0446"><strong>PEP 446</strong></a>).</p></li>
|
||
<li><p>command line option for <a class="reference internal" href="#whatsnew-isolated-mode"><span class="std std-ref">isolated mode</span></a>
|
||
(<a class="reference external" href="https://bugs.python.org/issue16499">bpo-16499</a>).</p></li>
|
||
<li><p><a class="reference internal" href="#codec-handling-improvements"><span class="std std-ref">improvements in the handling of codecs</span></a>
|
||
that are not text encodings (multiple issues).</p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew-pep-451"><span class="std std-ref">A ModuleSpec Type</span></a> for the Import System
|
||
(<span class="target" id="index-3"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0451"><strong>PEP 451</strong></a>). (Affects importer authors.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/marshal.html#module-marshal" title="marshal: Convert Python objects to streams of bytes and back (with different constraints)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">marshal</span></code></a> format has been made <a class="reference internal" href="#whatsnew-marshal-3"><span class="std std-ref">more compact and efficient</span></a> (<a class="reference external" href="https://bugs.python.org/issue16475">bpo-16475</a>).</p></li>
|
||
</ul>
|
||
<p>New library modules:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a>: <a class="reference internal" href="#whatsnew-asyncio"><span class="std std-ref">New provisional API for asynchronous IO</span></a> (<span class="target" id="index-4"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3156"><strong>PEP 3156</strong></a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the "pip" installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a>: <a class="reference internal" href="#whatsnew-ensurepip"><span class="std std-ref">Bootstrapping the pip installer</span></a>
|
||
(<span class="target" id="index-5"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0453"><strong>PEP 453</strong></a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a>: <a class="reference internal" href="#whatsnew-enum"><span class="std std-ref">Support for enumeration types</span></a>
|
||
(<span class="target" id="index-6"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0435"><strong>PEP 435</strong></a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a>: <a class="reference internal" href="#whatsnew-pathlib"><span class="std std-ref">Object-oriented filesystem paths</span></a>
|
||
(<span class="target" id="index-7"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0428"><strong>PEP 428</strong></a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/selectors.html#module-selectors" title="selectors: High-level I/O multiplexing."><code class="xref py py-mod docutils literal notranslate"><span class="pre">selectors</span></code></a>: <a class="reference internal" href="#whatsnew-selectors"><span class="std std-ref">High-level and efficient I/O multiplexing</span></a>, built upon the <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> module primitives (part
|
||
of <span class="target" id="index-8"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3156"><strong>PEP 3156</strong></a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/statistics.html#module-statistics" title="statistics: mathematical statistics functions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">statistics</span></code></a>: A basic <a class="reference internal" href="#whatsnew-statistics"><span class="std std-ref">numerically stable statistics library</span></a> (<span class="target" id="index-9"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0450"><strong>PEP 450</strong></a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a>: <a class="reference internal" href="#whatsnew-tracemalloc"><span class="std std-ref">Trace Python memory allocations</span></a> (<span class="target" id="index-10"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0454"><strong>PEP 454</strong></a>).</p></li>
|
||
</ul>
|
||
<p>Significantly improved library modules:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#whatsnew-singledispatch"><span class="std std-ref">Single-dispatch generic functions</span></a> in
|
||
<a class="reference internal" href="../library/functools.html#module-functools" title="functools: Higher-order functions and operations on callable objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">functools</span></code></a> (<span class="target" id="index-11"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0443"><strong>PEP 443</strong></a>).</p></li>
|
||
<li><p>New <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> <a class="reference internal" href="#whatsnew-protocol-4"><span class="std std-ref">protocol 4</span></a> (<span class="target" id="index-12"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3154"><strong>PEP 3154</strong></a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> now has <a class="reference internal" href="#whatsnew-multiprocessing-no-fork"><span class="std std-ref">an option to avoid using os.fork
|
||
on Unix</span></a> (<a class="reference external" href="https://bugs.python.org/issue8713">bpo-8713</a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a> has a new submodule, <a class="reference internal" href="../library/email.contentmanager.html#module-email.contentmanager" title="email.contentmanager: Storing and Retrieving Content from MIME Parts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">contentmanager</span></code></a>, and
|
||
a new <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-mod docutils literal notranslate"><span class="pre">Message</span></code></a> subclass
|
||
(<code class="xref py py-class docutils literal notranslate"><span class="pre">EmailMessage</span></code>) that <a class="reference internal" href="#whatsnew-email-contentmanager"><span class="std std-ref">simplify MIME
|
||
handling</span></a> (<a class="reference external" href="https://bugs.python.org/issue18891">bpo-18891</a>).</p></li>
|
||
<li><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> and <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> modules are now capable of
|
||
correct introspection of a much wider variety of callable objects,
|
||
which improves the output of the Python <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> system.</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ipaddress</span></code></a> module API has been declared stable</p></li>
|
||
</ul>
|
||
<p>Security improvements:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#whatsnew-pep-456"><span class="std std-ref">Secure and interchangeable hash algorithm</span></a>
|
||
(<span class="target" id="index-13"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0456"><strong>PEP 456</strong></a>).</p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew-pep-446"><span class="std std-ref">Make newly created file descriptors non-inheritable</span></a>
|
||
(<span class="target" id="index-14"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0446"><strong>PEP 446</strong></a>) to avoid leaking file descriptors to child processes.</p></li>
|
||
<li><p>New command line option for <a class="reference internal" href="#whatsnew-isolated-mode"><span class="std std-ref">isolated mode</span></a>,
|
||
(<a class="reference external" href="https://bugs.python.org/issue16499">bpo-16499</a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> now has <a class="reference internal" href="#whatsnew-multiprocessing-no-fork"><span class="std std-ref">an option to avoid using os.fork
|
||
on Unix</span></a>. <em>spawn</em> and <em>forkserver</em> are
|
||
more secure because they avoid sharing data with child processes.</p></li>
|
||
<li><p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> child processes on Windows no longer inherit
|
||
all of the parent’s inheritable handles, only the necessary ones.</p></li>
|
||
<li><p>A new <a class="reference internal" href="../library/hashlib.html#hashlib.pbkdf2_hmac" title="hashlib.pbkdf2_hmac"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.pbkdf2_hmac()</span></code></a> function provides
|
||
the <a class="reference external" href="https://en.wikipedia.org/wiki/PBKDF2">PKCS#5 password-based key derivation function 2</a>.</p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew-tls-11-12"><span class="std std-ref">TLSv1.1 and TLSv1.2 support</span></a> for <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>.</p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew34-win-cert-store"><span class="std std-ref">Retrieving certificates from the Windows system cert store support</span></a> for <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>.</p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew34-sni"><span class="std std-ref">Server-side SNI (Server Name Indication) support</span></a> for <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>.</p></li>
|
||
<li><p>The <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> class has a <a class="reference internal" href="#whatsnew34-sslcontext"><span class="std std-ref">lot of improvements</span></a>.</p></li>
|
||
<li><p>All modules in the standard library that support SSL now support server
|
||
certificate verification, including hostname matching
|
||
(<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">ssl.match_hostname()</span></code></a>) and CRLs (Certificate Revocation lists, see
|
||
<a class="reference internal" href="../library/ssl.html#ssl.SSLContext.load_verify_locations" title="ssl.SSLContext.load_verify_locations"><code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.SSLContext.load_verify_locations()</span></code></a>).</p></li>
|
||
</ul>
|
||
<p>CPython implementation improvements:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#whatsnew-pep-442"><span class="std std-ref">Safe object finalization</span></a> (<span class="target" id="index-15"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0442"><strong>PEP 442</strong></a>).</p></li>
|
||
<li><p>Leveraging <span class="target" id="index-16"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0442"><strong>PEP 442</strong></a>, in most cases <a class="reference internal" href="#whatsnew-pep-442"><span class="std std-ref">module globals are no longer set
|
||
to None during finalization</span></a> (<a class="reference external" href="https://bugs.python.org/issue18214">bpo-18214</a>).</p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew-pep-445"><span class="std std-ref">Configurable memory allocators</span></a> (<span class="target" id="index-17"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0445"><strong>PEP 445</strong></a>).</p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew-pep-436"><span class="std std-ref">Argument Clinic</span></a> (<span class="target" id="index-18"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0436"><strong>PEP 436</strong></a>).</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-453-explicit-bootstrapping-of-pip-in-python-installations">
|
||
<span id="whatsnew-pep-453"></span><h3>PEP 453: Explicit Bootstrapping of PIP in Python Installations<a class="headerlink" href="#pep-453-explicit-bootstrapping-of-pip-in-python-installations" title="Permalink to this headline">¶</a></h3>
|
||
<div class="section" id="bootstrapping-pip-by-default">
|
||
<h4>Bootstrapping pip By Default<a class="headerlink" href="#bootstrapping-pip-by-default" title="Permalink to this headline">¶</a></h4>
|
||
<p>The new <a class="reference internal" href="../library/ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the "pip" installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a> module (defined in <span class="target" id="index-19"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0453"><strong>PEP 453</strong></a>) provides a standard
|
||
cross-platform mechanism to bootstrap the pip installer into Python
|
||
installations and virtual environments. The version of <code class="docutils literal notranslate"><span class="pre">pip</span></code> included
|
||
with Python 3.4.0 is <code class="docutils literal notranslate"><span class="pre">pip</span></code> 1.5.4, and future 3.4.x maintenance releases
|
||
will update the bundled version to the latest version of <code class="docutils literal notranslate"><span class="pre">pip</span></code> that is
|
||
available at the time of creating the release candidate.</p>
|
||
<p>By default, the commands <code class="docutils literal notranslate"><span class="pre">pipX</span></code> and <code class="docutils literal notranslate"><span class="pre">pipX.Y</span></code> will be installed on all
|
||
platforms (where X.Y stands for the version of the Python installation),
|
||
along with the <code class="docutils literal notranslate"><span class="pre">pip</span></code> Python package and its dependencies. On Windows and
|
||
in virtual environments on all platforms, the unversioned <code class="docutils literal notranslate"><span class="pre">pip</span></code> command
|
||
will also be installed. On other platforms, the system wide unversioned
|
||
<code class="docutils literal notranslate"><span class="pre">pip</span></code> command typically refers to the separately installed Python 2
|
||
version.</p>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> command line utility and the <a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a>
|
||
module make use of the <a class="reference internal" href="../library/ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the "pip" installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a> module to make <code class="docutils literal notranslate"><span class="pre">pip</span></code> readily
|
||
available in virtual environments. When using the command line utility,
|
||
<code class="docutils literal notranslate"><span class="pre">pip</span></code> is installed by default, while when using the <a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a> module
|
||
<a class="reference internal" href="../library/venv.html#venv-api"><span class="std std-ref">API</span></a> installation of <code class="docutils literal notranslate"><span class="pre">pip</span></code> must be requested explicitly.</p>
|
||
<p>For CPython <a class="reference internal" href="../using/unix.html#building-python-on-unix"><span class="std std-ref">source builds on POSIX systems</span></a>,
|
||
the <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">install</span></code> and <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">altinstall</span></code> commands bootstrap <code class="docutils literal notranslate"><span class="pre">pip</span></code> by
|
||
default. This behaviour can be controlled through configure options, and
|
||
overridden through Makefile options.</p>
|
||
<p>On Windows and Mac OS X, the CPython installers now default to installing
|
||
<code class="docutils literal notranslate"><span class="pre">pip</span></code> along with CPython itself (users may opt out of installing it
|
||
during the installation process). Window users will need to opt in to the
|
||
automatic <code class="docutils literal notranslate"><span class="pre">PATH</span></code> modifications to have <code class="docutils literal notranslate"><span class="pre">pip</span></code> available from the command
|
||
line by default, otherwise it can still be accessed through the Python
|
||
launcher for Windows as <code class="docutils literal notranslate"><span class="pre">py</span> <span class="pre">-m</span> <span class="pre">pip</span></code>.</p>
|
||
<p>As <a class="reference external" href="https://www.python.org/dev/peps/pep-0453/#recommendations-for-downstream-distributors">discussed in the PEP</a>, platform packagers may choose not to install
|
||
these commands by default, as long as, when invoked, they provide clear and
|
||
simple directions on how to install them on that platform (usually using
|
||
the system package manager).</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>To avoid conflicts between parallel Python 2 and Python 3 installations,
|
||
only the versioned <code class="docutils literal notranslate"><span class="pre">pip3</span></code> and <code class="docutils literal notranslate"><span class="pre">pip3.4</span></code> commands are bootstrapped by
|
||
default when <code class="docutils literal notranslate"><span class="pre">ensurepip</span></code> is invoked directly - the <code class="docutils literal notranslate"><span class="pre">--default-pip</span></code>
|
||
option is needed to also request the unversioned <code class="docutils literal notranslate"><span class="pre">pip</span></code> command.
|
||
<code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> and the Windows installer ensure that the unqualified <code class="docutils literal notranslate"><span class="pre">pip</span></code>
|
||
command is made available in those environments, and <code class="docutils literal notranslate"><span class="pre">pip</span></code> can always be
|
||
invoked via the <code class="docutils literal notranslate"><span class="pre">-m</span></code> switch rather than directly to avoid ambiguity on
|
||
systems with multiple Python installations.</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="documentation-changes">
|
||
<h4>Documentation Changes<a class="headerlink" href="#documentation-changes" title="Permalink to this headline">¶</a></h4>
|
||
<p>As part of this change, the <a class="reference internal" href="../installing/index.html#installing-index"><span class="std std-ref">Installing Python Modules</span></a> and
|
||
<a class="reference internal" href="../distributing/index.html#distributing-index"><span class="std std-ref">Distributing Python Modules</span></a> sections of the documentation have been
|
||
completely redesigned as short getting started and FAQ documents. Most
|
||
packaging documentation has now been moved out to the Python Packaging
|
||
Authority maintained <a class="reference external" href="https://packaging.python.org">Python Packaging User Guide</a> and the documentation of the individual
|
||
projects.</p>
|
||
<p>However, as this migration is currently still incomplete, the legacy
|
||
versions of those guides remaining available as <a class="reference internal" href="../install/index.html#install-index"><span class="std std-ref">Installing Python Modules (Legacy version)</span></a>
|
||
and <a class="reference internal" href="../distutils/index.html#distutils-index"><span class="std std-ref">Distributing Python Modules (Legacy version)</span></a>.</p>
|
||
<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-0453"><strong>PEP 453</strong></a> – Explicit bootstrapping of pip in Python installations</dt><dd><p>PEP written by Donald Stufft and Nick Coghlan, implemented by
|
||
Donald Stufft, Nick Coghlan, Martin von Löwis and Ned Deily.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-446-newly-created-file-descriptors-are-non-inheritable">
|
||
<span id="whatsnew-pep-446"></span><h3>PEP 446: Newly Created File Descriptors Are Non-Inheritable<a class="headerlink" href="#pep-446-newly-created-file-descriptors-are-non-inheritable" 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-0446"><strong>PEP 446</strong></a> makes newly created file descriptors <a class="reference internal" href="../library/os.html#fd-inheritance"><span class="std std-ref">non-inheritable</span></a>. In general, this is the behavior an application will
|
||
want: when launching a new process, having currently open files also
|
||
open in the new process can lead to all sorts of hard to find bugs,
|
||
and potentially to security issues.</p>
|
||
<p>However, there are occasions when inheritance is desired. To support
|
||
these cases, the following new functions and methods are available:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/os.html#os.get_inheritable" title="os.get_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.get_inheritable()</span></code></a>, <a class="reference internal" href="../library/os.html#os.set_inheritable" title="os.set_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.set_inheritable()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.get_handle_inheritable" title="os.get_handle_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.get_handle_inheritable()</span></code></a>, <a class="reference internal" href="../library/os.html#os.set_handle_inheritable" title="os.set_handle_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.set_handle_inheritable()</span></code></a></p></li>
|
||
<li><p><a class="reference internal" href="../library/socket.html#socket.socket.get_inheritable" title="socket.socket.get_inheritable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.socket.get_inheritable()</span></code></a>, <a class="reference internal" href="../library/socket.html#socket.socket.set_inheritable" title="socket.socket.set_inheritable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.socket.set_inheritable()</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-22"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0446"><strong>PEP 446</strong></a> – Make newly created file descriptors non-inheritable</dt><dd><p>PEP written and implemented by Victor Stinner.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="improvements-to-codec-handling">
|
||
<span id="codec-handling-improvements"></span><h3>Improvements to Codec Handling<a class="headerlink" href="#improvements-to-codec-handling" title="Permalink to this headline">¶</a></h3>
|
||
<p>Since it was first introduced, the <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> module has always been
|
||
intended to operate as a type-neutral dynamic encoding and decoding
|
||
system. However, its close coupling with the Python text model, especially
|
||
the type restricted convenience methods on the builtin <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>,
|
||
<a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> types, has historically obscured that
|
||
fact.</p>
|
||
<p>As a key step in clarifying the situation, the <a class="reference internal" href="../library/codecs.html#codecs.encode" title="codecs.encode"><code class="xref py py-meth docutils literal notranslate"><span class="pre">codecs.encode()</span></code></a> and
|
||
<a class="reference internal" href="../library/codecs.html#codecs.decode" title="codecs.decode"><code class="xref py py-meth docutils literal notranslate"><span class="pre">codecs.decode()</span></code></a> convenience functions are now properly documented in
|
||
Python 2.7, 3.3 and 3.4. These functions have existed in the <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>
|
||
module (and have been covered by the regression test suite) since Python 2.4,
|
||
but were previously only discoverable through runtime introspection.</p>
|
||
<p>Unlike the convenience methods on <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> and
|
||
<a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a>, the <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> convenience functions support arbitrary
|
||
codecs in both Python 2 and Python 3, rather than being limited to Unicode text
|
||
encodings (in Python 3) or <code class="docutils literal notranslate"><span class="pre">basestring</span></code> <-> <code class="docutils literal notranslate"><span class="pre">basestring</span></code> conversions (in
|
||
Python 2).</p>
|
||
<p>In Python 3.4, the interpreter is able to identify the known non-text
|
||
encodings provided in the standard library and direct users towards these
|
||
general purpose convenience functions when appropriate:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="sa">b</span><span class="s2">"abcdef"</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">"hex"</span><span class="p">)</span>
|
||
<span class="gt">Traceback (most recent call last):</span>
|
||
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
|
||
<span class="gr">LookupError</span>: <span class="n">'hex' is not a text encoding; use codecs.decode() to handle arbitrary codecs</span>
|
||
|
||
<span class="gp">>>> </span><span class="s2">"hello"</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">"rot13"</span><span class="p">)</span>
|
||
<span class="gt">Traceback (most recent call last):</span>
|
||
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
|
||
<span class="gr">LookupError</span>: <span class="n">'rot13' is not a text encoding; use codecs.encode() to handle arbitrary codecs</span>
|
||
|
||
<span class="gp">>>> </span><span class="nb">open</span><span class="p">(</span><span class="s2">"foo.txt"</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">"hex"</span><span class="p">)</span>
|
||
<span class="gt">Traceback (most recent call last):</span>
|
||
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
|
||
<span class="gr">LookupError</span>: <span class="n">'hex' is not a text encoding; use codecs.open() to handle arbitrary codecs</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>In a related change, whenever it is feasible without breaking backwards
|
||
compatibility, exceptions raised during encoding and decoding operations
|
||
are wrapped in a chained exception of the same type that mentions the
|
||
name of the codec responsible for producing the error:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">codecs</span>
|
||
|
||
<span class="gp">>>> </span><span class="n">codecs</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="sa">b</span><span class="s2">"abcdefgh"</span><span class="p">,</span> <span class="s2">"hex"</span><span class="p">)</span>
|
||
<span class="gt">Traceback (most recent call last):</span>
|
||
File <span class="nb">"/usr/lib/python3.4/encodings/hex_codec.py"</span>, line <span class="m">20</span>, in <span class="n">hex_decode</span>
|
||
<span class="k">return</span> <span class="p">(</span><span class="n">binascii</span><span class="o">.</span><span class="n">a2b_hex</span><span class="p">(</span><span class="nb">input</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="nb">input</span><span class="p">))</span>
|
||
<span class="gr">binascii.Error</span>: <span class="n">Non-hexadecimal digit found</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">binascii.Error</span>: <span class="n">decoding with 'hex' codec failed (Error: Non-hexadecimal digit found)</span>
|
||
|
||
<span class="gp">>>> </span><span class="n">codecs</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">,</span> <span class="s2">"bz2"</span><span class="p">)</span>
|
||
<span class="gt">Traceback (most recent call last):</span>
|
||
File <span class="nb">"/usr/lib/python3.4/encodings/bz2_codec.py"</span>, line <span class="m">17</span>, in <span class="n">bz2_encode</span>
|
||
<span class="k">return</span> <span class="p">(</span><span class="n">bz2</span><span class="o">.</span><span class="n">compress</span><span class="p">(</span><span class="nb">input</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="nb">input</span><span class="p">))</span>
|
||
File <span class="nb">"/usr/lib/python3.4/bz2.py"</span>, line <span class="m">498</span>, in <span class="n">compress</span>
|
||
<span class="k">return</span> <span class="n">comp</span><span class="o">.</span><span class="n">compress</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">+</span> <span class="n">comp</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
|
||
<span class="gr">TypeError</span>: <span class="n">'str' does not support the buffer interface</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">TypeError</span>: <span class="n">encoding with 'bz2' codec failed (TypeError: 'str' does not support the buffer interface)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Finally, as the examples above show, these improvements have permitted
|
||
the restoration of the convenience aliases for the non-Unicode codecs that
|
||
were themselves restored in Python 3.2. This means that encoding binary data
|
||
to and from its hexadecimal representation (for example) can now be written
|
||
as:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">codecs</span> <span class="k">import</span> <span class="n">encode</span><span class="p">,</span> <span class="n">decode</span>
|
||
<span class="gp">>>> </span><span class="n">encode</span><span class="p">(</span><span class="sa">b</span><span class="s2">"hello"</span><span class="p">,</span> <span class="s2">"hex"</span><span class="p">)</span>
|
||
<span class="go">b'68656c6c6f'</span>
|
||
<span class="gp">>>> </span><span class="n">decode</span><span class="p">(</span><span class="sa">b</span><span class="s2">"68656c6c6f"</span><span class="p">,</span> <span class="s2">"hex"</span><span class="p">)</span>
|
||
<span class="go">b'hello'</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The binary and text transforms provided in the standard library are detailed
|
||
in <a class="reference internal" href="../library/codecs.html#binary-transforms"><span class="std std-ref">Binary Transforms</span></a> and <a class="reference internal" href="../library/codecs.html#text-transforms"><span class="std std-ref">Text Transforms</span></a>.</p>
|
||
<p>(Contributed by Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue7475">bpo-7475</a>, <a class="reference external" href="https://bugs.python.org/issue17827">bpo-17827</a>,
|
||
<a class="reference external" href="https://bugs.python.org/issue17828">bpo-17828</a> and <a class="reference external" href="https://bugs.python.org/issue19619">bpo-19619</a>.)</p>
|
||
</div>
|
||
<div class="section" id="pep-451-a-modulespec-type-for-the-import-system">
|
||
<span id="whatsnew-pep-451"></span><h3>PEP 451: A ModuleSpec Type for the Import System<a class="headerlink" href="#pep-451-a-modulespec-type-for-the-import-system" title="Permalink to this headline">¶</a></h3>
|
||
<p><span class="target" id="index-23"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0451"><strong>PEP 451</strong></a> provides an encapsulation of the information about a module that the
|
||
import machinery will use to load it (that is, a module specification). This
|
||
helps simplify both the import implementation and several import-related APIs.
|
||
The change is also a stepping stone for <a class="reference external" href="https://mail.python.org/pipermail/python-dev/2013-November/130111.html">several future import-related
|
||
improvements</a>.</p>
|
||
<p>The public-facing changes from the PEP are entirely backward-compatible.
|
||
Furthermore, they should be transparent to everyone but importer authors. Key
|
||
finder and loader methods have been deprecated, but they will continue working.
|
||
New importers should use the new methods described in the PEP. Existing
|
||
importers should be updated to implement the new methods. See the
|
||
<a class="reference internal" href="#deprecated-3-4"><span class="std std-ref">Deprecated</span></a> section for a list of methods that should be replaced and
|
||
their replacements.</p>
|
||
</div>
|
||
<div class="section" id="other-language-changes">
|
||
<h3>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Permalink to this headline">¶</a></h3>
|
||
<p>Some smaller changes made to the core Python language are:</p>
|
||
<ul class="simple">
|
||
<li><p>Unicode database updated to UCD version 6.3.</p></li>
|
||
<li><p><a class="reference internal" href="../library/functions.html#min" title="min"><code class="xref py py-func docutils literal notranslate"><span class="pre">min()</span></code></a> and <a class="reference internal" href="../library/functions.html#max" title="max"><code class="xref py py-func docutils literal notranslate"><span class="pre">max()</span></code></a> now accept a <em>default</em> keyword-only argument that
|
||
can be used to specify the value they return if the iterable they are
|
||
evaluating has no elements. (Contributed by Julian Berman in
|
||
<a class="reference external" href="https://bugs.python.org/issue18111">bpo-18111</a>.)</p></li>
|
||
<li><p>Module objects are now <a class="reference internal" href="../library/weakref.html#module-weakref" title="weakref: Support for weak references and weak dictionaries."><code class="xref py py-mod docutils literal notranslate"><span class="pre">weakref</span></code></a>’able.</p></li>
|
||
<li><p>Module <code class="docutils literal notranslate"><span class="pre">__file__</span></code> attributes (and related values) should now always
|
||
contain absolute paths by default, with the sole exception of
|
||
<code class="docutils literal notranslate"><span class="pre">__main__.__file__</span></code> when a script has been executed directly using
|
||
a relative path. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue18416">bpo-18416</a>.)</p></li>
|
||
<li><p>All the UTF-* codecs (except UTF-7) now reject surrogates during both
|
||
encoding and decoding unless the <code class="docutils literal notranslate"><span class="pre">surrogatepass</span></code> error handler is used,
|
||
with the exception of the UTF-16 decoder (which accepts valid surrogate pairs)
|
||
and the UTF-16 encoder (which produces them while encoding non-BMP characters).
|
||
(Contributed by Victor Stinner, Kang-Hao (Kenny) Lu and Serhiy Storchaka in
|
||
<a class="reference external" href="https://bugs.python.org/issue12892">bpo-12892</a>.)</p></li>
|
||
<li><p>New German EBCDIC <a class="reference internal" href="../library/codecs.html#standard-encodings"><span class="std std-ref">codec</span></a> <code class="docutils literal notranslate"><span class="pre">cp273</span></code>. (Contributed
|
||
by Michael Bierenfeld and Andrew Kuchling in <a class="reference external" href="https://bugs.python.org/issue1097797">bpo-1097797</a>.)</p></li>
|
||
<li><p>New Ukrainian <a class="reference internal" href="../library/codecs.html#standard-encodings"><span class="std std-ref">codec</span></a> <code class="docutils literal notranslate"><span class="pre">cp1125</span></code>. (Contributed by
|
||
Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue19668">bpo-19668</a>.)</p></li>
|
||
<li><p><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>.join() 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>.join() now accept arbitrary
|
||
buffer objects as arguments. (Contributed by Antoine Pitrou in
|
||
<a class="reference external" href="https://bugs.python.org/issue15958">bpo-15958</a>.)</p></li>
|
||
<li><p>The <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> constructor now accepts any object that has an <code class="docutils literal notranslate"><span class="pre">__index__</span></code>
|
||
method for its <em>base</em> argument. (Contributed by Mark Dickinson in
|
||
<a class="reference external" href="https://bugs.python.org/issue16772">bpo-16772</a>.)</p></li>
|
||
<li><p>Frame objects now have a <a class="reference internal" href="../reference/datamodel.html#frame.clear" title="frame.clear"><code class="xref py py-func docutils literal notranslate"><span class="pre">clear()</span></code></a> method that clears all
|
||
references to local variables from the frame. (Contributed by Antoine Pitrou
|
||
in <a class="reference external" href="https://bugs.python.org/issue17934">bpo-17934</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> is now registered as a <a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-class docutils literal notranslate"><span class="pre">Sequence</span></code></a>,
|
||
and supports the <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> builtin. (Contributed by Nick Coghlan
|
||
and Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue18690">bpo-18690</a> and <a class="reference external" href="https://bugs.python.org/issue19078">bpo-19078</a>.)</p></li>
|
||
<li><p>Signatures reported by <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> have been modified and improved in
|
||
several cases as a result of the introduction of Argument Clinic and other
|
||
changes to 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> and <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> modules.</p></li>
|
||
<li><p><a class="reference internal" href="../reference/datamodel.html#object.__length_hint__" title="object.__length_hint__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__length_hint__()</span></code></a> is now part of the formal language
|
||
specification (see <span class="target" id="index-24"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0424"><strong>PEP 424</strong></a>). (Contributed by Armin Ronacher in
|
||
<a class="reference external" href="https://bugs.python.org/issue16148">bpo-16148</a>.)</p></li>
|
||
</ul>
|
||
</div>
|
||
</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="asyncio">
|
||
<span id="whatsnew-asyncio"></span><h3>asyncio<a class="headerlink" href="#asyncio" title="Permalink to this headline">¶</a></h3>
|
||
<p>The new <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 (defined in <span class="target" id="index-25"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3156"><strong>PEP 3156</strong></a>) provides a standard
|
||
pluggable event loop model for Python, providing solid asynchronous IO
|
||
support in the standard library, and making it easier for other event loop
|
||
implementations to interoperate with the standard library and each other.</p>
|
||
<p>For Python 3.4, this module is considered a <a class="reference internal" href="../glossary.html#term-provisional-api"><span class="xref std std-term">provisional API</span></a>.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-26"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3156"><strong>PEP 3156</strong></a> – Asynchronous IO Support Rebooted: the “asyncio” Module</dt><dd><p>PEP written and implementation led by Guido van Rossum.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="ensurepip">
|
||
<span id="whatsnew-ensurepip"></span><h3>ensurepip<a class="headerlink" href="#ensurepip" title="Permalink to this headline">¶</a></h3>
|
||
<p>The new <a class="reference internal" href="../library/ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the "pip" installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a> module is the primary infrastructure for the
|
||
<span class="target" id="index-27"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0453"><strong>PEP 453</strong></a> implementation. In the normal course of events end users will not
|
||
need to interact with this module, but it can be used to manually bootstrap
|
||
<code class="docutils literal notranslate"><span class="pre">pip</span></code> if the automated bootstrapping into an installation or virtual
|
||
environment was declined.</p>
|
||
<p><a class="reference internal" href="../library/ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the "pip" installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a> includes a bundled copy of <code class="docutils literal notranslate"><span class="pre">pip</span></code>, up-to-date as of the first
|
||
release candidate of the release of CPython with which it ships (this applies
|
||
to both maintenance releases and feature releases). <code class="docutils literal notranslate"><span class="pre">ensurepip</span></code> does not
|
||
access the internet. If the installation has Internet access, after
|
||
<code class="docutils literal notranslate"><span class="pre">ensurepip</span></code> is run the bundled <code class="docutils literal notranslate"><span class="pre">pip</span></code> can be used to upgrade <code class="docutils literal notranslate"><span class="pre">pip</span></code> to a
|
||
more recent release than the bundled one. (Note that such an upgraded version
|
||
of <code class="docutils literal notranslate"><span class="pre">pip</span></code> is considered to be a separately installed package and will not be
|
||
removed if Python is uninstalled.)</p>
|
||
<p>The module is named <em>ensure</em>pip because if called when <code class="docutils literal notranslate"><span class="pre">pip</span></code> is already
|
||
installed, it does nothing. It also has an <code class="docutils literal notranslate"><span class="pre">--upgrade</span></code> option that will
|
||
cause it to install the bundled copy of <code class="docutils literal notranslate"><span class="pre">pip</span></code> if the existing installed
|
||
version of <code class="docutils literal notranslate"><span class="pre">pip</span></code> is older than the bundled copy.</p>
|
||
</div>
|
||
<div class="section" id="enum">
|
||
<span id="whatsnew-enum"></span><h3>enum<a class="headerlink" href="#enum" title="Permalink to this headline">¶</a></h3>
|
||
<p>The new <a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a> module (defined in <span class="target" id="index-28"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0435"><strong>PEP 435</strong></a>) provides a standard
|
||
implementation of enumeration types, allowing other modules (such as
|
||
<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>) to provide more informative error messages and better
|
||
debugging support by replacing opaque integer constants with backwards
|
||
compatible enumeration values.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-29"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0435"><strong>PEP 435</strong></a> – Adding an Enum type to the Python standard library</dt><dd><p>PEP written by Barry Warsaw, Eli Bendersky and Ethan Furman,
|
||
implemented by Ethan Furman.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pathlib">
|
||
<span id="whatsnew-pathlib"></span><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#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> module offers classes representing filesystem paths
|
||
with semantics appropriate for different operating systems. Path classes are
|
||
divided between <em>pure paths</em>, which provide purely computational operations
|
||
without I/O, and <em>concrete paths</em>, which inherit from pure paths but also
|
||
provide I/O operations.</p>
|
||
<p>For Python 3.4, this module is considered a <a class="reference internal" href="../glossary.html#term-provisional-api"><span class="xref std std-term">provisional API</span></a>.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-30"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0428"><strong>PEP 428</strong></a> – The pathlib module – object-oriented filesystem paths</dt><dd><p>PEP written and implemented by Antoine Pitrou.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="selectors">
|
||
<span id="whatsnew-selectors"></span><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#module-selectors" title="selectors: High-level I/O multiplexing."><code class="xref py py-mod docutils literal notranslate"><span class="pre">selectors</span></code></a> module (created as part of implementing <span class="target" id="index-31"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3156"><strong>PEP 3156</strong></a>)
|
||
allows high-level and efficient I/O multiplexing, built upon the
|
||
<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> module primitives.</p>
|
||
</div>
|
||
<div class="section" id="statistics">
|
||
<span id="whatsnew-statistics"></span><h3>statistics<a class="headerlink" href="#statistics" title="Permalink to this headline">¶</a></h3>
|
||
<p>The new <a class="reference internal" href="../library/statistics.html#module-statistics" title="statistics: mathematical statistics functions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">statistics</span></code></a> module (defined in <span class="target" id="index-32"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0450"><strong>PEP 450</strong></a>) offers some core
|
||
statistics functionality directly in the standard library. This module
|
||
supports calculation of the mean, median, mode, variance and standard
|
||
deviation of a data series.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-33"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0450"><strong>PEP 450</strong></a> – Adding A Statistics Module To The Standard Library</dt><dd><p>PEP written and implemented by Steven D’Aprano</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="tracemalloc">
|
||
<span id="whatsnew-tracemalloc"></span><h3>tracemalloc<a class="headerlink" href="#tracemalloc" title="Permalink to this headline">¶</a></h3>
|
||
<p>The new <a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a> module (defined in <span class="target" id="index-34"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0454"><strong>PEP 454</strong></a>) is a debug tool to
|
||
trace memory blocks allocated by Python. It provides the following information:</p>
|
||
<ul class="simple">
|
||
<li><p>Trace where an object was allocated</p></li>
|
||
<li><p>Statistics on allocated memory blocks per filename and per line number:
|
||
total size, number and average size of allocated memory blocks</p></li>
|
||
<li><p>Compute the differences between two snapshots to detect memory leaks</p></li>
|
||
</ul>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-35"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0454"><strong>PEP 454</strong></a> – Add a new tracemalloc module to trace Python memory allocations</dt><dd><p>PEP written and implemented by Victor Stinner</p>
|
||
</dd>
|
||
</dl>
|
||
</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="abc">
|
||
<h3>abc<a class="headerlink" href="#abc" title="Permalink to this headline">¶</a></h3>
|
||
<p>New function <a class="reference internal" href="../library/abc.html#abc.get_cache_token" title="abc.get_cache_token"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.get_cache_token()</span></code></a> can be used to know when to invalidate
|
||
caches that are affected by changes in the object graph. (Contributed
|
||
by Łukasz Langa in <a class="reference external" href="https://bugs.python.org/issue16832">bpo-16832</a>.)</p>
|
||
<p>New class <a class="reference internal" href="../library/abc.html#abc.ABC" title="abc.ABC"><code class="xref py py-class docutils literal notranslate"><span class="pre">ABC</span></code></a> has <a class="reference internal" href="../library/abc.html#abc.ABCMeta" title="abc.ABCMeta"><code class="xref py py-class docutils literal notranslate"><span class="pre">ABCMeta</span></code></a> as its meta class.
|
||
Using <code class="docutils literal notranslate"><span class="pre">ABC</span></code> as a base class has essentially the same effect as specifying
|
||
<code class="docutils literal notranslate"><span class="pre">metaclass=abc.ABCMeta</span></code>, but is simpler to type and easier to read.
|
||
(Contributed by Bruno Dupuis in <a class="reference external" href="https://bugs.python.org/issue16049">bpo-16049</a>.)</p>
|
||
</div>
|
||
<div class="section" id="aifc">
|
||
<h3>aifc<a class="headerlink" href="#aifc" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/aifc.html#aifc.aifc.getparams" title="aifc.aifc.getparams"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getparams()</span></code></a> method now returns a namedtuple rather than a
|
||
plain tuple. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue17818">bpo-17818</a>.)</p>
|
||
<p><a class="reference internal" href="../library/aifc.html#aifc.open" title="aifc.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">aifc.open()</span></code></a> now supports the context management 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> block, the <a class="reference internal" href="../library/aifc.html#aifc.aifc.close" title="aifc.aifc.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> method of the returned
|
||
object will be called automatically at the end of the block. (Contributed by
|
||
Serhiy Storchacha in <a class="reference external" href="https://bugs.python.org/issue16486">bpo-16486</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/aifc.html#aifc.aifc.writeframesraw" title="aifc.aifc.writeframesraw"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframesraw()</span></code></a> and <a class="reference internal" href="../library/aifc.html#aifc.aifc.writeframes" title="aifc.aifc.writeframes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframes()</span></code></a>
|
||
methods now accept any <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a>. (Contributed by Serhiy
|
||
Storchaka in <a class="reference external" href="https://bugs.python.org/issue8311">bpo-8311</a>.)</p>
|
||
</div>
|
||
<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.FileType" title="argparse.FileType"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileType</span></code></a> class now accepts <em>encoding</em> and
|
||
<em>errors</em> arguments, which are passed through to <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>. (Contributed
|
||
by Lucas Maystre in <a class="reference external" href="https://bugs.python.org/issue11175">bpo-11175</a>.)</p>
|
||
</div>
|
||
<div class="section" id="audioop">
|
||
<h3>audioop<a class="headerlink" href="#audioop" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/audioop.html#module-audioop" title="audioop: Manipulate raw audio data."><code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code></a> now supports 24-bit samples. (Contributed by Serhiy Storchaka
|
||
in <a class="reference external" href="https://bugs.python.org/issue12866">bpo-12866</a>.)</p>
|
||
<p>New <a class="reference internal" href="../library/audioop.html#audioop.byteswap" title="audioop.byteswap"><code class="xref py py-func docutils literal notranslate"><span class="pre">byteswap()</span></code></a> function converts big-endian samples to
|
||
little-endian and vice versa. (Contributed by Serhiy Storchaka in
|
||
<a class="reference external" href="https://bugs.python.org/issue19641">bpo-19641</a>.)</p>
|
||
<p>All <a class="reference internal" href="../library/audioop.html#module-audioop" title="audioop: Manipulate raw audio data."><code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code></a> functions now accept any <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a>. Strings
|
||
are not accepted: they didn’t work before, now they raise an error right away.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue16685">bpo-16685</a>.)</p>
|
||
</div>
|
||
<div class="section" id="base64">
|
||
<h3>base64<a class="headerlink" href="#base64" title="Permalink to this headline">¶</a></h3>
|
||
<p>The encoding and decoding functions in <a class="reference internal" href="../library/base64.html#module-base64" title="base64: RFC 3548: Base16, Base32, Base64 Data Encodings; Base85 and Ascii85"><code class="xref py py-mod docutils literal notranslate"><span class="pre">base64</span></code></a> now accept any
|
||
<a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a> in cases where it previously required a
|
||
<a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> or <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> instance. (Contributed by Nick Coghlan in
|
||
<a class="reference external" href="https://bugs.python.org/issue17839">bpo-17839</a>.)</p>
|
||
<p>New functions <a class="reference internal" href="../library/base64.html#base64.a85encode" title="base64.a85encode"><code class="xref py py-func docutils literal notranslate"><span class="pre">a85encode()</span></code></a>, <a class="reference internal" href="../library/base64.html#base64.a85decode" title="base64.a85decode"><code class="xref py py-func docutils literal notranslate"><span class="pre">a85decode()</span></code></a>,
|
||
<a class="reference internal" href="../library/base64.html#base64.b85encode" title="base64.b85encode"><code class="xref py py-func docutils literal notranslate"><span class="pre">b85encode()</span></code></a>, and <a class="reference internal" href="../library/base64.html#base64.b85decode" title="base64.b85decode"><code class="xref py py-func docutils literal notranslate"><span class="pre">b85decode()</span></code></a> provide the ability to
|
||
encode and decode binary data from and to <code class="docutils literal notranslate"><span class="pre">Ascii85</span></code> and the git/mercurial
|
||
<code class="docutils literal notranslate"><span class="pre">Base85</span></code> formats, respectively. The <code class="docutils literal notranslate"><span class="pre">a85</span></code> functions have options that can
|
||
be used to make them compatible with the variants of the <code class="docutils literal notranslate"><span class="pre">Ascii85</span></code> encoding,
|
||
including the Adobe variant. (Contributed by Martin Morrison, the Mercurial
|
||
project, Serhiy Storchaka, and Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue17618">bpo-17618</a>.)</p>
|
||
</div>
|
||
<div class="section" id="collections">
|
||
<h3>collections<a class="headerlink" href="#collections" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/collections.html#collections.ChainMap.new_child" title="collections.ChainMap.new_child"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ChainMap.new_child()</span></code></a> method now accepts an <em>m</em> argument specifying
|
||
the child map to add to the chain. This allows an existing mapping and/or a
|
||
custom mapping type to be used for the child. (Contributed by Vinay Sajip in
|
||
<a class="reference external" href="https://bugs.python.org/issue16613">bpo-16613</a>.)</p>
|
||
</div>
|
||
<div class="section" id="colorsys">
|
||
<h3>colorsys<a class="headerlink" href="#colorsys" title="Permalink to this headline">¶</a></h3>
|
||
<p>The number of digits in the coefficients for the RGB — YIQ conversions have
|
||
been expanded so that they match the FCC NTSC versions. The change in
|
||
results should be less than 1% and may better match results found elsewhere.
|
||
(Contributed by Brian Landers and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue14323">bpo-14323</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.suppress" title="contextlib.suppress"><code class="xref py py-class docutils literal notranslate"><span class="pre">contextlib.suppress</span></code></a> context manager helps to clarify the
|
||
intent of code that deliberately suppresses exceptions from a single
|
||
statement. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue15806">bpo-15806</a> and
|
||
Zero Piraeus in <a class="reference external" href="https://bugs.python.org/issue19266">bpo-19266</a>.)</p>
|
||
<p>The new <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">contextlib.redirect_stdout()</span></code></a> context manager makes it easier
|
||
for utility scripts to handle inflexible APIs that write their output to
|
||
<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> and don’t provide any options to redirect it. Using the
|
||
context manager, the <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> output can be redirected to any
|
||
other stream or, in conjunction with <a class="reference internal" href="../library/io.html#io.StringIO" title="io.StringIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.StringIO</span></code></a>, to a string.
|
||
The latter can be especially useful, for example, to capture output
|
||
from a function that was written to implement a command line interface.
|
||
It is recommended only for utility scripts because it affects the
|
||
global state of <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>. (Contributed by Raymond Hettinger
|
||
in <a class="reference external" href="https://bugs.python.org/issue15805">bpo-15805</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/contextlib.html#module-contextlib" title="contextlib: Utilities for with-statement contexts."><code class="xref py py-mod docutils literal notranslate"><span class="pre">contextlib</span></code></a> documentation has also been updated to include a
|
||
<a class="reference internal" href="../library/contextlib.html#single-use-reusable-and-reentrant-cms"><span class="std std-ref">discussion</span></a> of the
|
||
differences between single use, reusable and reentrant context managers.</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.open" title="dbm.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">dbm.open()</span></code></a> objects now support the context management 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 <code class="docutils literal notranslate"><span class="pre">close</span></code> method of the database
|
||
object will be called automatically at the end of the block. (Contributed by
|
||
Claudiu Popa and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue19282">bpo-19282</a>.)</p>
|
||
</div>
|
||
<div class="section" id="dis">
|
||
<h3>dis<a class="headerlink" href="#dis" title="Permalink to this headline">¶</a></h3>
|
||
<p>Functions <a class="reference internal" href="../library/dis.html#dis.show_code" title="dis.show_code"><code class="xref py py-func docutils literal notranslate"><span class="pre">show_code()</span></code></a>, <a class="reference internal" href="../library/dis.html#dis.dis" title="dis.dis"><code class="xref py py-func docutils literal notranslate"><span class="pre">dis()</span></code></a>, <a class="reference internal" href="../library/dis.html#dis.distb" title="dis.distb"><code class="xref py py-func docutils literal notranslate"><span class="pre">distb()</span></code></a>, and
|
||
<a class="reference internal" href="../library/dis.html#dis.disassemble" title="dis.disassemble"><code class="xref py py-func docutils literal notranslate"><span class="pre">disassemble()</span></code></a> now accept a keyword-only <em>file</em> argument that
|
||
controls where they write their output.</p>
|
||
<p>The <a class="reference internal" href="../library/dis.html#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> module is now built around an <a class="reference internal" href="../library/dis.html#dis.Instruction" title="dis.Instruction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Instruction</span></code></a> class
|
||
that provides object oriented access to the details of each individual bytecode
|
||
operation.</p>
|
||
<p>A new method, <a class="reference internal" href="../library/dis.html#dis.get_instructions" title="dis.get_instructions"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_instructions()</span></code></a>, provides an iterator that emits
|
||
the Instruction stream for a given piece of Python code. Thus it is now
|
||
possible to write a program that inspects and manipulates a bytecode
|
||
object in ways different from those provided by the <a class="reference internal" href="../library/dis.html#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> module
|
||
itself. For 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">dis</span>
|
||
<span class="gp">>>> </span><span class="k">for</span> <span class="n">instr</span> <span class="ow">in</span> <span class="n">dis</span><span class="o">.</span><span class="n">get_instructions</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">instr</span><span class="o">.</span><span class="n">opname</span><span class="p">)</span>
|
||
<span class="go">LOAD_FAST</span>
|
||
<span class="go">LOAD_CONST</span>
|
||
<span class="go">BINARY_ADD</span>
|
||
<span class="go">RETURN_VALUE</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The various display tools in the <a class="reference internal" href="../library/dis.html#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> module have been rewritten to use
|
||
these new components.</p>
|
||
<p>In addition, a new application-friendly class <a class="reference internal" href="../library/dis.html#dis.Bytecode" title="dis.Bytecode"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bytecode</span></code></a> provides
|
||
an object-oriented API for inspecting bytecode in both in human-readable form
|
||
and for iterating over instructions. The <a class="reference internal" href="../library/dis.html#dis.Bytecode" title="dis.Bytecode"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bytecode</span></code></a> constructor
|
||
takes the same arguments that <code class="xref py py-func docutils literal notranslate"><span class="pre">get_instruction()</span></code> does (plus an
|
||
optional <em>current_offset</em>), and the resulting object can be iterated to produce
|
||
<a class="reference internal" href="../library/dis.html#dis.Instruction" title="dis.Instruction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Instruction</span></code></a> objects. But it also has a <a class="reference internal" href="../library/dis.html#dis.Bytecode.dis" title="dis.Bytecode.dis"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a>
|
||
method, equivalent to calling <a class="reference internal" href="../library/dis.html#dis.dis" title="dis.dis"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> on the constructor argument, but
|
||
returned as a multi-line string:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">bytecode</span> <span class="o">=</span> <span class="n">dis</span><span class="o">.</span><span class="n">Bytecode</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">current_offset</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="k">for</span> <span class="n">instr</span> <span class="ow">in</span> <span class="n">bytecode</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> (</span><span class="si">{}</span><span class="s1">)'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">instr</span><span class="o">.</span><span class="n">opname</span><span class="p">,</span> <span class="n">instr</span><span class="o">.</span><span class="n">opcode</span><span class="p">))</span>
|
||
<span class="go">LOAD_FAST (124)</span>
|
||
<span class="go">LOAD_CONST (100)</span>
|
||
<span class="go">BINARY_ADD (23)</span>
|
||
<span class="go">RETURN_VALUE (83)</span>
|
||
<span class="gp">>>> </span><span class="n">bytecode</span><span class="o">.</span><span class="n">dis</span><span class="p">()</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()</span>
|
||
<span class="go">[' 1 0 LOAD_FAST 0 (x)',</span>
|
||
<span class="go"> ' --> 3 LOAD_CONST 1 (1)',</span>
|
||
<span class="go"> ' 6 BINARY_ADD',</span>
|
||
<span class="go"> ' 7 RETURN_VALUE']</span>
|
||
</pre></div>
|
||
</div>
|
||
<p><a class="reference internal" href="../library/dis.html#dis.Bytecode" title="dis.Bytecode"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bytecode</span></code></a> also has a class method,
|
||
<a class="reference internal" href="../library/dis.html#dis.Bytecode.from_traceback" title="dis.Bytecode.from_traceback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">from_traceback()</span></code></a>, that provides the ability to manipulate a
|
||
traceback (that is, <code class="docutils literal notranslate"><span class="pre">print(Bytecode.from_traceback(tb).dis())</span></code> is equivalent
|
||
to <code class="docutils literal notranslate"><span class="pre">distb(tb)</span></code>).</p>
|
||
<p>(Contributed by Nick Coghlan, Ryan Kelly and Thomas Kluyver in <a class="reference external" href="https://bugs.python.org/issue11816">bpo-11816</a>
|
||
and Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue17916">bpo-17916</a>.)</p>
|
||
<p>New function <a class="reference internal" href="../library/dis.html#dis.stack_effect" title="dis.stack_effect"><code class="xref py py-func docutils literal notranslate"><span class="pre">stack_effect()</span></code></a> computes the effect on the Python stack
|
||
of a given opcode and argument, information that is not otherwise available.
|
||
(Contributed by Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue19722">bpo-19722</a>.)</p>
|
||
</div>
|
||
<div class="section" id="doctest">
|
||
<h3>doctest<a class="headerlink" href="#doctest" title="Permalink to this headline">¶</a></h3>
|
||
<p>A new <a class="reference internal" href="../library/doctest.html#doctest-options"><span class="std std-ref">option flag</span></a>, <a class="reference internal" href="../library/doctest.html#doctest.FAIL_FAST" title="doctest.FAIL_FAST"><code class="xref py py-data docutils literal notranslate"><span class="pre">FAIL_FAST</span></code></a>, halts
|
||
test running as soon as the first failure is detected. (Contributed by R.
|
||
David Murray and Daniel Urban in <a class="reference external" href="https://bugs.python.org/issue16522">bpo-16522</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/doctest.html#module-doctest" title="doctest: Test pieces of code within docstrings."><code class="xref py py-mod docutils literal notranslate"><span class="pre">doctest</span></code></a> command line interface now uses <a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a>, and has two
|
||
new options, <code class="docutils literal notranslate"><span class="pre">-o</span></code> and <code class="docutils literal notranslate"><span class="pre">-f</span></code>. <code class="docutils literal notranslate"><span class="pre">-o</span></code> allows <a class="reference internal" href="../library/doctest.html#doctest-options"><span class="std std-ref">doctest options</span></a> to be specified on the command line, and <code class="docutils literal notranslate"><span class="pre">-f</span></code> is a
|
||
shorthand for <code class="docutils literal notranslate"><span class="pre">-o</span> <span class="pre">FAIL_FAST</span></code> (to parallel the similar option supported by the
|
||
<a class="reference internal" href="../library/unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code></a> CLI). (Contributed by R. David Murray in <a class="reference external" href="https://bugs.python.org/issue11390">bpo-11390</a>.)</p>
|
||
<p><a class="reference internal" href="../library/doctest.html#module-doctest" title="doctest: Test pieces of code within docstrings."><code class="xref py py-mod docutils literal notranslate"><span class="pre">doctest</span></code></a> will now find doctests in extension module <code class="docutils literal notranslate"><span class="pre">__doc__</span></code> strings.
|
||
(Contributed by Zachary Ware in <a class="reference external" href="https://bugs.python.org/issue3158">bpo-3158</a>.)</p>
|
||
</div>
|
||
<div class="section" id="email">
|
||
<h3>email<a class="headerlink" href="#email" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/email.compat32-message.html#email.message.Message.as_string" title="email.message.Message.as_string"><code class="xref py py-meth docutils literal notranslate"><span class="pre">as_string()</span></code></a> now accepts a <em>policy</em> argument to
|
||
override the default policy of the message when generating a string
|
||
representation of it. This means that <code class="docutils literal notranslate"><span class="pre">as_string</span></code> can now be used in more
|
||
circumstances, instead of having to create and use a <a class="reference internal" href="../library/email.generator.html#module-email.generator" title="email.generator: Generate flat text email messages from a message structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">generator</span></code></a> in
|
||
order to pass formatting parameters to its <code class="docutils literal notranslate"><span class="pre">flatten</span></code> method. (Contributed by
|
||
R. David Murray in <a class="reference external" href="https://bugs.python.org/issue18600">bpo-18600</a>.)</p>
|
||
<p>New method <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message.as_bytes" title="email.message.Message.as_bytes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">as_bytes()</span></code></a> added to produce a bytes
|
||
representation of the message in a fashion similar to how <code class="docutils literal notranslate"><span class="pre">as_string</span></code>
|
||
produces a string representation. It does not accept the <em>maxheaderlen</em>
|
||
argument, but does accept the <em>unixfrom</em> and <em>policy</em> arguments. The
|
||
<a class="reference internal" href="../library/email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message.__bytes__" title="email.message.Message.__bytes__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__bytes__()</span></code></a> method
|
||
calls it, meaning that <code class="docutils literal notranslate"><span class="pre">bytes(mymsg)</span></code> will now produce the intuitive
|
||
result: a bytes object containing the fully formatted message. (Contributed
|
||
by R. David Murray in <a class="reference external" href="https://bugs.python.org/issue18600">bpo-18600</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message.set_param" title="email.message.Message.set_param"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Message.set_param()</span></code></a> message now accepts a <em>replace</em> keyword argument.
|
||
When specified, the associated header will be updated without changing
|
||
its location in the list of headers. For backward compatibility, the default
|
||
is <code class="docutils literal notranslate"><span class="pre">False</span></code>. (Contributed by R. David Murray in <a class="reference external" href="https://bugs.python.org/issue18891">bpo-18891</a>.)</p>
|
||
<p id="whatsnew-email-contentmanager">A pair of new subclasses of <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> have been added
|
||
(<a class="reference internal" href="../library/email.message.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailMessage</span></code></a> and <a class="reference internal" href="../library/email.message.html#email.message.MIMEPart" title="email.message.MIMEPart"><code class="xref py py-class docutils literal notranslate"><span class="pre">MIMEPart</span></code></a>), along with a new sub-module,
|
||
<a class="reference internal" href="../library/email.contentmanager.html#module-email.contentmanager" title="email.contentmanager: Storing and Retrieving Content from MIME Parts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">contentmanager</span></code></a> and a new <a class="reference internal" href="../library/email.policy.html#module-email.policy" title="email.policy: Controlling the parsing and generating of messages"><code class="xref py py-mod docutils literal notranslate"><span class="pre">policy</span></code></a> attribute
|
||
<a class="reference internal" href="../library/email.policy.html#email.policy.EmailPolicy.content_manager" title="email.policy.EmailPolicy.content_manager"><code class="xref py py-attr docutils literal notranslate"><span class="pre">content_manager</span></code></a>. All documentation is
|
||
currently in the new module, which is being added as part of email’s new
|
||
<a class="reference internal" href="../glossary.html#term-provisional-api"><span class="xref std std-term">provisional API</span></a>. These classes provide a number of new methods that
|
||
make extracting content from and inserting content into email messages much
|
||
easier. For details, see the <a class="reference internal" href="../library/email.contentmanager.html#module-email.contentmanager" title="email.contentmanager: Storing and Retrieving Content from MIME Parts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">contentmanager</span></code></a> documentation and
|
||
the <a class="reference internal" href="../library/email.examples.html#email-examples"><span class="std std-ref">email: Examples</span></a>. These API additions complete the
|
||
bulk of the work that was planned as part of the email6 project. The currently
|
||
provisional API is scheduled to become final in Python 3.5 (possibly with a few
|
||
minor additions in the area of error handling). (Contributed by R. David
|
||
Murray in <a class="reference external" href="https://bugs.python.org/issue18891">bpo-18891</a>.)</p>
|
||
</div>
|
||
<div class="section" id="filecmp">
|
||
<h3>filecmp<a class="headerlink" href="#filecmp" title="Permalink to this headline">¶</a></h3>
|
||
<p>A new <a class="reference internal" href="../library/filecmp.html#filecmp.clear_cache" title="filecmp.clear_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">clear_cache()</span></code></a> function provides the ability to clear the
|
||
<a class="reference internal" href="../library/filecmp.html#module-filecmp" title="filecmp: Compare files efficiently."><code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code></a> comparison cache, which uses <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> information to
|
||
determine if the file has changed since the last compare. This can be used,
|
||
for example, if the file might have been changed and re-checked in less time
|
||
than the resolution of a particular filesystem’s file modification time field.
|
||
(Contributed by Mark Levitt in <a class="reference external" href="https://bugs.python.org/issue18149">bpo-18149</a>.)</p>
|
||
<p>New module attribute <a class="reference internal" href="../library/filecmp.html#filecmp.DEFAULT_IGNORES" title="filecmp.DEFAULT_IGNORES"><code class="xref py py-data docutils literal notranslate"><span class="pre">DEFAULT_IGNORES</span></code></a> provides the list of
|
||
directories that are used as the default value for the <em>ignore</em> parameter of
|
||
the <a class="reference internal" href="../library/filecmp.html#filecmp.dircmp" title="filecmp.dircmp"><code class="xref py py-func docutils literal notranslate"><span class="pre">dircmp()</span></code></a> function. (Contributed by Eli Bendersky in
|
||
<a class="reference external" href="https://bugs.python.org/issue15442">bpo-15442</a>.)</p>
|
||
</div>
|
||
<div class="section" id="functools">
|
||
<h3>functools<a class="headerlink" href="#functools" title="Permalink to this headline">¶</a></h3>
|
||
<p>The new <a class="reference internal" href="../library/functools.html#functools.partialmethod" title="functools.partialmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">partialmethod()</span></code></a> descriptor brings partial argument
|
||
application to descriptors, just as <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">partial()</span></code></a> provides
|
||
for normal callables. The new descriptor also makes it easier to get
|
||
arbitrary callables (including <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">partial()</span></code></a> instances)
|
||
to behave like normal instance methods when included in a class definition.
|
||
(Contributed by Alon Horev and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue4331">bpo-4331</a>.)</p>
|
||
<p id="whatsnew-singledispatch">The new <a class="reference internal" href="../library/functools.html#functools.singledispatch" title="functools.singledispatch"><code class="xref py py-func docutils literal notranslate"><span class="pre">singledispatch()</span></code></a> decorator brings support for
|
||
single-dispatch generic functions to the Python standard library. Where
|
||
object oriented programming focuses on grouping multiple operations on a
|
||
common set of data into a class, a generic function focuses on grouping
|
||
multiple implementations of an operation that allows it to work with
|
||
<em>different</em> kinds of data.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-36"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0443"><strong>PEP 443</strong></a> – Single-dispatch generic functions</dt><dd><p>PEP written and implemented by Łukasz Langa.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
<p><a class="reference internal" href="../library/functools.html#functools.total_ordering" title="functools.total_ordering"><code class="xref py py-func docutils literal notranslate"><span class="pre">total_ordering()</span></code></a> now supports a return value of
|
||
<a class="reference internal" href="../library/constants.html#NotImplemented" title="NotImplemented"><code class="xref py py-const docutils literal notranslate"><span class="pre">NotImplemented</span></code></a> from the underlying comparison function. (Contributed
|
||
by Katie Miller in <a class="reference external" href="https://bugs.python.org/issue10042">bpo-10042</a>.)</p>
|
||
<p>A pure-python version of the <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">partial()</span></code></a> function is now in the
|
||
stdlib; in CPython it is overridden by the C accelerated version, but it is
|
||
available for other implementations to use. (Contributed by Brian Thorne in
|
||
<a class="reference external" href="https://bugs.python.org/issue12428">bpo-12428</a>.)</p>
|
||
</div>
|
||
<div class="section" id="gc">
|
||
<h3>gc<a class="headerlink" href="#gc" title="Permalink to this headline">¶</a></h3>
|
||
<p>New function <a class="reference internal" href="../library/gc.html#gc.get_stats" title="gc.get_stats"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_stats()</span></code></a> returns a list of three per-generation
|
||
dictionaries containing the collections statistics since interpreter startup.
|
||
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue16351">bpo-16351</a>.)</p>
|
||
</div>
|
||
<div class="section" id="glob">
|
||
<h3>glob<a class="headerlink" href="#glob" title="Permalink to this headline">¶</a></h3>
|
||
<p>A new function <a class="reference internal" href="../library/glob.html#glob.escape" title="glob.escape"><code class="xref py py-func docutils literal notranslate"><span class="pre">escape()</span></code></a> provides a way to escape special characters
|
||
in a filename so that they do not become part of the globbing expansion but are
|
||
instead matched literally. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue8402">bpo-8402</a>.)</p>
|
||
</div>
|
||
<div class="section" id="hashlib">
|
||
<h3>hashlib<a class="headerlink" href="#hashlib" title="Permalink to this headline">¶</a></h3>
|
||
<p>A new <a class="reference internal" href="../library/hashlib.html#hashlib.pbkdf2_hmac" title="hashlib.pbkdf2_hmac"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.pbkdf2_hmac()</span></code></a> function provides
|
||
the <a class="reference external" href="https://en.wikipedia.org/wiki/PBKDF2">PKCS#5 password-based key derivation function 2</a>. (Contributed by Christian
|
||
Heimes in <a class="reference external" href="https://bugs.python.org/issue18582">bpo-18582</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/hashlib.html#hashlib.hash.name" title="hashlib.hash.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> attribute of <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> hash objects is now
|
||
a formally supported interface. It has always existed in CPython’s
|
||
<a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> (although it did not return lower case names for all supported
|
||
hashes), but it was not a public interface and so some other Python
|
||
implementations have not previously supported it. (Contributed by Jason R.
|
||
Coombs in <a class="reference external" href="https://bugs.python.org/issue18532">bpo-18532</a>.)</p>
|
||
</div>
|
||
<div class="section" id="hmac">
|
||
<h3>hmac<a class="headerlink" href="#hmac" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/hmac.html#module-hmac" title="hmac: Keyed-Hashing for Message Authentication (HMAC) implementation"><code class="xref py py-mod docutils literal notranslate"><span class="pre">hmac</span></code></a> now accepts <code class="docutils literal notranslate"><span class="pre">bytearray</span></code> as well as <code class="docutils literal notranslate"><span class="pre">bytes</span></code> for the <em>key</em>
|
||
argument to the <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">new()</span></code></a> function, and the <em>msg</em> parameter to both the
|
||
<a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">new()</span></code></a> function and the <a class="reference internal" href="../library/hmac.html#hmac.HMAC.update" title="hmac.HMAC.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> method now
|
||
accepts any type supported by the <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> module. (Contributed
|
||
by Jonas Borgström in <a class="reference external" href="https://bugs.python.org/issue18240">bpo-18240</a>.)</p>
|
||
<p>The <em>digestmod</em> argument to the <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">hmac.new()</span></code></a> function may now be any hash
|
||
digest name recognized by <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a>. In addition, the current behavior in
|
||
which the value of <em>digestmod</em> defaults to <code class="docutils literal notranslate"><span class="pre">MD5</span></code> is deprecated: in a
|
||
future version of Python there will be no default value. (Contributed by
|
||
Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue17276">bpo-17276</a>.)</p>
|
||
<p>With the addition of <a class="reference internal" href="../library/hmac.html#hmac.HMAC.block_size" title="hmac.HMAC.block_size"><code class="xref py py-attr docutils literal notranslate"><span class="pre">block_size</span></code></a> and <a class="reference internal" href="../library/hmac.html#hmac.HMAC.name" title="hmac.HMAC.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a>
|
||
attributes (and the formal documentation of the <a class="reference internal" href="../library/hmac.html#hmac.HMAC.digest_size" title="hmac.HMAC.digest_size"><code class="xref py py-attr docutils literal notranslate"><span class="pre">digest_size</span></code></a>
|
||
attribute), the <a class="reference internal" href="../library/hmac.html#module-hmac" title="hmac: Keyed-Hashing for Message Authentication (HMAC) implementation"><code class="xref py py-mod docutils literal notranslate"><span class="pre">hmac</span></code></a> module now conforms fully to the <span class="target" id="index-37"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0247"><strong>PEP 247</strong></a> API.
|
||
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue18775">bpo-18775</a>.)</p>
|
||
</div>
|
||
<div class="section" id="html">
|
||
<h3>html<a class="headerlink" href="#html" title="Permalink to this headline">¶</a></h3>
|
||
<p>New function <a class="reference internal" href="../library/html.html#html.unescape" title="html.unescape"><code class="xref py py-func docutils literal notranslate"><span class="pre">unescape()</span></code></a> function converts HTML5 character references to
|
||
the corresponding Unicode characters. (Contributed by Ezio Melotti in
|
||
<a class="reference external" href="https://bugs.python.org/issue2927">bpo-2927</a>.)</p>
|
||
<p><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> accepts a new keyword argument
|
||
<em>convert_charrefs</em> that, when <code class="docutils literal notranslate"><span class="pre">True</span></code>, automatically converts all character
|
||
references. For backward-compatibility, its value defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>, but
|
||
it will change to <code class="docutils literal notranslate"><span class="pre">True</span></code> in a future version of Python, so you are invited to
|
||
set it explicitly and update your code to use this new feature. (Contributed
|
||
by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue13633">bpo-13633</a>.)</p>
|
||
<p>The <em>strict</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 deprecated.
|
||
(Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue15114">bpo-15114</a>.)</p>
|
||
</div>
|
||
<div class="section" id="http">
|
||
<h3>http<a class="headerlink" href="#http" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/http.server.html#http.server.BaseHTTPRequestHandler.send_error" title="http.server.BaseHTTPRequestHandler.send_error"><code class="xref py py-meth docutils literal notranslate"><span class="pre">send_error()</span></code></a> now accepts an
|
||
optional additional <em>explain</em> parameter which can be used to provide an
|
||
extended error description, overriding the hardcoded default if there is one.
|
||
This extended error description will be formatted using the
|
||
<code class="xref py py-attr docutils literal notranslate"><span class="pre">error_message_format</span></code> attribute and sent as the body
|
||
of the error response. (Contributed by Karl Cow in <a class="reference external" href="https://bugs.python.org/issue12921">bpo-12921</a>.)</p>
|
||
<p>The <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> <a class="reference internal" href="../library/http.server.html#http-server-cli"><span class="std std-ref">command line interface</span></a> now has
|
||
a <code class="docutils literal notranslate"><span class="pre">-b/--bind</span></code> option that causes the server to listen on a specific address.
|
||
(Contributed by Malte Swart in <a class="reference external" href="https://bugs.python.org/issue17764">bpo-17764</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.3.0,
|
||
as well as changes made in future 3.4.x releases. This file is also available
|
||
from the IDLE <span class="menuselection">Help ‣ About IDLE</span> dialog.</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.abc.InspectLoader" title="importlib.abc.InspectLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">InspectLoader</span></code></a> ABC defines a new method,
|
||
<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-meth docutils literal notranslate"><span class="pre">source_to_code()</span></code></a> that accepts source
|
||
data and a path and returns a code object. The default implementation
|
||
is equivalent to <code class="docutils literal notranslate"><span class="pre">compile(data,</span> <span class="pre">path,</span> <span class="pre">'exec',</span> <span class="pre">dont_inherit=True)</span></code>.
|
||
(Contributed by Eric Snow and Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue15627">bpo-15627</a>.)</p>
|
||
<p><a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader" title="importlib.abc.InspectLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">InspectLoader</span></code></a> also now has a default implementation
|
||
for the <a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader.get_code" title="importlib.abc.InspectLoader.get_code"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_code()</span></code></a> method. However,
|
||
it will normally be desirable to override the default implementation
|
||
for performance reasons. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue18072">bpo-18072</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/importlib.html#importlib.reload" title="importlib.reload"><code class="xref py py-func docutils literal notranslate"><span class="pre">reload()</span></code></a> function has been moved from <a class="reference internal" href="../library/imp.html#module-imp" title="imp: Access the implementation of the import statement. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code></a> to
|
||
<a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> as part of the <a class="reference internal" href="../library/imp.html#module-imp" title="imp: Access the implementation of the import statement. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code></a> module deprecation. (Contributed by
|
||
Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue18193">bpo-18193</a>.)</p>
|
||
<p><a class="reference internal" href="../library/importlib.html#module-importlib.util" title="importlib.util: Utility code for importers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.util</span></code></a> now has a <a class="reference internal" href="../library/importlib.html#importlib.util.MAGIC_NUMBER" title="importlib.util.MAGIC_NUMBER"><code class="xref py py-data docutils literal notranslate"><span class="pre">MAGIC_NUMBER</span></code></a> attribute
|
||
providing access to the bytecode version number. This replaces the
|
||
<a class="reference internal" href="../library/imp.html#imp.get_magic" title="imp.get_magic"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_magic()</span></code></a> function in the deprecated <a class="reference internal" href="../library/imp.html#module-imp" title="imp: Access the implementation of the import statement. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code></a> module.
|
||
(Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue18192">bpo-18192</a>.)</p>
|
||
<p>New <a class="reference internal" href="../library/importlib.html#module-importlib.util" title="importlib.util: Utility code for importers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.util</span></code></a> functions <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">cache_from_source()</span></code></a>
|
||
and <a class="reference internal" href="../library/importlib.html#importlib.util.source_from_cache" title="importlib.util.source_from_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">source_from_cache()</span></code></a> replace the same-named functions
|
||
in the deprecated <a class="reference internal" href="../library/imp.html#module-imp" title="imp: Access the implementation of the import statement. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code></a> module. (Contributed by Brett Cannon in
|
||
<a class="reference external" href="https://bugs.python.org/issue18194">bpo-18194</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> bootstrap <code class="xref py py-class docutils literal notranslate"><span class="pre">NamespaceLoader</span></code> now conforms to
|
||
the <a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader" title="importlib.abc.InspectLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">InspectLoader</span></code></a> ABC, which means that <code class="docutils literal notranslate"><span class="pre">runpy</span></code> and
|
||
<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span></code> can now be used with namespace packages. (Contributed
|
||
by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue18058">bpo-18058</a>.)</p>
|
||
<p><a class="reference internal" href="../library/importlib.html#module-importlib.util" title="importlib.util: Utility code for importers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.util</span></code></a> has a new function <a class="reference internal" href="../library/importlib.html#importlib.util.decode_source" title="importlib.util.decode_source"><code class="xref py py-func docutils literal notranslate"><span class="pre">decode_source()</span></code></a>
|
||
that decodes source from bytes using universal newline processing. This is
|
||
useful for implementing <a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader.get_source" title="importlib.abc.InspectLoader.get_source"><code class="xref py py-meth docutils literal notranslate"><span class="pre">InspectLoader.get_source()</span></code></a> methods.</p>
|
||
<p><a class="reference internal" href="../library/importlib.html#importlib.machinery.ExtensionFileLoader" title="importlib.machinery.ExtensionFileLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.ExtensionFileLoader</span></code></a> now has a
|
||
<a class="reference internal" href="../library/importlib.html#importlib.machinery.ExtensionFileLoader.get_filename" title="importlib.machinery.ExtensionFileLoader.get_filename"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_filename()</span></code></a> method. This was
|
||
inadvertently omitted in the original implementation. (Contributed by Eric
|
||
Snow in <a class="reference external" href="https://bugs.python.org/issue19152">bpo-19152</a>.)</p>
|
||
</div>
|
||
<div class="section" id="inspect">
|
||
<h3>inspect<a class="headerlink" href="#inspect" title="Permalink to this headline">¶</a></h3>
|
||
<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> module now offers a basic <a class="reference internal" href="../library/inspect.html#inspect-module-cli"><span class="std std-ref">command line interface</span></a> to quickly display source code and other
|
||
information for modules, classes and functions. (Contributed by Claudiu Popa
|
||
and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue18626">bpo-18626</a>.)</p>
|
||
<p><a class="reference internal" href="../library/inspect.html#inspect.unwrap" title="inspect.unwrap"><code class="xref py py-func docutils literal notranslate"><span class="pre">unwrap()</span></code></a> makes it easy to unravel wrapper function chains
|
||
created by <a class="reference internal" href="../library/functools.html#functools.wraps" title="functools.wraps"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.wraps()</span></code></a> (and any other API that sets the
|
||
<code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute on a wrapper function). (Contributed by
|
||
Daniel Urban, Aaron Iles and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue13266">bpo-13266</a>.)</p>
|
||
<p>As part of the implementation of the new <a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a> module, the
|
||
<a class="reference internal" href="../library/inspect.html#module-inspect" title="inspect: Extract information and source code from live objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">inspect</span></code></a> module now has substantially better support for custom
|
||
<code class="docutils literal notranslate"><span class="pre">__dir__</span></code> methods and dynamic class attributes provided through
|
||
metaclasses. (Contributed by Ethan Furman in <a class="reference external" href="https://bugs.python.org/issue18929">bpo-18929</a> and
|
||
<a class="reference external" href="https://bugs.python.org/issue19030">bpo-19030</a>.)</p>
|
||
<p><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> and <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">getargspec()</span></code></a>
|
||
now use the <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">signature()</span></code></a> API. This allows them to
|
||
support a much broader range of callables, including those with
|
||
<code class="docutils literal notranslate"><span class="pre">__signature__</span></code> attributes, those with metadata provided by argument
|
||
clinic, <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> objects and more. Note that, unlike
|
||
<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>, these functions still ignore <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code>
|
||
attributes, and report the already bound first argument for bound methods,
|
||
so it is still necessary to update your code to use
|
||
<a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">signature()</span></code></a> directly if those features are desired.
|
||
(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue17481">bpo-17481</a>.)</p>
|
||
<p><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> now supports duck types of CPython functions,
|
||
which adds support for functions compiled with Cython. (Contributed
|
||
by Stefan Behnel and Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue17159">bpo-17159</a>.)</p>
|
||
</div>
|
||
<div class="section" id="ipaddress">
|
||
<h3>ipaddress<a class="headerlink" href="#ipaddress" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ipaddress</span></code></a> was added to the standard library in Python 3.3 as a
|
||
<a class="reference internal" href="../glossary.html#term-provisional-api"><span class="xref std std-term">provisional API</span></a>. With the release of Python 3.4, this qualification
|
||
has been removed: <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> is now considered a stable API, covered
|
||
by the normal standard library requirements to maintain backwards
|
||
compatibility.</p>
|
||
<p>A new <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Address.is_global" title="ipaddress.IPv4Address.is_global"><code class="xref py py-attr docutils literal notranslate"><span class="pre">is_global</span></code></a> property is <code class="docutils literal notranslate"><span class="pre">True</span></code> if
|
||
an address is globally routeable. (Contributed by Peter Moody in
|
||
<a class="reference external" href="https://bugs.python.org/issue17400">bpo-17400</a>.)</p>
|
||
</div>
|
||
<div class="section" id="logging">
|
||
<h3>logging<a class="headerlink" href="#logging" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.TimedRotatingFileHandler" title="logging.handlers.TimedRotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">TimedRotatingFileHandler</span></code></a> has a new <em>atTime</em>
|
||
parameter that can be used to specify the time of day when rollover should
|
||
happen. (Contributed by Ronald Oussoren in <a class="reference external" href="https://bugs.python.org/issue9556">bpo-9556</a>.)</p>
|
||
<p><a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SocketHandler" title="logging.handlers.SocketHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SocketHandler</span></code></a> and
|
||
<a class="reference internal" href="../library/logging.handlers.html#logging.handlers.DatagramHandler" title="logging.handlers.DatagramHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">DatagramHandler</span></code></a> now support Unix domain sockets (by
|
||
setting <em>port</em> to <code class="docutils literal notranslate"><span class="pre">None</span></code>). (Contributed by Vinay Sajip in commit
|
||
ce46195b56a9.)</p>
|
||
<p><a class="reference internal" href="../library/logging.config.html#logging.config.fileConfig" title="logging.config.fileConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">fileConfig()</span></code></a> now accepts a
|
||
<a class="reference internal" href="../library/configparser.html#configparser.RawConfigParser" title="configparser.RawConfigParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.RawConfigParser</span></code></a> subclass instance for the <em>fname</em>
|
||
parameter. This facilitates using a configuration file when logging
|
||
configuration is just a part of the overall application configuration, or where
|
||
the application modifies the configuration before passing it to
|
||
<a class="reference internal" href="../library/logging.config.html#logging.config.fileConfig" title="logging.config.fileConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">fileConfig()</span></code></a>. (Contributed by Vinay Sajip in
|
||
<a class="reference external" href="https://bugs.python.org/issue16110">bpo-16110</a>.)</p>
|
||
<p>Logging configuration data received from a socket via the
|
||
<a class="reference internal" href="../library/logging.config.html#logging.config.listen" title="logging.config.listen"><code class="xref py py-func docutils literal notranslate"><span class="pre">logging.config.listen()</span></code></a> function can now be validated before being
|
||
processed by supplying a verification function as the argument to the new
|
||
<em>verify</em> keyword argument. (Contributed by Vinay Sajip in <a class="reference external" href="https://bugs.python.org/issue15452">bpo-15452</a>.)</p>
|
||
</div>
|
||
<div class="section" id="marshal">
|
||
<span id="whatsnew-marshal-3"></span><h3>marshal<a class="headerlink" href="#marshal" title="Permalink to this headline">¶</a></h3>
|
||
<p>The default <a class="reference internal" href="../library/marshal.html#module-marshal" title="marshal: Convert Python objects to streams of bytes and back (with different constraints)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">marshal</span></code></a> version has been bumped to 3. The code implementing
|
||
the new version restores the Python2 behavior of recording only one copy of
|
||
interned strings and preserving the interning on deserialization, and extends
|
||
this “one copy” ability to any object type (including handling recursive
|
||
references). This reduces both the size of <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files and the amount of
|
||
memory a module occupies in memory when it is loaded from a <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> (or
|
||
<code class="docutils literal notranslate"><span class="pre">.pyo</span></code>) file. (Contributed by Kristján Valur Jónsson in <a class="reference external" href="https://bugs.python.org/issue16475">bpo-16475</a>,
|
||
with additional speedups by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue19219">bpo-19219</a>.)</p>
|
||
</div>
|
||
<div class="section" id="mmap">
|
||
<h3>mmap<a class="headerlink" href="#mmap" title="Permalink to this headline">¶</a></h3>
|
||
<p>mmap objects can now be <a class="reference internal" href="../library/weakref.html#module-weakref" title="weakref: Support for weak references and weak dictionaries."><code class="xref py py-mod docutils literal notranslate"><span class="pre">weakref</span></code></a>ed. (Contributed by Valerie Lambert in
|
||
<a class="reference external" href="https://bugs.python.org/issue4885">bpo-4885</a>.)</p>
|
||
</div>
|
||
<div class="section" id="multiprocessing">
|
||
<h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Permalink to this headline">¶</a></h3>
|
||
<p id="whatsnew-multiprocessing-no-fork">On Unix two new <a class="reference internal" href="../library/multiprocessing.html#multiprocessing-start-methods"><span class="std std-ref">start methods</span></a>,
|
||
<code class="docutils literal notranslate"><span class="pre">spawn</span></code> and <code class="docutils literal notranslate"><span class="pre">forkserver</span></code>, have been added for starting processes using
|
||
<a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a>. These make the mixing of processes with threads more
|
||
robust, and the <code class="docutils literal notranslate"><span class="pre">spawn</span></code> method matches the semantics that multiprocessing has
|
||
always used on Windows. New function
|
||
<a class="reference internal" href="../library/multiprocessing.html#multiprocessing.get_all_start_methods" title="multiprocessing.get_all_start_methods"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_all_start_methods()</span></code></a> reports all start methods
|
||
available on the platform, <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.get_start_method" title="multiprocessing.get_start_method"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_start_method()</span></code></a> reports
|
||
the current start method, and <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.set_start_method" title="multiprocessing.set_start_method"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_start_method()</span></code></a> sets
|
||
the start method. (Contributed by Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue8713">bpo-8713</a>.)</p>
|
||
<p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> also now has the concept of a <code class="docutils literal notranslate"><span class="pre">context</span></code>, which
|
||
determines how child processes are created. New function
|
||
<a class="reference internal" href="../library/multiprocessing.html#multiprocessing.get_context" title="multiprocessing.get_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_context()</span></code></a> returns a context that uses a specified
|
||
start method. It has the same API as the <a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> module itself,
|
||
so you can use it to create <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.pool.Pool" title="multiprocessing.pool.Pool"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pool</span></code></a>s and other
|
||
objects that will operate within that context. This allows a framework and an
|
||
application or different parts of the same application to use multiprocessing
|
||
without interfering with each other. (Contributed by Richard Oudkerk in
|
||
<a class="reference external" href="https://bugs.python.org/issue18999">bpo-18999</a>.)</p>
|
||
<p>Except when using the old <em>fork</em> start method, child processes no longer
|
||
inherit unneeded handles/file descriptors from their parents (part of
|
||
<a class="reference external" href="https://bugs.python.org/issue8713">bpo-8713</a>).</p>
|
||
<p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> now relies on <a class="reference internal" href="../library/runpy.html#module-runpy" title="runpy: Locate and run Python modules without importing them first."><code class="xref py py-mod docutils literal notranslate"><span class="pre">runpy</span></code></a> (which implements the
|
||
<code class="docutils literal notranslate"><span class="pre">-m</span></code> switch) to initialise <code class="docutils literal notranslate"><span class="pre">__main__</span></code> appropriately in child processes
|
||
when using the <code class="docutils literal notranslate"><span class="pre">spawn</span></code> or <code class="docutils literal notranslate"><span class="pre">forkserver</span></code> start methods. This resolves some
|
||
edge cases where combining multiprocessing, the <code class="docutils literal notranslate"><span class="pre">-m</span></code> command line switch,
|
||
and explicit relative imports could cause obscure failures in child
|
||
processes. (Contributed by Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue19946">bpo-19946</a>.)</p>
|
||
</div>
|
||
<div class="section" id="operator">
|
||
<h3>operator<a class="headerlink" href="#operator" title="Permalink to this headline">¶</a></h3>
|
||
<p>New function <a class="reference internal" href="../library/operator.html#operator.length_hint" title="operator.length_hint"><code class="xref py py-func docutils literal notranslate"><span class="pre">length_hint()</span></code></a> provides an implementation of the
|
||
specification for how the <a class="reference internal" href="../reference/datamodel.html#object.__length_hint__" title="object.__length_hint__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__length_hint__()</span></code></a> special method should
|
||
be used, as part of the <span class="target" id="index-38"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0424"><strong>PEP 424</strong></a> formal specification of this language
|
||
feature. (Contributed by Armin Ronacher in <a class="reference external" href="https://bugs.python.org/issue16148">bpo-16148</a>.)</p>
|
||
<p>There is now a pure-python version of the <a class="reference internal" href="../library/operator.html#module-operator" title="operator: Functions corresponding to the standard operators."><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code></a> module available for
|
||
reference and for use by alternate implementations of Python. (Contributed by
|
||
Zachary Ware in <a class="reference external" href="https://bugs.python.org/issue16694">bpo-16694</a>.)</p>
|
||
</div>
|
||
<div class="section" id="os">
|
||
<h3>os<a class="headerlink" href="#os" title="Permalink to this headline">¶</a></h3>
|
||
<p>There are new functions to get and set the <a class="reference internal" href="../library/os.html#fd-inheritance"><span class="std std-ref">inheritable flag</span></a> of a file descriptor (<a class="reference internal" href="../library/os.html#os.get_inheritable" title="os.get_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.get_inheritable()</span></code></a>,
|
||
<a class="reference internal" href="../library/os.html#os.set_inheritable" title="os.set_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.set_inheritable()</span></code></a>) or a Windows handle
|
||
(<a class="reference internal" href="../library/os.html#os.get_handle_inheritable" title="os.get_handle_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.get_handle_inheritable()</span></code></a>, <a class="reference internal" href="../library/os.html#os.set_handle_inheritable" title="os.set_handle_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.set_handle_inheritable()</span></code></a>).</p>
|
||
<p>New function <a class="reference internal" href="../library/os.html#os.cpu_count" title="os.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">cpu_count()</span></code></a> reports the number of CPUs available on the
|
||
platform on which Python is running (or <code class="docutils literal notranslate"><span class="pre">None</span></code> if the count can’t be
|
||
determined). The <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.cpu_count" title="multiprocessing.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">multiprocessing.cpu_count()</span></code></a> function is now implemented
|
||
in terms of this function). (Contributed by Trent Nelson, Yogesh Chaudhari,
|
||
Victor Stinner, and Charles-François Natali in <a class="reference external" href="https://bugs.python.org/issue17914">bpo-17914</a>.)</p>
|
||
<p><a class="reference internal" href="../library/os.path.html#os.path.samestat" title="os.path.samestat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.samestat()</span></code></a> is now available on the Windows platform (and the
|
||
<a class="reference internal" href="../library/os.path.html#os.path.samefile" title="os.path.samefile"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.samefile()</span></code></a> implementation is now shared between Unix and
|
||
Windows). (Contributed by Brian Curtin in <a class="reference external" href="https://bugs.python.org/issue11939">bpo-11939</a>.)</p>
|
||
<p><a class="reference internal" href="../library/os.path.html#os.path.ismount" title="os.path.ismount"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.ismount()</span></code></a> now recognizes volumes mounted below a drive
|
||
root on Windows. (Contributed by Tim Golden in <a class="reference external" href="https://bugs.python.org/issue9035">bpo-9035</a>.)</p>
|
||
<p><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">os.open()</span></code></a> supports two new flags on platforms that provide them,
|
||
<a class="reference internal" href="../library/os.html#os.O_PATH" title="os.O_PATH"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_PATH</span></code></a> (un-opened file descriptor), and <a class="reference internal" href="../library/os.html#os.O_TMPFILE" title="os.O_TMPFILE"><code class="xref py py-data docutils literal notranslate"><span class="pre">O_TMPFILE</span></code></a>
|
||
(unnamed temporary file; as of 3.4.0 release available only on Linux systems
|
||
with a kernel version of 3.11 or newer that have uapi headers). (Contributed
|
||
by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue18673">bpo-18673</a> and Benjamin Peterson, respectively.)</p>
|
||
</div>
|
||
<div class="section" id="pdb">
|
||
<h3>pdb<a class="headerlink" href="#pdb" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/pdb.html#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a> has been enhanced to handle generators, <a class="reference internal" href="../reference/simple_stmts.html#yield"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">yield</span></code></a>, and
|
||
<code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> in a more useful fashion. This is especially helpful when
|
||
debugging <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> based programs. (Contributed by Andrew Svetlov and
|
||
Xavier de Gaye in <a class="reference external" href="https://bugs.python.org/issue16596">bpo-16596</a>.)</p>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">print</span></code> command has been removed from <a class="reference internal" href="../library/pdb.html#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a>, restoring access to the
|
||
Python <a class="reference internal" href="../library/functions.html#print" title="print"><code class="xref py py-func docutils literal notranslate"><span class="pre">print()</span></code></a> function from the pdb command line. Python2’s <code class="docutils literal notranslate"><span class="pre">pdb</span></code> did
|
||
not have a <code class="docutils literal notranslate"><span class="pre">print</span></code> command; instead, entering <code class="docutils literal notranslate"><span class="pre">print</span></code> executed the
|
||
<code class="docutils literal notranslate"><span class="pre">print</span></code> statement. In Python3 <code class="docutils literal notranslate"><span class="pre">print</span></code> was mistakenly made an alias for the
|
||
pdb <a class="reference internal" href="../library/pdb.html#pdbcommand-p"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">p</span></code></a> command. <code class="docutils literal notranslate"><span class="pre">p</span></code>, however, prints the <code class="docutils literal notranslate"><span class="pre">repr</span></code> of its argument,
|
||
not the <code class="docutils literal notranslate"><span class="pre">str</span></code> like the Python2 <code class="docutils literal notranslate"><span class="pre">print</span></code> command did. Worse, the Python3
|
||
<code class="docutils literal notranslate"><span class="pre">pdb</span> <span class="pre">print</span></code> command shadowed the Python3 <code class="docutils literal notranslate"><span class="pre">print</span></code> function, making it
|
||
inaccessible at the <code class="docutils literal notranslate"><span class="pre">pdb</span></code> prompt. (Contributed by Connor Osborn in
|
||
<a class="reference external" href="https://bugs.python.org/issue18764">bpo-18764</a>.)</p>
|
||
</div>
|
||
<div class="section" id="pickle">
|
||
<span id="whatsnew-protocol-4"></span><h3>pickle<a class="headerlink" href="#pickle" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> now supports (but does not use by default) a new pickle protocol,
|
||
protocol 4. This new protocol addresses a number of issues that were present
|
||
in previous protocols, such as the serialization of nested classes, very large
|
||
strings and containers, and classes whose <a class="reference internal" href="../reference/datamodel.html#object.__new__" title="object.__new__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__new__()</span></code></a> method takes
|
||
keyword-only arguments. It also provides some efficiency improvements.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-39"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3154"><strong>PEP 3154</strong></a> – Pickle protocol 4</dt><dd><p>PEP written by Antoine Pitrou and implemented by Alexandre Vassalotti.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="plistlib">
|
||
<h3>plistlib<a class="headerlink" href="#plistlib" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/plistlib.html#module-plistlib" title="plistlib: Generate and parse Mac OS X plist files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code></a> now has an API that is similar to the standard pattern for
|
||
stdlib serialization protocols, with new <a class="reference internal" href="../library/plistlib.html#plistlib.load" title="plistlib.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">load()</span></code></a>,
|
||
<a class="reference internal" href="../library/plistlib.html#plistlib.dump" title="plistlib.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump()</span></code></a>, <a class="reference internal" href="../library/plistlib.html#plistlib.loads" title="plistlib.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">loads()</span></code></a>, and <a class="reference internal" href="../library/plistlib.html#plistlib.dumps" title="plistlib.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">dumps()</span></code></a>
|
||
functions. (The older API is now deprecated.) In addition to the already
|
||
supported XML plist format (<a class="reference internal" href="../library/plistlib.html#plistlib.FMT_XML" title="plistlib.FMT_XML"><code class="xref py py-data docutils literal notranslate"><span class="pre">FMT_XML</span></code></a>), it also now supports
|
||
the binary plist format (<a class="reference internal" href="../library/plistlib.html#plistlib.FMT_BINARY" title="plistlib.FMT_BINARY"><code class="xref py py-data docutils literal notranslate"><span class="pre">FMT_BINARY</span></code></a>). (Contributed by Ronald
|
||
Oussoren and others in <a class="reference external" href="https://bugs.python.org/issue14455">bpo-14455</a>.)</p>
|
||
</div>
|
||
<div class="section" id="poplib">
|
||
<h3>poplib<a class="headerlink" href="#poplib" title="Permalink to this headline">¶</a></h3>
|
||
<p>Two new methods have been added to <a class="reference internal" href="../library/poplib.html#module-poplib" title="poplib: POP3 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code></a>: <a class="reference internal" href="../library/poplib.html#poplib.POP3.capa" title="poplib.POP3.capa"><code class="xref py py-meth docutils literal notranslate"><span class="pre">capa()</span></code></a>,
|
||
which returns the list of capabilities advertised by the POP server, and
|
||
<a class="reference internal" href="../library/poplib.html#poplib.POP3.stls" title="poplib.POP3.stls"><code class="xref py py-meth docutils literal notranslate"><span class="pre">stls()</span></code></a>, which switches a clear-text POP3 session into an
|
||
encrypted POP3 session if the POP server supports it. (Contributed by Lorenzo
|
||
Catucci in <a class="reference external" href="https://bugs.python.org/issue4473">bpo-4473</a>.)</p>
|
||
</div>
|
||
<div class="section" id="pprint">
|
||
<h3>pprint<a class="headerlink" href="#pprint" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/pprint.html#module-pprint" title="pprint: Data pretty printer."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pprint</span></code></a> module’s <a class="reference internal" href="../library/pprint.html#pprint.PrettyPrinter" title="pprint.PrettyPrinter"><code class="xref py py-class docutils literal notranslate"><span class="pre">PrettyPrinter</span></code></a> class and its
|
||
<a class="reference internal" href="../library/pprint.html#pprint.pformat" title="pprint.pformat"><code class="xref py py-func docutils literal notranslate"><span class="pre">pformat()</span></code></a>, and <a class="reference internal" href="../library/pprint.html#pprint.pprint" title="pprint.pprint"><code class="xref py py-func docutils literal notranslate"><span class="pre">pprint()</span></code></a> functions have a new
|
||
option, <em>compact</em>, that controls how the output is formatted. Currently
|
||
setting <em>compact</em> to <code class="docutils literal notranslate"><span class="pre">True</span></code> means that sequences will be printed with as many
|
||
sequence elements as will fit within <em>width</em> on each (indented) line.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue19132">bpo-19132</a>.)</p>
|
||
<p>Long strings are now wrapped using Python’s normal line continuation
|
||
syntax. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue17150">bpo-17150</a>.)</p>
|
||
</div>
|
||
<div class="section" id="pty">
|
||
<h3>pty<a class="headerlink" href="#pty" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/pty.html#pty.spawn" title="pty.spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">pty.spawn()</span></code></a> now returns the status value from <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">os.waitpid()</span></code></a> on
|
||
the child process, instead of <code class="docutils literal notranslate"><span class="pre">None</span></code>. (Contributed by Gregory P. Smith.)</p>
|
||
</div>
|
||
<div class="section" id="pydoc">
|
||
<h3>pydoc<a class="headerlink" href="#pydoc" title="Permalink to this headline">¶</a></h3>
|
||
<p>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 is now based directly on 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>
|
||
introspection API, allowing it to provide signature information for a wider
|
||
variety of callable objects. This change also means that <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code>
|
||
attributes are now taken into account when displaying help information.
|
||
(Contributed by Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue19674">bpo-19674</a>.)</p>
|
||
<p>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 no longer displays the <code class="docutils literal notranslate"><span class="pre">self</span></code> parameter for
|
||
already bound methods. Instead, it aims to always display the exact current
|
||
signature of the supplied callable. (Contributed by Larry Hastings in
|
||
<a class="reference external" href="https://bugs.python.org/issue20710">bpo-20710</a>.)</p>
|
||
<p>In addition to the changes that have been made to <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> directly,
|
||
its handling of custom <code class="docutils literal notranslate"><span class="pre">__dir__</span></code> methods and various descriptor
|
||
behaviours has also been improved substantially by the underlying changes in
|
||
the <a class="reference internal" href="../library/inspect.html#module-inspect" title="inspect: Extract information and source code from live objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">inspect</span></code></a> module.</p>
|
||
<p>As 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> builtin is based on <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>, the above changes also
|
||
affect the behaviour of <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>.</p>
|
||
</div>
|
||
<div class="section" id="re">
|
||
<h3>re<a class="headerlink" href="#re" title="Permalink to this headline">¶</a></h3>
|
||
<p>New <a class="reference internal" href="../library/re.html#re.fullmatch" title="re.fullmatch"><code class="xref py py-func docutils literal notranslate"><span class="pre">fullmatch()</span></code></a> function and <code class="xref py py-meth docutils literal notranslate"><span class="pre">regex.fullmatch()</span></code> method anchor
|
||
the pattern at both ends of the string to match. This provides a way to be
|
||
explicit about the goal of the match, which avoids a class of subtle bugs where
|
||
<code class="docutils literal notranslate"><span class="pre">$</span></code> characters get lost during code changes or the addition of alternatives
|
||
to an existing regular expression. (Contributed by Matthew Barnett in
|
||
<a class="reference external" href="https://bugs.python.org/issue16203">bpo-16203</a>.)</p>
|
||
<p>The repr of <a class="reference internal" href="../library/re.html#re-objects"><span class="std std-ref">regex objects</span></a> now includes the pattern
|
||
and the flags; the repr of <a class="reference internal" href="../library/re.html#match-objects"><span class="std std-ref">match objects</span></a> now
|
||
includes the start, end, and the part of the string that matched. (Contributed
|
||
by Hugo Lopes Tavares and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue13592">bpo-13592</a> and
|
||
<a class="reference external" href="https://bugs.python.org/issue17087">bpo-17087</a>.)</p>
|
||
</div>
|
||
<div class="section" id="resource">
|
||
<h3>resource<a class="headerlink" href="#resource" title="Permalink to this headline">¶</a></h3>
|
||
<p>New <a class="reference internal" href="../library/resource.html#resource.prlimit" title="resource.prlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">prlimit()</span></code></a> function, available on Linux platforms with a
|
||
kernel version of 2.6.36 or later and glibc of 2.13 or later, provides the
|
||
ability to query or set the resource limits for processes other than the one
|
||
making the call. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue16595">bpo-16595</a>.)</p>
|
||
<p>On Linux kernel version 2.6.36 or later, there are also some new
|
||
Linux specific constants: <a class="reference internal" href="../library/resource.html#resource.RLIMIT_MSGQUEUE" title="resource.RLIMIT_MSGQUEUE"><code class="xref py py-attr docutils literal notranslate"><span class="pre">RLIMIT_MSGQUEUE</span></code></a>,
|
||
<a class="reference internal" href="../library/resource.html#resource.RLIMIT_NICE" title="resource.RLIMIT_NICE"><code class="xref py py-attr docutils literal notranslate"><span class="pre">RLIMIT_NICE</span></code></a>, <a class="reference internal" href="../library/resource.html#resource.RLIMIT_RTPRIO" title="resource.RLIMIT_RTPRIO"><code class="xref py py-attr docutils literal notranslate"><span class="pre">RLIMIT_RTPRIO</span></code></a>,
|
||
<a class="reference internal" href="../library/resource.html#resource.RLIMIT_RTTIME" title="resource.RLIMIT_RTTIME"><code class="xref py py-attr docutils literal notranslate"><span class="pre">RLIMIT_RTTIME</span></code></a>, and <a class="reference internal" href="../library/resource.html#resource.RLIMIT_SIGPENDING" title="resource.RLIMIT_SIGPENDING"><code class="xref py py-attr docutils literal notranslate"><span class="pre">RLIMIT_SIGPENDING</span></code></a>.
|
||
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue19324">bpo-19324</a>.)</p>
|
||
<p>On FreeBSD version 9 and later, there some new FreeBSD specific constants:
|
||
<a class="reference internal" href="../library/resource.html#resource.RLIMIT_SBSIZE" title="resource.RLIMIT_SBSIZE"><code class="xref py py-attr docutils literal notranslate"><span class="pre">RLIMIT_SBSIZE</span></code></a>, <a class="reference internal" href="../library/resource.html#resource.RLIMIT_SWAP" title="resource.RLIMIT_SWAP"><code class="xref py py-attr docutils literal notranslate"><span class="pre">RLIMIT_SWAP</span></code></a>, and
|
||
<a class="reference internal" href="../library/resource.html#resource.RLIMIT_NPTS" title="resource.RLIMIT_NPTS"><code class="xref py py-attr docutils literal notranslate"><span class="pre">RLIMIT_NPTS</span></code></a>. (Contributed by Claudiu Popa in
|
||
<a class="reference external" href="https://bugs.python.org/issue19343">bpo-19343</a>.)</p>
|
||
</div>
|
||
<div class="section" id="select">
|
||
<h3>select<a class="headerlink" href="#select" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/select.html#select.epoll" title="select.epoll"><code class="xref py py-class docutils literal notranslate"><span class="pre">epoll</span></code></a> objects now support the context management 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 <a class="reference internal" href="../library/select.html#select.epoll.close" title="select.epoll.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a>
|
||
method will be called automatically at the end of the block. (Contributed
|
||
by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue16488">bpo-16488</a>.)</p>
|
||
<p><a class="reference internal" href="../library/select.html#select.devpoll" title="select.devpoll"><code class="xref py py-class docutils literal notranslate"><span class="pre">devpoll</span></code></a> objects now have <a class="reference internal" href="../library/select.html#select.devpoll.fileno" title="select.devpoll.fileno"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code></a> and
|
||
<a class="reference internal" href="../library/select.html#select.devpoll.close" title="select.devpoll.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> methods, as well as a new attribute
|
||
<a class="reference internal" href="../library/select.html#select.devpoll.closed" title="select.devpoll.closed"><code class="xref py py-attr docutils literal notranslate"><span class="pre">closed</span></code></a>. (Contributed by Victor Stinner in
|
||
<a class="reference external" href="https://bugs.python.org/issue18794">bpo-18794</a>.)</p>
|
||
</div>
|
||
<div class="section" id="shelve">
|
||
<h3>shelve<a class="headerlink" href="#shelve" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/shelve.html#shelve.Shelf" title="shelve.Shelf"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shelf</span></code></a> instances may now be used in <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statements,
|
||
and will be automatically closed at the end of the <code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code> block.
|
||
(Contributed by Filip Gruszczyński in <a class="reference external" href="https://bugs.python.org/issue13896">bpo-13896</a>.)</p>
|
||
</div>
|
||
<div class="section" id="shutil">
|
||
<h3>shutil<a class="headerlink" href="#shutil" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">copyfile()</span></code></a> now raises a specific <a class="reference internal" href="../library/shutil.html#shutil.Error" title="shutil.Error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Error</span></code></a> subclass,
|
||
<a class="reference internal" href="../library/shutil.html#shutil.SameFileError" title="shutil.SameFileError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SameFileError</span></code></a>, when the source and destination are the same
|
||
file, which allows an application to take appropriate action on this specific
|
||
error. (Contributed by Atsuo Ishimoto and Hynek Schlawack in
|
||
<a class="reference external" href="https://bugs.python.org/issue1492704">bpo-1492704</a>.)</p>
|
||
</div>
|
||
<div class="section" id="smtpd">
|
||
<h3>smtpd<a class="headerlink" href="#smtpd" title="Permalink to this headline">¶</a></h3>
|
||
<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> 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>map</em> keyword argument which, if specified, is passed in to
|
||
<a class="reference internal" href="../library/asynchat.html#asynchat.async_chat" title="asynchat.async_chat"><code class="xref py py-class docutils literal notranslate"><span class="pre">asynchat.async_chat</span></code></a> as its <em>map</em> argument. This allows an application
|
||
to avoid affecting the global socket map. (Contributed by Vinay Sajip in
|
||
<a class="reference external" href="https://bugs.python.org/issue11959">bpo-11959</a>.)</p>
|
||
</div>
|
||
<div class="section" id="smtplib">
|
||
<h3>smtplib<a class="headerlink" href="#smtplib" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/smtplib.html#smtplib.SMTPException" title="smtplib.SMTPException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SMTPException</span></code></a> is now a subclass of <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>, which allows
|
||
both socket level errors and SMTP protocol level errors to be caught in one
|
||
try/except statement by code that only cares whether or not an error occurred.
|
||
(Contributed by Ned Jackson Lovely in <a class="reference external" href="https://bugs.python.org/issue2118">bpo-2118</a>.)</p>
|
||
</div>
|
||
<div class="section" id="socket">
|
||
<h3>socket<a class="headerlink" href="#socket" title="Permalink to this headline">¶</a></h3>
|
||
<p>The socket module now supports the <a class="reference internal" href="../library/socket.html#socket.CAN_BCM" title="socket.CAN_BCM"><code class="xref py py-data docutils literal notranslate"><span class="pre">CAN_BCM</span></code></a> protocol on
|
||
platforms that support it. (Contributed by Brian Thorne in <a class="reference external" href="https://bugs.python.org/issue15359">bpo-15359</a>.)</p>
|
||
<p>Socket objects have new methods to get or set their <a class="reference internal" href="../library/os.html#fd-inheritance"><span class="std std-ref">inheritable flag</span></a>, <a class="reference internal" href="../library/socket.html#socket.socket.get_inheritable" title="socket.socket.get_inheritable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_inheritable()</span></code></a> and
|
||
<a class="reference internal" href="../library/socket.html#socket.socket.set_inheritable" title="socket.socket.set_inheritable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_inheritable()</span></code></a>.</p>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">socket.AF_*</span></code> and <code class="docutils literal notranslate"><span class="pre">socket.SOCK_*</span></code> constants are now enumeration values
|
||
using the new <a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a> module. This allows meaningful names to be printed
|
||
during debugging, instead of integer “magic numbers”.</p>
|
||
<p>The <a class="reference internal" href="../library/socket.html#socket.AF_LINK" title="socket.AF_LINK"><code class="xref py py-data docutils literal notranslate"><span class="pre">AF_LINK</span></code></a> constant is now available on BSD and OSX.</p>
|
||
<p><a class="reference internal" href="../library/socket.html#socket.inet_pton" title="socket.inet_pton"><code class="xref py py-func docutils literal notranslate"><span class="pre">inet_pton()</span></code></a> and <a class="reference internal" href="../library/socket.html#socket.inet_ntop" title="socket.inet_ntop"><code class="xref py py-func docutils literal notranslate"><span class="pre">inet_ntop()</span></code></a> are now supported
|
||
on Windows. (Contributed by Atsuo Ishimoto in <a class="reference external" href="https://bugs.python.org/issue7171">bpo-7171</a>.)</p>
|
||
</div>
|
||
<div class="section" id="sqlite3">
|
||
<h3>sqlite3<a class="headerlink" href="#sqlite3" title="Permalink to this headline">¶</a></h3>
|
||
<p>A new boolean parameter to the <a class="reference internal" href="../library/sqlite3.html#sqlite3.connect" title="sqlite3.connect"><code class="xref py py-func docutils literal notranslate"><span class="pre">connect()</span></code></a> function, <em>uri</em>, can be
|
||
used to indicate that the <em>database</em> parameter is a <code class="docutils literal notranslate"><span class="pre">uri</span></code> (see the <a class="reference external" href="https://www.sqlite.org/uri.html">SQLite
|
||
URI documentation</a>). (Contributed by poq in
|
||
<a class="reference external" href="https://bugs.python.org/issue13773">bpo-13773</a>.)</p>
|
||
</div>
|
||
<div class="section" id="ssl">
|
||
<h3>ssl<a class="headerlink" href="#ssl" title="Permalink to this headline">¶</a></h3>
|
||
<p id="whatsnew-tls-11-12"><a class="reference internal" href="../library/ssl.html#ssl.PROTOCOL_TLSv1_1" title="ssl.PROTOCOL_TLSv1_1"><code class="xref py py-data docutils literal notranslate"><span class="pre">PROTOCOL_TLSv1_1</span></code></a> and <a class="reference internal" href="../library/ssl.html#ssl.PROTOCOL_TLSv1_2" title="ssl.PROTOCOL_TLSv1_2"><code class="xref py py-data docutils literal notranslate"><span class="pre">PROTOCOL_TLSv1_2</span></code></a> (TLSv1.1 and
|
||
TLSv1.2 support) have been added; support for these protocols is only available if
|
||
Python is linked with OpenSSL 1.0.1 or later. (Contributed by Michele Orrù and
|
||
Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue16692">bpo-16692</a>.)</p>
|
||
<p id="whatsnew34-sslcontext">New function <a class="reference internal" href="../library/ssl.html#ssl.create_default_context" title="ssl.create_default_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">create_default_context()</span></code></a> provides a standard way to
|
||
obtain 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">SSLContext</span></code></a> whose settings are intended to be a
|
||
reasonable balance between compatibility and security. These settings are
|
||
more stringent than the defaults provided by the <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">SSLContext</span></code></a>
|
||
constructor, and may be adjusted in the future, without prior deprecation, if
|
||
best-practice security requirements change. The new recommended best
|
||
practice for using stdlib libraries that support SSL is to use
|
||
<a class="reference internal" href="../library/ssl.html#ssl.create_default_context" title="ssl.create_default_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">create_default_context()</span></code></a> to obtain 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">SSLContext</span></code></a>
|
||
object, modify it if needed, and then pass it as the <em>context</em> argument
|
||
of the appropriate stdlib API. (Contributed by Christian Heimes
|
||
in <a class="reference external" href="https://bugs.python.org/issue19689">bpo-19689</a>.)</p>
|
||
<p><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">SSLContext</span></code></a> method <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.load_verify_locations" title="ssl.SSLContext.load_verify_locations"><code class="xref py py-meth docutils literal notranslate"><span class="pre">load_verify_locations()</span></code></a>
|
||
accepts a new optional argument <em>cadata</em>, which can be used to provide PEM or
|
||
DER encoded certificates directly via strings or bytes, respectively.
|
||
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue18138">bpo-18138</a>.)</p>
|
||
<p>New function <a class="reference internal" href="../library/ssl.html#ssl.get_default_verify_paths" title="ssl.get_default_verify_paths"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_default_verify_paths()</span></code></a> returns
|
||
a named tuple of the paths and environment variables that the
|
||
<a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_default_verify_paths" title="ssl.SSLContext.set_default_verify_paths"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_default_verify_paths()</span></code></a> method uses to set
|
||
OpenSSL’s default <code class="docutils literal notranslate"><span class="pre">cafile</span></code> and <code class="docutils literal notranslate"><span class="pre">capath</span></code>. This can be an aid in
|
||
debugging default verification issues. (Contributed by Christian Heimes
|
||
in <a class="reference external" href="https://bugs.python.org/issue18143">bpo-18143</a>.)</p>
|
||
<p><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">SSLContext</span></code></a> has a new method,
|
||
<a class="reference internal" href="../library/ssl.html#ssl.SSLContext.cert_store_stats" title="ssl.SSLContext.cert_store_stats"><code class="xref py py-meth docutils literal notranslate"><span class="pre">cert_store_stats()</span></code></a>, that reports the number of loaded
|
||
<code class="docutils literal notranslate"><span class="pre">X.509</span></code> certs, <code class="docutils literal notranslate"><span class="pre">X.509</span> <span class="pre">CA</span></code> certs, and certificate revocation lists
|
||
(<code class="docutils literal notranslate"><span class="pre">crl</span></code>s), as well as a <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.get_ca_certs" title="ssl.SSLContext.get_ca_certs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_ca_certs()</span></code></a> method that
|
||
returns a list of the loaded <code class="docutils literal notranslate"><span class="pre">CA</span></code> certificates. (Contributed by Christian
|
||
Heimes in <a class="reference external" href="https://bugs.python.org/issue18147">bpo-18147</a>.)</p>
|
||
<p>If OpenSSL 0.9.8 or later is available, <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">SSLContext</span></code></a> has a new
|
||
attribute <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.verify_flags" title="ssl.SSLContext.verify_flags"><code class="xref py py-attr docutils literal notranslate"><span class="pre">verify_flags</span></code></a> that can be used to control the
|
||
certificate verification process by setting it to some combination of the new
|
||
constants <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_DEFAULT" title="ssl.VERIFY_DEFAULT"><code class="xref py py-data docutils literal notranslate"><span class="pre">VERIFY_DEFAULT</span></code></a>, <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_CRL_CHECK_LEAF" title="ssl.VERIFY_CRL_CHECK_LEAF"><code class="xref py py-data docutils literal notranslate"><span class="pre">VERIFY_CRL_CHECK_LEAF</span></code></a>,
|
||
<a class="reference internal" href="../library/ssl.html#ssl.VERIFY_CRL_CHECK_CHAIN" title="ssl.VERIFY_CRL_CHECK_CHAIN"><code class="xref py py-data docutils literal notranslate"><span class="pre">VERIFY_CRL_CHECK_CHAIN</span></code></a>, or <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_X509_STRICT" title="ssl.VERIFY_X509_STRICT"><code class="xref py py-data docutils literal notranslate"><span class="pre">VERIFY_X509_STRICT</span></code></a>.
|
||
OpenSSL does not do any CRL verification by default. (Contributed by
|
||
Christien Heimes in <a class="reference external" href="https://bugs.python.org/issue8813">bpo-8813</a>.)</p>
|
||
<p>New <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">SSLContext</span></code></a> method <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.load_default_certs" title="ssl.SSLContext.load_default_certs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">load_default_certs()</span></code></a>
|
||
loads a set of default “certificate authority” (CA) certificates from default
|
||
locations, which vary according to the platform. It can be used to load both
|
||
TLS web server authentication certificates
|
||
(<code class="docutils literal notranslate"><span class="pre">purpose=</span></code><a class="reference internal" href="../library/ssl.html#ssl.Purpose.SERVER_AUTH" title="ssl.Purpose.SERVER_AUTH"><code class="xref py py-data docutils literal notranslate"><span class="pre">SERVER_AUTH</span></code></a>) for a client to use to verify a
|
||
server, and certificates for a server to use in verifying client certificates
|
||
(<code class="docutils literal notranslate"><span class="pre">purpose=</span></code><a class="reference internal" href="../library/ssl.html#ssl.Purpose.CLIENT_AUTH" title="ssl.Purpose.CLIENT_AUTH"><code class="xref py py-data docutils literal notranslate"><span class="pre">CLIENT_AUTH</span></code></a>). (Contributed by Christian
|
||
Heimes in <a class="reference external" href="https://bugs.python.org/issue19292">bpo-19292</a>.)</p>
|
||
<p id="whatsnew34-win-cert-store">Two new windows-only functions, <a class="reference internal" href="../library/ssl.html#ssl.enum_certificates" title="ssl.enum_certificates"><code class="xref py py-func docutils literal notranslate"><span class="pre">enum_certificates()</span></code></a> and
|
||
<a class="reference internal" href="../library/ssl.html#ssl.enum_crls" title="ssl.enum_crls"><code class="xref py py-func docutils literal notranslate"><span class="pre">enum_crls()</span></code></a> provide the ability to retrieve certificates,
|
||
certificate information, and CRLs from the Windows cert store. (Contributed
|
||
by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue17134">bpo-17134</a>.)</p>
|
||
<p id="whatsnew34-sni">Support for server-side SNI (Server Name Indication) using the new
|
||
<a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_servername_callback" title="ssl.SSLContext.set_servername_callback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLContext.set_servername_callback()</span></code></a> method.
|
||
(Contributed by Daniel Black in <a class="reference external" href="https://bugs.python.org/issue8109">bpo-8109</a>.)</p>
|
||
<p>The dictionary returned by <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.getpeercert" title="ssl.SSLSocket.getpeercert"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.getpeercert()</span></code></a> contains additional
|
||
<code class="docutils literal notranslate"><span class="pre">X509v3</span></code> extension items: <code class="docutils literal notranslate"><span class="pre">crlDistributionPoints</span></code>, <code class="docutils literal notranslate"><span class="pre">calIssuers</span></code>, and
|
||
<code class="docutils literal notranslate"><span class="pre">OCSP</span></code> URIs. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue18379">bpo-18379</a>.)</p>
|
||
</div>
|
||
<div class="section" id="stat">
|
||
<h3>stat<a class="headerlink" href="#stat" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> module is now backed by a C implementation in <code class="xref py py-mod docutils literal notranslate"><span class="pre">_stat</span></code>. A C
|
||
implementation is required as most of the values aren’t standardized and
|
||
are platform-dependent. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue11016">bpo-11016</a>.)</p>
|
||
<p>The module supports new <a class="reference internal" href="../library/stat.html#stat.ST_MODE" title="stat.ST_MODE"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ST_MODE</span></code></a> flags, <a class="reference internal" href="../library/stat.html#stat.S_IFDOOR" title="stat.S_IFDOOR"><code class="xref py py-mod docutils literal notranslate"><span class="pre">S_IFDOOR</span></code></a>,
|
||
<a class="reference internal" href="../library/stat.html#stat.S_IFPORT" title="stat.S_IFPORT"><code class="xref py py-attr docutils literal notranslate"><span class="pre">S_IFPORT</span></code></a>, and <a class="reference internal" href="../library/stat.html#stat.S_IFWHT" title="stat.S_IFWHT"><code class="xref py py-attr docutils literal notranslate"><span class="pre">S_IFWHT</span></code></a>. (Contributed by
|
||
Christian Hiemes in <a class="reference external" href="https://bugs.python.org/issue11016">bpo-11016</a>.)</p>
|
||
</div>
|
||
<div class="section" id="struct">
|
||
<h3>struct<a class="headerlink" href="#struct" title="Permalink to this headline">¶</a></h3>
|
||
<p>New function <a class="reference internal" href="../library/struct.html#struct.iter_unpack" title="struct.iter_unpack"><code class="xref py py-mod docutils literal notranslate"><span class="pre">iter_unpack</span></code></a> and a new
|
||
<a class="reference internal" href="../library/struct.html#struct.Struct.iter_unpack" title="struct.Struct.iter_unpack"><code class="xref py py-meth docutils literal notranslate"><span class="pre">struct.Struct.iter_unpack()</span></code></a> method on compiled formats provide streamed
|
||
unpacking of a buffer containing repeated instances of a given format of data.
|
||
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue17804">bpo-17804</a>.)</p>
|
||
</div>
|
||
<div class="section" id="subprocess">
|
||
<h3>subprocess<a class="headerlink" href="#subprocess" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/subprocess.html#subprocess.check_output" title="subprocess.check_output"><code class="xref py py-func docutils literal notranslate"><span class="pre">check_output()</span></code></a> now accepts an <em>input</em> argument that can
|
||
be used to provide the contents of <code class="docutils literal notranslate"><span class="pre">stdin</span></code> for the command that is run.
|
||
(Contributed by Zack Weinberg in <a class="reference external" href="https://bugs.python.org/issue16624">bpo-16624</a>.)</p>
|
||
<p><code class="xref py py-func docutils literal notranslate"><span class="pre">getstatus()</span></code> and <a class="reference internal" href="../library/subprocess.html#subprocess.getstatusoutput" title="subprocess.getstatusoutput"><code class="xref py py-func docutils literal notranslate"><span class="pre">getstatusoutput()</span></code></a> now
|
||
work on Windows. This change was actually inadvertently made in 3.3.4.
|
||
(Contributed by Tim Golden in <a class="reference external" href="https://bugs.python.org/issue10197">bpo-10197</a>.)</p>
|
||
</div>
|
||
<div class="section" id="sunau">
|
||
<h3>sunau<a class="headerlink" href="#sunau" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">getparams()</span></code> method now returns a namedtuple rather than a
|
||
plain tuple. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue18901">bpo-18901</a>.)</p>
|
||
<p><a class="reference internal" href="../library/sunau.html#sunau.open" title="sunau.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sunau.open()</span></code></a> now supports the context management 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> block, the <code class="docutils literal notranslate"><span class="pre">close</span></code> method of the returned object will be
|
||
called automatically at the end of the block. (Contributed by Serhiy Storchaka
|
||
in <a class="reference external" href="https://bugs.python.org/issue18878">bpo-18878</a>.)</p>
|
||
<p><a class="reference internal" href="../library/sunau.html#sunau.AU_write.setsampwidth" title="sunau.AU_write.setsampwidth"><code class="xref py py-meth docutils literal notranslate"><span class="pre">AU_write.setsampwidth()</span></code></a> now supports 24 bit samples, thus adding
|
||
support for writing 24 sample using the module. (Contributed by
|
||
Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue19261">bpo-19261</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/sunau.html#sunau.AU_write.writeframesraw" title="sunau.AU_write.writeframesraw"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframesraw()</span></code></a> and
|
||
<a class="reference internal" href="../library/sunau.html#sunau.AU_write.writeframes" title="sunau.AU_write.writeframes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframes()</span></code></a> methods now accept any <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like
|
||
object</span></a>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue8311">bpo-8311</a>.)</p>
|
||
</div>
|
||
<div class="section" id="sys">
|
||
<h3>sys<a class="headerlink" href="#sys" title="Permalink to this headline">¶</a></h3>
|
||
<p>New function <a class="reference internal" href="../library/sys.html#sys.getallocatedblocks" title="sys.getallocatedblocks"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getallocatedblocks()</span></code></a> returns the current number of
|
||
blocks allocated by the interpreter. (In CPython with the default
|
||
<code class="docutils literal notranslate"><span class="pre">--with-pymalloc</span></code> setting, this is allocations made through the
|
||
<a class="reference internal" href="../c-api/memory.html#c.PyObject_Malloc" title="PyObject_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Malloc()</span></code></a> API.) This can be useful for tracking memory leaks,
|
||
especially if automated via a test suite. (Contributed by Antoine Pitrou
|
||
in <a class="reference external" href="https://bugs.python.org/issue13390">bpo-13390</a>.)</p>
|
||
<p>When the Python interpreter starts in <a class="reference internal" href="../tutorial/interpreter.html#tut-interactive"><span class="std std-ref">interactive mode</span></a>, it checks for an <a class="reference internal" href="../library/sys.html#sys.__interactivehook__" title="sys.__interactivehook__"><code class="xref py py-data docutils literal notranslate"><span class="pre">__interactivehook__</span></code></a> attribute
|
||
on the <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> module. If the attribute exists, its value is called with no
|
||
arguments just before interactive mode is started. The check is made after the
|
||
<span class="target" id="index-40"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a> file is read, so it can be set there. The <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a>
|
||
module <a class="reference internal" href="../library/site.html#rlcompleter-config"><span class="std std-ref">sets it</span></a> to a function that enables tab
|
||
completion and history saving (in <code class="file docutils literal notranslate"><span class="pre">~/.python-history</span></code>) if the platform
|
||
supports <a class="reference internal" href="../library/readline.html#module-readline" title="readline: GNU readline support for Python. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code></a>. If you do not want this (new) behavior, you can
|
||
override it in <span class="target" id="index-41"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">sitecustomize</span></code>, or
|
||
<code class="xref py py-mod docutils literal notranslate"><span class="pre">usercustomize</span></code> by deleting this attribute from <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> (or setting it
|
||
to some other callable). (Contributed by Éric Araujo and Antoine Pitrou in
|
||
<a class="reference external" href="https://bugs.python.org/issue5845">bpo-5845</a>.)</p>
|
||
</div>
|
||
<div class="section" id="tarfile">
|
||
<h3>tarfile<a class="headerlink" href="#tarfile" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a> module now supports a simple <a class="reference internal" href="../library/tarfile.html#tarfile-commandline"><span class="std std-ref">Command-Line Interface</span></a> when
|
||
called as a script directly or via <code class="docutils literal notranslate"><span class="pre">-m</span></code>. This can be used to create and
|
||
extract tarfile archives. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue13477">bpo-13477</a>.)</p>
|
||
</div>
|
||
<div class="section" id="textwrap">
|
||
<h3>textwrap<a class="headerlink" href="#textwrap" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/textwrap.html#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> class has two new attributes/constructor
|
||
arguments: <a class="reference internal" href="../library/textwrap.html#textwrap.TextWrapper.max_lines" title="textwrap.TextWrapper.max_lines"><code class="xref py py-attr docutils literal notranslate"><span class="pre">max_lines</span></code></a>, which limits the number of
|
||
lines in the output, and <a class="reference internal" href="../library/textwrap.html#textwrap.TextWrapper.placeholder" title="textwrap.TextWrapper.placeholder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">placeholder</span></code></a>, which is a
|
||
string that will appear at the end of the output if it has been truncated
|
||
because of <em>max_lines</em>. Building on these capabilities, a new convenience
|
||
function <a class="reference internal" href="../library/textwrap.html#textwrap.shorten" title="textwrap.shorten"><code class="xref py py-func docutils literal notranslate"><span class="pre">shorten()</span></code></a> collapses all of the whitespace in the input
|
||
to single spaces and produces a single line of a given <em>width</em> that ends with
|
||
the <em>placeholder</em> (by default, <code class="docutils literal notranslate"><span class="pre">[...]</span></code>). (Contributed by Antoine Pitrou and
|
||
Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue18585">bpo-18585</a> and <a class="reference external" href="https://bugs.python.org/issue18725">bpo-18725</a>.)</p>
|
||
</div>
|
||
<div class="section" id="threading">
|
||
<h3>threading<a class="headerlink" href="#threading" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/threading.html#threading.Thread" title="threading.Thread"><code class="xref py py-class docutils literal notranslate"><span class="pre">Thread</span></code></a> object representing the main thread can be
|
||
obtained from the new <a class="reference internal" href="../library/threading.html#threading.main_thread" title="threading.main_thread"><code class="xref py py-func docutils literal notranslate"><span class="pre">main_thread()</span></code></a> function. In normal
|
||
conditions this will be the thread from which the Python interpreter was
|
||
started. (Contributed by Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue18882">bpo-18882</a>.)</p>
|
||
</div>
|
||
<div class="section" id="traceback">
|
||
<h3>traceback<a class="headerlink" href="#traceback" title="Permalink to this headline">¶</a></h3>
|
||
<p>A new <a class="reference internal" href="../library/traceback.html#traceback.clear_frames" title="traceback.clear_frames"><code class="xref py py-func docutils literal notranslate"><span class="pre">traceback.clear_frames()</span></code></a> function takes a traceback object
|
||
and clears the local variables in all of the frames it references,
|
||
reducing the amount of memory consumed. (Contributed by Andrew Kuchling in
|
||
<a class="reference external" href="https://bugs.python.org/issue1565525">bpo-1565525</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.DynamicClassAttribute" title="types.DynamicClassAttribute"><code class="xref py py-func docutils literal notranslate"><span class="pre">DynamicClassAttribute()</span></code></a> descriptor provides a way to define
|
||
an attribute that acts normally when looked up through an instance object, but
|
||
which is routed to the <em>class</em> <code class="docutils literal notranslate"><span class="pre">__getattr__</span></code> when looked up through the
|
||
class. This allows one to have properties active on a class, and have virtual
|
||
attributes on the class with the same name (see <code class="xref py py-mod docutils literal notranslate"><span class="pre">Enum</span></code> for an example).
|
||
(Contributed by Ethan Furman in <a class="reference external" href="https://bugs.python.org/issue19030">bpo-19030</a>.)</p>
|
||
</div>
|
||
<div class="section" id="urllib">
|
||
<h3>urllib<a class="headerlink" href="#urllib" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/urllib.request.html#module-urllib.request" title="urllib.request: Extensible library for opening URLs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request</span></code></a> now supports <code class="docutils literal notranslate"><span class="pre">data:</span></code> URLs via the
|
||
<a class="reference internal" href="../library/urllib.request.html#urllib.request.DataHandler" title="urllib.request.DataHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">DataHandler</span></code></a> class. (Contributed by Mathias Panzenböck
|
||
in <a class="reference external" href="https://bugs.python.org/issue16423">bpo-16423</a>.)</p>
|
||
<p>The http method that will be used by a <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> class
|
||
can now be specified by setting a <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request.method" title="urllib.request.Request.method"><code class="xref py py-class docutils literal notranslate"><span class="pre">method</span></code></a>
|
||
class attribute on the subclass. (Contributed by Jason R Coombs in
|
||
<a class="reference external" href="https://bugs.python.org/issue18978">bpo-18978</a>.)</p>
|
||
<p><a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> objects are now reusable: if the
|
||
<a class="reference internal" href="../library/urllib.request.html#urllib.request.Request.full_url" title="urllib.request.Request.full_url"><code class="xref py py-attr docutils literal notranslate"><span class="pre">full_url</span></code></a> or <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request.data" title="urllib.request.Request.data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">data</span></code></a>
|
||
attributes are modified, all relevant internal properties are updated. This
|
||
means, for example, that it is now possible to use the same
|
||
<a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> object in more than one
|
||
<a class="reference internal" href="../library/urllib.request.html#urllib.request.OpenerDirector.open" title="urllib.request.OpenerDirector.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">OpenerDirector.open()</span></code></a> call with different <em>data</em> arguments, or to
|
||
modify a <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a>’s <code class="docutils literal notranslate"><span class="pre">url</span></code> rather than recomputing it
|
||
from scratch. There is also a new
|
||
<a class="reference internal" href="../library/urllib.request.html#urllib.request.Request.remove_header" title="urllib.request.Request.remove_header"><code class="xref py py-meth docutils literal notranslate"><span class="pre">remove_header()</span></code></a> method that can be used to remove
|
||
headers from a <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a>. (Contributed by Alexey
|
||
Kachayev in <a class="reference external" href="https://bugs.python.org/issue16464">bpo-16464</a>, Daniel Wozniak in <a class="reference external" href="https://bugs.python.org/issue17485">bpo-17485</a>, and Damien Brecht
|
||
and Senthil Kumaran in <a class="reference external" href="https://bugs.python.org/issue17272">bpo-17272</a>.)</p>
|
||
<p><a class="reference internal" href="../library/urllib.error.html#urllib.error.HTTPError" title="urllib.error.HTTPError"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPError</span></code></a> objects now have a
|
||
<a class="reference internal" href="../library/urllib.error.html#urllib.error.HTTPError.headers" title="urllib.error.HTTPError.headers"><code class="xref py py-attr docutils literal notranslate"><span class="pre">headers</span></code></a> attribute that provides access to the
|
||
HTTP response headers associated with the error. (Contributed by
|
||
Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue15701">bpo-15701</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.TestCase" title="unittest.TestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestCase</span></code></a> class has a new method,
|
||
<a class="reference internal" href="../library/unittest.html#unittest.TestCase.subTest" title="unittest.TestCase.subTest"><code class="xref py py-meth docutils literal notranslate"><span class="pre">subTest()</span></code></a>, that produces a context manager whose
|
||
<a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> block becomes a “sub-test”. This context manager allows a test
|
||
method to dynamically generate subtests by, say, calling the <code class="docutils literal notranslate"><span class="pre">subTest</span></code>
|
||
context manager inside a loop. A single test method can thereby produce an
|
||
indefinite number of separately-identified and separately-counted tests, all of
|
||
which will run even if one or more of them fail. For example:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">NumbersTest</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
|
||
<span class="k">def</span> <span class="nf">test_even</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">6</span><span class="p">):</span>
|
||
<span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">subTest</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="n">i</span><span class="p">):</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="n">i</span> <span class="o">%</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>will result in six subtests, each identified in the unittest verbose output
|
||
with a label consisting of the variable name <code class="docutils literal notranslate"><span class="pre">i</span></code> and a particular value for
|
||
that variable (<code class="docutils literal notranslate"><span class="pre">i=0</span></code>, <code class="docutils literal notranslate"><span class="pre">i=1</span></code>, etc). See <a class="reference internal" href="../library/unittest.html#subtests"><span class="std std-ref">Distinguishing test iterations using subtests</span></a> for the full
|
||
version of this example. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue16997">bpo-16997</a>.)</p>
|
||
<p><a class="reference internal" href="../library/unittest.html#unittest.main" title="unittest.main"><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.main()</span></code></a> now accepts an iterable of test names for
|
||
<em>defaultTest</em>, where previously it only accepted a single test name as a
|
||
string. (Contributed by Jyrki Pulliainen in <a class="reference external" href="https://bugs.python.org/issue15132">bpo-15132</a>.)</p>
|
||
<p>If <a class="reference internal" href="../library/unittest.html#unittest.SkipTest" title="unittest.SkipTest"><code class="xref py py-class docutils literal notranslate"><span class="pre">SkipTest</span></code></a> is raised during test discovery (that is, at the
|
||
module level in the test file), it is now reported as a skip instead of an
|
||
error. (Contributed by Zach Ware in <a class="reference external" href="https://bugs.python.org/issue16935">bpo-16935</a>.)</p>
|
||
<p><a class="reference internal" href="../library/unittest.html#unittest.TestLoader.discover" title="unittest.TestLoader.discover"><code class="xref py py-meth docutils literal notranslate"><span class="pre">discover()</span></code></a> now sorts the discovered files to provide
|
||
consistent test ordering. (Contributed by Martin Melin and Jeff Ramnani in
|
||
<a class="reference external" href="https://bugs.python.org/issue16709">bpo-16709</a>.)</p>
|
||
<p><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">TestSuite</span></code></a> now drops references to tests as soon as the test
|
||
has been run, if the test is successful. On Python interpreters that do
|
||
garbage collection, this allows the tests to be garbage collected if nothing
|
||
else is holding a reference to the test. It is possible to override this
|
||
behavior by creating a <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">TestSuite</span></code></a> subclass that defines a
|
||
custom <code class="docutils literal notranslate"><span class="pre">_removeTestAtIndex</span></code> method. (Contributed by Tom Wardill, Matt
|
||
McClure, and Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue11798">bpo-11798</a>.)</p>
|
||
<p>A new test assertion context-manager, <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertLogs" title="unittest.TestCase.assertLogs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertLogs()</span></code></a>,
|
||
will ensure that a given block of code emits a log message using the
|
||
<a class="reference internal" href="../library/logging.html#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> module. By default the message can come from any logger and
|
||
have a priority of <code class="docutils literal notranslate"><span class="pre">INFO</span></code> or higher, but both the logger name and an
|
||
alternative minimum logging level may be specified. The object returned by the
|
||
context manager can be queried for the <a class="reference internal" href="../library/logging.html#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a>s and/or
|
||
formatted messages that were logged. (Contributed by Antoine Pitrou in
|
||
<a class="reference external" href="https://bugs.python.org/issue18937">bpo-18937</a>.)</p>
|
||
<p>Test discovery now works with namespace packages (Contributed by Claudiu Popa
|
||
in <a class="reference external" href="https://bugs.python.org/issue17457">bpo-17457</a>.)</p>
|
||
<p><a class="reference internal" href="../library/unittest.mock.html#module-unittest.mock" title="unittest.mock: Mock object library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest.mock</span></code></a> objects now inspect their specification signatures when
|
||
matching calls, which means an argument can now be matched by either position
|
||
or name, instead of only by position. (Contributed by Antoine Pitrou in
|
||
<a class="reference external" href="https://bugs.python.org/issue17015">bpo-17015</a>.)</p>
|
||
<p><code class="xref py py-func docutils literal notranslate"><span class="pre">mock_open()</span></code> objects now have <code class="docutils literal notranslate"><span class="pre">readline</span></code> and <code class="docutils literal notranslate"><span class="pre">readlines</span></code>
|
||
methods. (Contributed by Toshio Kuratomi in <a class="reference external" href="https://bugs.python.org/issue17467">bpo-17467</a>.)</p>
|
||
</div>
|
||
<div class="section" id="venv">
|
||
<h3>venv<a class="headerlink" href="#venv" title="Permalink to this headline">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a> now includes activation scripts for the <code class="docutils literal notranslate"><span class="pre">csh</span></code> and <code class="docutils literal notranslate"><span class="pre">fish</span></code>
|
||
shells. (Contributed by Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue15417">bpo-15417</a>.)</p>
|
||
<p><a class="reference internal" href="../library/venv.html#venv.EnvBuilder" title="venv.EnvBuilder"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvBuilder</span></code></a> and the <a class="reference internal" href="../library/venv.html#venv.create" title="venv.create"><code class="xref py py-func docutils literal notranslate"><span class="pre">create()</span></code></a> convenience function
|
||
take a new keyword argument <em>with_pip</em>, which defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>, that
|
||
controls whether or not <a class="reference internal" href="../library/venv.html#venv.EnvBuilder" title="venv.EnvBuilder"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvBuilder</span></code></a> ensures that <code class="docutils literal notranslate"><span class="pre">pip</span></code> is
|
||
installed in the virtual environment. (Contributed by Nick Coghlan in
|
||
<a class="reference external" href="https://bugs.python.org/issue19552">bpo-19552</a> as part of the <span class="target" id="index-42"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0453"><strong>PEP 453</strong></a> implementation.)</p>
|
||
</div>
|
||
<div class="section" id="wave">
|
||
<h3>wave<a class="headerlink" href="#wave" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">getparams()</span></code> method now returns a namedtuple rather than a
|
||
plain tuple. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue17487">bpo-17487</a>.)</p>
|
||
<p><a class="reference internal" href="../library/wave.html#wave.open" title="wave.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">wave.open()</span></code></a> now supports the context management protocol. (Contributed
|
||
by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue17616">bpo-17616</a>.)</p>
|
||
<p><a class="reference internal" href="../library/wave.html#module-wave" title="wave: Provide an interface to the WAV sound format."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wave</span></code></a> can now <a class="reference internal" href="../library/wave.html#wave-write-objects"><span class="std std-ref">write output to unseekable files</span></a>. (Contributed by David Jones, Guilherme Polo, and Serhiy
|
||
Storchaka in <a class="reference external" href="https://bugs.python.org/issue5202">bpo-5202</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/wave.html#wave.Wave_write.writeframesraw" title="wave.Wave_write.writeframesraw"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframesraw()</span></code></a> and
|
||
<a class="reference internal" href="../library/wave.html#wave.Wave_write.writeframes" title="wave.Wave_write.writeframes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframes()</span></code></a> methods now accept any <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like
|
||
object</span></a>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue8311">bpo-8311</a>.)</p>
|
||
</div>
|
||
<div class="section" id="weakref">
|
||
<h3>weakref<a class="headerlink" href="#weakref" title="Permalink to this headline">¶</a></h3>
|
||
<p>New <a class="reference internal" href="../library/weakref.html#weakref.WeakMethod" title="weakref.WeakMethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">WeakMethod</span></code></a> class simulates weak references to bound
|
||
methods. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue14631">bpo-14631</a>.)</p>
|
||
<p>New <a class="reference internal" href="../library/weakref.html#weakref.finalize" title="weakref.finalize"><code class="xref py py-class docutils literal notranslate"><span class="pre">finalize</span></code></a> class makes it possible to register a callback
|
||
to be invoked when an object is garbage collected, without needing to
|
||
carefully manage the lifecycle of the weak reference itself. (Contributed by
|
||
Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue15528">bpo-15528</a>.)</p>
|
||
<p>The callback, if any, associated with a <a class="reference internal" href="../library/weakref.html#weakref.ref" title="weakref.ref"><code class="xref py py-class docutils literal notranslate"><span class="pre">ref</span></code></a> is now
|
||
exposed via the <a class="reference internal" href="../library/weakref.html#weakref.ref.__callback__" title="weakref.ref.__callback__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__callback__</span></code></a> attribute. (Contributed
|
||
by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue17643">bpo-17643</a>.)</p>
|
||
</div>
|
||
<div class="section" id="xml-etree">
|
||
<h3>xml.etree<a class="headerlink" href="#xml-etree" title="Permalink to this headline">¶</a></h3>
|
||
<p>A new parser, <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLPullParser" title="xml.etree.ElementTree.XMLPullParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLPullParser</span></code></a>, allows a
|
||
non-blocking applications to parse XML documents. An example can be
|
||
seen at <a class="reference internal" href="../library/xml.etree.elementtree.html#elementtree-pull-parsing"><span class="std std-ref">Pull API for non-blocking parsing</span></a>. (Contributed by Antoine
|
||
Pitrou in <a class="reference external" href="https://bugs.python.org/issue17741">bpo-17741</a>.)</p>
|
||
<p>The <a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code></a> <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring" title="xml.etree.ElementTree.tostring"><code class="xref py py-func docutils literal notranslate"><span class="pre">tostring()</span></code></a> and
|
||
<a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.tostringlist" title="xml.etree.ElementTree.tostringlist"><code class="xref py py-func docutils literal notranslate"><span class="pre">tostringlist()</span></code></a> functions, and the
|
||
<a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree" title="xml.etree.ElementTree.ElementTree"><code class="xref py py-class docutils literal notranslate"><span class="pre">ElementTree</span></code></a>
|
||
<a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree.write" title="xml.etree.ElementTree.ElementTree.write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code></a> method, now have a
|
||
<em>short_empty_elements</em> <a class="reference internal" href="../glossary.html#keyword-only-parameter"><span class="std std-ref">keyword-only parameter</span></a>
|
||
providing control over whether elements with no content are written in
|
||
abbreviated (<code class="docutils literal notranslate"><span class="pre"><tag</span> <span class="pre">/></span></code>) or expanded (<code class="docutils literal notranslate"><span class="pre"><tag></tag></span></code>) form. (Contributed by
|
||
Ariel Poliak and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue14377">bpo-14377</a>.)</p>
|
||
</div>
|
||
<div class="section" id="zipfile">
|
||
<h3>zipfile<a class="headerlink" href="#zipfile" title="Permalink to this headline">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/zipfile.html#zipfile.PyZipFile.writepy" title="zipfile.PyZipFile.writepy"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writepy()</span></code></a> method of the
|
||
<a class="reference internal" href="../library/zipfile.html#zipfile.PyZipFile" title="zipfile.PyZipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">PyZipFile</span></code></a> class has a new <em>filterfunc</em> option that can be
|
||
used to control which directories and files are added to the archive. For
|
||
example, this could be used to exclude test files from the archive.
|
||
(Contributed by Christian Tismer in <a class="reference external" href="https://bugs.python.org/issue19274">bpo-19274</a>.)</p>
|
||
<p>The <em>allowZip64</em> parameter to <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile" title="zipfile.ZipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">ZipFile</span></code></a> and
|
||
<code class="xref py py-class docutils literal notranslate"><span class="pre">PyZipfile</span></code> is now <code class="docutils literal notranslate"><span class="pre">True</span></code> by default. (Contributed by
|
||
William Mallard in <a class="reference external" href="https://bugs.python.org/issue17201">bpo-17201</a>.)</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="cpython-implementation-changes">
|
||
<h2>CPython Implementation Changes<a class="headerlink" href="#cpython-implementation-changes" title="Permalink to this headline">¶</a></h2>
|
||
<div class="section" id="pep-445-customization-of-cpython-memory-allocators">
|
||
<span id="whatsnew-pep-445"></span><h3>PEP 445: Customization of CPython Memory Allocators<a class="headerlink" href="#pep-445-customization-of-cpython-memory-allocators" title="Permalink to this headline">¶</a></h3>
|
||
<p><span class="target" id="index-43"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0445"><strong>PEP 445</strong></a> adds new C level interfaces to customize memory allocation in
|
||
the CPython interpreter.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-44"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0445"><strong>PEP 445</strong></a> – Add new APIs to customize Python memory allocators</dt><dd><p>PEP written and implemented by Victor Stinner.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-442-safe-object-finalization">
|
||
<span id="whatsnew-pep-442"></span><h3>PEP 442: Safe Object Finalization<a class="headerlink" href="#pep-442-safe-object-finalization" title="Permalink to this headline">¶</a></h3>
|
||
<p><span class="target" id="index-45"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0442"><strong>PEP 442</strong></a> removes the current limitations and quirks of object finalization
|
||
in CPython. With it, objects with <a class="reference internal" href="../reference/datamodel.html#object.__del__" title="object.__del__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__del__()</span></code></a> methods, as well as
|
||
generators with <a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">finally</span></code></a> clauses, can be finalized when they are
|
||
part of a reference cycle.</p>
|
||
<p>As part of this change, module globals are no longer forcibly set to
|
||
<a class="reference internal" href="../library/constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> during interpreter shutdown in most cases, instead relying
|
||
on the normal operation of the cyclic garbage collector. This avoids a
|
||
whole class of interpreter-shutdown-time errors, usually involving
|
||
<code class="docutils literal notranslate"><span class="pre">__del__</span></code> methods, that have plagued Python since the cyclic GC
|
||
was first introduced.</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-46"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0442"><strong>PEP 442</strong></a> – Safe object finalization</dt><dd><p>PEP written and implemented by Antoine Pitrou.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pep-456-secure-and-interchangeable-hash-algorithm">
|
||
<span id="whatsnew-pep-456"></span><h3>PEP 456: Secure and Interchangeable Hash Algorithm<a class="headerlink" href="#pep-456-secure-and-interchangeable-hash-algorithm" title="Permalink to this headline">¶</a></h3>
|
||
<p><span class="target" id="index-47"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0456"><strong>PEP 456</strong></a> follows up on earlier security fix work done on Python’s hash
|
||
algorithm to address certain DOS attacks to which public facing APIs backed by
|
||
dictionary lookups may be subject. (See <a class="reference external" href="https://bugs.python.org/issue14621">bpo-14621</a> for the start of the
|
||
current round of improvements.) The PEP unifies CPython’s hash code to make it
|
||
easier for a packager to substitute a different hash algorithm, and switches
|
||
Python’s default implementation to a SipHash implementation on platforms that
|
||
have a 64 bit data type. Any performance differences in comparison with the
|
||
older FNV algorithm are trivial.</p>
|
||
<p>The PEP adds additional fields to the <a class="reference internal" href="../library/sys.html#sys.hash_info" title="sys.hash_info"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.hash_info</span></code></a> struct sequence to
|
||
describe the hash algorithm in use by the currently executing binary. Otherwise,
|
||
the PEP does not alter any existing CPython APIs.</p>
|
||
</div>
|
||
<div class="section" id="pep-436-argument-clinic">
|
||
<span id="whatsnew-pep-436"></span><h3>PEP 436: Argument Clinic<a class="headerlink" href="#pep-436-argument-clinic" title="Permalink to this headline">¶</a></h3>
|
||
<p>“Argument Clinic” (<span class="target" id="index-48"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0436"><strong>PEP 436</strong></a>) is now part of the CPython build process
|
||
and can be used to simplify the process of defining and maintaining
|
||
accurate signatures for builtins and standard library extension modules
|
||
implemented in C.</p>
|
||
<p>Some standard library extension modules have been converted to use Argument
|
||
Clinic in Python 3.4, and <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> and <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> have been updated
|
||
accordingly.</p>
|
||
<p>It is expected that signature metadata for programmatic introspection will
|
||
be added to additional callables implemented in C as part of Python 3.4
|
||
maintenance releases.</p>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>The Argument Clinic PEP is not fully up to date with the state of the
|
||
implementation. This has been deemed acceptable by the release manager
|
||
and core development team in this case, as Argument Clinic will not
|
||
be made available as a public API for third party use in Python 3.4.</p>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">See also</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-49"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0436"><strong>PEP 436</strong></a> – The Argument Clinic DSL</dt><dd><p>PEP written and implemented by Larry Hastings.</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="other-build-and-c-api-changes">
|
||
<h3>Other Build and C API Changes<a class="headerlink" href="#other-build-and-c-api-changes" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>The new <a class="reference internal" href="../c-api/type.html#c.PyType_GetSlot" title="PyType_GetSlot"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetSlot()</span></code></a> function has been added to the stable ABI,
|
||
allowing retrieval of function pointers from named type slots when using
|
||
the limited API. (Contributed by Martin von Löwis in <a class="reference external" href="https://bugs.python.org/issue17162">bpo-17162</a>.)</p></li>
|
||
<li><p>The new <a class="reference internal" href="../c-api/init.html#c.Py_SetStandardStreamEncoding" title="Py_SetStandardStreamEncoding"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetStandardStreamEncoding()</span></code></a> pre-initialization API
|
||
allows applications embedding the CPython interpreter to reliably force
|
||
a particular encoding and error handler for the standard streams.
|
||
(Contributed by Bastien Montagne and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue16129">bpo-16129</a>.)</p></li>
|
||
<li><p>Most Python C APIs that don’t mutate string arguments are now correctly
|
||
marked as accepting <code class="docutils literal notranslate"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></code> rather than <code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*</span></code>. (Contributed
|
||
by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue1772673">bpo-1772673</a>.)</p></li>
|
||
<li><p>A new shell version of <code class="docutils literal notranslate"><span class="pre">python-config</span></code> can be used even when a python
|
||
interpreter is not available (for example, in cross compilation scenarios).</p></li>
|
||
<li><p><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> now supports width and precision
|
||
specifications for <code class="docutils literal notranslate"><span class="pre">%s</span></code>, <code class="docutils literal notranslate"><span class="pre">%A</span></code>, <code class="docutils literal notranslate"><span class="pre">%U</span></code>, <code class="docutils literal notranslate"><span class="pre">%V</span></code>, <code class="docutils literal notranslate"><span class="pre">%S</span></code>, and <code class="docutils literal notranslate"><span class="pre">%R</span></code>.
|
||
(Contributed by Ysj Ray and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue7330">bpo-7330</a>.)</p></li>
|
||
<li><p>New function <a class="reference internal" href="../c-api/tuple.html#c.PyStructSequence_InitType2" title="PyStructSequence_InitType2"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStructSequence_InitType2()</span></code></a> supplements the
|
||
existing <a class="reference internal" href="../c-api/tuple.html#c.PyStructSequence_InitType" title="PyStructSequence_InitType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStructSequence_InitType()</span></code></a> function. The difference
|
||
is that it returns <code class="docutils literal notranslate"><span class="pre">0</span></code> on success and <code class="docutils literal notranslate"><span class="pre">-1</span></code> on failure.</p></li>
|
||
<li><p>The CPython source can now be compiled using the address sanity checking
|
||
features of recent versions of GCC and clang: the false alarms in the small
|
||
object allocator have been silenced. (Contributed by Dhiru Kholia in
|
||
<a class="reference external" href="https://bugs.python.org/issue18596">bpo-18596</a>.)</p></li>
|
||
<li><p>The Windows build now uses <a class="reference external" href="https://en.wikipedia.org/wiki/Address_space_layout_randomization">Address Space Layout Randomization</a> and <a class="reference external" href="https://en.wikipedia.org/wiki/Data_Execution_Prevention">Data Execution Prevention</a>. (Contributed by
|
||
Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue16632">bpo-16632</a>.)</p></li>
|
||
<li><p>New function <a class="reference internal" href="../c-api/object.html#c.PyObject_LengthHint" title="PyObject_LengthHint"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_LengthHint()</span></code></a> is the C API equivalent
|
||
of <a class="reference internal" href="../library/operator.html#operator.length_hint" title="operator.length_hint"><code class="xref py py-func docutils literal notranslate"><span class="pre">operator.length_hint()</span></code></a>. (Contributed by Armin Ronacher in
|
||
<a class="reference external" href="https://bugs.python.org/issue16148">bpo-16148</a>.)</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="other-improvements">
|
||
<span id="other-improvements-3-4"></span><h3>Other Improvements<a class="headerlink" href="#other-improvements" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple" id="whatsnew-isolated-mode">
|
||
<li><p>The <a class="reference internal" href="../using/cmdline.html#using-on-cmdline"><span class="std std-ref">python</span></a> command has a new <a class="reference internal" href="../using/cmdline.html#using-on-misc-options"><span class="std std-ref">option</span></a>, <code class="docutils literal notranslate"><span class="pre">-I</span></code>, which causes it to run in “isolated mode”,
|
||
which means that <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> contains neither the script’s directory nor
|
||
the user’s <code class="docutils literal notranslate"><span class="pre">site-packages</span></code> directory, and all <span class="target" id="index-50"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON*</span></code> environment
|
||
variables are ignored (it implies both <code class="docutils literal notranslate"><span class="pre">-s</span></code> and <code class="docutils literal notranslate"><span class="pre">-E</span></code>). Other
|
||
restrictions may also be applied in the future, with the goal being to
|
||
isolate the execution of a script from the user’s environment. This is
|
||
appropriate, for example, when Python is used to run a system script. On
|
||
most POSIX systems it can and should be used in the <code class="docutils literal notranslate"><span class="pre">#!</span></code> line of system
|
||
scripts. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue16499">bpo-16499</a>.)</p></li>
|
||
<li><p>Tab-completion is now enabled by default in the interactive interpreter
|
||
on systems that support <a class="reference internal" href="../library/readline.html#module-readline" title="readline: GNU readline support for Python. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code></a>. History is also enabled by default,
|
||
and is written to (and read from) the file <code class="file docutils literal notranslate"><span class="pre">~/.python-history</span></code>.
|
||
(Contributed by Antoine Pitrou and Éric Araujo in <a class="reference external" href="https://bugs.python.org/issue5845">bpo-5845</a>.)</p></li>
|
||
<li><p>Invoking the Python interpreter with <code class="docutils literal notranslate"><span class="pre">--version</span></code> now outputs the version to
|
||
standard output instead of standard error (<a class="reference external" href="https://bugs.python.org/issue18338">bpo-18338</a>). Similar changes
|
||
were made to <a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue18920">bpo-18920</a>) and other modules that have
|
||
script-like invocation capabilities (<a class="reference external" href="https://bugs.python.org/issue18922">bpo-18922</a>).</p></li>
|
||
<li><p>The CPython Windows installer now adds <code class="docutils literal notranslate"><span class="pre">.py</span></code> to the <span class="target" id="index-51"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATHEXT</span></code>
|
||
variable when extensions are registered, allowing users to run a python
|
||
script at the windows command prompt by just typing its name without the
|
||
<code class="docutils literal notranslate"><span class="pre">.py</span></code> extension. (Contributed by Paul Moore in <a class="reference external" href="https://bugs.python.org/issue18569">bpo-18569</a>.)</p></li>
|
||
<li><p>A new <code class="docutils literal notranslate"><span class="pre">make</span></code> target <a class="reference external" href="https://devguide.python.org/coverage/#measuring-coverage-of-c-code-with-gcov-and-lcov">coverage-report</a>
|
||
will build python, run the test suite, and generate an HTML coverage report
|
||
for the C codebase using <code class="docutils literal notranslate"><span class="pre">gcov</span></code> and <a class="reference external" href="http://ltp.sourceforge.net/coverage/lcov.php">lcov</a>.</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">-R</span></code> option to the <a class="reference internal" href="../library/test.html#regrtest"><span class="std std-ref">python regression test suite</span></a> now
|
||
also checks for memory allocation leaks, using
|
||
<a class="reference internal" href="../library/sys.html#sys.getallocatedblocks" title="sys.getallocatedblocks"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getallocatedblocks()</span></code></a>. (Contributed by Antoine Pitrou in
|
||
<a class="reference external" href="https://bugs.python.org/issue13390">bpo-13390</a>.)</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span></code> now works with namespace packages.</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> module is now implemented in C, which means it gets the
|
||
values for its constants from the C header files, instead of having the
|
||
values hard-coded in the python module as was previously the case.</p></li>
|
||
<li><p>Loading multiple python modules from a single OS module (<code class="docutils literal notranslate"><span class="pre">.so</span></code>, <code class="docutils literal notranslate"><span class="pre">.dll</span></code>)
|
||
now works correctly (previously it silently returned the first python
|
||
module in the file). (Contributed by Václav Šmilauer in <a class="reference external" href="https://bugs.python.org/issue16421">bpo-16421</a>.)</p></li>
|
||
<li><p>A new opcode, <a class="reference internal" href="../library/dis.html#opcode-LOAD_CLASSDEREF"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_CLASSDEREF</span></code></a>, has been added to fix a bug in the
|
||
loading of free variables in class bodies that could be triggered by certain
|
||
uses of <a class="reference internal" href="../reference/datamodel.html#prepare"><span class="std std-ref">__prepare__</span></a>. (Contributed by Benjamin Peterson in
|
||
<a class="reference external" href="https://bugs.python.org/issue17853">bpo-17853</a>.)</p></li>
|
||
<li><p>A number of MemoryError-related crashes were identified and fixed by Victor
|
||
Stinner using his <span class="target" id="index-52"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0445"><strong>PEP 445</strong></a>-based <code class="docutils literal notranslate"><span class="pre">pyfailmalloc</span></code> tool (<a class="reference external" href="https://bugs.python.org/issue18408">bpo-18408</a>,
|
||
<a class="reference external" href="https://bugs.python.org/issue18520">bpo-18520</a>).</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> command now accepts a <code class="docutils literal notranslate"><span class="pre">--copies</span></code> option
|
||
to use copies rather than symlinks even on systems where symlinks are the
|
||
default. (Contributed by Vinay Sajip in <a class="reference external" href="https://bugs.python.org/issue18807">bpo-18807</a>.)</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> command also accepts a <code class="docutils literal notranslate"><span class="pre">--without-pip</span></code>
|
||
option to suppress the otherwise-automatic bootstrapping of pip into
|
||
the virtual environment. (Contributed by Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue19552">bpo-19552</a>
|
||
as part of the <span class="target" id="index-53"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0453"><strong>PEP 453</strong></a> implementation.)</p></li>
|
||
<li><p>The encoding name is now optional in the value set for the
|
||
<span class="target" id="index-54"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONIOENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONIOENCODING</span></code></a> environment variable. This makes it possible to
|
||
set just the error handler, without changing the default encoding.
|
||
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue18818">bpo-18818</a>.)</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/bz2.html#module-bz2" title="bz2: Interfaces for bzip2 compression and decompression."><code class="xref py py-mod docutils literal notranslate"><span class="pre">bz2</span></code></a>, <a class="reference internal" href="../library/lzma.html#module-lzma" title="lzma: A Python wrapper for the liblzma compression library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">lzma</span></code></a>, and <a class="reference internal" href="../library/gzip.html#module-gzip" title="gzip: Interfaces for gzip compression and decompression using file objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gzip</span></code></a> module <code class="docutils literal notranslate"><span class="pre">open</span></code> functions now
|
||
support <code class="docutils literal notranslate"><span class="pre">x</span></code> (exclusive creation) mode. (Contributed by Tim Heaney and
|
||
Vajrasky Kok in <a class="reference external" href="https://bugs.python.org/issue19201">bpo-19201</a>, <a class="reference external" href="https://bugs.python.org/issue19222">bpo-19222</a>, and <a class="reference external" href="https://bugs.python.org/issue19223">bpo-19223</a>.)</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="significant-optimizations">
|
||
<h3>Significant Optimizations<a class="headerlink" href="#significant-optimizations" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>The UTF-32 decoder is now 3x to 4x faster. (Contributed by Serhiy Storchaka
|
||
in <a class="reference external" href="https://bugs.python.org/issue14625">bpo-14625</a>.)</p></li>
|
||
<li><p>The cost of hash collisions for sets is now reduced. Each hash table
|
||
probe now checks a series of consecutive, adjacent key/hash pairs before
|
||
continuing to make random probes through the hash table. This exploits
|
||
cache locality to make collision resolution less expensive.
|
||
The collision resolution scheme can be described as a hybrid of linear
|
||
probing and open addressing. The number of additional linear probes
|
||
defaults to nine. This can be changed at compile-time by defining
|
||
LINEAR_PROBES to be any value. Set LINEAR_PROBES=0 to turn-off
|
||
linear probing entirely. (Contributed by Raymond Hettinger in
|
||
<a class="reference external" href="https://bugs.python.org/issue18771">bpo-18771</a>.)</p></li>
|
||
<li><p>The interpreter starts about 30% faster. A couple of measures lead to the
|
||
speedup. The interpreter loads fewer modules on startup, e.g. the <a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a>,
|
||
<a class="reference internal" href="../library/collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a> and <a class="reference internal" href="../library/locale.html#module-locale" title="locale: Internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">locale</span></code></a> modules and their dependencies are no
|
||
longer imported by default. The marshal module has been improved to load
|
||
compiled Python code faster. (Contributed by Antoine Pitrou, Christian
|
||
Heimes and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue19219">bpo-19219</a>, <a class="reference external" href="https://bugs.python.org/issue19218">bpo-19218</a>, <a class="reference external" href="https://bugs.python.org/issue19209">bpo-19209</a>,
|
||
<a class="reference external" href="https://bugs.python.org/issue19205">bpo-19205</a> and <a class="reference external" href="https://bugs.python.org/issue9548">bpo-9548</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><code class="xref py py-class docutils literal notranslate"><span class="pre">bz2.BZ2File</span></code></a> is now as fast or faster than the Python2 version for
|
||
most cases. <a class="reference internal" href="../library/lzma.html#lzma.LZMAFile" title="lzma.LZMAFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">lzma.LZMAFile</span></code></a> has also been optimized. (Contributed by
|
||
Serhiy Storchaka and Nadeem Vawda in <a class="reference external" href="https://bugs.python.org/issue16034">bpo-16034</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/random.html#random.getrandbits" title="random.getrandbits"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.getrandbits()</span></code></a> is 20%-40% faster for small integers (the most
|
||
common use case). (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue16674">bpo-16674</a>.)</p></li>
|
||
<li><p>By taking advantage of the new storage format for strings, pickling of
|
||
strings is now significantly faster. (Contributed by Victor Stinner and
|
||
Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue15596">bpo-15596</a>.)</p></li>
|
||
<li><p>A performance issue in <code class="xref py py-meth docutils literal notranslate"><span class="pre">io.FileIO.readall()</span></code> has been solved. This
|
||
particularly affects Windows, and significantly speeds up the case of piping
|
||
significant amounts of data through <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a>. (Contributed
|
||
by Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue15758">bpo-15758</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/html.html#html.escape" title="html.escape"><code class="xref py py-func docutils literal notranslate"><span class="pre">html.escape()</span></code></a> is now 10x faster. (Contributed by Matt Bryant in
|
||
<a class="reference external" href="https://bugs.python.org/issue18020">bpo-18020</a>.)</p></li>
|
||
<li><p>On Windows, the native <code class="docutils literal notranslate"><span class="pre">VirtualAlloc</span></code> is now used instead of the CRT
|
||
<code class="docutils literal notranslate"><span class="pre">malloc</span></code> in <code class="docutils literal notranslate"><span class="pre">obmalloc</span></code>. Artificial benchmarks show about a 3% memory
|
||
savings.</p></li>
|
||
<li><p><a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.urandom()</span></code></a> now uses a lazily-opened persistent file descriptor
|
||
so as to avoid using many file descriptors when run in parallel from
|
||
multiple threads. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue18756">bpo-18756</a>.)</p></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="deprecated">
|
||
<span id="deprecated-3-4"></span><h2>Deprecated<a class="headerlink" href="#deprecated" title="Permalink to this headline">¶</a></h2>
|
||
<p>This section covers various APIs and other features that have been deprecated
|
||
in Python 3.4, and will be removed in Python 3.5 or later. In most (but not
|
||
all) cases, using the deprecated APIs will produce a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>
|
||
when the interpreter is run with deprecation warnings enabled (for example, by
|
||
using <code class="docutils literal notranslate"><span class="pre">-Wd</span></code>).</p>
|
||
<div class="section" id="deprecations-in-the-python-api">
|
||
<h3>Deprecations in the Python API<a class="headerlink" href="#deprecations-in-the-python-api" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>As mentioned in <a class="reference internal" href="#whatsnew-pep-451"><span class="std std-ref">PEP 451: A ModuleSpec Type for the Import System</span></a>, a number of <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a>
|
||
methods and functions are deprecated: <a class="reference internal" href="../library/importlib.html#importlib.find_loader" title="importlib.find_loader"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.find_loader()</span></code></a> is
|
||
replaced by <a class="reference internal" href="../library/importlib.html#importlib.util.find_spec" title="importlib.util.find_spec"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.find_spec()</span></code></a>;
|
||
<a class="reference internal" href="../library/importlib.html#importlib.machinery.PathFinder.find_module" title="importlib.machinery.PathFinder.find_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.PathFinder.find_module()</span></code></a> is replaced by
|
||
<a class="reference internal" href="../library/importlib.html#importlib.machinery.PathFinder.find_spec" title="importlib.machinery.PathFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.PathFinder.find_spec()</span></code></a>;
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.MetaPathFinder.find_module" title="importlib.abc.MetaPathFinder.find_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder.find_module()</span></code></a> is replaced by
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.MetaPathFinder.find_spec" title="importlib.abc.MetaPathFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder.find_spec()</span></code></a>;
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.PathEntryFinder.find_loader" title="importlib.abc.PathEntryFinder.find_loader"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_loader()</span></code></a> and
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.PathEntryFinder.find_module" title="importlib.abc.PathEntryFinder.find_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find_module()</span></code></a> are replaced by
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.PathEntryFinder.find_spec" title="importlib.abc.PathEntryFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_spec()</span></code></a>; all of the <code class="docutils literal notranslate"><span class="pre">xxxLoader</span></code> ABC
|
||
<code class="docutils literal notranslate"><span class="pre">load_module</span></code> methods (<a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.load_module" title="importlib.abc.Loader.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.load_module()</span></code></a>,
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader.load_module" title="importlib.abc.InspectLoader.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.InspectLoader.load_module()</span></code></a>,
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.FileLoader.load_module" title="importlib.abc.FileLoader.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.FileLoader.load_module()</span></code></a>,
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.SourceLoader.load_module" title="importlib.abc.SourceLoader.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.SourceLoader.load_module()</span></code></a>) should no longer be
|
||
implemented, instead loaders should implement an
|
||
<code class="docutils literal notranslate"><span class="pre">exec_module</span></code> method
|
||
(<a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.exec_module" title="importlib.abc.Loader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.exec_module()</span></code></a>,
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader.exec_module" title="importlib.abc.InspectLoader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.InspectLoader.exec_module()</span></code></a>
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.SourceLoader.exec_module" title="importlib.abc.SourceLoader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.SourceLoader.exec_module()</span></code></a>) and let the import system
|
||
take care of the rest; and
|
||
<a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.module_repr" title="importlib.abc.Loader.module_repr"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.module_repr()</span></code></a>,
|
||
<a class="reference internal" href="../library/importlib.html#importlib.util.module_for_loader" title="importlib.util.module_for_loader"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.util.module_for_loader()</span></code></a>, <a class="reference internal" href="../library/importlib.html#importlib.util.set_loader" title="importlib.util.set_loader"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.util.set_loader()</span></code></a>,
|
||
and <a class="reference internal" href="../library/importlib.html#importlib.util.set_package" title="importlib.util.set_package"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.util.set_package()</span></code></a> are no longer needed because their
|
||
functions are now handled automatically by the import system.</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/imp.html#module-imp" title="imp: Access the implementation of the import statement. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code></a> module is pending deprecation. To keep compatibility with
|
||
Python 2/3 code bases, the module’s removal is currently not scheduled.</p></li>
|
||
<li><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 is pending deprecation and is slated for removal
|
||
in Python 3.6.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">MD5</span></code> as the default <em>digestmod</em> for the <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">hmac.new()</span></code></a> function is
|
||
deprecated. Python 3.6 will require an explicit digest name or constructor as
|
||
<em>digestmod</em> argument.</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 has been documented
|
||
as deprecated in its docstring for quite some time. It now emits a
|
||
<a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> and will be removed completely in Python 3.5.</p></li>
|
||
<li><p>The undocumented <em>endtime</em> argument to <a class="reference internal" href="../library/subprocess.html#subprocess.Popen.wait" title="subprocess.Popen.wait"><code class="xref py py-meth docutils literal notranslate"><span class="pre">subprocess.Popen.wait()</span></code></a> should
|
||
not have been exposed and is hopefully not in use; it is deprecated and
|
||
will mostly likely be removed in Python 3.5.</p></li>
|
||
<li><p>The <em>strict</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 deprecated.</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/plistlib.html#module-plistlib" title="plistlib: Generate and parse Mac OS X plist files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code></a> <a class="reference internal" href="../library/plistlib.html#plistlib.readPlist" title="plistlib.readPlist"><code class="xref py py-func docutils literal notranslate"><span class="pre">readPlist()</span></code></a>,
|
||
<a class="reference internal" href="../library/plistlib.html#plistlib.writePlist" title="plistlib.writePlist"><code class="xref py py-func docutils literal notranslate"><span class="pre">writePlist()</span></code></a>, <a class="reference internal" href="../library/plistlib.html#plistlib.readPlistFromBytes" title="plistlib.readPlistFromBytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">readPlistFromBytes()</span></code></a>, and
|
||
<a class="reference internal" href="../library/plistlib.html#plistlib.writePlistToBytes" title="plistlib.writePlistToBytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">writePlistToBytes()</span></code></a> functions are deprecated in favor of the
|
||
corresponding new functions <a class="reference internal" href="../library/plistlib.html#plistlib.load" title="plistlib.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">load()</span></code></a>, <a class="reference internal" href="../library/plistlib.html#plistlib.dump" title="plistlib.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump()</span></code></a>,
|
||
<a class="reference internal" href="../library/plistlib.html#plistlib.loads" title="plistlib.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">loads()</span></code></a>, and <a class="reference internal" href="../library/plistlib.html#plistlib.dumps" title="plistlib.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">dumps()</span></code></a>. <a class="reference internal" href="../library/plistlib.html#plistlib.Data" title="plistlib.Data"><code class="xref py py-func docutils literal notranslate"><span class="pre">Data()</span></code></a>
|
||
is deprecated in favor of just using the <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> constructor.</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/sysconfig.html#module-sysconfig" title="sysconfig: Python's configuration information"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sysconfig</span></code></a> key <code class="docutils literal notranslate"><span class="pre">SO</span></code> is deprecated, it has been replaced by
|
||
<code class="docutils literal notranslate"><span class="pre">EXT_SUFFIX</span></code>.</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">U</span></code> mode accepted by various <code class="docutils literal notranslate"><span class="pre">open</span></code> functions is deprecated.
|
||
In Python3 it does not do anything useful, and should be replaced by
|
||
appropriate uses of <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.TextIOWrapper</span></code></a> (if needed) and its <em>newline</em>
|
||
argument.</p></li>
|
||
<li><p>The <em>parser</em> argument of <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.iterparse" title="xml.etree.ElementTree.iterparse"><code class="xref py py-func docutils literal notranslate"><span class="pre">xml.etree.ElementTree.iterparse()</span></code></a> has
|
||
been deprecated, as has the <em>html</em> argument of
|
||
<a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLParser" title="xml.etree.ElementTree.XMLParser"><code class="xref py py-func docutils literal notranslate"><span class="pre">XMLParser()</span></code></a>. To prepare for the removal of the
|
||
latter, all arguments to <code class="docutils literal notranslate"><span class="pre">XMLParser</span></code> should be passed by keyword.</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="deprecated-features">
|
||
<h3>Deprecated Features<a class="headerlink" href="#deprecated-features" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>Running <a class="reference internal" href="../library/idle.html#idle"><span class="std std-ref">IDLE</span></a> with the <code class="docutils literal notranslate"><span class="pre">-n</span></code> flag (no subprocess) is deprecated.
|
||
However, the feature will not be removed until <a class="reference external" href="https://bugs.python.org/issue18823">bpo-18823</a> is resolved.</p></li>
|
||
<li><p>The site module adding a “site-python” directory to sys.path, if it
|
||
exists, is deprecated (<a class="reference external" href="https://bugs.python.org/issue19375">bpo-19375</a>).</p></li>
|
||
</ul>
|
||
</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="operating-systems-no-longer-supported">
|
||
<h3>Operating Systems No Longer Supported<a class="headerlink" href="#operating-systems-no-longer-supported" title="Permalink to this headline">¶</a></h3>
|
||
<p>Support for the following operating systems has been removed from the source
|
||
and build tools:</p>
|
||
<ul class="simple">
|
||
<li><p>OS/2 (<a class="reference external" href="https://bugs.python.org/issue16135">bpo-16135</a>).</p></li>
|
||
<li><p>Windows 2000 (changeset e52df05b496a).</p></li>
|
||
<li><p>Windows systems where <code class="docutils literal notranslate"><span class="pre">COMSPEC</span></code> points to <code class="docutils literal notranslate"><span class="pre">command.com</span></code> (<a class="reference external" href="https://bugs.python.org/issue14470">bpo-14470</a>).</p></li>
|
||
<li><p>VMS (<a class="reference external" href="https://bugs.python.org/issue16136">bpo-16136</a>).</p></li>
|
||
</ul>
|
||
</div>
|
||
<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 unmaintained <code class="docutils literal notranslate"><span class="pre">Misc/TextMate</span></code> and <code class="docutils literal notranslate"><span class="pre">Misc/vim</span></code> directories have been
|
||
removed (see the <a class="reference external" href="https://devguide.python.org">devguide</a>
|
||
for suggestions on what to use instead).</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">SO</span></code> makefile macro is removed (it was replaced by the
|
||
<code class="docutils literal notranslate"><span class="pre">SHLIB_SUFFIX</span></code> and <code class="docutils literal notranslate"><span class="pre">EXT_SUFFIX</span></code> macros) (<a class="reference external" href="https://bugs.python.org/issue16754">bpo-16754</a>).</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">PyThreadState.tick_counter</span></code> field has been removed; its value has
|
||
been meaningless since Python 3.2, when the “new GIL” was introduced
|
||
(<a class="reference external" href="https://bugs.python.org/issue19199">bpo-19199</a>).</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">PyLoader</span></code> and <code class="docutils literal notranslate"><span class="pre">PyPycLoader</span></code> have been removed from <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a>.
|
||
(Contributed by Taras Lyapun in <a class="reference external" href="https://bugs.python.org/issue15641">bpo-15641</a>.)</p></li>
|
||
<li><p>The <em>strict</em> argument to <a class="reference internal" href="../library/http.client.html#http.client.HTTPConnection" title="http.client.HTTPConnection"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPConnection</span></code></a> and
|
||
<a class="reference internal" href="../library/http.client.html#http.client.HTTPSConnection" title="http.client.HTTPSConnection"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPSConnection</span></code></a> has been removed. HTTP 0.9-style
|
||
“Simple Responses” are no longer supported.</p></li>
|
||
<li><p>The deprecated <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request.Request</span></code></a> getter and setter methods
|
||
<code class="docutils literal notranslate"><span class="pre">add_data</span></code>, <code class="docutils literal notranslate"><span class="pre">has_data</span></code>, <code class="docutils literal notranslate"><span class="pre">get_data</span></code>, <code class="docutils literal notranslate"><span class="pre">get_type</span></code>, <code class="docutils literal notranslate"><span class="pre">get_host</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">get_selector</span></code>, <code class="docutils literal notranslate"><span class="pre">set_proxy</span></code>, <code class="docutils literal notranslate"><span class="pre">get_origin_req_host</span></code>, and
|
||
<code class="docutils literal notranslate"><span class="pre">is_unverifiable</span></code> have been removed (use direct attribute access instead).</p></li>
|
||
<li><p>Support for loading the deprecated <code class="docutils literal notranslate"><span class="pre">TYPE_INT64</span></code> has been removed from
|
||
<a class="reference internal" href="../library/marshal.html#module-marshal" title="marshal: Convert Python objects to streams of bytes and back (with different constraints)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">marshal</span></code></a>. (Contributed by Dan Riti in <a class="reference external" href="https://bugs.python.org/issue15480">bpo-15480</a>.)</p></li>
|
||
<li><p><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>: positional-only parameters are now required
|
||
to have a valid name.</p></li>
|
||
<li><p><a class="reference internal" href="../reference/datamodel.html#object.__format__" title="object.__format__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__format__()</span></code></a> no longer accepts non-empty format strings, it now
|
||
raises a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> instead. Using a non-empty string has been
|
||
deprecated since Python 3.2. This change has been made to prevent a
|
||
situation where previously working (but incorrect) code would start failing
|
||
if an object gained a __format__ method, which means that your code may now
|
||
raise a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> if you are using an <code class="docutils literal notranslate"><span class="pre">'s'</span></code> format code with objects
|
||
that do not have a __format__ method that handles it. See <a class="reference external" href="https://bugs.python.org/issue7994">bpo-7994</a> for
|
||
background.</p></li>
|
||
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">difflib.SequenceMatcher.isbjunk()</span></code> and
|
||
<code class="xref py py-meth docutils literal notranslate"><span class="pre">difflib.SequenceMatcher.isbpopular()</span></code> were deprecated in 3.2, and have
|
||
now been removed: use <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">in</span> <span class="pre">sm.bjunk</span></code> and
|
||
<code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">in</span> <span class="pre">sm.bpopular</span></code>, where <em>sm</em> is a <a class="reference internal" href="../library/difflib.html#difflib.SequenceMatcher" title="difflib.SequenceMatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">SequenceMatcher</span></code></a> object
|
||
(<a class="reference external" href="https://bugs.python.org/issue13248">bpo-13248</a>).</p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="code-cleanups">
|
||
<h3>Code Cleanups<a class="headerlink" href="#code-cleanups" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>The unused and undocumented internal <code class="docutils literal notranslate"><span class="pre">Scanner</span></code> class has been removed from
|
||
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.</p></li>
|
||
<li><p>The private and effectively unused <code class="docutils literal notranslate"><span class="pre">_gestalt</span></code> module has been removed,
|
||
along with the private <a class="reference internal" href="../library/platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code></a> functions <code class="docutils literal notranslate"><span class="pre">_mac_ver_lookup</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">_mac_ver_gstalt</span></code>, and <code class="docutils literal notranslate"><span class="pre">_bcd2str</span></code>, which would only have ever been called
|
||
on badly broken OSX systems (see <a class="reference external" href="https://bugs.python.org/issue18393">bpo-18393</a>).</p></li>
|
||
<li><p>The hardcoded copies of certain <a class="reference internal" href="../library/stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> constants that were included in
|
||
the <a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a> module namespace have been removed.</p></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="porting-to-python-3-4">
|
||
<h2>Porting to Python 3.4<a class="headerlink" href="#porting-to-python-3-4" 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-command-behavior">
|
||
<h3>Changes in ‘python’ Command Behavior<a class="headerlink" href="#changes-in-python-command-behavior" title="Permalink to this headline">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>In a posix shell, setting the <span class="target" id="index-55"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> environment variable to
|
||
an empty value is equivalent to not setting it at all. However, setting
|
||
<span class="target" id="index-56"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a> to an empty value was <em>not</em> equivalent to not setting it
|
||
at all: setting <span class="target" id="index-57"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a> to an empty value was equivalent to
|
||
setting it to <code class="docutils literal notranslate"><span class="pre">.</span></code>, which leads to confusion when reasoning by analogy to
|
||
how <span class="target" id="index-58"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> works. The behavior now conforms to the posix convention
|
||
for <span class="target" id="index-59"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code>.</p></li>
|
||
<li><p>The [X refs, Y blocks] output of a debug (<code class="docutils literal notranslate"><span class="pre">--with-pydebug</span></code>) build of the
|
||
CPython interpreter is now off by default. It can be re-enabled using the
|
||
<code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">showrefcount</span></code> option. (Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue17323">bpo-17323</a>.)</p></li>
|
||
<li><p>The python command and most stdlib scripts (as well as <a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a>) now
|
||
output <code class="docutils literal notranslate"><span class="pre">--version</span></code> information to <code class="docutils literal notranslate"><span class="pre">stdout</span></code> instead of <code class="docutils literal notranslate"><span class="pre">stderr</span></code> (for
|
||
issue list see <a class="reference internal" href="#other-improvements-3-4"><span class="std std-ref">Other Improvements</span></a> above).</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>The ABCs defined in <a class="reference internal" href="../library/importlib.html#module-importlib.abc" title="importlib.abc: Abstract base classes related to import"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.abc</span></code></a> now either raise the appropriate
|
||
exception or return a default value instead of raising
|
||
<a class="reference internal" href="../library/exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> blindly. This will only affect code calling
|
||
<a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a> and falling through all the way to the ABCs. For compatibility,
|
||
catch both <a class="reference internal" href="../library/exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> or the appropriate exception as needed.</p></li>
|
||
<li><p>The module type now initializes the <a class="reference internal" href="../reference/import.html#__package__" title="__package__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__package__</span></code></a> and <a class="reference internal" href="../reference/import.html#__loader__" title="__loader__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__loader__</span></code></a>
|
||
attributes to <code class="docutils literal notranslate"><span class="pre">None</span></code> by default. To determine if these attributes were set
|
||
in a backwards-compatible fashion, use e.g.
|
||
<code class="docutils literal notranslate"><span class="pre">getattr(module,</span> <span class="pre">'__loader__',</span> <span class="pre">None)</span> <span class="pre">is</span> <span class="pre">not</span> <span class="pre">None</span></code>. (<a class="reference external" href="https://bugs.python.org/issue17115">bpo-17115</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/importlib.html#importlib.util.module_for_loader" title="importlib.util.module_for_loader"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.util.module_for_loader()</span></code></a> now sets <code class="docutils literal notranslate"><span class="pre">__loader__</span></code> and
|
||
<code class="docutils literal notranslate"><span class="pre">__package__</span></code> unconditionally to properly support reloading. If this is not
|
||
desired then you will need to set these attributes manually. You can use
|
||
<code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.module_to_load()</span></code> for module management.</p></li>
|
||
<li><p>Import now resets relevant attributes (e.g. <code class="docutils literal notranslate"><span class="pre">__name__</span></code>, <code class="docutils literal notranslate"><span class="pre">__loader__</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">__package__</span></code>, <code class="docutils literal notranslate"><span class="pre">__file__</span></code>, <code class="docutils literal notranslate"><span class="pre">__cached__</span></code>) unconditionally when reloading.
|
||
Note that this restores a pre-3.3 behavior in that it means a module is
|
||
re-found when re-loaded (<a class="reference external" href="https://bugs.python.org/issue19413">bpo-19413</a>).</p></li>
|
||
<li><p>Frozen packages no longer set <code class="docutils literal notranslate"><span class="pre">__path__</span></code> to a list containing the package
|
||
name, they now set it to an empty list. The previous behavior could cause
|
||
the import system to do the wrong thing on submodule imports if there was
|
||
also a directory with the same name as the frozen package. The correct way
|
||
to determine if a module is a package or not is to use <code class="docutils literal notranslate"><span class="pre">hasattr(module,</span>
|
||
<span class="pre">'__path__')</span></code> (<a class="reference external" href="https://bugs.python.org/issue18065">bpo-18065</a>).</p></li>
|
||
<li><p>Frozen modules no longer define a <code class="docutils literal notranslate"><span class="pre">__file__</span></code> attribute. It’s semantically
|
||
incorrect for frozen modules to set the attribute as they are not loaded from
|
||
any explicit location. If you must know that a module comes from frozen code
|
||
then you can see if the module’s <code class="docutils literal notranslate"><span class="pre">__spec__.location</span></code> is set to <code class="docutils literal notranslate"><span class="pre">'frozen'</span></code>,
|
||
check if the loader is a subclass of
|
||
<a class="reference internal" href="../library/importlib.html#importlib.machinery.FrozenImporter" title="importlib.machinery.FrozenImporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.FrozenImporter</span></code></a>,
|
||
or if Python 2 compatibility is necessary you can use <code class="xref py py-func docutils literal notranslate"><span class="pre">imp.is_frozen()</span></code>.</p></li>
|
||
<li><p><a class="reference internal" href="../library/py_compile.html#py_compile.compile" title="py_compile.compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">py_compile.compile()</span></code></a> now raises <a class="reference internal" href="../library/exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> if the file path
|
||
it would write to is a symlink or a non-regular file. This is to act as a
|
||
warning that import will overwrite those files with a regular file regardless
|
||
of what type of file path they were originally.</p></li>
|
||
<li><p><a class="reference internal" href="../library/importlib.html#importlib.abc.SourceLoader.get_source" title="importlib.abc.SourceLoader.get_source"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.SourceLoader.get_source()</span></code></a> no longer raises
|
||
<a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> when the source code being loaded triggers 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> or <a class="reference internal" href="../library/exceptions.html#UnicodeDecodeError" title="UnicodeDecodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeDecodeError</span></code></a>. As <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> is
|
||
meant to be raised only when source code cannot be found but it should, it was
|
||
felt to be over-reaching/overloading of that meaning when the source code is
|
||
found but improperly structured. If you were catching ImportError before and
|
||
wish to continue to ignore syntax or decoding issues, catch all three
|
||
exceptions now.</p></li>
|
||
<li><p><a class="reference internal" href="../library/functools.html#functools.update_wrapper" title="functools.update_wrapper"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.update_wrapper()</span></code></a> and <a class="reference internal" href="../library/functools.html#functools.wraps" title="functools.wraps"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.wraps()</span></code></a> now correctly
|
||
set the <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute to the function being wrapped, even if
|
||
that function also had its <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute set. This means
|
||
<code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attributes now correctly link a stack of decorated
|
||
functions rather than every <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute in the chain
|
||
referring to the innermost function. Introspection libraries that
|
||
assumed the previous behaviour was intentional can use
|
||
<a class="reference internal" href="../library/inspect.html#inspect.unwrap" title="inspect.unwrap"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.unwrap()</span></code></a> to access the first function in the chain that has
|
||
no <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute.</p></li>
|
||
<li><p><a class="reference internal" href="../library/inspect.html#inspect.getfullargspec" title="inspect.getfullargspec"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getfullargspec()</span></code></a> has been reimplemented on top of
|
||
<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> and hence handles a much wider variety of callable
|
||
objects than it did in the past. It is expected that additional builtin and
|
||
extension module callables will gain signature metadata over the course of
|
||
the Python 3.4 series. Code that assumes that
|
||
<a class="reference internal" href="../library/inspect.html#inspect.getfullargspec" title="inspect.getfullargspec"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getfullargspec()</span></code></a> will fail on non-Python callables may need
|
||
to be adjusted accordingly.</p></li>
|
||
<li><p><a class="reference internal" href="../library/importlib.html#importlib.machinery.PathFinder" title="importlib.machinery.PathFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.PathFinder</span></code></a> now passes on the current working
|
||
directory to objects in <a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_hooks</span></code></a> for the empty string. This
|
||
results 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> never containing <code class="docutils literal notranslate"><span class="pre">''</span></code>, thus
|
||
iterating through <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> based on <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>
|
||
will not find all keys. A module’s <code class="docutils literal notranslate"><span class="pre">__file__</span></code> when imported in the current
|
||
working directory will also now have an absolute path, including when using
|
||
<code class="docutils literal notranslate"><span class="pre">-m</span></code> with the interpreter (except for <code class="docutils literal notranslate"><span class="pre">__main__.__file__</span></code> when a script
|
||
has been executed directly using a relative path) (Contributed by Brett
|
||
Cannon in <a class="reference external" href="https://bugs.python.org/issue18416">bpo-18416</a>). is specified on the command-line)
|
||
(<a class="reference external" href="https://bugs.python.org/issue18416">bpo-18416</a>).</p></li>
|
||
<li><p>The removal of the <em>strict</em> argument to <a class="reference internal" href="../library/http.client.html#http.client.HTTPConnection" title="http.client.HTTPConnection"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPConnection</span></code></a>
|
||
and <a class="reference internal" href="../library/http.client.html#http.client.HTTPSConnection" title="http.client.HTTPSConnection"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPSConnection</span></code></a> changes the meaning of the
|
||
remaining arguments if you are specifying them positionally rather than by
|
||
keyword. If you’ve been paying attention to deprecation warnings your code
|
||
should already be specifying any additional arguments via keywords.</p></li>
|
||
<li><p>Strings between <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">...</span></code> statements now <em>always</em> raise
|
||
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>. Previously if there was no leading docstring, an
|
||
interstitial string would sometimes be ignored. This brings CPython into
|
||
compliance with the language spec; Jython and PyPy already were.
|
||
(<a class="reference external" href="https://bugs.python.org/issue17434">bpo-17434</a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.getpeercert" title="ssl.SSLSocket.getpeercert"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLSocket.getpeercert()</span></code></a> and <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">ssl.SSLSocket.do_handshake()</span></code></a>
|
||
now raise an <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> with <code class="docutils literal notranslate"><span class="pre">ENOTCONN</span></code> when the <code class="docutils literal notranslate"><span class="pre">SSLSocket</span></code> is not
|
||
connected, instead of the previous behavior of raising an
|
||
<a class="reference internal" href="../library/exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a>. In addition, <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.getpeercert" title="ssl.SSLSocket.getpeercert"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getpeercert()</span></code></a>
|
||
will raise a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> if the handshake has not yet been done.</p></li>
|
||
<li><p><a class="reference internal" href="../library/base64.html#base64.b32decode" title="base64.b32decode"><code class="xref py py-func docutils literal notranslate"><span class="pre">base64.b32decode()</span></code></a> now raises a <a class="reference internal" href="../library/binascii.html#binascii.Error" title="binascii.Error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">binascii.Error</span></code></a> when the
|
||
input string contains non-b32-alphabet characters, instead of a
|
||
<a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>. This particular <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> was missed when the other
|
||
<a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>s were converted. (Contributed by Serhiy Storchaka in
|
||
<a class="reference external" href="https://bugs.python.org/issue18011">bpo-18011</a>.) Note: this change was also inadvertently applied in Python
|
||
3.3.3.</p></li>
|
||
<li><p>The <code class="xref py py-attr docutils literal notranslate"><span class="pre">file</span></code> attribute is now automatically closed when
|
||
the creating <code class="xref py py-class docutils literal notranslate"><span class="pre">cgi.FieldStorage</span></code> instance is garbage collected. If you
|
||
were pulling the file object out separately from the <code class="xref py py-class docutils literal notranslate"><span class="pre">cgi.FieldStorage</span></code>
|
||
instance and not keeping the instance alive, then you should either store the
|
||
entire <code class="xref py py-class docutils literal notranslate"><span class="pre">cgi.FieldStorage</span></code> instance or read the contents of the file
|
||
before the <code class="xref py py-class docutils literal notranslate"><span class="pre">cgi.FieldStorage</span></code> instance is garbage collected.</p></li>
|
||
<li><p>Calling <code class="docutils literal notranslate"><span class="pre">read</span></code> or <code class="docutils literal notranslate"><span class="pre">write</span></code> on a closed SSL socket now raises an
|
||
informative <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> rather than the previous more mysterious
|
||
<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> (<a class="reference external" href="https://bugs.python.org/issue9177">bpo-9177</a>).</p></li>
|
||
<li><p><a class="reference internal" href="../reference/datamodel.html#slice.indices" title="slice.indices"><code class="xref py py-meth docutils literal notranslate"><span class="pre">slice.indices()</span></code></a> no longer produces an <a class="reference internal" href="../library/exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a> for huge
|
||
values. As a consequence of this fix, <a class="reference internal" href="../reference/datamodel.html#slice.indices" title="slice.indices"><code class="xref py py-meth docutils literal notranslate"><span class="pre">slice.indices()</span></code></a> now raises a
|
||
<a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> if given a negative length; previously it returned nonsense
|
||
values (<a class="reference external" href="https://bugs.python.org/issue14794">bpo-14794</a>).</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a> constructor, unlike the <a class="reference internal" href="../library/cmath.html#module-cmath" title="cmath: Mathematical functions for complex numbers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">cmath</span></code></a> functions, was
|
||
incorrectly accepting <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> values if an object’s <code class="docutils literal notranslate"><span class="pre">__complex__</span></code>
|
||
special method returned one. This now raises a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>.
|
||
(<a class="reference external" href="https://bugs.python.org/issue16290">bpo-16290</a>.)</p></li>
|
||
<li><p>The <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> constructor in 3.2 and 3.3 erroneously accepts <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>
|
||
values for the <em>base</em> parameter. It is unlikely anyone was doing this, but
|
||
if so, it will now raise a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue16772">bpo-16772</a>).</p></li>
|
||
<li><p>Defaults for keyword-only arguments are now evaluated <em>after</em> defaults for
|
||
regular keyword arguments, instead of before. Hopefully no one wrote any
|
||
code that depends on the previous buggy behavior (<a class="reference external" href="https://bugs.python.org/issue16967">bpo-16967</a>).</p></li>
|
||
<li><p>Stale thread states are now cleared after <a class="reference internal" href="../library/os.html#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">fork()</span></code></a>. This may cause
|
||
some system resources to be released that previously were incorrectly kept
|
||
perpetually alive (for example, database connections kept in thread-local
|
||
storage). (<a class="reference external" href="https://bugs.python.org/issue17094">bpo-17094</a>.)</p></li>
|
||
<li><p>Parameter names in <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code> dicts are now mangled properly,
|
||
similarly to <code class="docutils literal notranslate"><span class="pre">__kwdefaults__</span></code>. (Contributed by Yury Selivanov in
|
||
<a class="reference external" href="https://bugs.python.org/issue20625">bpo-20625</a>.)</p></li>
|
||
<li><p><a class="reference internal" href="../library/hashlib.html#hashlib.hash.name" title="hashlib.hash.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">hashlib.hash.name</span></code></a> now always returns the identifier in lower case.
|
||
Previously some builtin hashes had uppercase names, but now that it is a
|
||
formal public interface the naming has been made consistent (<a class="reference external" href="https://bugs.python.org/issue18532">bpo-18532</a>).</p></li>
|
||
<li><p>Because <a class="reference internal" href="../library/unittest.html#unittest.TestSuite" title="unittest.TestSuite"><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest.TestSuite</span></code></a> now drops references to tests after they
|
||
are run, test harnesses that re-use a <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">TestSuite</span></code></a> to re-run
|
||
a set of tests may fail. Test suites should not be re-used in this fashion
|
||
since it means state is retained between test runs, breaking the test
|
||
isolation that <a class="reference internal" href="../library/unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code></a> is designed to provide. However, if the lack
|
||
of isolation is considered acceptable, the old behavior can be restored by
|
||
creating a <a class="reference internal" href="../library/unittest.html#unittest.TestSuite" title="unittest.TestSuite"><code class="xref py py-mod docutils literal notranslate"><span class="pre">TestSuite</span></code></a> subclass that defines a
|
||
<code class="docutils literal notranslate"><span class="pre">_removeTestAtIndex</span></code> method that does nothing (see
|
||
<a class="reference internal" href="../library/unittest.html#unittest.TestSuite.__iter__" title="unittest.TestSuite.__iter__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TestSuite.__iter__()</span></code></a>) (<a class="reference external" href="https://bugs.python.org/issue11798">bpo-11798</a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code></a> now uses <a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a> for command line parsing. There are
|
||
certain invalid command forms that used to work that are no longer allowed;
|
||
in theory this should not cause backward compatibility issues since the
|
||
disallowed command forms didn’t make any sense and are unlikely to be in use.</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>, <a class="reference internal" href="../library/re.html#re.findall" title="re.findall"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.findall()</span></code></a>, and <a class="reference internal" href="../library/re.html#re.sub" title="re.sub"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.sub()</span></code></a> functions, and
|
||
the <code class="xref py py-meth docutils literal notranslate"><span class="pre">group()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">groups()</span></code> methods of
|
||
<code class="docutils literal notranslate"><span class="pre">match</span></code> objects now always return a <em>bytes</em> object when the string
|
||
to be matched is a <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a>. Previously the return type
|
||
matched the input type, so if your code was depending on the return value
|
||
being, say, a <code class="docutils literal notranslate"><span class="pre">bytearray</span></code>, you will need to change your code.</p></li>
|
||
<li><p><a class="reference internal" href="../library/audioop.html#module-audioop" title="audioop: Manipulate raw audio data."><code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code></a> functions now raise an error immediately if passed string
|
||
input, instead of failing randomly later on (<a class="reference external" href="https://bugs.python.org/issue16685">bpo-16685</a>).</p></li>
|
||
<li><p>The new <em>convert_charrefs</em> argument to <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>
|
||
currently defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code> for backward compatibility, but will
|
||
eventually be changed to default to <code class="docutils literal notranslate"><span class="pre">True</span></code>. It is recommended that you add
|
||
this keyword, with the appropriate value, to any
|
||
<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> calls in your code (<a class="reference external" href="https://bugs.python.org/issue13633">bpo-13633</a>).</p></li>
|
||
<li><p>Since the <em>digestmod</em> argument to the <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">hmac.new()</span></code></a> function will in the
|
||
future have no default, all calls to <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">hmac.new()</span></code></a> should be changed to
|
||
explicitly specify a <em>digestmod</em> (<a class="reference external" href="https://bugs.python.org/issue17276">bpo-17276</a>).</p></li>
|
||
<li><p>Calling <a class="reference internal" href="../library/sysconfig.html#sysconfig.get_config_var" title="sysconfig.get_config_var"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconfig.get_config_var()</span></code></a> with the <code class="docutils literal notranslate"><span class="pre">SO</span></code> key, or looking
|
||
<code class="docutils literal notranslate"><span class="pre">SO</span></code> up in the results of a call to <a class="reference internal" href="../library/sysconfig.html#sysconfig.get_config_vars" title="sysconfig.get_config_vars"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconfig.get_config_vars()</span></code></a>
|
||
is deprecated. This key should be replaced by <code class="docutils literal notranslate"><span class="pre">EXT_SUFFIX</span></code> or
|
||
<code class="docutils literal notranslate"><span class="pre">SHLIB_SUFFIX</span></code>, depending on the context (<a class="reference external" href="https://bugs.python.org/issue19555">bpo-19555</a>).</p></li>
|
||
<li><p>Any calls to <code class="docutils literal notranslate"><span class="pre">open</span></code> functions that specify <code class="docutils literal notranslate"><span class="pre">U</span></code> should be modified.
|
||
<code class="docutils literal notranslate"><span class="pre">U</span></code> is ineffective in Python3 and will eventually raise an error if used.
|
||
Depending on the function, the equivalent of its old Python2 behavior can be
|
||
achieved using either a <em>newline</em> argument, or if necessary by wrapping the
|
||
stream in <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-mod docutils literal notranslate"><span class="pre">TextIOWrapper</span></code></a> to use its <em>newline</em> argument
|
||
(<a class="reference external" href="https://bugs.python.org/issue15204">bpo-15204</a>).</p></li>
|
||
<li><p>If you use <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> in a script and desire that pip
|
||
<em>not</em> be installed, you must add <code class="docutils literal notranslate"><span class="pre">--without-pip</span></code> to your command
|
||
invocation.</p></li>
|
||
<li><p>The default behavior of <a class="reference internal" href="../library/json.html#json.dump" title="json.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.dump()</span></code></a> and <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> when
|
||
an indent is specified has changed: it no longer produces trailing
|
||
spaces after the item separating commas at the ends of lines. This
|
||
will matter only if you have tests that are doing white-space-sensitive
|
||
comparisons of such output (<a class="reference external" href="https://bugs.python.org/issue16333">bpo-16333</a>).</p></li>
|
||
<li><p><a class="reference internal" href="../library/doctest.html#module-doctest" title="doctest: Test pieces of code within docstrings."><code class="xref py py-mod docutils literal notranslate"><span class="pre">doctest</span></code></a> now looks for doctests in extension module <code class="docutils literal notranslate"><span class="pre">__doc__</span></code>
|
||
strings, so if your doctest test discovery includes extension modules that
|
||
have things that look like doctests in them you may see test failures you’ve
|
||
never seen before when running your tests (<a class="reference external" href="https://bugs.python.org/issue3158">bpo-3158</a>).</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a> module has been slightly refactored as
|
||
part of the Python startup improvements. As a consequence of this, it is no
|
||
longer the case that importing <a class="reference internal" href="../library/collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a> automatically imports
|
||
<a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a>. If your program depended on the (undocumented)
|
||
implicit import, you will need to add an explicit <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">collections.abc</span></code>
|
||
(<a class="reference external" href="https://bugs.python.org/issue20784">bpo-20784</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><a class="reference internal" href="../c-api/veryhigh.html#c.PyEval_EvalFrameEx" title="PyEval_EvalFrameEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_EvalFrameEx()</span></code></a>, <a class="reference internal" href="../c-api/object.html#c.PyObject_Repr" title="PyObject_Repr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Repr()</span></code></a>, and
|
||
<a class="reference internal" href="../c-api/object.html#c.PyObject_Str" title="PyObject_Str"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Str()</span></code></a>, along with some other internal C APIs, now include
|
||
a debugging assertion that ensures they are not used in situations where
|
||
they may silently discard a currently active exception. In cases where
|
||
discarding the active exception is expected and desired (for example,
|
||
because it has already been saved locally with <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Fetch" title="PyErr_Fetch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Fetch()</span></code></a> or
|
||
is being deliberately replaced with a different exception), an explicit
|
||
<a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Clear" title="PyErr_Clear"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Clear()</span></code></a> call will be needed to avoid triggering the
|
||
assertion when invoking these operations (directly or indirectly) and
|
||
running against a version of Python that is compiled with assertions
|
||
enabled.</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetImportError" title="PyErr_SetImportError"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetImportError()</span></code></a> now sets <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> when its <strong>msg</strong>
|
||
argument is not set. Previously only <code class="docutils literal notranslate"><span class="pre">NULL</span></code> was returned with no exception
|
||
set.</p></li>
|
||
<li><p>The result of the <a class="reference internal" href="../c-api/veryhigh.html#c.PyOS_ReadlineFunctionPointer" title="PyOS_ReadlineFunctionPointer"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyOS_ReadlineFunctionPointer</span></code></a> callback must
|
||
now be a string allocated by <a class="reference internal" href="../c-api/memory.html#c.PyMem_RawMalloc" title="PyMem_RawMalloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawMalloc()</span></code></a> or
|
||
<a class="reference internal" href="../c-api/memory.html#c.PyMem_RawRealloc" title="PyMem_RawRealloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawRealloc()</span></code></a>, or <em>NULL</em> if an error occurred, instead of a
|
||
string allocated by <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a> or <a class="reference internal" href="../c-api/memory.html#c.PyMem_Realloc" title="PyMem_Realloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Realloc()</span></code></a>
|
||
(<a class="reference external" href="https://bugs.python.org/issue16742">bpo-16742</a>)</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_set_key_value" title="PyThread_set_key_value"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_set_key_value()</span></code></a> now always set the value. In Python
|
||
3.3, the function did nothing if the key already exists (if the current
|
||
value is a non-NULL pointer).</p></li>
|
||
<li><p>The <code class="docutils literal notranslate"><span class="pre">f_tstate</span></code> (thread state) field of the <a class="reference internal" href="../c-api/veryhigh.html#c.PyFrameObject" title="PyFrameObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyFrameObject</span></code></a>
|
||
structure has been removed to fix a bug: see <a class="reference external" href="https://bugs.python.org/issue14432">bpo-14432</a> for the
|
||
rationale.</p></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="changed-in-3-4-3">
|
||
<h2>Changed in 3.4.3<a class="headerlink" href="#changed-in-3-4-3" title="Permalink to this headline">¶</a></h2>
|
||
<div class="section" id="pep-476-enabling-certificate-verification-by-default-for-stdlib-http-clients">
|
||
<span id="pep-476"></span><h3>PEP 476: Enabling certificate verification by default for stdlib http clients<a class="headerlink" href="#pep-476-enabling-certificate-verification-by-default-for-stdlib-http-clients" title="Permalink to this headline">¶</a></h3>
|
||
<p><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 modules which use it, such as <a class="reference internal" href="../library/urllib.request.html#module-urllib.request" title="urllib.request: Extensible library for opening URLs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request</span></code></a> and
|
||
<a class="reference internal" href="../library/xmlrpc.client.html#module-xmlrpc.client" title="xmlrpc.client: XML-RPC client access."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpc.client</span></code></a>, will now verify that the server presents a certificate
|
||
which is signed by a CA in the platform trust store and whose hostname matches
|
||
the hostname being requested by default, significantly improving security for
|
||
many applications.</p>
|
||
<p>For applications which require the old previous behavior, they can pass an
|
||
alternate context:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">urllib.request</span>
|
||
<span class="kn">import</span> <span class="nn">ssl</span>
|
||
|
||
<span class="c1"># This disables all verification</span>
|
||
<span class="n">context</span> <span class="o">=</span> <span class="n">ssl</span><span class="o">.</span><span class="n">_create_unverified_context</span><span class="p">()</span>
|
||
|
||
<span class="c1"># This allows using a specific certificate for the host, which doesn't need</span>
|
||
<span class="c1"># to be in the trust store</span>
|
||
<span class="n">context</span> <span class="o">=</span> <span class="n">ssl</span><span class="o">.</span><span class="n">create_default_context</span><span class="p">(</span><span class="n">cafile</span><span class="o">=</span><span class="s2">"/path/to/file.crt"</span><span class="p">)</span>
|
||
|
||
<span class="n">urllib</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s2">"https://invalid-cert"</span><span class="p">,</span> <span class="n">context</span><span class="o">=</span><span class="n">context</span><span class="p">)</span>
|
||
</pre></div>
|
||
</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.4</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-453-explicit-bootstrapping-of-pip-in-python-installations">PEP 453: Explicit Bootstrapping of PIP in Python Installations</a><ul>
|
||
<li><a class="reference internal" href="#bootstrapping-pip-by-default">Bootstrapping pip By Default</a></li>
|
||
<li><a class="reference internal" href="#documentation-changes">Documentation Changes</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#pep-446-newly-created-file-descriptors-are-non-inheritable">PEP 446: Newly Created File Descriptors Are Non-Inheritable</a></li>
|
||
<li><a class="reference internal" href="#improvements-to-codec-handling">Improvements to Codec Handling</a></li>
|
||
<li><a class="reference internal" href="#pep-451-a-modulespec-type-for-the-import-system">PEP 451: A ModuleSpec Type for the Import System</a></li>
|
||
<li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#new-modules">New Modules</a><ul>
|
||
<li><a class="reference internal" href="#asyncio">asyncio</a></li>
|
||
<li><a class="reference internal" href="#ensurepip">ensurepip</a></li>
|
||
<li><a class="reference internal" href="#enum">enum</a></li>
|
||
<li><a class="reference internal" href="#pathlib">pathlib</a></li>
|
||
<li><a class="reference internal" href="#selectors">selectors</a></li>
|
||
<li><a class="reference internal" href="#statistics">statistics</a></li>
|
||
<li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
|
||
<li><a class="reference internal" href="#abc">abc</a></li>
|
||
<li><a class="reference internal" href="#aifc">aifc</a></li>
|
||
<li><a class="reference internal" href="#argparse">argparse</a></li>
|
||
<li><a class="reference internal" href="#audioop">audioop</a></li>
|
||
<li><a class="reference internal" href="#base64">base64</a></li>
|
||
<li><a class="reference internal" href="#collections">collections</a></li>
|
||
<li><a class="reference internal" href="#colorsys">colorsys</a></li>
|
||
<li><a class="reference internal" href="#contextlib">contextlib</a></li>
|
||
<li><a class="reference internal" href="#dbm">dbm</a></li>
|
||
<li><a class="reference internal" href="#dis">dis</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="#filecmp">filecmp</a></li>
|
||
<li><a class="reference internal" href="#functools">functools</a></li>
|
||
<li><a class="reference internal" href="#gc">gc</a></li>
|
||
<li><a class="reference internal" href="#glob">glob</a></li>
|
||
<li><a class="reference internal" href="#hashlib">hashlib</a></li>
|
||
<li><a class="reference internal" href="#hmac">hmac</a></li>
|
||
<li><a class="reference internal" href="#html">html</a></li>
|
||
<li><a class="reference internal" href="#http">http</a></li>
|
||
<li><a class="reference internal" href="#idlelib-and-idle">idlelib and IDLE</a></li>
|
||
<li><a class="reference internal" href="#importlib">importlib</a></li>
|
||
<li><a class="reference internal" href="#inspect">inspect</a></li>
|
||
<li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
|
||
<li><a class="reference internal" href="#logging">logging</a></li>
|
||
<li><a class="reference internal" href="#marshal">marshal</a></li>
|
||
<li><a class="reference internal" href="#mmap">mmap</a></li>
|
||
<li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
|
||
<li><a class="reference internal" href="#operator">operator</a></li>
|
||
<li><a class="reference internal" href="#os">os</a></li>
|
||
<li><a class="reference internal" href="#pdb">pdb</a></li>
|
||
<li><a class="reference internal" href="#pickle">pickle</a></li>
|
||
<li><a class="reference internal" href="#plistlib">plistlib</a></li>
|
||
<li><a class="reference internal" href="#poplib">poplib</a></li>
|
||
<li><a class="reference internal" href="#pprint">pprint</a></li>
|
||
<li><a class="reference internal" href="#pty">pty</a></li>
|
||
<li><a class="reference internal" href="#pydoc">pydoc</a></li>
|
||
<li><a class="reference internal" href="#re">re</a></li>
|
||
<li><a class="reference internal" href="#resource">resource</a></li>
|
||
<li><a class="reference internal" href="#select">select</a></li>
|
||
<li><a class="reference internal" href="#shelve">shelve</a></li>
|
||
<li><a class="reference internal" href="#shutil">shutil</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="#socket">socket</a></li>
|
||
<li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
|
||
<li><a class="reference internal" href="#ssl">ssl</a></li>
|
||
<li><a class="reference internal" href="#stat">stat</a></li>
|
||
<li><a class="reference internal" href="#struct">struct</a></li>
|
||
<li><a class="reference internal" href="#subprocess">subprocess</a></li>
|
||
<li><a class="reference internal" href="#sunau">sunau</a></li>
|
||
<li><a class="reference internal" href="#sys">sys</a></li>
|
||
<li><a class="reference internal" href="#tarfile">tarfile</a></li>
|
||
<li><a class="reference internal" href="#textwrap">textwrap</a></li>
|
||
<li><a class="reference internal" href="#threading">threading</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="#urllib">urllib</a></li>
|
||
<li><a class="reference internal" href="#unittest">unittest</a></li>
|
||
<li><a class="reference internal" href="#venv">venv</a></li>
|
||
<li><a class="reference internal" href="#wave">wave</a></li>
|
||
<li><a class="reference internal" href="#weakref">weakref</a></li>
|
||
<li><a class="reference internal" href="#xml-etree">xml.etree</a></li>
|
||
<li><a class="reference internal" href="#zipfile">zipfile</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#cpython-implementation-changes">CPython Implementation Changes</a><ul>
|
||
<li><a class="reference internal" href="#pep-445-customization-of-cpython-memory-allocators">PEP 445: Customization of CPython Memory Allocators</a></li>
|
||
<li><a class="reference internal" href="#pep-442-safe-object-finalization">PEP 442: Safe Object Finalization</a></li>
|
||
<li><a class="reference internal" href="#pep-456-secure-and-interchangeable-hash-algorithm">PEP 456: Secure and Interchangeable Hash Algorithm</a></li>
|
||
<li><a class="reference internal" href="#pep-436-argument-clinic">PEP 436: Argument Clinic</a></li>
|
||
<li><a class="reference internal" href="#other-build-and-c-api-changes">Other Build and C API Changes</a></li>
|
||
<li><a class="reference internal" href="#other-improvements">Other Improvements</a></li>
|
||
<li><a class="reference internal" href="#significant-optimizations">Significant Optimizations</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
|
||
<li><a class="reference internal" href="#deprecations-in-the-python-api">Deprecations in the Python API</a></li>
|
||
<li><a class="reference internal" href="#deprecated-features">Deprecated Features</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#removed">Removed</a><ul>
|
||
<li><a class="reference internal" href="#operating-systems-no-longer-supported">Operating Systems No Longer Supported</a></li>
|
||
<li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
|
||
<li><a class="reference internal" href="#code-cleanups">Code Cleanups</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#porting-to-python-3-4">Porting to Python 3.4</a><ul>
|
||
<li><a class="reference internal" href="#changes-in-python-command-behavior">Changes in ‘python’ Command 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="#changed-in-3-4-3">Changed in 3.4.3</a><ul>
|
||
<li><a class="reference internal" href="#pep-476-enabling-certificate-verification-by-default-for-stdlib-http-clients">PEP 476: Enabling certificate verification by default for stdlib http clients</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="3.5.html"
|
||
title="previous chapter">What’s New In Python 3.5</a></p>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="3.3.html"
|
||
title="next chapter">What’s New In Python 3.3</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.4.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.3.html" title="What’s New In Python 3.3"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.5.html" title="What’s New In Python 3.5"
|
||
>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> |