1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
<html xmlns="http://www.w3.org/1999/xhtml">
7
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9
<title>What’s New In Python 3.4 — Python 3.5.2 documentation</title>
11
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
12
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
14
<script type="text/javascript">
15
var DOCUMENTATION_OPTIONS = {
18
COLLAPSE_INDEX: false,
23
<script type="text/javascript" src="../_static/jquery.js"></script>
24
<script type="text/javascript" src="../_static/underscore.js"></script>
25
<script type="text/javascript" src="../_static/doctools.js"></script>
26
<script type="text/javascript" src="../_static/sidebar.js"></script>
27
<link rel="search" type="application/opensearchdescription+xml"
28
title="Search within Python 3.5.2 documentation"
29
href="../_static/opensearch.xml"/>
30
<link rel="author" title="About these documents" href="../about.html" />
31
<link rel="copyright" title="Copyright" href="../copyright.html" />
32
<link rel="top" title="Python 3.5.2 documentation" href="../contents.html" />
33
<link rel="up" title="What’s New in Python" href="index.html" />
34
<link rel="next" title="What’s New In Python 3.3" href="3.3.html" />
35
<link rel="prev" title="What’s New In Python 3.5" href="3.5.html" />
36
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
38
<script type="text/javascript" src="../_static/copybutton.js"></script>
39
<script type="text/javascript" src="../_static/version_switch.js"></script>
45
<body role="document">
46
<div class="related" role="navigation" aria-label="related navigation">
49
<li class="right" style="margin-right: 10px">
50
<a href="../genindex.html" title="General Index"
51
accesskey="I">index</a></li>
53
<a href="../py-modindex.html" title="Python Module Index"
56
<a href="3.3.html" title="What’s New In Python 3.3"
57
accesskey="N">next</a> |</li>
59
<a href="3.5.html" title="What’s New In Python 3.5"
60
accesskey="P">previous</a> |</li>
61
<li><img src="../_static/py.png" alt=""
62
style="vertical-align: middle; margin-top: -1px"/></li>
63
<li><a href="https://www.python.org/">Python</a> »</li>
65
<span class="version_switcher_placeholder">3.5.2</span>
66
<a href="../index.html">Documentation </a> »
69
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> »</li>
73
<div class="inline-search" style="display: none" role="search">
74
<form class="inline-search" action="../search.html" method="get">
75
<input placeholder="Quick search" type="text" name="q" />
76
<input type="submit" value="Go" />
77
<input type="hidden" name="check_keywords" value="yes" />
78
<input type="hidden" name="area" value="default" />
81
<script type="text/javascript">$('.inline-search').show(0);</script>
88
<div class="document">
89
<div class="documentwrapper">
90
<div class="bodywrapper">
91
<div class="body" role="main">
93
<div class="section" id="what-s-new-in-python-3-4">
94
<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>
95
<table class="docutils field-list" frame="void" rules="none">
96
<col class="field-name" />
97
<col class="field-body" />
99
<tr class="field-odd field"><th class="field-name">Author:</th><td class="field-body">R. David Murray <<a class="reference external" href="mailto:rdmurray%40bitdance.com">rdmurray<span>@</span>bitdance<span>.</span>com</a>> (Editor)</td>
103
<p>This article explains the new features in Python 3.4, compared to 3.3.
104
Python 3.4 was released on March 16, 2014. For full details, see the
105
<a class="reference external" href="https://docs.python.org/3.4/whatsnew/changelog.html">changelog</a>.</p>
106
<div class="admonition seealso">
107
<p class="first admonition-title">See also</p>
108
<p class="last"><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>
110
<div class="section" id="summary-release-highlights">
111
<h2>Summary – Release Highlights<a class="headerlink" href="#summary-release-highlights" title="Permalink to this headline">¶</a></h2>
112
<p>New syntax features:</p>
114
<li>No new syntax features were added in Python 3.4.</li>
116
<p>Other new features:</p>
118
<li><a class="reference internal" href="#whatsnew-pep-453"><span>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>).</li>
119
<li><a class="reference internal" href="#whatsnew-pep-446"><span>Newly created file descriptors are non-inheritable</span></a>
120
(<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>).</li>
121
<li>command line option for <a class="reference internal" href="#whatsnew-isolated-mode"><span>isolated mode</span></a>
122
(<a class="reference external" href="https://bugs.python.org/issue16499">issue 16499</a>).</li>
123
<li><a class="reference internal" href="#codec-handling-improvements"><span>improvements in the handling of codecs</span></a>
124
that are not text encodings (multiple issues).</li>
125
<li><a class="reference internal" href="#whatsnew-pep-451"><span>A ModuleSpec Type</span></a> for the Import System
126
(<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.)</li>
127
<li>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"><span class="pre">marshal</span></code></a> format has been made <a class="reference internal" href="#whatsnew-marshal-3"><span>more compact and efficient</span></a> (<a class="reference external" href="https://bugs.python.org/issue16475">issue 16475</a>).</li>
129
<p>New library modules:</p>
131
<li><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O, event loop, coroutines and tasks."><code class="xref py py-mod docutils literal"><span class="pre">asyncio</span></code></a>: <a class="reference internal" href="#whatsnew-asyncio"><span>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>).</li>
132
<li><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"><span class="pre">ensurepip</span></code></a>: <a class="reference internal" href="#whatsnew-ensurepip"><span>Bootstrapping the pip installer</span></a>
133
(<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>).</li>
134
<li><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"><span class="pre">enum</span></code></a>: <a class="reference internal" href="#whatsnew-enum"><span>Support for enumeration types</span></a>
135
(<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>).</li>
136
<li><a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal"><span class="pre">pathlib</span></code></a>: <a class="reference internal" href="#whatsnew-pathlib"><span>Object-oriented filesystem paths</span></a>
137
(<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>).</li>
138
<li><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"><span class="pre">selectors</span></code></a>: <a class="reference internal" href="#whatsnew-selectors"><span>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"><span class="pre">select</span></code></a> module primitives (part
139
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>).</li>
140
<li><a class="reference internal" href="../library/statistics.html#module-statistics" title="statistics: mathematical statistics functions"><code class="xref py py-mod docutils literal"><span class="pre">statistics</span></code></a>: A basic <a class="reference internal" href="#whatsnew-statistics"><span>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>).</li>
141
<li><a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal"><span class="pre">tracemalloc</span></code></a>: <a class="reference internal" href="#whatsnew-tracemalloc"><span>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>).</li>
143
<p>Significantly improved library modules:</p>
145
<li><a class="reference internal" href="#whatsnew-singledispatch"><span>Single-dispatch generic functions</span></a> in
146
<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"><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>).</li>
147
<li>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"><span class="pre">pickle</span></code></a> <a class="reference internal" href="#whatsnew-protocol-4"><span>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>).</li>
148
<li><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal"><span class="pre">multiprocessing</span></code></a> now has <a class="reference internal" href="#whatsnew-multiprocessing-no-fork"><span>an option to avoid using os.fork
149
on Unix</span></a> (<a class="reference external" href="https://bugs.python.org/issue8713">issue 8713</a>).</li>
150
<li><a class="reference internal" href="../library/email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal"><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"><span class="pre">contentmanager</span></code></a>, and
151
a new <a class="reference internal" href="../library/email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-mod docutils literal"><span class="pre">Message</span></code></a> subclass
152
(<code class="xref py py-class docutils literal"><span class="pre">EmailMessage</span></code>) that <a class="reference internal" href="#whatsnew-email-contentmanager"><span>simplify MIME
153
handling</span></a> (<a class="reference external" href="https://bugs.python.org/issue18891">issue 18891</a>).</li>
154
<li>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"><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"><span class="pre">pydoc</span></code></a> modules are now capable of
155
correct introspection of a much wider variety of callable objects,
156
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"><span class="pre">help()</span></code></a> system.</li>
157
<li>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"><span class="pre">ipaddress</span></code></a> module API has been declared stable</li>
159
<p>Security improvements:</p>
161
<li><a class="reference internal" href="#whatsnew-pep-456"><span>Secure and interchangeable hash algorithm</span></a>
162
(<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>).</li>
163
<li><a class="reference internal" href="#whatsnew-pep-446"><span>Make newly created file descriptors non-inheritable</span></a>
164
(<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.</li>
165
<li>New command line option for <a class="reference internal" href="#whatsnew-isolated-mode"><span>isolated mode</span></a>,
166
(<a class="reference external" href="https://bugs.python.org/issue16499">issue 16499</a>).</li>
167
<li><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal"><span class="pre">multiprocessing</span></code></a> now has <a class="reference internal" href="#whatsnew-multiprocessing-no-fork"><span>an option to avoid using os.fork
168
on Unix</span></a>. <em>spawn</em> and <em>forkserver</em> are
169
more secure because they avoid sharing data with child processes.</li>
170
<li><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal"><span class="pre">multiprocessing</span></code></a> child processes on Windows no longer inherit
171
all of the parent’s inheritable handles, only the necessary ones.</li>
172
<li>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"><span class="pre">hashlib.pbkdf2_hmac()</span></code></a> function provides
173
the <a class="reference external" href="https://en.wikipedia.org/wiki/PBKDF2">PKCS#5 password-based key derivation function 2</a>.</li>
174
<li><a class="reference internal" href="#whatsnew-tls-11-12"><span>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"><span class="pre">ssl</span></code></a>.</li>
175
<li><a class="reference internal" href="#whatsnew34-win-cert-store"><span>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"><span class="pre">ssl</span></code></a>.</li>
176
<li><a class="reference internal" href="#whatsnew34-sni"><span>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"><span class="pre">ssl</span></code></a>.</li>
177
<li>The <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal"><span class="pre">ssl.SSLContext</span></code></a> class has a <a class="reference internal" href="#whatsnew34-sslcontext"><span>lot of improvements</span></a>.</li>
178
<li>All modules in the standard library that support SSL now support server
179
certificate verification, including hostname matching
180
(<a class="reference internal" href="../library/ssl.html#ssl.match_hostname" title="ssl.match_hostname"><code class="xref py py-func docutils literal"><span class="pre">ssl.match_hostname()</span></code></a>) and CRLs (Certificate Revocation lists, see
181
<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"><span class="pre">ssl.SSLContext.load_verify_locations()</span></code></a>).</li>
183
<p>CPython implementation improvements:</p>
185
<li><a class="reference internal" href="#whatsnew-pep-442"><span>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>).</li>
186
<li>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>module globals are no longer set
187
to None during finalization</span></a> (<a class="reference external" href="https://bugs.python.org/issue18214">issue 18214</a>).</li>
188
<li><a class="reference internal" href="#whatsnew-pep-445"><span>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>).</li>
189
<li><a class="reference internal" href="#whatsnew-pep-436"><span>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>).</li>
191
<p>Please read on for a comprehensive list of user-facing changes, including many
192
other smaller improvements, CPython optimizations, deprecations, and potential
195
<div class="section" id="new-features">
196
<h2>New Features<a class="headerlink" href="#new-features" title="Permalink to this headline">¶</a></h2>
197
<div class="section" id="pep-453-explicit-bootstrapping-of-pip-in-python-installations">
198
<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>
199
<div class="section" id="bootstrapping-pip-by-default">
200
<h4>Bootstrapping pip By Default<a class="headerlink" href="#bootstrapping-pip-by-default" title="Permalink to this headline">¶</a></h4>
201
<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"><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
202
cross-platform mechanism to bootstrap the pip installer into Python
203
installations and virtual environments. The version of <code class="docutils literal"><span class="pre">pip</span></code> included
204
with Python 3.4.0 is <code class="docutils literal"><span class="pre">pip</span></code> 1.5.4, and future 3.4.x maintenance releases
205
will update the bundled version to the latest version of <code class="docutils literal"><span class="pre">pip</span></code> that is
206
available at the time of creating the release candidate.</p>
207
<p>By default, the commands <code class="docutils literal"><span class="pre">pipX</span></code> and <code class="docutils literal"><span class="pre">pipX.Y</span></code> will be installed on all
208
platforms (where X.Y stands for the version of the Python installation),
209
along with the <code class="docutils literal"><span class="pre">pip</span></code> Python package and its dependencies. On Windows and
210
in virtual environments on all platforms, the unversioned <code class="docutils literal"><span class="pre">pip</span></code> command
211
will also be installed. On other platforms, the system wide unversioned
212
<code class="docutils literal"><span class="pre">pip</span></code> command typically refers to the separately installed Python 2
214
<p>The <a class="reference internal" href="../using/scripts.html#scripts-pyvenv"><span>pyvenv</span></a> 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"><span class="pre">venv</span></code></a>
215
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"><span class="pre">ensurepip</span></code></a> module to make <code class="docutils literal"><span class="pre">pip</span></code> readily
216
available in virtual environments. When using the command line utility,
217
<code class="docutils literal"><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"><span class="pre">venv</span></code></a> module
218
<a class="reference internal" href="../library/venv.html#venv-api"><span>API</span></a> installation of <code class="docutils literal"><span class="pre">pip</span></code> must be requested explicitly.</p>
219
<p>For CPython <a class="reference internal" href="../using/unix.html#building-python-on-unix"><span>source builds on POSIX systems</span></a>,
220
the <code class="docutils literal"><span class="pre">make</span> <span class="pre">install</span></code> and <code class="docutils literal"><span class="pre">make</span> <span class="pre">altinstall</span></code> commands bootstrap <code class="docutils literal"><span class="pre">pip</span></code> by
221
default. This behaviour can be controlled through configure options, and
222
overridden through Makefile options.</p>
223
<p>On Windows and Mac OS X, the CPython installers now default to installing
224
<code class="docutils literal"><span class="pre">pip</span></code> along with CPython itself (users may opt out of installing it
225
during the installation process). Window users will need to opt in to the
226
automatic <code class="docutils literal"><span class="pre">PATH</span></code> modifications to have <code class="docutils literal"><span class="pre">pip</span></code> available from the command
227
line by default, otherwise it can still be accessed through the Python
228
launcher for Windows as <code class="docutils literal"><span class="pre">py</span> <span class="pre">-m</span> <span class="pre">pip</span></code>.</p>
229
<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
230
these commands by default, as long as, when invoked, they provide clear and
231
simple directions on how to install them on that platform (usually using
232
the system package manager).</p>
233
<div class="admonition note">
234
<p class="first admonition-title">Note</p>
235
<p class="last">To avoid conflicts between parallel Python 2 and Python 3 installations,
236
only the versioned <code class="docutils literal"><span class="pre">pip3</span></code> and <code class="docutils literal"><span class="pre">pip3.4</span></code> commands are bootstrapped by
237
default when <code class="docutils literal"><span class="pre">ensurepip</span></code> is invoked directly - the <code class="docutils literal"><span class="pre">--default-pip</span></code>
238
option is needed to also request the unversioned <code class="docutils literal"><span class="pre">pip</span></code> command.
239
<code class="docutils literal"><span class="pre">pyvenv</span></code> and the Windows installer ensure that the unqualified <code class="docutils literal"><span class="pre">pip</span></code>
240
command is made available in those environments, and <code class="docutils literal"><span class="pre">pip</span></code> can always be
241
invoked via the <code class="docutils literal"><span class="pre">-m</span></code> switch rather than directly to avoid ambiguity on
242
systems with multiple Python installations.</p>
245
<div class="section" id="documentation-changes">
246
<h4>Documentation Changes<a class="headerlink" href="#documentation-changes" title="Permalink to this headline">¶</a></h4>
247
<p>As part of this change, the <a class="reference internal" href="../installing/index.html#installing-index"><span>Installing Python Modules</span></a> and
248
<a class="reference internal" href="../distributing/index.html#distributing-index"><span>Distributing Python Modules</span></a> sections of the documentation have been
249
completely redesigned as short getting started and FAQ documents. Most
250
packaging documentation has now been moved out to the Python Packaging
251
Authority maintained <a class="reference external" href="https://packaging.python.org">Python Packaging User Guide</a> and the documentation of the individual
253
<p>However, as this migration is currently still incomplete, the legacy
254
versions of those guides remaining available as <a class="reference internal" href="../install/index.html#install-index"><span>Installing Python Modules (Legacy version)</span></a>
255
and <a class="reference internal" href="../distutils/index.html#distutils-index"><span>Distributing Python Modules (Legacy version)</span></a>.</p>
256
<div class="admonition seealso">
257
<p class="first admonition-title">See also</p>
258
<dl class="last docutils">
259
<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>
260
<dd>PEP written by Donald Stufft and Nick Coghlan, implemented by
261
Donald Stufft, Nick Coghlan, Martin von Löwis and Ned Deily.</dd>
266
<div class="section" id="pep-446-newly-created-file-descriptors-are-non-inheritable">
267
<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>
268
<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>non-inheritable</span></a>. In general, this is the behavior an application will
269
want: when launching a new process, having currently open files also
270
open in the new process can lead to all sorts of hard to find bugs,
271
and potentially to security issues.</p>
272
<p>However, there are occasions when inheritance is desired. To support
273
these cases, the following new functions and methods are available:</p>
275
<li><a class="reference internal" href="../library/os.html#os.get_inheritable" title="os.get_inheritable"><code class="xref py py-func docutils literal"><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"><span class="pre">os.set_inheritable()</span></code></a></li>
276
<li><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"><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"><span class="pre">os.set_handle_inheritable()</span></code></a></li>
277
<li><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"><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"><span class="pre">socket.socket.set_inheritable()</span></code></a></li>
279
<div class="admonition seealso">
280
<p class="first admonition-title">See also</p>
281
<dl class="last docutils">
282
<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>
283
<dd>PEP written and implemented by Victor Stinner.</dd>
287
<div class="section" id="improvements-to-codec-handling">
288
<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>
289
<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"><span class="pre">codecs</span></code></a> module has always been
290
intended to operate as a type-neutral dynamic encoding and decoding
291
system. However, its close coupling with the Python text model, especially
292
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"><span class="pre">str</span></code></a>,
293
<a class="reference internal" href="../library/functions.html#bytes" title="bytes"><code class="xref py py-class docutils literal"><span class="pre">bytes</span></code></a> and <a class="reference internal" href="../library/functions.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal"><span class="pre">bytearray</span></code></a> types, has historically obscured that
295
<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"><span class="pre">codecs.encode()</span></code></a> and
296
<a class="reference internal" href="../library/codecs.html#codecs.decode" title="codecs.decode"><code class="xref py py-meth docutils literal"><span class="pre">codecs.decode()</span></code></a> convenience functions are now properly documented in
297
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"><span class="pre">codecs</span></code></a>
298
module (and have been covered by the regression test suite) since Python 2.4,
299
but were previously only discoverable through runtime introspection.</p>
300
<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"><span class="pre">str</span></code></a>, <a class="reference internal" href="../library/functions.html#bytes" title="bytes"><code class="xref py py-class docutils literal"><span class="pre">bytes</span></code></a> and
301
<a class="reference internal" href="../library/functions.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal"><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"><span class="pre">codecs</span></code></a> convenience functions support arbitrary
302
codecs in both Python 2 and Python 3, rather than being limited to Unicode text
303
encodings (in Python 3) or <code class="docutils literal"><span class="pre">basestring</span></code> <-> <code class="docutils literal"><span class="pre">basestring</span></code> conversions (in
305
<p>In Python 3.4, the interpreter is able to identify the known non-text
306
encodings provided in the standard library and direct users towards these
307
general purpose convenience functions when appropriate:</p>
308
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">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>
309
<span class="gt">Traceback (most recent call last):</span>
310
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
311
<span class="gr">LookupError</span>: <span class="n">'hex' is not a text encoding; use codecs.decode() to handle arbitrary codecs</span>
313
<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>
314
<span class="gt">Traceback (most recent call last):</span>
315
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
316
<span class="gr">LookupError</span>: <span class="n">'rot13' is not a text encoding; use codecs.encode() to handle arbitrary codecs</span>
318
<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>
319
<span class="gt">Traceback (most recent call last):</span>
320
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
321
<span class="gr">LookupError</span>: <span class="n">'hex' is not a text encoding; use codecs.open() to handle arbitrary codecs</span>
324
<p>In a related change, whenever it is feasible without breaking backwards
325
compatibility, exceptions raised during encoding and decoding operations
326
are wrapped in a chained exception of the same type that mentions the
327
name of the codec responsible for producing the error:</p>
328
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">codecs</span>
330
<span class="gp">>>> </span><span class="n">codecs</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="n">b</span><span class="s2">"abcdefgh"</span><span class="p">,</span> <span class="s2">"hex"</span><span class="p">)</span>
331
<span class="gt">Traceback (most recent call last):</span>
332
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>
333
<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>
334
<span class="gr">binascii.Error</span>: <span class="n">Non-hexadecimal digit found</span>
336
<span class="go">The above exception was the direct cause of the following exception:</span>
338
<span class="gt">Traceback (most recent call last):</span>
339
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
340
<span class="gr">binascii.Error</span>: <span class="n">decoding with 'hex' codec failed (Error: Non-hexadecimal digit found)</span>
342
<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>
343
<span class="gt">Traceback (most recent call last):</span>
344
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>
345
<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>
346
File <span class="nb">"/usr/lib/python3.4/bz2.py"</span>, line <span class="m">498</span>, in <span class="n">compress</span>
347
<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>
348
<span class="gr">TypeError</span>: <span class="n">'str' does not support the buffer interface</span>
350
<span class="go">The above exception was the direct cause of the following exception:</span>
352
<span class="gt">Traceback (most recent call last):</span>
353
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
354
<span class="gr">TypeError</span>: <span class="n">encoding with 'bz2' codec failed (TypeError: 'str' does not support the buffer interface)</span>
357
<p>Finally, as the examples above show, these improvements have permitted
358
the restoration of the convenience aliases for the non-Unicode codecs that
359
were themselves restored in Python 3.2. This means that encoding binary data
360
to and from its hexadecimal representation (for example) can now be written
362
<div class="highlight-python3"><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>
363
<span class="gp">>>> </span><span class="n">encode</span><span class="p">(</span><span class="n">b</span><span class="s2">"hello"</span><span class="p">,</span> <span class="s2">"hex"</span><span class="p">)</span>
364
<span class="go">b'68656c6c6f'</span>
365
<span class="gp">>>> </span><span class="n">decode</span><span class="p">(</span><span class="n">b</span><span class="s2">"68656c6c6f"</span><span class="p">,</span> <span class="s2">"hex"</span><span class="p">)</span>
366
<span class="go">b'hello'</span>
369
<p>The binary and text transforms provided in the standard library are detailed
370
in <a class="reference internal" href="../library/codecs.html#binary-transforms"><span>Binary Transforms</span></a> and <a class="reference internal" href="../library/codecs.html#text-transforms"><span>Text Transforms</span></a>.</p>
371
<p>(Contributed by Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue7475">issue 7475</a>, <a class="reference external" href="https://bugs.python.org/issue17827">issue 17827</a>,
372
<a class="reference external" href="https://bugs.python.org/issue17828">issue 17828</a> and <a class="reference external" href="https://bugs.python.org/issue19619">issue 19619</a>.)</p>
374
<div class="section" id="pep-451-a-modulespec-type-for-the-import-system">
375
<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>
376
<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
377
import machinery will use to load it (that is, a module specification). This
378
helps simplify both the import implementation and several import-related APIs.
379
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
380
improvements</a>.</p>
381
<p>The public-facing changes from the PEP are entirely backward-compatible.
382
Furthermore, they should be transparent to everyone but importer authors. Key
383
finder and loader methods have been deprecated, but they will continue working.
384
New importers should use the new methods described in the PEP. Existing
385
importers should be updated to implement the new methods. See the
386
<a class="reference internal" href="#deprecated-3-4"><span>Deprecated</span></a> section for a list of methods that should be replaced and
387
their replacements.</p>
389
<div class="section" id="other-language-changes">
390
<h3>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Permalink to this headline">¶</a></h3>
391
<p>Some smaller changes made to the core Python language are:</p>
393
<li>Unicode database updated to UCD version 6.3.</li>
394
<li><a class="reference internal" href="../library/functions.html#min" title="min"><code class="xref py py-func docutils literal"><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"><span class="pre">max()</span></code></a> now accept a <em>default</em> keyword-only argument that
395
can be used to specify the value they return if the iterable they are
396
evaluating has no elements. (Contributed by Julian Berman in
397
<a class="reference external" href="https://bugs.python.org/issue18111">issue 18111</a>.)</li>
398
<li>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"><span class="pre">weakref</span></code></a>‘able.</li>
399
<li>Module <code class="docutils literal"><span class="pre">__file__</span></code> attributes (and related values) should now always
400
contain absolute paths by default, with the sole exception of
401
<code class="docutils literal"><span class="pre">__main__.__file__</span></code> when a script has been executed directly using
402
a relative path. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue18416">issue 18416</a>.)</li>
403
<li>All the UTF-* codecs (except UTF-7) now reject surrogates during both
404
encoding and decoding unless the <code class="docutils literal"><span class="pre">surrogatepass</span></code> error handler is used,
405
with the exception of the UTF-16 decoder (which accepts valid surrogate pairs)
406
and the UTF-16 encoder (which produces them while encoding non-BMP characters).
407
(Contributed by Victor Stinner, Kang-Hao (Kenny) Lu and Serhiy Storchaka in
408
<a class="reference external" href="https://bugs.python.org/issue12892">issue 12892</a>.)</li>
409
<li>New German EBCDIC <a class="reference internal" href="../library/codecs.html#standard-encodings"><span>codec</span></a> <code class="docutils literal"><span class="pre">cp273</span></code>. (Contributed
410
by Michael Bierenfeld and Andrew Kuchling in <a class="reference external" href="https://bugs.python.org/issue1097797">issue 1097797</a>.)</li>
411
<li>New Ukrainian <a class="reference internal" href="../library/codecs.html#standard-encodings"><span>codec</span></a> <code class="docutils literal"><span class="pre">cp1125</span></code>. (Contributed by
412
Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue19668">issue 19668</a>.)</li>
413
<li><a class="reference internal" href="../library/functions.html#bytes" title="bytes"><code class="xref py py-class docutils literal"><span class="pre">bytes</span></code></a>.join() and <a class="reference internal" href="../library/functions.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal"><span class="pre">bytearray</span></code></a>.join() now accept arbitrary
414
buffer objects as arguments. (Contributed by Antoine Pitrou in
415
<a class="reference external" href="https://bugs.python.org/issue15958">issue 15958</a>.)</li>
416
<li>The <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal"><span class="pre">int</span></code></a> constructor now accepts any object that has an <code class="docutils literal"><span class="pre">__index__</span></code>
417
method for its <em>base</em> argument. (Contributed by Mark Dickinson in
418
<a class="reference external" href="https://bugs.python.org/issue16772">issue 16772</a>.)</li>
419
<li>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"><span class="pre">clear()</span></code></a> method that clears all
420
references to local variables from the frame. (Contributed by Antoine Pitrou
421
in <a class="reference external" href="https://bugs.python.org/issue17934">issue 17934</a>.)</li>
422
<li><a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-class docutils literal"><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"><span class="pre">Sequence</span></code></a>,
423
and supports the <a class="reference internal" href="../library/functions.html#reversed" title="reversed"><code class="xref py py-func docutils literal"><span class="pre">reversed()</span></code></a> builtin. (Contributed by Nick Coghlan
424
and Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue18690">issue 18690</a> and <a class="reference external" href="https://bugs.python.org/issue19078">issue 19078</a>.)</li>
425
<li>Signatures reported by <a class="reference internal" href="../library/functions.html#help" title="help"><code class="xref py py-func docutils literal"><span class="pre">help()</span></code></a> have been modified and improved in
426
several cases as a result of the introduction of Argument Clinic and other
427
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"><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"><span class="pre">pydoc</span></code></a> modules.</li>
428
<li><a class="reference internal" href="../reference/datamodel.html#object.__length_hint__" title="object.__length_hint__"><code class="xref py py-meth docutils literal"><span class="pre">__length_hint__()</span></code></a> is now part of the formal language
429
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
430
<a class="reference external" href="https://bugs.python.org/issue16148">issue 16148</a>.)</li>
434
<div class="section" id="new-modules">
435
<h2>New Modules<a class="headerlink" href="#new-modules" title="Permalink to this headline">¶</a></h2>
436
<div class="section" id="asyncio">
437
<span id="whatsnew-asyncio"></span><h3>asyncio<a class="headerlink" href="#asyncio" title="Permalink to this headline">¶</a></h3>
438
<p>The new <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O, event loop, coroutines and tasks."><code class="xref py py-mod docutils literal"><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
439
pluggable event loop model for Python, providing solid asynchronous IO
440
support in the standard library, and making it easier for other event loop
441
implementations to interoperate with the standard library and each other.</p>
442
<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>
443
<div class="admonition seealso">
444
<p class="first admonition-title">See also</p>
445
<dl class="last docutils">
446
<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>
447
<dd>PEP written and implementation led by Guido van Rossum.</dd>
451
<div class="section" id="ensurepip">
452
<span id="whatsnew-ensurepip"></span><h3>ensurepip<a class="headerlink" href="#ensurepip" title="Permalink to this headline">¶</a></h3>
453
<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"><span class="pre">ensurepip</span></code></a> module is the primary infrastructure for the
454
<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
455
need to interact with this module, but it can be used to manually bootstrap
456
<code class="docutils literal"><span class="pre">pip</span></code> if the automated bootstrapping into an installation or virtual
457
environment was declined.</p>
458
<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"><span class="pre">ensurepip</span></code></a> includes a bundled copy of <code class="docutils literal"><span class="pre">pip</span></code>, up-to-date as of the first
459
release candidate of the release of CPython with which it ships (this applies
460
to both maintenance releases and feature releases). <code class="docutils literal"><span class="pre">ensurepip</span></code> does not
461
access the internet. If the installation has Internet access, after
462
<code class="docutils literal"><span class="pre">ensurepip</span></code> is run the bundled <code class="docutils literal"><span class="pre">pip</span></code> can be used to upgrade <code class="docutils literal"><span class="pre">pip</span></code> to a
463
more recent release than the bundled one. (Note that such an upgraded version
464
of <code class="docutils literal"><span class="pre">pip</span></code> is considered to be a separately installed package and will not be
465
removed if Python is uninstalled.)</p>
466
<p>The module is named <em>ensure</em>pip because if called when <code class="docutils literal"><span class="pre">pip</span></code> is already
467
installed, it does nothing. It also has an <code class="docutils literal"><span class="pre">--upgrade</span></code> option that will
468
cause it to install the bundled copy of <code class="docutils literal"><span class="pre">pip</span></code> if the existing installed
469
version of <code class="docutils literal"><span class="pre">pip</span></code> is older than the bundled copy.</p>
471
<div class="section" id="enum">
472
<span id="whatsnew-enum"></span><h3>enum<a class="headerlink" href="#enum" title="Permalink to this headline">¶</a></h3>
473
<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"><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
474
implementation of enumeration types, allowing other modules (such as
475
<a class="reference internal" href="../library/socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal"><span class="pre">socket</span></code></a>) to provide more informative error messages and better
476
debugging support by replacing opaque integer constants with backwards
477
compatible enumeration values.</p>
478
<div class="admonition seealso">
479
<p class="first admonition-title">See also</p>
480
<dl class="last docutils">
481
<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>
482
<dd>PEP written by Barry Warsaw, Eli Bendersky and Ethan Furman,
483
implemented by Ethan Furman.</dd>
487
<div class="section" id="pathlib">
488
<span id="whatsnew-pathlib"></span><h3>pathlib<a class="headerlink" href="#pathlib" title="Permalink to this headline">¶</a></h3>
489
<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"><span class="pre">pathlib</span></code></a> module offers classes representing filesystem paths
490
with semantics appropriate for different operating systems. Path classes are
491
divided between <em>pure paths</em>, which provide purely computational operations
492
without I/O, and <em>concrete paths</em>, which inherit from pure paths but also
493
provide I/O operations.</p>
494
<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>
495
<div class="admonition seealso">
496
<p class="first admonition-title">See also</p>
497
<dl class="last docutils">
498
<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>
499
<dd>PEP written and implemented by Antoine Pitrou.</dd>
503
<div class="section" id="selectors">
504
<span id="whatsnew-selectors"></span><h3>selectors<a class="headerlink" href="#selectors" title="Permalink to this headline">¶</a></h3>
505
<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"><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>)
506
allows high-level and efficient I/O multiplexing, built upon the
507
<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"><span class="pre">select</span></code></a> module primitives.</p>
509
<div class="section" id="statistics">
510
<span id="whatsnew-statistics"></span><h3>statistics<a class="headerlink" href="#statistics" title="Permalink to this headline">¶</a></h3>
511
<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"><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
512
statistics functionality directly in the standard library. This module
513
supports calculation of the mean, median, mode, variance and standard
514
deviation of a data series.</p>
515
<div class="admonition seealso">
516
<p class="first admonition-title">See also</p>
517
<dl class="last docutils">
518
<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>
519
<dd>PEP written and implemented by Steven D’Aprano</dd>
523
<div class="section" id="tracemalloc">
524
<span id="whatsnew-tracemalloc"></span><h3>tracemalloc<a class="headerlink" href="#tracemalloc" title="Permalink to this headline">¶</a></h3>
525
<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"><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
526
trace memory blocks allocated by Python. It provides the following information:</p>
528
<li>Trace where an object was allocated</li>
529
<li>Statistics on allocated memory blocks per filename and per line number:
530
total size, number and average size of allocated memory blocks</li>
531
<li>Compute the differences between two snapshots to detect memory leaks</li>
533
<div class="admonition seealso">
534
<p class="first admonition-title">See also</p>
535
<dl class="last docutils">
536
<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>
537
<dd>PEP written and implemented by Victor Stinner</dd>
542
<div class="section" id="improved-modules">
543
<h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Permalink to this headline">¶</a></h2>
544
<div class="section" id="abc">
545
<h3>abc<a class="headerlink" href="#abc" title="Permalink to this headline">¶</a></h3>
546
<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"><span class="pre">abc.get_cache_token()</span></code></a> can be used to know when to invalidate
547
caches that are affected by changes in the object graph. (Contributed
548
by Łukasz Langa in <a class="reference external" href="https://bugs.python.org/issue16832">issue 16832</a>.)</p>
549
<p>New class <a class="reference internal" href="../library/abc.html#abc.ABC" title="abc.ABC"><code class="xref py py-class docutils literal"><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"><span class="pre">ABCMeta</span></code></a> as its meta class.
550
Using <code class="docutils literal"><span class="pre">ABC</span></code> as a base class has essentially the same effect as specifying
551
<code class="docutils literal"><span class="pre">metaclass=abc.ABCMeta</span></code>, but is simpler to type and easier to read.
552
(Contributed by Bruno Dupuis in <a class="reference external" href="https://bugs.python.org/issue16049">issue 16049</a>.)</p>
554
<div class="section" id="aifc">
555
<h3>aifc<a class="headerlink" href="#aifc" title="Permalink to this headline">¶</a></h3>
556
<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"><span class="pre">getparams()</span></code></a> method now returns a namedtuple rather than a
557
plain tuple. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue17818">issue 17818</a>.)</p>
558
<p><a class="reference internal" href="../library/aifc.html#aifc.open" title="aifc.open"><code class="xref py py-func docutils literal"><span class="pre">aifc.open()</span></code></a> now supports the context management protocol: when used in a
559
<a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal"><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"><span class="pre">close()</span></code></a> method of the returned
560
object will be called automatically at the end of the block. (Contributed by
561
Serhiy Storchacha in <a class="reference external" href="https://bugs.python.org/issue16486">issue 16486</a>.)</p>
562
<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"><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"><span class="pre">writeframes()</span></code></a>
563
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
564
Storchaka in <a class="reference external" href="https://bugs.python.org/issue8311">issue 8311</a>.)</p>
566
<div class="section" id="argparse">
567
<h3>argparse<a class="headerlink" href="#argparse" title="Permalink to this headline">¶</a></h3>
568
<p>The <a class="reference internal" href="../library/argparse.html#argparse.FileType" title="argparse.FileType"><code class="xref py py-class docutils literal"><span class="pre">FileType</span></code></a> class now accepts <em>encoding</em> and
569
<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"><span class="pre">open()</span></code></a>. (Contributed
570
by Lucas Maystre in <a class="reference external" href="https://bugs.python.org/issue11175">issue 11175</a>.)</p>
572
<div class="section" id="audioop">
573
<h3>audioop<a class="headerlink" href="#audioop" title="Permalink to this headline">¶</a></h3>
574
<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"><span class="pre">audioop</span></code></a> now supports 24-bit samples. (Contributed by Serhiy Storchaka
575
in <a class="reference external" href="https://bugs.python.org/issue12866">issue 12866</a>.)</p>
576
<p>New <a class="reference internal" href="../library/audioop.html#audioop.byteswap" title="audioop.byteswap"><code class="xref py py-func docutils literal"><span class="pre">byteswap()</span></code></a> function converts big-endian samples to
577
little-endian and vice versa. (Contributed by Serhiy Storchaka in
578
<a class="reference external" href="https://bugs.python.org/issue19641">issue 19641</a>.)</p>
579
<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"><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
580
are not accepted: they didn’t work before, now they raise an error right away.
581
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue16685">issue 16685</a>.)</p>
583
<div class="section" id="base64">
584
<h3>base64<a class="headerlink" href="#base64" title="Permalink to this headline">¶</a></h3>
585
<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"><span class="pre">base64</span></code></a> now accept any
586
<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
587
<a class="reference internal" href="../library/functions.html#bytes" title="bytes"><code class="xref py py-class docutils literal"><span class="pre">bytes</span></code></a> or <a class="reference internal" href="../library/functions.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal"><span class="pre">bytearray</span></code></a> instance. (Contributed by Nick Coghlan in
588
<a class="reference external" href="https://bugs.python.org/issue17839">issue 17839</a>.)</p>
589
<p>New functions <a class="reference internal" href="../library/base64.html#base64.a85encode" title="base64.a85encode"><code class="xref py py-func docutils literal"><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"><span class="pre">a85decode()</span></code></a>,
590
<a class="reference internal" href="../library/base64.html#base64.b85encode" title="base64.b85encode"><code class="xref py py-func docutils literal"><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"><span class="pre">b85decode()</span></code></a> provide the ability to
591
encode and decode binary data from and to <code class="docutils literal"><span class="pre">Ascii85</span></code> and the git/mercurial
592
<code class="docutils literal"><span class="pre">Base85</span></code> formats, respectively. The <code class="docutils literal"><span class="pre">a85</span></code> functions have options that can
593
be used to make them compatible with the variants of the <code class="docutils literal"><span class="pre">Ascii85</span></code> encoding,
594
including the Adobe variant. (Contributed by Martin Morrison, the Mercurial
595
project, Serhiy Storchaka, and Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue17618">issue 17618</a>.)</p>
597
<div class="section" id="collections">
598
<h3>collections<a class="headerlink" href="#collections" title="Permalink to this headline">¶</a></h3>
599
<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"><span class="pre">ChainMap.new_child()</span></code></a> method now accepts an <em>m</em> argument specifying
600
the child map to add to the chain. This allows an existing mapping and/or a
601
custom mapping type to be used for the child. (Contributed by Vinay Sajip in
602
<a class="reference external" href="https://bugs.python.org/issue16613">issue 16613</a>.)</p>
604
<div class="section" id="colorsys">
605
<h3>colorsys<a class="headerlink" href="#colorsys" title="Permalink to this headline">¶</a></h3>
606
<p>The number of digits in the coefficients for the RGB — YIQ conversions have
607
been expanded so that they match the FCC NTSC versions. The change in
608
results should be less than 1% and may better match results found elsewhere.
609
(Contributed by Brian Landers and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue14323">issue 14323</a>.)</p>
611
<div class="section" id="contextlib">
612
<h3>contextlib<a class="headerlink" href="#contextlib" title="Permalink to this headline">¶</a></h3>
613
<p>The new <a class="reference internal" href="../library/contextlib.html#contextlib.suppress" title="contextlib.suppress"><code class="xref py py-class docutils literal"><span class="pre">contextlib.suppress</span></code></a> context manager helps to clarify the
614
intent of code that deliberately suppresses exceptions from a single
615
statement. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue15806">issue 15806</a> and
616
Zero Piraeus in <a class="reference external" href="https://bugs.python.org/issue19266">issue 19266</a>.)</p>
617
<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"><span class="pre">contextlib.redirect_stdout()</span></code></a> context manager makes it easier
618
for utility scripts to handle inflexible APIs that write their output to
619
<a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal"><span class="pre">sys.stdout</span></code></a> and don’t provide any options to redirect it. Using the
620
context manager, the <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal"><span class="pre">sys.stdout</span></code></a> output can be redirected to any
621
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"><span class="pre">io.StringIO</span></code></a>, to a string.
622
The latter can be especially useful, for example, to capture output
623
from a function that was written to implement a command line interface.
624
It is recommended only for utility scripts because it affects the
625
global state of <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal"><span class="pre">sys.stdout</span></code></a>. (Contributed by Raymond Hettinger
626
in <a class="reference external" href="https://bugs.python.org/issue15805">issue 15805</a>.)</p>
627
<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"><span class="pre">contextlib</span></code></a> documentation has also been updated to include a
628
<a class="reference internal" href="../library/contextlib.html#single-use-reusable-and-reentrant-cms"><span>discussion</span></a> of the
629
differences between single use, reusable and reentrant context managers.</p>
631
<div class="section" id="dbm">
632
<h3>dbm<a class="headerlink" href="#dbm" title="Permalink to this headline">¶</a></h3>
633
<p><a class="reference internal" href="../library/dbm.html#dbm.open" title="dbm.open"><code class="xref py py-func docutils literal"><span class="pre">dbm.open()</span></code></a> objects now support the context management protocol. When
634
used in a <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal"><span class="pre">with</span></code></a> statement, the <code class="docutils literal"><span class="pre">close</span></code> method of the database
635
object will be called automatically at the end of the block. (Contributed by
636
Claudiu Popa and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue19282">issue 19282</a>.)</p>
638
<div class="section" id="dis">
639
<h3>dis<a class="headerlink" href="#dis" title="Permalink to this headline">¶</a></h3>
640
<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"><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"><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"><span class="pre">distb()</span></code></a>, and
641
<a class="reference internal" href="../library/dis.html#dis.disassemble" title="dis.disassemble"><code class="xref py py-func docutils literal"><span class="pre">disassemble()</span></code></a> now accept a keyword-only <em>file</em> argument that
642
controls where they write their output.</p>
643
<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"><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"><span class="pre">Instruction</span></code></a> class
644
that provides object oriented access to the details of each individual bytecode
646
<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"><span class="pre">get_instructions()</span></code></a>, provides an iterator that emits
647
the Instruction stream for a given piece of Python code. Thus it is now
648
possible to write a program that inspects and manipulates a bytecode
649
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"><span class="pre">dis</span></code></a> module
650
itself. For example:</p>
651
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">dis</span>
652
<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>
653
<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>
654
<span class="go">LOAD_FAST</span>
655
<span class="go">LOAD_CONST</span>
656
<span class="go">BINARY_ADD</span>
657
<span class="go">RETURN_VALUE</span>
660
<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"><span class="pre">dis</span></code></a> module have been rewritten to use
661
these new components.</p>
662
<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"><span class="pre">Bytecode</span></code></a> provides
663
an object-oriented API for inspecting bytecode in both in human-readable form
664
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"><span class="pre">Bytecode</span></code></a> constructor
665
takes the same arguments that <code class="xref py py-func docutils literal"><span class="pre">get_instruction()</span></code> does (plus an
666
optional <em>current_offset</em>), and the resulting object can be iterated to produce
667
<a class="reference internal" href="../library/dis.html#dis.Instruction" title="dis.Instruction"><code class="xref py py-class docutils literal"><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"><span class="pre">dis</span></code></a>
668
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"><span class="pre">dis</span></code></a> on the constructor argument, but
669
returned as a multi-line string:</p>
670
<div class="highlight-python3"><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>
671
<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>
672
<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>
673
<span class="go">LOAD_FAST (124)</span>
674
<span class="go">LOAD_CONST (100)</span>
675
<span class="go">BINARY_ADD (23)</span>
676
<span class="go">RETURN_VALUE (83)</span>
677
<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>
678
<span class="go">[' 1 0 LOAD_FAST 0 (x)',</span>
679
<span class="go"> ' --> 3 LOAD_CONST 1 (1)',</span>
680
<span class="go"> ' 6 BINARY_ADD',</span>
681
<span class="go"> ' 7 RETURN_VALUE']</span>
684
<p><a class="reference internal" href="../library/dis.html#dis.Bytecode" title="dis.Bytecode"><code class="xref py py-class docutils literal"><span class="pre">Bytecode</span></code></a> also has a class method,
685
<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"><span class="pre">from_traceback()</span></code></a>, that provides the ability to manipulate a
686
traceback (that is, <code class="docutils literal"><span class="pre">print(Bytecode.from_traceback(tb).dis())</span></code> is equivalent
687
to <code class="docutils literal"><span class="pre">distb(tb)</span></code>).</p>
688
<p>(Contributed by Nick Coghlan, Ryan Kelly and Thomas Kluyver in <a class="reference external" href="https://bugs.python.org/issue11816">issue 11816</a>
689
and Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue17916">issue 17916</a>.)</p>
690
<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"><span class="pre">stack_effect()</span></code></a> computes the effect on the Python stack
691
of a given opcode and argument, information that is not otherwise available.
692
(Contributed by Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue19722">issue 19722</a>.)</p>
694
<div class="section" id="doctest">
695
<h3>doctest<a class="headerlink" href="#doctest" title="Permalink to this headline">¶</a></h3>
696
<p>A new <a class="reference internal" href="../library/doctest.html#doctest-options"><span>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"><span class="pre">FAIL_FAST</span></code></a>, halts
697
test running as soon as the first failure is detected. (Contributed by R.
698
David Murray and Daniel Urban in <a class="reference external" href="https://bugs.python.org/issue16522">issue 16522</a>.)</p>
699
<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"><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"><span class="pre">argparse</span></code></a>, and has two
700
new options, <code class="docutils literal"><span class="pre">-o</span></code> and <code class="docutils literal"><span class="pre">-f</span></code>. <code class="docutils literal"><span class="pre">-o</span></code> allows <a class="reference internal" href="../library/doctest.html#doctest-options"><span>doctest options</span></a> to be specified on the command line, and <code class="docutils literal"><span class="pre">-f</span></code> is a
701
shorthand for <code class="docutils literal"><span class="pre">-o</span> <span class="pre">FAIL_FAST</span></code> (to parallel the similar option supported by the
702
<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"><span class="pre">unittest</span></code></a> CLI). (Contributed by R. David Murray in <a class="reference external" href="https://bugs.python.org/issue11390">issue 11390</a>.)</p>
703
<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"><span class="pre">doctest</span></code></a> will now find doctests in extension module <code class="docutils literal"><span class="pre">__doc__</span></code> strings.
704
(Contributed by Zachary Ware in <a class="reference external" href="https://bugs.python.org/issue3158">issue 3158</a>.)</p>
706
<div class="section" id="email">
707
<h3>email<a class="headerlink" href="#email" title="Permalink to this headline">¶</a></h3>
708
<p><a class="reference internal" href="../library/email.message.html#email.message.Message.as_string" title="email.message.Message.as_string"><code class="xref py py-meth docutils literal"><span class="pre">as_string()</span></code></a> now accepts a <em>policy</em> argument to
709
override the default policy of the message when generating a string
710
representation of it. This means that <code class="docutils literal"><span class="pre">as_string</span></code> can now be used in more
711
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"><span class="pre">generator</span></code></a> in
712
order to pass formatting parameters to its <code class="docutils literal"><span class="pre">flatten</span></code> method. (Contributed by
713
R. David Murray in <a class="reference external" href="https://bugs.python.org/issue18600">issue 18600</a>.)</p>
714
<p>New method <a class="reference internal" href="../library/email.message.html#email.message.Message.as_bytes" title="email.message.Message.as_bytes"><code class="xref py py-meth docutils literal"><span class="pre">as_bytes()</span></code></a> added to produce a bytes
715
representation of the message in a fashion similar to how <code class="docutils literal"><span class="pre">as_string</span></code>
716
produces a string representation. It does not accept the <em>maxheaderlen</em>
717
argument, but does accept the <em>unixfrom</em> and <em>policy</em> arguments. The
718
<a class="reference internal" href="../library/email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a> <a class="reference internal" href="../library/email.message.html#email.message.Message.__bytes__" title="email.message.Message.__bytes__"><code class="xref py py-meth docutils literal"><span class="pre">__bytes__()</span></code></a> method
719
calls it, meaning that <code class="docutils literal"><span class="pre">bytes(mymsg)</span></code> will now produce the intuitive
720
result: a bytes object containing the fully formatted message. (Contributed
721
by R. David Murray in <a class="reference external" href="https://bugs.python.org/issue18600">issue 18600</a>.)</p>
722
<p>The <a class="reference internal" href="../library/email.message.html#email.message.Message.set_param" title="email.message.Message.set_param"><code class="xref py py-meth docutils literal"><span class="pre">Message.set_param()</span></code></a> message now accepts a <em>replace</em> keyword argument.
723
When specified, the associated header will be updated without changing
724
its location in the list of headers. For backward compatibility, the default
725
is <code class="docutils literal"><span class="pre">False</span></code>. (Contributed by R. David Murray in <a class="reference external" href="https://bugs.python.org/issue18891">issue 18891</a>.)</p>
726
<p id="whatsnew-email-contentmanager">A pair of new subclasses of <a class="reference internal" href="../library/email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal"><span class="pre">Message</span></code></a> have been added
727
(<a class="reference internal" href="../library/email.contentmanager.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal"><span class="pre">EmailMessage</span></code></a> and <a class="reference internal" href="../library/email.contentmanager.html#email.message.MIMEPart" title="email.message.MIMEPart"><code class="xref py py-class docutils literal"><span class="pre">MIMEPart</span></code></a>), along with a new sub-module,
728
<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"><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"><span class="pre">policy</span></code></a> attribute
729
<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"><span class="pre">content_manager</span></code></a>. All documentation is
730
currently in the new module, which is being added as part of email’s new
731
<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
732
make extracting content from and inserting content into email messages much
733
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"><span class="pre">contentmanager</span></code></a> documentation and
734
the <a class="reference internal" href="../library/email-examples.html#email-contentmanager-api-examples"><span>Examples using the Provisional API</span></a>. These API additions complete the
735
bulk of the work that was planned as part of the email6 project. The currently
736
provisional API is scheduled to become final in Python 3.5 (possibly with a few
737
minor additions in the area of error handling). (Contributed by R. David
738
Murray in <a class="reference external" href="https://bugs.python.org/issue18891">issue 18891</a>.)</p>
740
<div class="section" id="filecmp">
741
<h3>filecmp<a class="headerlink" href="#filecmp" title="Permalink to this headline">¶</a></h3>
742
<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"><span class="pre">clear_cache()</span></code></a> function provides the ability to clear the
743
<a class="reference internal" href="../library/filecmp.html#module-filecmp" title="filecmp: Compare files efficiently."><code class="xref py py-mod docutils literal"><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"><span class="pre">os.stat()</span></code></a> information to
744
determine if the file has changed since the last compare. This can be used,
745
for example, if the file might have been changed and re-checked in less time
746
than the resolution of a particular filesystem’s file modification time field.
747
(Contributed by Mark Levitt in <a class="reference external" href="https://bugs.python.org/issue18149">issue 18149</a>.)</p>
748
<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"><span class="pre">DEFAULT_IGNORES</span></code></a> provides the list of
749
directories that are used as the default value for the <em>ignore</em> parameter of
750
the <a class="reference internal" href="../library/filecmp.html#filecmp.dircmp" title="filecmp.dircmp"><code class="xref py py-func docutils literal"><span class="pre">dircmp()</span></code></a> function. (Contributed by Eli Bendersky in
751
<a class="reference external" href="https://bugs.python.org/issue15442">issue 15442</a>.)</p>
753
<div class="section" id="functools">
754
<h3>functools<a class="headerlink" href="#functools" title="Permalink to this headline">¶</a></h3>
755
<p>The new <a class="reference internal" href="../library/functools.html#functools.partialmethod" title="functools.partialmethod"><code class="xref py py-func docutils literal"><span class="pre">partialmethod()</span></code></a> descriptor brings partial argument
756
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"><span class="pre">partial()</span></code></a> provides
757
for normal callables. The new descriptor also makes it easier to get
758
arbitrary callables (including <a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal"><span class="pre">partial()</span></code></a> instances)
759
to behave like normal instance methods when included in a class definition.
760
(Contributed by Alon Horev and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue4331">issue 4331</a>.)</p>
761
<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"><span class="pre">singledispatch()</span></code></a> decorator brings support for
762
single-dispatch generic functions to the Python standard library. Where
763
object oriented programming focuses on grouping multiple operations on a
764
common set of data into a class, a generic function focuses on grouping
765
multiple implementations of an operation that allows it to work with
766
<em>different</em> kinds of data.</p>
767
<div class="admonition seealso">
768
<p class="first admonition-title">See also</p>
769
<dl class="last docutils">
770
<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>
771
<dd>PEP written and implemented by Łukasz Langa.</dd>
774
<p><a class="reference internal" href="../library/functools.html#functools.total_ordering" title="functools.total_ordering"><code class="xref py py-func docutils literal"><span class="pre">total_ordering()</span></code></a> now supports a return value of
775
<a class="reference internal" href="../library/constants.html#NotImplemented" title="NotImplemented"><code class="xref py py-const docutils literal"><span class="pre">NotImplemented</span></code></a> from the underlying comparison function. (Contributed
776
by Katie Miller in <a class="reference external" href="https://bugs.python.org/issue10042">issue 10042</a>.)</p>
777
<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"><span class="pre">partial()</span></code></a> function is now in the
778
stdlib; in CPython it is overridden by the C accelerated version, but it is
779
available for other implementations to use. (Contributed by Brian Thorne in
780
<a class="reference external" href="https://bugs.python.org/issue12428">issue 12428</a>.)</p>
782
<div class="section" id="gc">
783
<h3>gc<a class="headerlink" href="#gc" title="Permalink to this headline">¶</a></h3>
784
<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"><span class="pre">get_stats()</span></code></a> returns a list of three per-generation
785
dictionaries containing the collections statistics since interpreter startup.
786
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue16351">issue 16351</a>.)</p>
788
<div class="section" id="glob">
789
<h3>glob<a class="headerlink" href="#glob" title="Permalink to this headline">¶</a></h3>
790
<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"><span class="pre">escape()</span></code></a> provides a way to escape special characters
791
in a filename so that they do not become part of the globbing expansion but are
792
instead matched literally. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue8402">issue 8402</a>.)</p>
794
<div class="section" id="hashlib">
795
<h3>hashlib<a class="headerlink" href="#hashlib" title="Permalink to this headline">¶</a></h3>
796
<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"><span class="pre">hashlib.pbkdf2_hmac()</span></code></a> function provides
797
the <a class="reference external" href="https://en.wikipedia.org/wiki/PBKDF2">PKCS#5 password-based key derivation function 2</a>. (Contributed by Christian
798
Heimes in <a class="reference external" href="https://bugs.python.org/issue18582">issue 18582</a>.)</p>
799
<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"><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"><span class="pre">hashlib</span></code></a> hash objects is now
800
a formally supported interface. It has always existed in CPython’s
801
<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"><span class="pre">hashlib</span></code></a> (although it did not return lower case names for all supported
802
hashes), but it was not a public interface and so some other Python
803
implementations have not previously supported it. (Contributed by Jason R.
804
Coombs in <a class="reference external" href="https://bugs.python.org/issue18532">issue 18532</a>.)</p>
806
<div class="section" id="hmac">
807
<h3>hmac<a class="headerlink" href="#hmac" title="Permalink to this headline">¶</a></h3>
808
<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"><span class="pre">hmac</span></code></a> now accepts <code class="docutils literal"><span class="pre">bytearray</span></code> as well as <code class="docutils literal"><span class="pre">bytes</span></code> for the <em>key</em>
809
argument to the <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal"><span class="pre">new()</span></code></a> function, and the <em>msg</em> parameter to both the
810
<a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal"><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"><span class="pre">update()</span></code></a> method now
811
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"><span class="pre">hashlib</span></code></a> module. (Contributed
812
by Jonas Borgström in <a class="reference external" href="https://bugs.python.org/issue18240">issue 18240</a>.)</p>
813
<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"><span class="pre">hmac.new()</span></code></a> function may now be any hash
814
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"><span class="pre">hashlib</span></code></a>. In addition, the current behavior in
815
which the value of <em>digestmod</em> defaults to <code class="docutils literal"><span class="pre">MD5</span></code> is deprecated: in a
816
future version of Python there will be no default value. (Contributed by
817
Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue17276">issue 17276</a>.)</p>
818
<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"><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"><span class="pre">name</span></code></a>
819
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"><span class="pre">digest_size</span></code></a>
820
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"><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.
821
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue18775">issue 18775</a>.)</p>
823
<div class="section" id="html">
824
<h3>html<a class="headerlink" href="#html" title="Permalink to this headline">¶</a></h3>
825
<p>New function <a class="reference internal" href="../library/html.html#html.unescape" title="html.unescape"><code class="xref py py-func docutils literal"><span class="pre">unescape()</span></code></a> function converts HTML5 character references to
826
the corresponding Unicode characters. (Contributed by Ezio Melotti in
827
<a class="reference external" href="https://bugs.python.org/issue2927">issue 2927</a>.)</p>
828
<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"><span class="pre">HTMLParser</span></code></a> accepts a new keyword argument
829
<em>convert_charrefs</em> that, when <code class="docutils literal"><span class="pre">True</span></code>, automatically converts all character
830
references. For backward-compatibility, its value defaults to <code class="docutils literal"><span class="pre">False</span></code>, but
831
it will change to <code class="docutils literal"><span class="pre">True</span></code> in a future version of Python, so you are invited to
832
set it explicitly and update your code to use this new feature. (Contributed
833
by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue13633">issue 13633</a>.)</p>
834
<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"><span class="pre">HTMLParser</span></code></a> is now deprecated.
835
(Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue15114">issue 15114</a>.)</p>
837
<div class="section" id="http">
838
<h3>http<a class="headerlink" href="#http" title="Permalink to this headline">¶</a></h3>
839
<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"><span class="pre">send_error()</span></code></a> now accepts an
840
optional additional <em>explain</em> parameter which can be used to provide an
841
extended error description, overriding the hardcoded default if there is one.
842
This extended error description will be formatted using the
843
<code class="xref py py-attr docutils literal"><span class="pre">error_message_format</span></code> attribute and sent as the body
844
of the error response. (Contributed by Karl Cow in <a class="reference external" href="https://bugs.python.org/issue12921">issue 12921</a>.)</p>
845
<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"><span class="pre">http.server</span></code></a> <a class="reference internal" href="../library/http.server.html#http-server-cli"><span>command line interface</span></a> now has
846
a <code class="docutils literal"><span class="pre">-b/--bind</span></code> option that causes the server to listen on a specific address.
847
(Contributed by Malte Swart in <a class="reference external" href="https://bugs.python.org/issue17764">issue 17764</a>.)</p>
849
<div class="section" id="idlelib-and-idle">
850
<h3>idlelib and IDLE<a class="headerlink" href="#idlelib-and-idle" title="Permalink to this headline">¶</a></h3>
851
<p>Since idlelib implements the IDLE shell and editor and is not intended for
852
import by other programs, it gets improvements with every release. See
853
<code class="file docutils literal"><span class="pre">Lib/idlelib/NEWS.txt</span></code> for a cumulative list of changes since 3.3.0,
854
as well as changes made in future 3.4.x releases. This file is also available
855
from the IDLE <span class="menuselection">Help ‣ About IDLE</span> dialog.</p>
857
<div class="section" id="importlib">
858
<h3>importlib<a class="headerlink" href="#importlib" title="Permalink to this headline">¶</a></h3>
859
<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"><span class="pre">InspectLoader</span></code></a> ABC defines a new method,
860
<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"><span class="pre">source_to_code()</span></code></a> that accepts source
861
data and a path and returns a code object. The default implementation
862
is equivalent to <code class="docutils literal"><span class="pre">compile(data,</span> <span class="pre">path,</span> <span class="pre">'exec',</span> <span class="pre">dont_inherit=True)</span></code>.
863
(Contributed by Eric Snow and Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue15627">issue 15627</a>.)</p>
864
<p><a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader" title="importlib.abc.InspectLoader"><code class="xref py py-class docutils literal"><span class="pre">InspectLoader</span></code></a> also now has a default implementation
865
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"><span class="pre">get_code()</span></code></a> method. However,
866
it will normally be desirable to override the default implementation
867
for performance reasons. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue18072">issue 18072</a>.)</p>
868
<p>The <a class="reference internal" href="../library/importlib.html#importlib.reload" title="importlib.reload"><code class="xref py py-func docutils literal"><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"><span class="pre">imp</span></code></a> to
869
<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"><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"><span class="pre">imp</span></code></a> module deprecation. (Contributed by
870
Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue18193">issue 18193</a>.)</p>
871
<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"><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"><span class="pre">MAGIC_NUMBER</span></code></a> attribute
872
providing access to the bytecode version number. This replaces the
873
<a class="reference internal" href="../library/imp.html#imp.get_magic" title="imp.get_magic"><code class="xref py py-func docutils literal"><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"><span class="pre">imp</span></code></a> module.
874
(Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue18192">issue 18192</a>.)</p>
875
<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"><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"><span class="pre">cache_from_source()</span></code></a>
876
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"><span class="pre">source_from_cache()</span></code></a> replace the same-named functions
877
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"><span class="pre">imp</span></code></a> module. (Contributed by Brett Cannon in
878
<a class="reference external" href="https://bugs.python.org/issue18194">issue 18194</a>.)</p>
879
<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"><span class="pre">importlib</span></code></a> bootstrap <code class="xref py py-class docutils literal"><span class="pre">NamespaceLoader</span></code> now conforms to
880
the <a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader" title="importlib.abc.InspectLoader"><code class="xref py py-class docutils literal"><span class="pre">InspectLoader</span></code></a> ABC, which means that <code class="docutils literal"><span class="pre">runpy</span></code> and
881
<code class="docutils literal"><span class="pre">python</span> <span class="pre">-m</span></code> can now be used with namespace packages. (Contributed
882
by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue18058">issue 18058</a>.)</p>
883
<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"><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"><span class="pre">decode_source()</span></code></a>
884
that decodes source from bytes using universal newline processing. This is
885
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"><span class="pre">InspectLoader.get_source()</span></code></a> methods.</p>
886
<p><a class="reference internal" href="../library/importlib.html#importlib.machinery.ExtensionFileLoader" title="importlib.machinery.ExtensionFileLoader"><code class="xref py py-class docutils literal"><span class="pre">importlib.machinery.ExtensionFileLoader</span></code></a> now has a
887
<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"><span class="pre">get_filename()</span></code></a> method. This was
888
inadvertently omitted in the original implementation. (Contributed by Eric
889
Snow in <a class="reference external" href="https://bugs.python.org/issue19152">issue 19152</a>.)</p>
891
<div class="section" id="inspect">
892
<h3>inspect<a class="headerlink" href="#inspect" title="Permalink to this headline">¶</a></h3>
893
<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"><span class="pre">inspect</span></code></a> module now offers a basic <a class="reference internal" href="../library/inspect.html#inspect-module-cli"><span>command line interface</span></a> to quickly display source code and other
894
information for modules, classes and functions. (Contributed by Claudiu Popa
895
and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue18626">issue 18626</a>.)</p>
896
<p><a class="reference internal" href="../library/inspect.html#inspect.unwrap" title="inspect.unwrap"><code class="xref py py-func docutils literal"><span class="pre">unwrap()</span></code></a> makes it easy to unravel wrapper function chains
897
created by <a class="reference internal" href="../library/functools.html#functools.wraps" title="functools.wraps"><code class="xref py py-func docutils literal"><span class="pre">functools.wraps()</span></code></a> (and any other API that sets the
898
<code class="docutils literal"><span class="pre">__wrapped__</span></code> attribute on a wrapper function). (Contributed by
899
Daniel Urban, Aaron Iles and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue13266">issue 13266</a>.)</p>
900
<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"><span class="pre">enum</span></code></a> module, the
901
<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"><span class="pre">inspect</span></code></a> module now has substantially better support for custom
902
<code class="docutils literal"><span class="pre">__dir__</span></code> methods and dynamic class attributes provided through
903
metaclasses. (Contributed by Ethan Furman in <a class="reference external" href="https://bugs.python.org/issue18929">issue 18929</a> and
904
<a class="reference external" href="https://bugs.python.org/issue19030">issue 19030</a>.)</p>
905
<p><a class="reference internal" href="../library/inspect.html#inspect.getfullargspec" title="inspect.getfullargspec"><code class="xref py py-func docutils literal"><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"><span class="pre">getargspec()</span></code></a>
906
now use the <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal"><span class="pre">signature()</span></code></a> API. This allows them to
907
support a much broader range of callables, including those with
908
<code class="docutils literal"><span class="pre">__signature__</span></code> attributes, those with metadata provided by argument
909
clinic, <a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal"><span class="pre">functools.partial()</span></code></a> objects and more. Note that, unlike
910
<a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal"><span class="pre">signature()</span></code></a>, these functions still ignore <code class="docutils literal"><span class="pre">__wrapped__</span></code>
911
attributes, and report the already bound first argument for bound methods,
912
so it is still necessary to update your code to use
913
<a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal"><span class="pre">signature()</span></code></a> directly if those features are desired.
914
(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue17481">issue 17481</a>.)</p>
915
<p><a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal"><span class="pre">signature()</span></code></a> now supports duck types of CPython functions,
916
which adds support for functions compiled with Cython. (Contributed
917
by Stefan Behnel and Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue17159">issue 17159</a>.)</p>
919
<div class="section" id="ipaddress">
920
<h3>ipaddress<a class="headerlink" href="#ipaddress" title="Permalink to this headline">¶</a></h3>
921
<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"><span class="pre">ipaddress</span></code></a> was added to the standard library in Python 3.3 as a
922
<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
923
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"><span class="pre">ipaddress</span></code></a> is now considered a stable API, covered
924
by the normal standard library requirements to maintain backwards
926
<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"><span class="pre">is_global</span></code></a> property is <code class="docutils literal"><span class="pre">True</span></code> if
927
an address is globally routeable. (Contributed by Peter Moody in
928
<a class="reference external" href="https://bugs.python.org/issue17400">issue 17400</a>.)</p>
930
<div class="section" id="logging">
931
<h3>logging<a class="headerlink" href="#logging" title="Permalink to this headline">¶</a></h3>
932
<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"><span class="pre">TimedRotatingFileHandler</span></code></a> has a new <em>atTime</em>
933
parameter that can be used to specify the time of day when rollover should
934
happen. (Contributed by Ronald Oussoren in <a class="reference external" href="https://bugs.python.org/issue9556">issue 9556</a>.)</p>
935
<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"><span class="pre">SocketHandler</span></code></a> and
936
<a class="reference internal" href="../library/logging.handlers.html#logging.handlers.DatagramHandler" title="logging.handlers.DatagramHandler"><code class="xref py py-class docutils literal"><span class="pre">DatagramHandler</span></code></a> now support Unix domain sockets (by
937
setting <em>port</em> to <code class="docutils literal"><span class="pre">None</span></code>). (Contributed by Vinay Sajip in commit
939
<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"><span class="pre">fileConfig()</span></code></a> now accepts a
940
<a class="reference internal" href="../library/configparser.html#configparser.RawConfigParser" title="configparser.RawConfigParser"><code class="xref py py-class docutils literal"><span class="pre">configparser.RawConfigParser</span></code></a> subclass instance for the <em>fname</em>
941
parameter. This facilitates using a configuration file when logging
942
configuration is just a part of the overall application configuration, or where
943
the application modifies the configuration before passing it to
944
<a class="reference internal" href="../library/logging.config.html#logging.config.fileConfig" title="logging.config.fileConfig"><code class="xref py py-func docutils literal"><span class="pre">fileConfig()</span></code></a>. (Contributed by Vinay Sajip in
945
<a class="reference external" href="https://bugs.python.org/issue16110">issue 16110</a>.)</p>
946
<p>Logging configuration data received from a socket via the
947
<a class="reference internal" href="../library/logging.config.html#logging.config.listen" title="logging.config.listen"><code class="xref py py-func docutils literal"><span class="pre">logging.config.listen()</span></code></a> function can now be validated before being
948
processed by supplying a verification function as the argument to the new
949
<em>verify</em> keyword argument. (Contributed by Vinay Sajip in <a class="reference external" href="https://bugs.python.org/issue15452">issue 15452</a>.)</p>
951
<div class="section" id="marshal">
952
<span id="whatsnew-marshal-3"></span><h3>marshal<a class="headerlink" href="#marshal" title="Permalink to this headline">¶</a></h3>
953
<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"><span class="pre">marshal</span></code></a> version has been bumped to 3. The code implementing
954
the new version restores the Python2 behavior of recording only one copy of
955
interned strings and preserving the interning on deserialization, and extends
956
this “one copy” ability to any object type (including handling recursive
957
references). This reduces both the size of <code class="docutils literal"><span class="pre">.pyc</span></code> files and the amount of
958
memory a module occupies in memory when it is loaded from a <code class="docutils literal"><span class="pre">.pyc</span></code> (or
959
<code class="docutils literal"><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">issue 16475</a>,
960
with additional speedups by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue19219">issue 19219</a>.)</p>
962
<div class="section" id="mmap">
963
<h3>mmap<a class="headerlink" href="#mmap" title="Permalink to this headline">¶</a></h3>
964
<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"><span class="pre">weakref</span></code></a>ed. (Contributed by Valerie Lambert in
965
<a class="reference external" href="https://bugs.python.org/issue4885">issue 4885</a>.)</p>
967
<div class="section" id="multiprocessing">
968
<h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Permalink to this headline">¶</a></h3>
969
<p id="whatsnew-multiprocessing-no-fork">On Unix two new <a class="reference internal" href="../library/multiprocessing.html#multiprocessing-start-methods"><span>start methods</span></a>,
970
<code class="docutils literal"><span class="pre">spawn</span></code> and <code class="docutils literal"><span class="pre">forkserver</span></code>, have been added for starting processes using
971
<a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal"><span class="pre">multiprocessing</span></code></a>. These make the mixing of processes with threads more
972
robust, and the <code class="docutils literal"><span class="pre">spawn</span></code> method matches the semantics that multiprocessing has
973
always used on Windows. New function
974
<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"><span class="pre">get_all_start_methods()</span></code></a> reports all start methods
975
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"><span class="pre">get_start_method()</span></code></a> reports
976
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"><span class="pre">set_start_method()</span></code></a> sets
977
the start method. (Contributed by Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue8713">issue 8713</a>.)</p>
978
<p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal"><span class="pre">multiprocessing</span></code></a> also now has the concept of a <code class="docutils literal"><span class="pre">context</span></code>, which
979
determines how child processes are created. New function
980
<a class="reference internal" href="../library/multiprocessing.html#multiprocessing.get_context" title="multiprocessing.get_context"><code class="xref py py-func docutils literal"><span class="pre">get_context()</span></code></a> returns a context that uses a specified
981
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"><span class="pre">multiprocessing</span></code></a> module itself,
982
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"><span class="pre">Pool</span></code></a>s and other
983
objects that will operate within that context. This allows a framework and an
984
application or different parts of the same application to use multiprocessing
985
without interfering with each other. (Contributed by Richard Oudkerk in
986
<a class="reference external" href="https://bugs.python.org/issue18999">issue 18999</a>.)</p>
987
<p>Except when using the old <em>fork</em> start method, child processes no longer
988
inherit unneeded handles/file descriptors from their parents (part of
989
<a class="reference external" href="https://bugs.python.org/issue8713">issue 8713</a>).</p>
990
<p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal"><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"><span class="pre">runpy</span></code></a> (which implements the
991
<code class="docutils literal"><span class="pre">-m</span></code> switch) to initialise <code class="docutils literal"><span class="pre">__main__</span></code> appropriately in child processes
992
when using the <code class="docutils literal"><span class="pre">spawn</span></code> or <code class="docutils literal"><span class="pre">forkserver</span></code> start methods. This resolves some
993
edge cases where combining multiprocessing, the <code class="docutils literal"><span class="pre">-m</span></code> command line switch,
994
and explicit relative imports could cause obscure failures in child
995
processes. (Contributed by Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue19946">issue 19946</a>.)</p>
997
<div class="section" id="operator">
998
<h3>operator<a class="headerlink" href="#operator" title="Permalink to this headline">¶</a></h3>
999
<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"><span class="pre">length_hint()</span></code></a> provides an implementation of the
1000
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"><span class="pre">__length_hint__()</span></code></a> special method should
1001
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
1002
feature. (Contributed by Armin Ronacher in <a class="reference external" href="https://bugs.python.org/issue16148">issue 16148</a>.)</p>
1003
<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"><span class="pre">operator</span></code></a> module available for
1004
reference and for use by alternate implementations of Python. (Contributed by
1005
Zachary Ware in <a class="reference external" href="https://bugs.python.org/issue16694">issue 16694</a>.)</p>
1007
<div class="section" id="os">
1008
<h3>os<a class="headerlink" href="#os" title="Permalink to this headline">¶</a></h3>
1009
<p>There are new functions to get and set the <a class="reference internal" href="../library/os.html#fd-inheritance"><span>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"><span class="pre">os.get_inheritable()</span></code></a>,
1010
<a class="reference internal" href="../library/os.html#os.set_inheritable" title="os.set_inheritable"><code class="xref py py-func docutils literal"><span class="pre">os.set_inheritable()</span></code></a>) or a Windows handle
1011
(<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"><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"><span class="pre">os.set_handle_inheritable()</span></code></a>).</p>
1012
<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"><span class="pre">cpu_count()</span></code></a> reports the number of CPUs available on the
1013
platform on which Python is running (or <code class="docutils literal"><span class="pre">None</span></code> if the count can’t be
1014
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"><span class="pre">multiprocessing.cpu_count()</span></code></a> function is now implemented
1015
in terms of this function). (Contributed by Trent Nelson, Yogesh Chaudhari,
1016
Victor Stinner, and Charles-François Natali in <a class="reference external" href="https://bugs.python.org/issue17914">issue 17914</a>.)</p>
1017
<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"><span class="pre">os.path.samestat()</span></code></a> is now available on the Windows platform (and the
1018
<a class="reference internal" href="../library/os.path.html#os.path.samefile" title="os.path.samefile"><code class="xref py py-func docutils literal"><span class="pre">os.path.samefile()</span></code></a> implementation is now shared between Unix and
1019
Windows). (Contributed by Brian Curtin in <a class="reference external" href="https://bugs.python.org/issue11939">issue 11939</a>.)</p>
1020
<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"><span class="pre">os.path.ismount()</span></code></a> now recognizes volumes mounted below a drive
1021
root on Windows. (Contributed by Tim Golden in <a class="reference external" href="https://bugs.python.org/issue9035">issue 9035</a>.)</p>
1022
<p><a class="reference internal" href="../library/os.html#os.open" title="os.open"><code class="xref py py-func docutils literal"><span class="pre">os.open()</span></code></a> supports two new flags on platforms that provide them,
1023
<a class="reference internal" href="../library/os.html#os.O_PATH" title="os.O_PATH"><code class="xref py py-data docutils literal"><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"><span class="pre">O_TMPFILE</span></code></a>
1024
(unnamed temporary file; as of 3.4.0 release available only on Linux systems
1025
with a kernel version of 3.11 or newer that have uapi headers). (Contributed
1026
by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue18673">issue 18673</a> and Benjamin Peterson, respectively.)</p>
1028
<div class="section" id="pdb">
1029
<h3>pdb<a class="headerlink" href="#pdb" title="Permalink to this headline">¶</a></h3>
1030
<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"><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"><span class="pre">yield</span></code></a>, and
1031
<code class="docutils literal"><span class="pre">yield</span> <span class="pre">from</span></code> in a more useful fashion. This is especially helpful when
1032
debugging <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O, event loop, coroutines and tasks."><code class="xref py py-mod docutils literal"><span class="pre">asyncio</span></code></a> based programs. (Contributed by Andrew Svetlov and
1033
Xavier de Gaye in <a class="reference external" href="https://bugs.python.org/issue16596">issue 16596</a>.)</p>
1034
<p>The <code class="docutils literal"><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"><span class="pre">pdb</span></code></a>, restoring access to the
1035
Python <a class="reference internal" href="../library/functions.html#print" title="print"><code class="xref py py-func docutils literal"><span class="pre">print()</span></code></a> function from the pdb command line. Python2’s <code class="docutils literal"><span class="pre">pdb</span></code> did
1036
not have a <code class="docutils literal"><span class="pre">print</span></code> command; instead, entering <code class="docutils literal"><span class="pre">print</span></code> executed the
1037
<code class="docutils literal"><span class="pre">print</span></code> statement. In Python3 <code class="docutils literal"><span class="pre">print</span></code> was mistakenly made an alias for the
1038
pdb <a class="reference internal" href="../library/pdb.html#pdbcommand-p"><code class="xref std std-pdbcmd docutils literal"><span class="pre">p</span></code></a> command. <code class="docutils literal"><span class="pre">p</span></code>, however, prints the <code class="docutils literal"><span class="pre">repr</span></code> of its argument,
1039
not the <code class="docutils literal"><span class="pre">str</span></code> like the Python2 <code class="docutils literal"><span class="pre">print</span></code> command did. Worse, the Python3
1040
<code class="docutils literal"><span class="pre">pdb</span> <span class="pre">print</span></code> command shadowed the Python3 <code class="docutils literal"><span class="pre">print</span></code> function, making it
1041
inaccessible at the <code class="docutils literal"><span class="pre">pdb</span></code> prompt. (Contributed by Connor Osborn in
1042
<a class="reference external" href="https://bugs.python.org/issue18764">issue 18764</a>.)</p>
1044
<div class="section" id="pickle">
1045
<span id="whatsnew-protocol-4"></span><h3>pickle<a class="headerlink" href="#pickle" title="Permalink to this headline">¶</a></h3>
1046
<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"><span class="pre">pickle</span></code></a> now supports (but does not use by default) a new pickle protocol,
1047
protocol 4. This new protocol addresses a number of issues that were present
1048
in previous protocols, such as the serialization of nested classes, very large
1049
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"><span class="pre">__new__()</span></code></a> method takes
1050
keyword-only arguments. It also provides some efficiency improvements.</p>
1051
<div class="admonition seealso">
1052
<p class="first admonition-title">See also</p>
1053
<dl class="last docutils">
1054
<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>
1055
<dd>PEP written by Antoine Pitrou and implemented by Alexandre Vassalotti.</dd>
1059
<div class="section" id="plistlib">
1060
<h3>plistlib<a class="headerlink" href="#plistlib" title="Permalink to this headline">¶</a></h3>
1061
<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"><span class="pre">plistlib</span></code></a> now has an API that is similar to the standard pattern for
1062
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"><span class="pre">load()</span></code></a>,
1063
<a class="reference internal" href="../library/plistlib.html#plistlib.dump" title="plistlib.dump"><code class="xref py py-func docutils literal"><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"><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"><span class="pre">dumps()</span></code></a>
1064
functions. (The older API is now deprecated.) In addition to the already
1065
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"><span class="pre">FMT_XML</span></code></a>), it also now supports
1066
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"><span class="pre">FMT_BINARY</span></code></a>). (Contributed by Ronald
1067
Oussoren and others in <a class="reference external" href="https://bugs.python.org/issue14455">issue 14455</a>.)</p>
1069
<div class="section" id="poplib">
1070
<h3>poplib<a class="headerlink" href="#poplib" title="Permalink to this headline">¶</a></h3>
1071
<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"><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"><span class="pre">capa()</span></code></a>,
1072
which returns the list of capabilities advertised by the POP server, and
1073
<a class="reference internal" href="../library/poplib.html#poplib.POP3.stls" title="poplib.POP3.stls"><code class="xref py py-meth docutils literal"><span class="pre">stls()</span></code></a>, which switches a clear-text POP3 session into an
1074
encrypted POP3 session if the POP server supports it. (Contributed by Lorenzo
1075
Catucci in <a class="reference external" href="https://bugs.python.org/issue4473">issue 4473</a>.)</p>
1077
<div class="section" id="pprint">
1078
<h3>pprint<a class="headerlink" href="#pprint" title="Permalink to this headline">¶</a></h3>
1079
<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"><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"><span class="pre">PrettyPrinter</span></code></a> class and its
1080
<a class="reference internal" href="../library/pprint.html#pprint.pformat" title="pprint.pformat"><code class="xref py py-func docutils literal"><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"><span class="pre">pprint()</span></code></a> functions have a new
1081
option, <em>compact</em>, that controls how the output is formatted. Currently
1082
setting <em>compact</em> to <code class="docutils literal"><span class="pre">True</span></code> means that sequences will be printed with as many
1083
sequence elements as will fit within <em>width</em> on each (indented) line.
1084
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue19132">issue 19132</a>.)</p>
1085
<p>Long strings are now wrapped using Python’s normal line continuation
1086
syntax. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue17150">issue 17150</a>.)</p>
1088
<div class="section" id="pty">
1089
<h3>pty<a class="headerlink" href="#pty" title="Permalink to this headline">¶</a></h3>
1090
<p><a class="reference internal" href="../library/pty.html#pty.spawn" title="pty.spawn"><code class="xref py py-func docutils literal"><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"><span class="pre">os.waitpid()</span></code></a> on
1091
the child process, instead of <code class="docutils literal"><span class="pre">None</span></code>. (Contributed by Gregory P. Smith.)</p>
1093
<div class="section" id="pydoc">
1094
<h3>pydoc<a class="headerlink" href="#pydoc" title="Permalink to this headline">¶</a></h3>
1095
<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"><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"><span class="pre">inspect.signature()</span></code></a>
1096
introspection API, allowing it to provide signature information for a wider
1097
variety of callable objects. This change also means that <code class="docutils literal"><span class="pre">__wrapped__</span></code>
1098
attributes are now taken into account when displaying help information.
1099
(Contributed by Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue19674">issue 19674</a>.)</p>
1100
<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"><span class="pre">pydoc</span></code></a> module no longer displays the <code class="docutils literal"><span class="pre">self</span></code> parameter for
1101
already bound methods. Instead, it aims to always display the exact current
1102
signature of the supplied callable. (Contributed by Larry Hastings in
1103
<a class="reference external" href="https://bugs.python.org/issue20710">issue 20710</a>.)</p>
1104
<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"><span class="pre">pydoc</span></code></a> directly,
1105
its handling of custom <code class="docutils literal"><span class="pre">__dir__</span></code> methods and various descriptor
1106
behaviours has also been improved substantially by the underlying changes in
1107
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"><span class="pre">inspect</span></code></a> module.</p>
1108
<p>As the <a class="reference internal" href="../library/functions.html#help" title="help"><code class="xref py py-func docutils literal"><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"><span class="pre">pydoc</span></code></a>, the above changes also
1109
affect the behaviour of <a class="reference internal" href="../library/functions.html#help" title="help"><code class="xref py py-func docutils literal"><span class="pre">help()</span></code></a>.</p>
1111
<div class="section" id="re">
1112
<h3>re<a class="headerlink" href="#re" title="Permalink to this headline">¶</a></h3>
1113
<p>New <a class="reference internal" href="../library/re.html#re.fullmatch" title="re.fullmatch"><code class="xref py py-func docutils literal"><span class="pre">fullmatch()</span></code></a> function and <a class="reference internal" href="../library/re.html#re.regex.fullmatch" title="re.regex.fullmatch"><code class="xref py py-meth docutils literal"><span class="pre">regex.fullmatch()</span></code></a> method anchor
1114
the pattern at both ends of the string to match. This provides a way to be
1115
explicit about the goal of the match, which avoids a class of subtle bugs where
1116
<code class="docutils literal"><span class="pre">$</span></code> characters get lost during code changes or the addition of alternatives
1117
to an existing regular expression. (Contributed by Matthew Barnett in
1118
<a class="reference external" href="https://bugs.python.org/issue16203">issue 16203</a>.)</p>
1119
<p>The repr of <a class="reference internal" href="../library/re.html#re-objects"><span>regex objects</span></a> now includes the pattern
1120
and the flags; the repr of <a class="reference internal" href="../library/re.html#match-objects"><span>match objects</span></a> now
1121
includes the start, end, and the part of the string that matched. (Contributed
1122
by Hugo Lopes Tavares and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue13592">issue 13592</a> and
1123
<a class="reference external" href="https://bugs.python.org/issue17087">issue 17087</a>.)</p>
1125
<div class="section" id="resource">
1126
<h3>resource<a class="headerlink" href="#resource" title="Permalink to this headline">¶</a></h3>
1127
<p>New <a class="reference internal" href="../library/resource.html#resource.prlimit" title="resource.prlimit"><code class="xref py py-func docutils literal"><span class="pre">prlimit()</span></code></a> function, available on Linux platforms with a
1128
kernel version of 2.6.36 or later and glibc of 2.13 or later, provides the
1129
ability to query or set the resource limits for processes other than the one
1130
making the call. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue16595">issue 16595</a>.)</p>
1131
<p>On Linux kernel version 2.6.36 or later, there are also some new
1132
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"><span class="pre">RLIMIT_MSGQUEUE</span></code></a>,
1133
<a class="reference internal" href="../library/resource.html#resource.RLIMIT_NICE" title="resource.RLIMIT_NICE"><code class="xref py py-attr docutils literal"><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"><span class="pre">RLIMIT_RTPRIO</span></code></a>,
1134
<a class="reference internal" href="../library/resource.html#resource.RLIMIT_RTTIME" title="resource.RLIMIT_RTTIME"><code class="xref py py-attr docutils literal"><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"><span class="pre">RLIMIT_SIGPENDING</span></code></a>.
1135
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue19324">issue 19324</a>.)</p>
1136
<p>On FreeBSD version 9 and later, there some new FreeBSD specific constants:
1137
<a class="reference internal" href="../library/resource.html#resource.RLIMIT_SBSIZE" title="resource.RLIMIT_SBSIZE"><code class="xref py py-attr docutils literal"><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"><span class="pre">RLIMIT_SWAP</span></code></a>, and
1138
<a class="reference internal" href="../library/resource.html#resource.RLIMIT_NPTS" title="resource.RLIMIT_NPTS"><code class="xref py py-attr docutils literal"><span class="pre">RLIMIT_NPTS</span></code></a>. (Contributed by Claudiu Popa in
1139
<a class="reference external" href="https://bugs.python.org/issue19343">issue 19343</a>.)</p>
1141
<div class="section" id="select">
1142
<h3>select<a class="headerlink" href="#select" title="Permalink to this headline">¶</a></h3>
1143
<p><a class="reference internal" href="../library/select.html#select.epoll" title="select.epoll"><code class="xref py py-class docutils literal"><span class="pre">epoll</span></code></a> objects now support the context management protocol.
1144
When used in a <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal"><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"><span class="pre">close()</span></code></a>
1145
method will be called automatically at the end of the block. (Contributed
1146
by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue16488">issue 16488</a>.)</p>
1147
<p><a class="reference internal" href="../library/select.html#select.devpoll" title="select.devpoll"><code class="xref py py-class docutils literal"><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"><span class="pre">fileno()</span></code></a> and
1148
<a class="reference internal" href="../library/select.html#select.devpoll.close" title="select.devpoll.close"><code class="xref py py-meth docutils literal"><span class="pre">close()</span></code></a> methods, as well as a new attribute
1149
<a class="reference internal" href="../library/select.html#select.devpoll.closed" title="select.devpoll.closed"><code class="xref py py-attr docutils literal"><span class="pre">closed</span></code></a>. (Contributed by Victor Stinner in
1150
<a class="reference external" href="https://bugs.python.org/issue18794">issue 18794</a>.)</p>
1152
<div class="section" id="shelve">
1153
<h3>shelve<a class="headerlink" href="#shelve" title="Permalink to this headline">¶</a></h3>
1154
<p><a class="reference internal" href="../library/shelve.html#shelve.Shelf" title="shelve.Shelf"><code class="xref py py-class docutils literal"><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"><span class="pre">with</span></code></a> statements,
1155
and will be automatically closed at the end of the <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal"><span class="pre">with</span></code></a> block.
1156
(Contributed by Filip Gruszczyński in <a class="reference external" href="https://bugs.python.org/issue13896">issue 13896</a>.)</p>
1158
<div class="section" id="shutil">
1159
<h3>shutil<a class="headerlink" href="#shutil" title="Permalink to this headline">¶</a></h3>
1160
<p><a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal"><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"><span class="pre">Error</span></code></a> subclass,
1161
<a class="reference internal" href="../library/shutil.html#shutil.SameFileError" title="shutil.SameFileError"><code class="xref py py-exc docutils literal"><span class="pre">SameFileError</span></code></a>, when the source and destination are the same
1162
file, which allows an application to take appropriate action on this specific
1163
error. (Contributed by Atsuo Ishimoto and Hynek Schlawack in
1164
<a class="reference external" href="https://bugs.python.org/issue1492704">issue 1492704</a>.)</p>
1166
<div class="section" id="smtpd">
1167
<h3>smtpd<a class="headerlink" href="#smtpd" title="Permalink to this headline">¶</a></h3>
1168
<p>The <a class="reference internal" href="../library/smtpd.html#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal"><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"><span class="pre">SMTPChannel</span></code></a> classes now
1169
accept a <em>map</em> keyword argument which, if specified, is passed in to
1170
<a class="reference internal" href="../library/asynchat.html#asynchat.async_chat" title="asynchat.async_chat"><code class="xref py py-class docutils literal"><span class="pre">asynchat.async_chat</span></code></a> as its <em>map</em> argument. This allows an application
1171
to avoid affecting the global socket map. (Contributed by Vinay Sajip in
1172
<a class="reference external" href="https://bugs.python.org/issue11959">issue 11959</a>.)</p>
1174
<div class="section" id="smtplib">
1175
<h3>smtplib<a class="headerlink" href="#smtplib" title="Permalink to this headline">¶</a></h3>
1176
<p><a class="reference internal" href="../library/smtplib.html#smtplib.SMTPException" title="smtplib.SMTPException"><code class="xref py py-exc docutils literal"><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"><span class="pre">OSError</span></code></a>, which allows
1177
both socket level errors and SMTP protocol level errors to be caught in one
1178
try/except statement by code that only cares whether or not an error occurred.
1179
(Contributed by Ned Jackson Lovely in <a class="reference external" href="https://bugs.python.org/issue2118">issue 2118</a>.)</p>
1181
<div class="section" id="socket">
1182
<h3>socket<a class="headerlink" href="#socket" title="Permalink to this headline">¶</a></h3>
1183
<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"><span class="pre">CAN_BCM</span></code></a> protocol on
1184
platforms that support it. (Contributed by Brian Thorne in <a class="reference external" href="https://bugs.python.org/issue15359">issue 15359</a>.)</p>
1185
<p>Socket objects have new methods to get or set their <a class="reference internal" href="../library/os.html#fd-inheritance"><span>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"><span class="pre">get_inheritable()</span></code></a> and
1186
<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"><span class="pre">set_inheritable()</span></code></a>.</p>
1187
<p>The <code class="docutils literal"><span class="pre">socket.AF_*</span></code> and <code class="docutils literal"><span class="pre">socket.SOCK_*</span></code> constants are now enumeration values
1188
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"><span class="pre">enum</span></code></a> module. This allows meaningful names to be printed
1189
during debugging, instead of integer “magic numbers”.</p>
1190
<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"><span class="pre">AF_LINK</span></code></a> constant is now available on BSD and OSX.</p>
1191
<p><a class="reference internal" href="../library/socket.html#socket.inet_pton" title="socket.inet_pton"><code class="xref py py-func docutils literal"><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"><span class="pre">inet_ntop()</span></code></a> are now supported
1192
on Windows. (Contributed by Atsuo Ishimoto in <a class="reference external" href="https://bugs.python.org/issue7171">issue 7171</a>.)</p>
1194
<div class="section" id="sqlite3">
1195
<h3>sqlite3<a class="headerlink" href="#sqlite3" title="Permalink to this headline">¶</a></h3>
1196
<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"><span class="pre">connect()</span></code></a> function, <em>uri</em>, can be
1197
used to indicate that the <em>database</em> parameter is a <code class="docutils literal"><span class="pre">uri</span></code> (see the <a class="reference external" href="https://www.sqlite.org/uri.html">SQLite
1198
URI documentation</a>). (Contributed by poq in
1199
<a class="reference external" href="https://bugs.python.org/issue13773">issue 13773</a>.)</p>
1201
<div class="section" id="ssl">
1202
<h3>ssl<a class="headerlink" href="#ssl" title="Permalink to this headline">¶</a></h3>
1203
<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"><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"><span class="pre">PROTOCOL_TLSv1_2</span></code></a> (TLSv1.1 and
1204
TLSv1.2 support) have been added; support for these protocols is only available if
1205
Python is linked with OpenSSL 1.0.1 or later. (Contributed by Michele Orrù and
1206
Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue16692">issue 16692</a>.)</p>
1207
<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"><span class="pre">create_default_context()</span></code></a> provides a standard way to
1208
obtain an <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal"><span class="pre">SSLContext</span></code></a> whose settings are intended to be a
1209
reasonable balance between compatibility and security. These settings are
1210
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"><span class="pre">SSLContext</span></code></a>
1211
constructor, and may be adjusted in the future, without prior deprecation, if
1212
best-practice security requirements change. The new recommended best
1213
practice for using stdlib libraries that support SSL is to use
1214
<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"><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"><span class="pre">SSLContext</span></code></a>
1215
object, modify it if needed, and then pass it as the <em>context</em> argument
1216
of the appropriate stdlib API. (Contributed by Christian Heimes
1217
in <a class="reference external" href="https://bugs.python.org/issue19689">issue 19689</a>.)</p>
1218
<p><a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal"><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"><span class="pre">load_verify_locations()</span></code></a>
1219
accepts a new optional argument <em>cadata</em>, which can be used to provide PEM or
1220
DER encoded certificates directly via strings or bytes, respectively.
1221
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue18138">issue 18138</a>.)</p>
1222
<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"><span class="pre">get_default_verify_paths()</span></code></a> returns
1223
a named tuple of the paths and environment variables that the
1224
<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"><span class="pre">set_default_verify_paths()</span></code></a> method uses to set
1225
OpenSSL’s default <code class="docutils literal"><span class="pre">cafile</span></code> and <code class="docutils literal"><span class="pre">capath</span></code>. This can be an aid in
1226
debugging default verification issues. (Contributed by Christian Heimes
1227
in <a class="reference external" href="https://bugs.python.org/issue18143">issue 18143</a>.)</p>
1228
<p><a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal"><span class="pre">SSLContext</span></code></a> has a new method,
1229
<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"><span class="pre">cert_store_stats()</span></code></a>, that reports the number of loaded
1230
<code class="docutils literal"><span class="pre">X.509</span></code> certs, <code class="docutils literal"><span class="pre">X.509</span> <span class="pre">CA</span></code> certs, and certificate revocation lists (<code class="docutils literal"><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"><span class="pre">get_ca_certs()</span></code></a> method that returns a
1231
list of the loaded <code class="docutils literal"><span class="pre">CA</span></code> certificates. (Contributed by Christian Heimes in
1232
<a class="reference external" href="https://bugs.python.org/issue18147">issue 18147</a>.)</p>
1233
<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"><span class="pre">SSLContext</span></code></a> has a new
1234
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"><span class="pre">verify_flags</span></code></a> that can be used to control the
1235
certificate verification process by setting it to some combination of the new
1236
constants <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_DEFAULT" title="ssl.VERIFY_DEFAULT"><code class="xref py py-data docutils literal"><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"><span class="pre">VERIFY_CRL_CHECK_LEAF</span></code></a>,
1237
<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"><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"><span class="pre">VERIFY_X509_STRICT</span></code></a>.
1238
OpenSSL does not do any CRL verification by default. (Contributed by
1239
Christien Heimes in <a class="reference external" href="https://bugs.python.org/issue8813">issue 8813</a>.)</p>
1240
<p>New <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal"><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"><span class="pre">load_default_certs()</span></code></a>
1241
loads a set of default “certificate authority” (CA) certificates from default
1242
locations, which vary according to the platform. It can be used to load both
1243
TLS web server authentication certificates
1244
(<code class="docutils literal"><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"><span class="pre">SERVER_AUTH</span></code></a>) for a client to use to verify a
1245
server, and certificates for a server to use in verifying client certificates
1246
(<code class="docutils literal"><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"><span class="pre">CLIENT_AUTH</span></code></a>). (Contributed by Christian
1247
Heimes in <a class="reference external" href="https://bugs.python.org/issue19292">issue 19292</a>.)</p>
1248
<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"><span class="pre">enum_certificates()</span></code></a> and
1249
<a class="reference internal" href="../library/ssl.html#ssl.enum_crls" title="ssl.enum_crls"><code class="xref py py-func docutils literal"><span class="pre">enum_crls()</span></code></a> provide the ability to retrieve certificates,
1250
certificate information, and CRLs from the Windows cert store. (Contributed
1251
by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue17134">issue 17134</a>.)</p>
1252
<p id="whatsnew34-sni">Support for server-side SNI (Server Name Indication) using the new
1253
<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"><span class="pre">ssl.SSLContext.set_servername_callback()</span></code></a> method.
1254
(Contributed by Daniel Black in <a class="reference external" href="https://bugs.python.org/issue8109">issue 8109</a>.)</p>
1255
<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"><span class="pre">SSLSocket.getpeercert()</span></code></a> contains additional
1256
<code class="docutils literal"><span class="pre">X509v3</span></code> extension items: <code class="docutils literal"><span class="pre">crlDistributionPoints</span></code>, <code class="docutils literal"><span class="pre">calIssuers</span></code>, and
1257
<code class="docutils literal"><span class="pre">OCSP</span></code> URIs. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue18379">issue 18379</a>.)</p>
1259
<div class="section" id="stat">
1260
<h3>stat<a class="headerlink" href="#stat" title="Permalink to this headline">¶</a></h3>
1261
<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"><span class="pre">stat</span></code></a> module is now backed by a C implementation in <code class="xref py py-mod docutils literal"><span class="pre">_stat</span></code>. A C
1262
implementation is required as most of the values aren’t standardized and
1263
are platform-dependent. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue11016">issue 11016</a>.)</p>
1264
<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"><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"><span class="pre">S_IFDOOR</span></code></a>,
1265
<a class="reference internal" href="../library/stat.html#stat.S_IFPORT" title="stat.S_IFPORT"><code class="xref py py-attr docutils literal"><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"><span class="pre">S_IFWHT</span></code></a>. (Contributed by
1266
Christian Hiemes in <a class="reference external" href="https://bugs.python.org/issue11016">issue 11016</a>.)</p>
1268
<div class="section" id="struct">
1269
<h3>struct<a class="headerlink" href="#struct" title="Permalink to this headline">¶</a></h3>
1270
<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"><span class="pre">iter_unpack</span></code></a> and a new
1271
<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"><span class="pre">struct.Struct.iter_unpack()</span></code></a> method on compiled formats provide streamed
1272
unpacking of a buffer containing repeated instances of a given format of data.
1273
(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue17804">issue 17804</a>.)</p>
1275
<div class="section" id="subprocess">
1276
<h3>subprocess<a class="headerlink" href="#subprocess" title="Permalink to this headline">¶</a></h3>
1277
<p><a class="reference internal" href="../library/subprocess.html#subprocess.check_output" title="subprocess.check_output"><code class="xref py py-func docutils literal"><span class="pre">check_output()</span></code></a> now accepts an <em>input</em> argument that can
1278
be used to provide the contents of <code class="docutils literal"><span class="pre">stdin</span></code> for the command that is run.
1279
(Contributed by Zack Weinberg in <a class="reference external" href="https://bugs.python.org/issue16624">issue 16624</a>.)</p>
1280
<p><code class="xref py py-func docutils literal"><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"><span class="pre">getstatusoutput()</span></code></a> now
1281
work on Windows. This change was actually inadvertently made in 3.3.4.
1282
(Contributed by Tim Golden in <a class="reference external" href="https://bugs.python.org/issue10197">issue 10197</a>.)</p>
1284
<div class="section" id="sunau">
1285
<h3>sunau<a class="headerlink" href="#sunau" title="Permalink to this headline">¶</a></h3>
1286
<p>The <code class="xref py py-meth docutils literal"><span class="pre">getparams()</span></code> method now returns a namedtuple rather than a
1287
plain tuple. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue18901">issue 18901</a>.)</p>
1288
<p><a class="reference internal" href="../library/sunau.html#sunau.open" title="sunau.open"><code class="xref py py-meth docutils literal"><span class="pre">sunau.open()</span></code></a> now supports the context management protocol: when used in a
1289
<a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal"><span class="pre">with</span></code></a> block, the <code class="docutils literal"><span class="pre">close</span></code> method of the returned object will be
1290
called automatically at the end of the block. (Contributed by Serhiy Storchaka
1291
in <a class="reference external" href="https://bugs.python.org/issue18878">issue 18878</a>.)</p>
1292
<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"><span class="pre">AU_write.setsampwidth()</span></code></a> now supports 24 bit samples, thus adding
1293
support for writing 24 sample using the module. (Contributed by
1294
Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue19261">issue 19261</a>.)</p>
1295
<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"><span class="pre">writeframesraw()</span></code></a> and
1296
<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"><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
1297
object</span></a>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue8311">issue 8311</a>.)</p>
1299
<div class="section" id="sys">
1300
<h3>sys<a class="headerlink" href="#sys" title="Permalink to this headline">¶</a></h3>
1301
<p>New function <a class="reference internal" href="../library/sys.html#sys.getallocatedblocks" title="sys.getallocatedblocks"><code class="xref py py-func docutils literal"><span class="pre">sys.getallocatedblocks()</span></code></a> returns the current number of
1302
blocks allocated by the interpreter. (In CPython with the default
1303
<code class="docutils literal"><span class="pre">--with-pymalloc</span></code> setting, this is allocations made through the
1304
<code class="xref c c-func docutils literal"><span class="pre">PyObject_Malloc()</span></code> API.) This can be useful for tracking memory leaks,
1305
especially if automated via a test suite. (Contributed by Antoine Pitrou
1306
in <a class="reference external" href="https://bugs.python.org/issue13390">issue 13390</a>.)</p>
1307
<p>When the Python interpreter starts in <a class="reference internal" href="../tutorial/interpreter.html#tut-interactive"><span>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"><span class="pre">__interactivehook__</span></code></a> attribute
1308
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"><span class="pre">sys</span></code></a> module. If the attribute exists, its value is called with no
1309
arguments just before interactive mode is started. The check is made after the
1310
<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"><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"><span class="pre">site</span></code></a>
1311
module <a class="reference internal" href="../library/site.html#rlcompleter-config"><span>sets it</span></a> to a function that enables tab
1312
completion and history saving (in <code class="file docutils literal"><span class="pre">~/.python-history</span></code>) if the platform
1313
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"><span class="pre">readline</span></code></a>. If you do not want this (new) behavior, you can
1314
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"><span class="pre">PYTHONSTARTUP</span></code></a>, <code class="xref py py-mod docutils literal"><span class="pre">sitecustomize</span></code>, or
1315
<code class="xref py py-mod docutils literal"><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"><span class="pre">sys</span></code></a> (or setting it
1316
to some other callable). (Contributed by Éric Araujo and Antoine Pitrou in
1317
<a class="reference external" href="https://bugs.python.org/issue5845">issue 5845</a>.)</p>
1319
<div class="section" id="tarfile">
1320
<h3>tarfile<a class="headerlink" href="#tarfile" title="Permalink to this headline">¶</a></h3>
1321
<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"><span class="pre">tarfile</span></code></a> module now supports a simple <a class="reference internal" href="../library/tarfile.html#tarfile-commandline"><span>Command Line Interface</span></a> when
1322
called as a script directly or via <code class="docutils literal"><span class="pre">-m</span></code>. This can be used to create and
1323
extract tarfile archives. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue13477">issue 13477</a>.)</p>
1325
<div class="section" id="textwrap">
1326
<h3>textwrap<a class="headerlink" href="#textwrap" title="Permalink to this headline">¶</a></h3>
1327
<p>The <a class="reference internal" href="../library/textwrap.html#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal"><span class="pre">TextWrapper</span></code></a> class has two new attributes/constructor
1328
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"><span class="pre">max_lines</span></code></a>, which limits the number of
1329
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"><span class="pre">placeholder</span></code></a>, which is a
1330
string that will appear at the end of the output if it has been truncated
1331
because of <em>max_lines</em>. Building on these capabilities, a new convenience
1332
function <a class="reference internal" href="../library/textwrap.html#textwrap.shorten" title="textwrap.shorten"><code class="xref py py-func docutils literal"><span class="pre">shorten()</span></code></a> collapses all of the whitespace in the input
1333
to single spaces and produces a single line of a given <em>width</em> that ends with
1334
the <em>placeholder</em> (by default, <code class="docutils literal"><span class="pre">[...]</span></code>). (Contributed by Antoine Pitrou and
1335
Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue18585">issue 18585</a> and <a class="reference external" href="https://bugs.python.org/issue18725">issue 18725</a>.)</p>
1337
<div class="section" id="threading">
1338
<h3>threading<a class="headerlink" href="#threading" title="Permalink to this headline">¶</a></h3>
1339
<p>The <a class="reference internal" href="../library/threading.html#threading.Thread" title="threading.Thread"><code class="xref py py-class docutils literal"><span class="pre">Thread</span></code></a> object representing the main thread can be
1340
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"><span class="pre">main_thread()</span></code></a> function. In normal
1341
conditions this will be the thread from which the Python interpreter was
1342
started. (Contributed by Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue18882">issue 18882</a>.)</p>
1344
<div class="section" id="traceback">
1345
<h3>traceback<a class="headerlink" href="#traceback" title="Permalink to this headline">¶</a></h3>
1346
<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"><span class="pre">traceback.clear_frames()</span></code></a> function takes a traceback object
1347
and clears the local variables in all of the frames it references,
1348
reducing the amount of memory consumed. (Contributed by Andrew Kuchling in
1349
<a class="reference external" href="https://bugs.python.org/issue1565525">issue 1565525</a>.)</p>
1351
<div class="section" id="types">
1352
<h3>types<a class="headerlink" href="#types" title="Permalink to this headline">¶</a></h3>
1353
<p>A new <a class="reference internal" href="../library/types.html#types.DynamicClassAttribute" title="types.DynamicClassAttribute"><code class="xref py py-func docutils literal"><span class="pre">DynamicClassAttribute()</span></code></a> descriptor provides a way to define
1354
an attribute that acts normally when looked up through an instance object, but
1355
which is routed to the <em>class</em> <code class="docutils literal"><span class="pre">__getattr__</span></code> when looked up through the
1356
class. This allows one to have properties active on a class, and have virtual
1357
attributes on the class with the same name (see <code class="xref py py-mod docutils literal"><span class="pre">Enum</span></code> for an example).
1358
(Contributed by Ethan Furman in <a class="reference external" href="https://bugs.python.org/issue19030">issue 19030</a>.)</p>
1360
<div class="section" id="urllib">
1361
<h3>urllib<a class="headerlink" href="#urllib" title="Permalink to this headline">¶</a></h3>
1362
<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"><span class="pre">urllib.request</span></code></a> now supports <code class="docutils literal"><span class="pre">data:</span></code> URLs via the
1363
<a class="reference internal" href="../library/urllib.request.html#urllib.request.DataHandler" title="urllib.request.DataHandler"><code class="xref py py-class docutils literal"><span class="pre">DataHandler</span></code></a> class. (Contributed by Mathias Panzenböck
1364
in <a class="reference external" href="https://bugs.python.org/issue16423">issue 16423</a>.)</p>
1365
<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"><span class="pre">Request</span></code></a> class
1366
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"><span class="pre">method</span></code></a>
1367
class attribute on the subclass. (Contributed by Jason R Coombs in
1368
<a class="reference external" href="https://bugs.python.org/issue18978">issue 18978</a>.)</p>
1369
<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"><span class="pre">Request</span></code></a> objects are now reusable: if the
1370
<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"><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"><span class="pre">data</span></code></a>
1371
attributes are modified, all relevant internal properties are updated. This
1372
means, for example, that it is now possible to use the same
1373
<a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-class docutils literal"><span class="pre">Request</span></code></a> object in more than one
1374
<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"><span class="pre">OpenerDirector.open()</span></code></a> call with different <em>data</em> arguments, or to
1375
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"><span class="pre">Request</span></code></a>‘s <code class="docutils literal"><span class="pre">url</span></code> rather than recomputing it
1376
from scratch. There is also a new
1377
<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"><span class="pre">remove_header()</span></code></a> method that can be used to remove
1378
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"><span class="pre">Request</span></code></a>. (Contributed by Alexey
1379
Kachayev in <a class="reference external" href="https://bugs.python.org/issue16464">issue 16464</a>, Daniel Wozniak in <a class="reference external" href="https://bugs.python.org/issue17485">issue 17485</a>, and Damien Brecht
1380
and Senthil Kumaran in <a class="reference external" href="https://bugs.python.org/issue17272">issue 17272</a>.)</p>
1381
<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"><span class="pre">HTTPError</span></code></a> objects now have a
1382
<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"><span class="pre">headers</span></code></a> attribute that provides access to the
1383
HTTP response headers associated with the error. (Contributed by
1384
Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue15701">issue 15701</a>.)</p>
1386
<div class="section" id="unittest">
1387
<h3>unittest<a class="headerlink" href="#unittest" title="Permalink to this headline">¶</a></h3>
1388
<p>The <a class="reference internal" href="../library/unittest.html#unittest.TestCase" title="unittest.TestCase"><code class="xref py py-class docutils literal"><span class="pre">TestCase</span></code></a> class has a new method,
1389
<a class="reference internal" href="../library/unittest.html#unittest.TestCase.subTest" title="unittest.TestCase.subTest"><code class="xref py py-meth docutils literal"><span class="pre">subTest()</span></code></a>, that produces a context manager whose
1390
<a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal"><span class="pre">with</span></code></a> block becomes a “sub-test”. This context manager allows a test
1391
method to dynamically generate subtests by, say, calling the <code class="docutils literal"><span class="pre">subTest</span></code>
1392
context manager inside a loop. A single test method can thereby produce an
1393
indefinite number of separately-identified and separately-counted tests, all of
1394
which will run even if one or more of them fail. For example:</p>
1395
<div class="highlight-python3"><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>
1396
<span class="k">def</span> <span class="nf">test_even</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
1397
<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>
1398
<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>
1399
<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>
1402
<p>will result in six subtests, each identified in the unittest verbose output
1403
with a label consisting of the variable name <code class="docutils literal"><span class="pre">i</span></code> and a particular value for
1404
that variable (<code class="docutils literal"><span class="pre">i=0</span></code>, <code class="docutils literal"><span class="pre">i=1</span></code>, etc). See <a class="reference internal" href="../library/unittest.html#subtests"><span>Distinguishing test iterations using subtests</span></a> for the full
1405
version of this example. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue16997">issue 16997</a>.)</p>
1406
<p><a class="reference internal" href="../library/unittest.html#unittest.main" title="unittest.main"><code class="xref py py-func docutils literal"><span class="pre">unittest.main()</span></code></a> now accepts an iterable of test names for
1407
<em>defaultTest</em>, where previously it only accepted a single test name as a
1408
string. (Contributed by Jyrki Pulliainen in <a class="reference external" href="https://bugs.python.org/issue15132">issue 15132</a>.)</p>
1409
<p>If <a class="reference internal" href="../library/unittest.html#unittest.SkipTest" title="unittest.SkipTest"><code class="xref py py-class docutils literal"><span class="pre">SkipTest</span></code></a> is raised during test discovery (that is, at the
1410
module level in the test file), it is now reported as a skip instead of an
1411
error. (Contributed by Zach Ware in <a class="reference external" href="https://bugs.python.org/issue16935">issue 16935</a>.)</p>
1412
<p><a class="reference internal" href="../library/unittest.html#unittest.TestLoader.discover" title="unittest.TestLoader.discover"><code class="xref py py-meth docutils literal"><span class="pre">discover()</span></code></a> now sorts the discovered files to provide
1413
consistent test ordering. (Contributed by Martin Melin and Jeff Ramnani in
1414
<a class="reference external" href="https://bugs.python.org/issue16709">issue 16709</a>.)</p>
1415
<p><a class="reference internal" href="../library/unittest.html#unittest.TestSuite" title="unittest.TestSuite"><code class="xref py py-class docutils literal"><span class="pre">TestSuite</span></code></a> now drops references to tests as soon as the test
1416
has been run, if the test is successful. On Python interpreters that do
1417
garbage collection, this allows the tests to be garbage collected if nothing
1418
else is holding a reference to the test. It is possible to override this
1419
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"><span class="pre">TestSuite</span></code></a> subclass that defines a
1420
custom <code class="docutils literal"><span class="pre">_removeTestAtIndex</span></code> method. (Contributed by Tom Wardill, Matt
1421
McClure, and Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue11798">issue 11798</a>.)</p>
1422
<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"><span class="pre">assertLogs()</span></code></a>,
1423
will ensure that a given block of code emits a log message using the
1424
<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"><span class="pre">logging</span></code></a> module. By default the message can come from any logger and
1425
have a priority of <code class="docutils literal"><span class="pre">INFO</span></code> or higher, but both the logger name and an
1426
alternative minimum logging level may be specified. The object returned by the
1427
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"><span class="pre">LogRecord</span></code></a>s and/or
1428
formatted messages that were logged. (Contributed by Antoine Pitrou in
1429
<a class="reference external" href="https://bugs.python.org/issue18937">issue 18937</a>.)</p>
1430
<p>Test discovery now works with namespace packages (Contributed by Claudiu Popa
1431
in <a class="reference external" href="https://bugs.python.org/issue17457">issue 17457</a>.)</p>
1432
<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"><span class="pre">unittest.mock</span></code></a> objects now inspect their specification signatures when
1433
matching calls, which means an argument can now be matched by either position
1434
or name, instead of only by position. (Contributed by Antoine Pitrou in
1435
<a class="reference external" href="https://bugs.python.org/issue17015">issue 17015</a>.)</p>
1436
<p><code class="xref py py-func docutils literal"><span class="pre">mock_open()</span></code> objects now have <code class="docutils literal"><span class="pre">readline</span></code> and <code class="docutils literal"><span class="pre">readlines</span></code>
1437
methods. (Contributed by Toshio Kuratomi in <a class="reference external" href="https://bugs.python.org/issue17467">issue 17467</a>.)</p>
1439
<div class="section" id="venv">
1440
<h3>venv<a class="headerlink" href="#venv" title="Permalink to this headline">¶</a></h3>
1441
<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"><span class="pre">venv</span></code></a> now includes activation scripts for the <code class="docutils literal"><span class="pre">csh</span></code> and <code class="docutils literal"><span class="pre">fish</span></code>
1442
shells. (Contributed by Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue15417">issue 15417</a>.)</p>
1443
<p><a class="reference internal" href="../library/venv.html#venv.EnvBuilder" title="venv.EnvBuilder"><code class="xref py py-class docutils literal"><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"><span class="pre">create()</span></code></a> convenience function
1444
take a new keyword argument <em>with_pip</em>, which defaults to <code class="docutils literal"><span class="pre">False</span></code>, that
1445
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"><span class="pre">EnvBuilder</span></code></a> ensures that <code class="docutils literal"><span class="pre">pip</span></code> is
1446
installed in the virtual environment. (Contributed by Nick Coghlan in
1447
<a class="reference external" href="https://bugs.python.org/issue19552">issue 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>
1449
<div class="section" id="wave">
1450
<h3>wave<a class="headerlink" href="#wave" title="Permalink to this headline">¶</a></h3>
1451
<p>The <code class="xref py py-meth docutils literal"><span class="pre">getparams()</span></code> method now returns a namedtuple rather than a
1452
plain tuple. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue17487">issue 17487</a>.)</p>
1453
<p><a class="reference internal" href="../library/wave.html#wave.open" title="wave.open"><code class="xref py py-meth docutils literal"><span class="pre">wave.open()</span></code></a> now supports the context management protocol. (Contributed
1454
by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue17616">issue 17616</a>.)</p>
1455
<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"><span class="pre">wave</span></code></a> can now <a class="reference internal" href="../library/wave.html#wave-write-objects"><span>write output to unseekable files</span></a>. (Contributed by David Jones, Guilherme Polo, and Serhiy
1456
Storchaka in <a class="reference external" href="https://bugs.python.org/issue5202">issue 5202</a>.)</p>
1457
<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"><span class="pre">writeframesraw()</span></code></a> and
1458
<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"><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
1459
object</span></a>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue8311">issue 8311</a>.)</p>
1461
<div class="section" id="weakref">
1462
<h3>weakref<a class="headerlink" href="#weakref" title="Permalink to this headline">¶</a></h3>
1463
<p>New <a class="reference internal" href="../library/weakref.html#weakref.WeakMethod" title="weakref.WeakMethod"><code class="xref py py-class docutils literal"><span class="pre">WeakMethod</span></code></a> class simulates weak references to bound
1464
methods. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue14631">issue 14631</a>.)</p>
1465
<p>New <a class="reference internal" href="../library/weakref.html#weakref.finalize" title="weakref.finalize"><code class="xref py py-class docutils literal"><span class="pre">finalize</span></code></a> class makes it possible to register a callback
1466
to be invoked when an object is garbage collected, without needing to
1467
carefully manage the lifecycle of the weak reference itself. (Contributed by
1468
Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue15528">issue 15528</a>.)</p>
1469
<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"><span class="pre">ref</span></code></a> is now
1470
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"><span class="pre">__callback__</span></code></a> attribute. (Contributed
1471
by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue17643">issue 17643</a>.)</p>
1473
<div class="section" id="xml-etree">
1474
<h3>xml.etree<a class="headerlink" href="#xml-etree" title="Permalink to this headline">¶</a></h3>
1475
<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"><span class="pre">XMLPullParser</span></code></a>, allows a
1476
non-blocking applications to parse XML documents. An example can be
1477
seen at <a class="reference internal" href="../library/xml.etree.elementtree.html#elementtree-pull-parsing"><span>Pull API for non-blocking parsing</span></a>. (Contributed by Antoine
1478
Pitrou in <a class="reference external" href="https://bugs.python.org/issue17741">issue 17741</a>.)</p>
1479
<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"><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"><span class="pre">tostring()</span></code></a> and
1480
<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"><span class="pre">tostringlist()</span></code></a> functions, and the
1481
<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"><span class="pre">ElementTree</span></code></a>
1482
<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"><span class="pre">write()</span></code></a> method, now have a
1483
<em>short_empty_elements</em> <a class="reference internal" href="../glossary.html#keyword-only-parameter"><span>keyword-only parameter</span></a>
1484
providing control over whether elements with no content are written in
1485
abbreviated (<code class="docutils literal"><span class="pre"><tag</span> <span class="pre">/></span></code>) or expanded (<code class="docutils literal"><span class="pre"><tag></tag></span></code>) form. (Contributed by
1486
Ariel Poliak and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue14377">issue 14377</a>.)</p>
1488
<div class="section" id="zipfile">
1489
<h3>zipfile<a class="headerlink" href="#zipfile" title="Permalink to this headline">¶</a></h3>
1490
<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"><span class="pre">writepy()</span></code></a> method of the
1491
<a class="reference internal" href="../library/zipfile.html#zipfile.PyZipFile" title="zipfile.PyZipFile"><code class="xref py py-class docutils literal"><span class="pre">PyZipFile</span></code></a> class has a new <em>filterfunc</em> option that can be
1492
used to control which directories and files are added to the archive. For
1493
example, this could be used to exclude test files from the archive.
1494
(Contributed by Christian Tismer in <a class="reference external" href="https://bugs.python.org/issue19274">issue 19274</a>.)</p>
1495
<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"><span class="pre">ZipFile</span></code></a> and
1496
<code class="xref py py-class docutils literal"><span class="pre">PyZipfile</span></code> is now <code class="docutils literal"><span class="pre">True</span></code> by default. (Contributed by
1497
William Mallard in <a class="reference external" href="https://bugs.python.org/issue17201">issue 17201</a>.)</p>
1500
<div class="section" id="cpython-implementation-changes">
1501
<h2>CPython Implementation Changes<a class="headerlink" href="#cpython-implementation-changes" title="Permalink to this headline">¶</a></h2>
1502
<div class="section" id="pep-445-customization-of-cpython-memory-allocators">
1503
<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>
1504
<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
1505
the CPython interpreter.</p>
1506
<div class="admonition seealso">
1507
<p class="first admonition-title">See also</p>
1508
<dl class="last docutils">
1509
<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>
1510
<dd>PEP written and implemented by Victor Stinner.</dd>
1514
<div class="section" id="pep-442-safe-object-finalization">
1515
<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>
1516
<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
1517
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"><span class="pre">__del__()</span></code></a> methods, as well as
1518
generators with <a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal"><span class="pre">finally</span></code></a> clauses, can be finalized when they are
1519
part of a reference cycle.</p>
1520
<p>As part of this change, module globals are no longer forcibly set to
1521
<a class="reference internal" href="../library/constants.html#None" title="None"><code class="xref py py-const docutils literal"><span class="pre">None</span></code></a> during interpreter shutdown in most cases, instead relying
1522
on the normal operation of the cyclic garbage collector. This avoids a
1523
whole class of interpreter-shutdown-time errors, usually involving
1524
<code class="docutils literal"><span class="pre">__del__</span></code> methods, that have plagued Python since the cyclic GC
1525
was first introduced.</p>
1526
<div class="admonition seealso">
1527
<p class="first admonition-title">See also</p>
1528
<dl class="last docutils">
1529
<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>
1530
<dd>PEP written and implemented by Antoine Pitrou.</dd>
1534
<div class="section" id="pep-456-secure-and-interchangeable-hash-algorithm">
1535
<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>
1536
<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
1537
algorithm to address certain DOS attacks to which public facing APIs backed by
1538
dictionary lookups may be subject. (See <a class="reference external" href="https://bugs.python.org/issue14621">issue 14621</a> for the start of the
1539
current round of improvements.) The PEP unifies CPython’s hash code to make it
1540
easier for a packager to substitute a different hash algorithm, and switches
1541
Python’s default implementation to a SipHash implementation on platforms that
1542
have a 64 bit data type. Any performance differences in comparison with the
1543
older FNV algorithm are trivial.</p>
1544
<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"><span class="pre">sys.hash_info</span></code></a> struct sequence to
1545
describe the hash algorithm in use by the currently executing binary. Otherwise,
1546
the PEP does not alter any existing CPython APIs.</p>
1548
<div class="section" id="pep-436-argument-clinic">
1549
<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>
1550
<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
1551
and can be used to simplify the process of defining and maintaining
1552
accurate signatures for builtins and standard library extension modules
1553
implemented in C.</p>
1554
<p>Some standard library extension modules have been converted to use Argument
1555
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"><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"><span class="pre">inspect</span></code></a> have been updated
1557
<p>It is expected that signature metadata for programmatic introspection will
1558
be added to additional callables implemented in C as part of Python 3.4
1559
maintenance releases.</p>
1560
<div class="admonition note">
1561
<p class="first admonition-title">Note</p>
1562
<p class="last">The Argument Clinic PEP is not fully up to date with the state of the
1563
implementation. This has been deemed acceptable by the release manager
1564
and core development team in this case, as Argument Clinic will not
1565
be made available as a public API for third party use in Python 3.4.</p>
1567
<div class="admonition seealso">
1568
<p class="first admonition-title">See also</p>
1569
<dl class="last docutils">
1570
<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>
1571
<dd>PEP written and implemented by Larry Hastings.</dd>
1575
<div class="section" id="other-build-and-c-api-changes">
1576
<h3>Other Build and C API Changes<a class="headerlink" href="#other-build-and-c-api-changes" title="Permalink to this headline">¶</a></h3>
1578
<li>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"><span class="pre">PyType_GetSlot()</span></code></a> function has been added to the stable ABI,
1579
allowing retrieval of function pointers from named type slots when using
1580
the limited API. (Contributed by Martin von Löwis in <a class="reference external" href="https://bugs.python.org/issue17162">issue 17162</a>.)</li>
1581
<li>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"><span class="pre">Py_SetStandardStreamEncoding()</span></code></a> pre-initialization API
1582
allows applications embedding the CPython interpreter to reliably force
1583
a particular encoding and error handler for the standard streams.
1584
(Contributed by Bastien Montagne and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue16129">issue 16129</a>.)</li>
1585
<li>Most Python C APIs that don’t mutate string arguments are now correctly
1586
marked as accepting <code class="docutils literal"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></code> rather than <code class="docutils literal"><span class="pre">char</span> <span class="pre">*</span></code>. (Contributed
1587
by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue1772673">issue 1772673</a>.)</li>
1588
<li>A new shell version of <code class="docutils literal"><span class="pre">python-config</span></code> can be used even when a python
1589
interpreter is not available (for example, in cross compilation scenarios).</li>
1590
<li><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal"><span class="pre">PyUnicode_FromFormat()</span></code></a> now supports width and precision
1591
specifications for <code class="docutils literal"><span class="pre">%s</span></code>, <code class="docutils literal"><span class="pre">%A</span></code>, <code class="docutils literal"><span class="pre">%U</span></code>, <code class="docutils literal"><span class="pre">%V</span></code>, <code class="docutils literal"><span class="pre">%S</span></code>, and <code class="docutils literal"><span class="pre">%R</span></code>.
1592
(Contributed by Ysj Ray and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue7330">issue 7330</a>.)</li>
1593
<li>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"><span class="pre">PyStructSequence_InitType2()</span></code></a> supplements the
1594
existing <a class="reference internal" href="../c-api/tuple.html#c.PyStructSequence_InitType" title="PyStructSequence_InitType"><code class="xref c c-func docutils literal"><span class="pre">PyStructSequence_InitType()</span></code></a> function. The difference
1595
is that it returns <code class="docutils literal"><span class="pre">0</span></code> on success and <code class="docutils literal"><span class="pre">-1</span></code> on failure.</li>
1596
<li>The CPython source can now be compiled using the address sanity checking
1597
features of recent versions of GCC and clang: the false alarms in the small
1598
object allocator have been silenced. (Contributed by Dhiru Kholia in
1599
<a class="reference external" href="https://bugs.python.org/issue18596">issue 18596</a>.)</li>
1600
<li>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
1601
Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue16632">issue 16632</a>.)</li>
1602
<li>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"><span class="pre">PyObject_LengthHint()</span></code></a> is the C API equivalent
1603
of <a class="reference internal" href="../library/operator.html#operator.length_hint" title="operator.length_hint"><code class="xref py py-func docutils literal"><span class="pre">operator.length_hint()</span></code></a>. (Contributed by Armin Ronacher in
1604
<a class="reference external" href="https://bugs.python.org/issue16148">issue 16148</a>.)</li>
1607
<div class="section" id="other-improvements">
1608
<span id="other-improvements-3-4"></span><h3>Other Improvements<a class="headerlink" href="#other-improvements" title="Permalink to this headline">¶</a></h3>
1609
<ul class="simple" id="whatsnew-isolated-mode">
1610
<li>The <a class="reference internal" href="../using/cmdline.html#using-on-cmdline"><span>python</span></a> command has a new <a class="reference internal" href="../using/cmdline.html#using-on-misc-options"><span>option</span></a>, <code class="docutils literal"><span class="pre">-I</span></code>, which causes it to run in “isolated mode”,
1611
which means that <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal"><span class="pre">sys.path</span></code></a> contains neither the script’s directory nor
1612
the user’s <code class="docutils literal"><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"><span class="pre">PYTHON*</span></code> environment
1613
variables are ignored (it implies both <code class="docutils literal"><span class="pre">-s</span></code> and <code class="docutils literal"><span class="pre">-E</span></code>). Other
1614
restrictions may also be applied in the future, with the goal being to
1615
isolate the execution of a script from the user’s environment. This is
1616
appropriate, for example, when Python is used to run a system script. On
1617
most POSIX systems it can and should be used in the <code class="docutils literal"><span class="pre">#!</span></code> line of system
1618
scripts. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue16499">issue 16499</a>.)</li>
1619
<li>Tab-completion is now enabled by default in the interactive interpreter
1620
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"><span class="pre">readline</span></code></a>. History is also enabled by default,
1621
and is written to (and read from) the file <code class="file docutils literal"><span class="pre">~/.python-history</span></code>.
1622
(Contributed by Antoine Pitrou and Éric Araujo in <a class="reference external" href="https://bugs.python.org/issue5845">issue 5845</a>.)</li>
1623
<li>Invoking the Python interpreter with <code class="docutils literal"><span class="pre">--version</span></code> now outputs the version to
1624
standard output instead of standard error (<a class="reference external" href="https://bugs.python.org/issue18338">issue 18338</a>). Similar changes
1625
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"><span class="pre">argparse</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue18920">issue 18920</a>) and other modules that have
1626
script-like invocation capabilities (<a class="reference external" href="https://bugs.python.org/issue18922">issue 18922</a>).</li>
1627
<li>The CPython Windows installer now adds <code class="docutils literal"><span class="pre">.py</span></code> to the <span class="target" id="index-51"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATHEXT</span></code>
1628
variable when extensions are registered, allowing users to run a python
1629
script at the windows command prompt by just typing its name without the
1630
<code class="docutils literal"><span class="pre">.py</span></code> extension. (Contributed by Paul Moore in <a class="reference external" href="https://bugs.python.org/issue18569">issue 18569</a>.)</li>
1631
<li>A new <code class="docutils literal"><span class="pre">make</span></code> target <a class="reference external" href="https://docs.python.org/devguide/coverage.html#measuring-coverage-of-c-code-with-gcov-and-lcov">coverage-report</a>
1632
will build python, run the test suite, and generate an HTML coverage report
1633
for the C codebase using <code class="docutils literal"><span class="pre">gcov</span></code> and <a class="reference external" href="http://ltp.sourceforge.net/coverage/lcov.php">lcov</a>.</li>
1634
<li>The <code class="docutils literal"><span class="pre">-R</span></code> option to the <a class="reference internal" href="../library/test.html#regrtest"><span>python regression test suite</span></a> now
1635
also checks for memory allocation leaks, using
1636
<a class="reference internal" href="../library/sys.html#sys.getallocatedblocks" title="sys.getallocatedblocks"><code class="xref py py-func docutils literal"><span class="pre">sys.getallocatedblocks()</span></code></a>. (Contributed by Antoine Pitrou in
1637
<a class="reference external" href="https://bugs.python.org/issue13390">issue 13390</a>.)</li>
1638
<li><code class="docutils literal"><span class="pre">python</span> <span class="pre">-m</span></code> now works with namespace packages.</li>
1639
<li>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"><span class="pre">stat</span></code></a> module is now implemented in C, which means it gets the
1640
values for its constants from the C header files, instead of having the
1641
values hard-coded in the python module as was previously the case.</li>
1642
<li>Loading multiple python modules from a single OS module (<code class="docutils literal"><span class="pre">.so</span></code>, <code class="docutils literal"><span class="pre">.dll</span></code>)
1643
now works correctly (previously it silently returned the first python
1644
module in the file). (Contributed by Václav Šmilauer in <a class="reference external" href="https://bugs.python.org/issue16421">issue 16421</a>.)</li>
1645
<li>A new opcode, <a class="reference internal" href="../library/dis.html#opcode-LOAD_CLASSDEREF"><code class="xref std std-opcode docutils literal"><span class="pre">LOAD_CLASSDEREF</span></code></a>, has been added to fix a bug in the
1646
loading of free variables in class bodies that could be triggered by certain
1647
uses of <a class="reference internal" href="../reference/datamodel.html#prepare"><span>__prepare__</span></a>. (Contributed by Benjamin Peterson in
1648
<a class="reference external" href="https://bugs.python.org/issue17853">issue 17853</a>.)</li>
1649
<li>A number of MemoryError-related crashes were identified and fixed by Victor
1650
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"><span class="pre">pyfailmalloc</span></code> tool (<a class="reference external" href="https://bugs.python.org/issue18408">issue 18408</a>,
1651
<a class="reference external" href="https://bugs.python.org/issue18520">issue 18520</a>).</li>
1652
<li>The <a class="reference internal" href="../using/scripts.html#scripts-pyvenv"><span>pyvenv</span></a> command now accepts a <code class="docutils literal"><span class="pre">--copies</span></code> option
1653
to use copies rather than symlinks even on systems where symlinks are the
1654
default. (Contributed by Vinay Sajip in <a class="reference external" href="https://bugs.python.org/issue18807">issue 18807</a>.)</li>
1655
<li>The <a class="reference internal" href="../using/scripts.html#scripts-pyvenv"><span>pyvenv</span></a> command also accepts a <code class="docutils literal"><span class="pre">--without-pip</span></code>
1656
option to suppress the otherwise-automatic bootstrapping of pip into
1657
the virtual environment. (Contributed by Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue19552">issue 19552</a>
1658
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.)</li>
1659
<li>The encoding name is now optional in the value set for the
1660
<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"><span class="pre">PYTHONIOENCODING</span></code></a> environment variable. This makes it possible to
1661
set just the error handler, without changing the default encoding.
1662
(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue18818">issue 18818</a>.)</li>
1663
<li>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"><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"><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"><span class="pre">gzip</span></code></a> module <code class="docutils literal"><span class="pre">open</span></code> functions now
1664
support <code class="docutils literal"><span class="pre">x</span></code> (exclusive creation) mode. (Contributed by Tim Heaney and
1665
Vajrasky Kok in <a class="reference external" href="https://bugs.python.org/issue19201">issue 19201</a>, <a class="reference external" href="https://bugs.python.org/issue19222">issue 19222</a>, and <a class="reference external" href="https://bugs.python.org/issue19223">issue 19223</a>.)</li>
1668
<div class="section" id="significant-optimizations">
1669
<h3>Significant Optimizations<a class="headerlink" href="#significant-optimizations" title="Permalink to this headline">¶</a></h3>
1671
<li>The UTF-32 decoder is now 3x to 4x faster. (Contributed by Serhiy Storchaka
1672
in <a class="reference external" href="https://bugs.python.org/issue14625">issue 14625</a>.)</li>
1673
<li>The cost of hash collisions for sets is now reduced. Each hash table
1674
probe now checks a series of consecutive, adjacent key/hash pairs before
1675
continuing to make random probes through the hash table. This exploits
1676
cache locality to make collision resolution less expensive.
1677
The collision resolution scheme can be described as a hybrid of linear
1678
probing and open addressing. The number of additional linear probes
1679
defaults to nine. This can be changed at compile-time by defining
1680
LINEAR_PROBES to be any value. Set LINEAR_PROBES=0 to turn-off
1681
linear probing entirely. (Contributed by Raymond Hettinger in
1682
<a class="reference external" href="https://bugs.python.org/issue18771">issue 18771</a>.)</li>
1683
<li>The interpreter starts about 30% faster. A couple of measures lead to the
1684
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"><span class="pre">re</span></code></a>,
1685
<a class="reference internal" href="../library/collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal"><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"><span class="pre">locale</span></code></a> modules and their dependencies are no
1686
longer imported by default. The marshal module has been improved to load
1687
compiled Python code faster. (Contributed by Antoine Pitrou, Christian
1688
Heimes and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue19219">issue 19219</a>, <a class="reference external" href="https://bugs.python.org/issue19218">issue 19218</a>, <a class="reference external" href="https://bugs.python.org/issue19209">issue 19209</a>,
1689
<a class="reference external" href="https://bugs.python.org/issue19205">issue 19205</a> and <a class="reference external" href="https://bugs.python.org/issue9548">issue 9548</a>.)</li>
1690
<li><a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><code class="xref py py-class docutils literal"><span class="pre">bz2.BZ2File</span></code></a> is now as fast or faster than the Python2 version for
1691
most cases. <a class="reference internal" href="../library/lzma.html#lzma.LZMAFile" title="lzma.LZMAFile"><code class="xref py py-class docutils literal"><span class="pre">lzma.LZMAFile</span></code></a> has also been optimized. (Contributed by
1692
Serhiy Storchaka and Nadeem Vawda in <a class="reference external" href="https://bugs.python.org/issue16034">issue 16034</a>.)</li>
1693
<li><a class="reference internal" href="../library/random.html#random.getrandbits" title="random.getrandbits"><code class="xref py py-func docutils literal"><span class="pre">random.getrandbits()</span></code></a> is 20%-40% faster for small integers (the most
1694
common use case). (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue16674">issue 16674</a>.)</li>
1695
<li>By taking advantage of the new storage format for strings, pickling of
1696
strings is now significantly faster. (Contributed by Victor Stinner and
1697
Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue15596">issue 15596</a>.)</li>
1698
<li>A performance issue in <code class="xref py py-meth docutils literal"><span class="pre">io.FileIO.readall()</span></code> has been solved. This
1699
particularly affects Windows, and significantly speeds up the case of piping
1700
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"><span class="pre">subprocess</span></code></a>. (Contributed
1701
by Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue15758">issue 15758</a>.)</li>
1702
<li><a class="reference internal" href="../library/html.html#html.escape" title="html.escape"><code class="xref py py-func docutils literal"><span class="pre">html.escape()</span></code></a> is now 10x faster. (Contributed by Matt Bryant in
1703
<a class="reference external" href="https://bugs.python.org/issue18020">issue 18020</a>.)</li>
1704
<li>On Windows, the native <code class="docutils literal"><span class="pre">VirtualAlloc</span></code> is now used instead of the CRT
1705
<code class="docutils literal"><span class="pre">malloc</span></code> in <code class="docutils literal"><span class="pre">obmalloc</span></code>. Artificial benchmarks show about a 3% memory
1707
<li><a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal"><span class="pre">os.urandom()</span></code></a> now uses a lazily-opened persistent file descriptor
1708
so as to avoid using many file descriptors when run in parallel from
1709
multiple threads. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue18756">issue 18756</a>.)</li>
1713
<div class="section" id="deprecated">
1714
<span id="deprecated-3-4"></span><h2>Deprecated<a class="headerlink" href="#deprecated" title="Permalink to this headline">¶</a></h2>
1715
<p>This section covers various APIs and other features that have been deprecated
1716
in Python 3.4, and will be removed in Python 3.5 or later. In most (but not
1717
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"><span class="pre">DeprecationWarning</span></code></a>
1718
when the interpreter is run with deprecation warnings enabled (for example, by
1719
using <code class="docutils literal"><span class="pre">-Wd</span></code>).</p>
1720
<div class="section" id="deprecations-in-the-python-api">
1721
<h3>Deprecations in the Python API<a class="headerlink" href="#deprecations-in-the-python-api" title="Permalink to this headline">¶</a></h3>
1723
<li>As mentioned in <a class="reference internal" href="#whatsnew-pep-451"><span>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"><span class="pre">importlib</span></code></a>
1724
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"><span class="pre">importlib.find_loader()</span></code></a> is
1725
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"><span class="pre">importlib.util.find_spec()</span></code></a>;
1726
<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"><span class="pre">importlib.machinery.PathFinder.find_module()</span></code></a> is replaced by
1727
<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"><span class="pre">importlib.machinery.PathFinder.find_spec()</span></code></a>;
1728
<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"><span class="pre">importlib.abc.MetaPathFinder.find_module()</span></code></a> is replaced by
1729
<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"><span class="pre">importlib.abc.MetaPathFinder.find_spec()</span></code></a>;
1730
<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"><span class="pre">importlib.abc.PathEntryFinder.find_loader()</span></code></a> and
1731
<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"><span class="pre">find_module()</span></code></a> are replaced by
1732
<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"><span class="pre">importlib.abc.PathEntryFinder.find_spec()</span></code></a>; all of the <code class="docutils literal"><span class="pre">xxxLoader</span></code> ABC
1733
<code class="docutils literal"><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"><span class="pre">importlib.abc.Loader.load_module()</span></code></a>,
1734
<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"><span class="pre">importlib.abc.InspectLoader.load_module()</span></code></a>,
1735
<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"><span class="pre">importlib.abc.FileLoader.load_module()</span></code></a>,
1736
<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"><span class="pre">importlib.abc.SourceLoader.load_module()</span></code></a>) should no longer be
1737
implemented, instead loaders should implement an
1738
<code class="docutils literal"><span class="pre">exec_module</span></code> method
1739
(<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"><span class="pre">importlib.abc.Loader.exec_module()</span></code></a>,
1740
<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"><span class="pre">importlib.abc.InspectLoader.exec_module()</span></code></a>
1741
<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"><span class="pre">importlib.abc.SourceLoader.exec_module()</span></code></a>) and let the import system
1742
take care of the rest; and
1743
<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"><span class="pre">importlib.abc.Loader.module_repr()</span></code></a>,
1744
<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"><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"><span class="pre">importlib.util.set_loader()</span></code></a>,
1745
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"><span class="pre">importlib.util.set_package()</span></code></a> are no longer needed because their
1746
functions are now handled automatically by the import system.</li>
1747
<li>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"><span class="pre">imp</span></code></a> module is pending deprecation. To keep compatibility with
1748
Python 2/3 code bases, the module’s removal is currently not scheduled.</li>
1749
<li>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"><span class="pre">formatter</span></code></a> module is pending deprecation and is slated for removal
1751
<li><code class="docutils literal"><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"><span class="pre">hmac.new()</span></code></a> function is
1752
deprecated. Python 3.6 will require an explicit digest name or constructor as
1753
<em>digestmod</em> argument.</li>
1754
<li>The internal <code class="docutils literal"><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"><span class="pre">ftplib</span></code></a> module has been documented
1755
as deprecated in its docstring for quite some time. It now emits a
1756
<a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal"><span class="pre">DeprecationWarning</span></code></a> and will be removed completely in Python 3.5.</li>
1757
<li>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"><span class="pre">subprocess.Popen.wait()</span></code></a> should
1758
not have been exposed and is hopefully not in use; it is deprecated and
1759
will mostly likely be removed in Python 3.5.</li>
1760
<li>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"><span class="pre">HTMLParser</span></code></a> is deprecated.</li>
1761
<li>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"><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"><span class="pre">readPlist()</span></code></a>,
1762
<a class="reference internal" href="../library/plistlib.html#plistlib.writePlist" title="plistlib.writePlist"><code class="xref py py-func docutils literal"><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"><span class="pre">readPlistFromBytes()</span></code></a>, and
1763
<a class="reference internal" href="../library/plistlib.html#plistlib.writePlistToBytes" title="plistlib.writePlistToBytes"><code class="xref py py-func docutils literal"><span class="pre">writePlistToBytes()</span></code></a> functions are deprecated in favor of the
1764
corresponding new functions <a class="reference internal" href="../library/plistlib.html#plistlib.load" title="plistlib.load"><code class="xref py py-func docutils literal"><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"><span class="pre">dump()</span></code></a>,
1765
<a class="reference internal" href="../library/plistlib.html#plistlib.loads" title="plistlib.loads"><code class="xref py py-func docutils literal"><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"><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"><span class="pre">Data()</span></code></a>
1766
is deprecated in favor of just using the <a class="reference internal" href="../library/functions.html#bytes" title="bytes"><code class="xref py py-class docutils literal"><span class="pre">bytes</span></code></a> constructor.</li>
1767
<li>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"><span class="pre">sysconfig</span></code></a> key <code class="docutils literal"><span class="pre">SO</span></code> is deprecated, it has been replaced by
1768
<code class="docutils literal"><span class="pre">EXT_SUFFIX</span></code>.</li>
1769
<li>The <code class="docutils literal"><span class="pre">U</span></code> mode accepted by various <code class="docutils literal"><span class="pre">open</span></code> functions is deprecated.
1770
In Python3 it does not do anything useful, and should be replaced by
1771
appropriate uses of <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-class docutils literal"><span class="pre">io.TextIOWrapper</span></code></a> (if needed) and its <em>newline</em>
1773
<li>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"><span class="pre">xml.etree.ElementTree.iterparse()</span></code></a> has
1774
been deprecated, as has the <em>html</em> argument of
1775
<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"><span class="pre">XMLParser()</span></code></a>. To prepare for the removal of the
1776
latter, all arguments to <code class="docutils literal"><span class="pre">XMLParser</span></code> should be passed by keyword.</li>
1779
<div class="section" id="deprecated-features">
1780
<h3>Deprecated Features<a class="headerlink" href="#deprecated-features" title="Permalink to this headline">¶</a></h3>
1782
<li>Running <a class="reference internal" href="../library/idle.html#idle"><span>IDLE</span></a> with the <code class="docutils literal"><span class="pre">-n</span></code> flag (no subprocess) is deprecated.
1783
However, the feature will not be removed until <a class="reference external" href="https://bugs.python.org/issue18823">issue 18823</a> is resolved.</li>
1784
<li>The site module adding a “site-python” directory to sys.path, if it
1785
exists, is deprecated (<a class="reference external" href="https://bugs.python.org/issue19375">issue 19375</a>).</li>
1789
<div class="section" id="removed">
1790
<h2>Removed<a class="headerlink" href="#removed" title="Permalink to this headline">¶</a></h2>
1791
<div class="section" id="operating-systems-no-longer-supported">
1792
<h3>Operating Systems No Longer Supported<a class="headerlink" href="#operating-systems-no-longer-supported" title="Permalink to this headline">¶</a></h3>
1793
<p>Support for the following operating systems has been removed from the source
1794
and build tools:</p>
1796
<li>OS/2 (<a class="reference external" href="https://bugs.python.org/issue16135">issue 16135</a>).</li>
1797
<li>Windows 2000 (changeset e52df05b496a).</li>
1798
<li>Windows systems where <code class="docutils literal"><span class="pre">COMSPEC</span></code> points to <code class="docutils literal"><span class="pre">command.com</span></code> (<a class="reference external" href="https://bugs.python.org/issue14470">issue 14470</a>).</li>
1799
<li>VMS (<a class="reference external" href="https://bugs.python.org/issue16136">issue 16136</a>).</li>
1802
<div class="section" id="api-and-feature-removals">
1803
<h3>API and Feature Removals<a class="headerlink" href="#api-and-feature-removals" title="Permalink to this headline">¶</a></h3>
1804
<p>The following obsolete and previously deprecated APIs and features have been
1807
<li>The unmaintained <code class="docutils literal"><span class="pre">Misc/TextMate</span></code> and <code class="docutils literal"><span class="pre">Misc/vim</span></code> directories have been
1808
removed (see the <a class="reference external" href="https://docs.python.org/devguide">devguide</a>
1809
for suggestions on what to use instead).</li>
1810
<li>The <code class="docutils literal"><span class="pre">SO</span></code> makefile macro is removed (it was replaced by the
1811
<code class="docutils literal"><span class="pre">SHLIB_SUFFIX</span></code> and <code class="docutils literal"><span class="pre">EXT_SUFFIX</span></code> macros) (<a class="reference external" href="https://bugs.python.org/issue16754">issue 16754</a>).</li>
1812
<li>The <code class="docutils literal"><span class="pre">PyThreadState.tick_counter</span></code> field has been removed; its value has
1813
been meaningless since Python 3.2, when the “new GIL” was introduced
1814
(<a class="reference external" href="https://bugs.python.org/issue19199">issue 19199</a>).</li>
1815
<li><code class="docutils literal"><span class="pre">PyLoader</span></code> and <code class="docutils literal"><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"><span class="pre">importlib</span></code></a>.
1816
(Contributed by Taras Lyapun in <a class="reference external" href="https://bugs.python.org/issue15641">issue 15641</a>.)</li>
1817
<li>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"><span class="pre">HTTPConnection</span></code></a> and
1818
<a class="reference internal" href="../library/http.client.html#http.client.HTTPSConnection" title="http.client.HTTPSConnection"><code class="xref py py-class docutils literal"><span class="pre">HTTPSConnection</span></code></a> has been removed. HTTP 0.9-style
1819
“Simple Responses” are no longer supported.</li>
1820
<li>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"><span class="pre">urllib.request.Request</span></code></a> getter and setter methods
1821
<code class="docutils literal"><span class="pre">add_data</span></code>, <code class="docutils literal"><span class="pre">has_data</span></code>, <code class="docutils literal"><span class="pre">get_data</span></code>, <code class="docutils literal"><span class="pre">get_type</span></code>, <code class="docutils literal"><span class="pre">get_host</span></code>,
1822
<code class="docutils literal"><span class="pre">get_selector</span></code>, <code class="docutils literal"><span class="pre">set_proxy</span></code>, <code class="docutils literal"><span class="pre">get_origin_req_host</span></code>, and
1823
<code class="docutils literal"><span class="pre">is_unverifiable</span></code> have been removed (use direct attribute access instead).</li>
1824
<li>Support for loading the deprecated <code class="docutils literal"><span class="pre">TYPE_INT64</span></code> has been removed from
1825
<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"><span class="pre">marshal</span></code></a>. (Contributed by Dan Riti in <a class="reference external" href="https://bugs.python.org/issue15480">issue 15480</a>.)</li>
1826
<li><a class="reference internal" href="../library/inspect.html#inspect.Signature" title="inspect.Signature"><code class="xref py py-class docutils literal"><span class="pre">inspect.Signature</span></code></a>: positional-only parameters are now required
1827
to have a valid name.</li>
1828
<li><a class="reference internal" href="../reference/datamodel.html#object.__format__" title="object.__format__"><code class="xref py py-meth docutils literal"><span class="pre">object.__format__()</span></code></a> no longer accepts non-empty format strings, it now
1829
raises a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code></a> instead. Using a non-empty string has been
1830
deprecated since Python 3.2. This change has been made to prevent a
1831
situation where previously working (but incorrect) code would start failing
1832
if an object gained a __format__ method, which means that your code may now
1833
raise a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code></a> if you are using an <code class="docutils literal"><span class="pre">'s'</span></code> format code with objects
1834
that do not have a __format__ method that handles it. See <a class="reference external" href="https://bugs.python.org/issue7994">issue 7994</a> for
1836
<li><code class="xref py py-meth docutils literal"><span class="pre">difflib.SequenceMatcher.isbjunk()</span></code> and
1837
<code class="xref py py-meth docutils literal"><span class="pre">difflib.SequenceMatcher.isbpopular()</span></code> were deprecated in 3.2, and have
1838
now been removed: use <code class="docutils literal"><span class="pre">x</span> <span class="pre">in</span> <span class="pre">sm.bjunk</span></code> and
1839
<code class="docutils literal"><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"><span class="pre">SequenceMatcher</span></code></a> object
1840
(<a class="reference external" href="https://bugs.python.org/issue13248">issue 13248</a>).</li>
1843
<div class="section" id="code-cleanups">
1844
<h3>Code Cleanups<a class="headerlink" href="#code-cleanups" title="Permalink to this headline">¶</a></h3>
1846
<li>The unused and undocumented internal <code class="docutils literal"><span class="pre">Scanner</span></code> class has been removed from
1847
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"><span class="pre">pydoc</span></code></a> module.</li>
1848
<li>The private and effectively unused <code class="docutils literal"><span class="pre">_gestalt</span></code> module has been removed,
1849
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"><span class="pre">platform</span></code></a> functions <code class="docutils literal"><span class="pre">_mac_ver_lookup</span></code>,
1850
<code class="docutils literal"><span class="pre">_mac_ver_gstalt</span></code>, and <code class="docutils literal"><span class="pre">_bcd2str</span></code>, which would only have ever been called
1851
on badly broken OSX systems (see <a class="reference external" href="https://bugs.python.org/issue18393">issue 18393</a>).</li>
1852
<li>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"><span class="pre">stat</span></code></a> constants that were included in
1853
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"><span class="pre">tarfile</span></code></a> module namespace have been removed.</li>
1857
<div class="section" id="porting-to-python-3-4">
1858
<h2>Porting to Python 3.4<a class="headerlink" href="#porting-to-python-3-4" title="Permalink to this headline">¶</a></h2>
1859
<p>This section lists previously described changes and other bugfixes
1860
that may require changes to your code.</p>
1861
<div class="section" id="changes-in-python-command-behavior">
1862
<h3>Changes in ‘python’ Command Behavior<a class="headerlink" href="#changes-in-python-command-behavior" title="Permalink to this headline">¶</a></h3>
1864
<li>In a posix shell, setting the <span class="target" id="index-55"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> environment variable to
1865
an empty value is equivalent to not setting it at all. However, setting
1866
<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"><span class="pre">PYTHONPATH</span></code></a> to an empty value was <em>not</em> equivalent to not setting it
1867
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"><span class="pre">PYTHONPATH</span></code></a> to an empty value was equivalent to
1868
setting it to <code class="docutils literal"><span class="pre">.</span></code>, which leads to confusion when reasoning by analogy to
1869
how <span class="target" id="index-58"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> works. The behavior now conforms to the posix convention
1870
for <span class="target" id="index-59"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code>.</li>
1871
<li>The [X refs, Y blocks] output of a debug (<code class="docutils literal"><span class="pre">--with-pydebug</span></code>) build of the
1872
CPython interpreter is now off by default. It can be re-enabled using the
1873
<code class="docutils literal"><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">issue 17323</a>.)</li>
1874
<li>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"><span class="pre">argparse</span></code></a>) now
1875
output <code class="docutils literal"><span class="pre">--version</span></code> information to <code class="docutils literal"><span class="pre">stdout</span></code> instead of <code class="docutils literal"><span class="pre">stderr</span></code> (for
1876
issue list see <a class="reference internal" href="#other-improvements-3-4"><span>Other Improvements</span></a> above).</li>
1879
<div class="section" id="changes-in-the-python-api">
1880
<h3>Changes in the Python API<a class="headerlink" href="#changes-in-the-python-api" title="Permalink to this headline">¶</a></h3>
1882
<li>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"><span class="pre">importlib.abc</span></code></a> now either raise the appropriate
1883
exception or return a default value instead of raising
1884
<a class="reference internal" href="../library/exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></code></a> blindly. This will only affect code calling
1885
<a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-func docutils literal"><span class="pre">super()</span></code></a> and falling through all the way to the ABCs. For compatibility,
1886
catch both <a class="reference internal" href="../library/exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></code></a> or the appropriate exception as needed.</li>
1887
<li>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"><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"><span class="pre">__loader__</span></code></a>
1888
attributes to <code class="docutils literal"><span class="pre">None</span></code> by default. To determine if these attributes were set
1889
in a backwards-compatible fashion, use e.g.
1890
<code class="docutils literal"><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">issue 17115</a>.)</li>
1891
<li><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"><span class="pre">importlib.util.module_for_loader()</span></code></a> now sets <code class="docutils literal"><span class="pre">__loader__</span></code> and
1892
<code class="docutils literal"><span class="pre">__package__</span></code> unconditionally to properly support reloading. If this is not
1893
desired then you will need to set these attributes manually. You can use
1894
<code class="xref py py-func docutils literal"><span class="pre">importlib.util.module_to_load()</span></code> for module management.</li>
1895
<li>Import now resets relevant attributes (e.g. <code class="docutils literal"><span class="pre">__name__</span></code>, <code class="docutils literal"><span class="pre">__loader__</span></code>,
1896
<code class="docutils literal"><span class="pre">__package__</span></code>, <code class="docutils literal"><span class="pre">__file__</span></code>, <code class="docutils literal"><span class="pre">__cached__</span></code>) unconditionally when reloading.
1897
Note that this restores a pre-3.3 behavior in that it means a module is
1898
re-found when re-loaded (<a class="reference external" href="https://bugs.python.org/issue19413">issue 19413</a>).</li>
1899
<li>Frozen packages no longer set <code class="docutils literal"><span class="pre">__path__</span></code> to a list containing the package
1900
name, they now set it to an empty list. The previous behavior could cause
1901
the import system to do the wrong thing on submodule imports if there was
1902
also a directory with the same name as the frozen package. The correct way
1903
to determine if a module is a package or not is to use <code class="docutils literal"><span class="pre">hasattr(module,</span>
1904
<span class="pre">'__path__')</span></code> (<a class="reference external" href="https://bugs.python.org/issue18065">issue 18065</a>).</li>
1905
<li>Frozen modules no longer define a <code class="docutils literal"><span class="pre">__file__</span></code> attribute. It’s semantically
1906
incorrect for frozen modules to set the attribute as they are not loaded from
1907
any explicit location. If you must know that a module comes from frozen code
1908
then you can see if the module’s <code class="docutils literal"><span class="pre">__spec__.location</span></code> is set to <code class="docutils literal"><span class="pre">'frozen'</span></code>,
1909
check if the loader is a subclass of
1910
<a class="reference internal" href="../library/importlib.html#importlib.machinery.FrozenImporter" title="importlib.machinery.FrozenImporter"><code class="xref py py-class docutils literal"><span class="pre">importlib.machinery.FrozenImporter</span></code></a>,
1911
or if Python 2 compatibility is necessary you can use <code class="xref py py-func docutils literal"><span class="pre">imp.is_frozen()</span></code>.</li>
1912
<li><a class="reference internal" href="../library/py_compile.html#py_compile.compile" title="py_compile.compile"><code class="xref py py-func docutils literal"><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"><span class="pre">FileExistsError</span></code></a> if the file path
1913
it would write to is a symlink or a non-regular file. This is to act as a
1914
warning that import will overwrite those files with a regular file regardless
1915
of what type of file path they were originally.</li>
1916
<li><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"><span class="pre">importlib.abc.SourceLoader.get_source()</span></code></a> no longer raises
1917
<a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal"><span class="pre">ImportError</span></code></a> when the source code being loaded triggers a
1918
<a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal"><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"><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"><span class="pre">ImportError</span></code></a> is
1919
meant to be raised only when source code cannot be found but it should, it was
1920
felt to be over-reaching/overloading of that meaning when the source code is
1921
found but improperly structured. If you were catching ImportError before and
1922
wish to continue to ignore syntax or decoding issues, catch all three
1923
exceptions now.</li>
1924
<li><a class="reference internal" href="../library/functools.html#functools.update_wrapper" title="functools.update_wrapper"><code class="xref py py-func docutils literal"><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"><span class="pre">functools.wraps()</span></code></a> now correctly
1925
set the <code class="docutils literal"><span class="pre">__wrapped__</span></code> attribute to the function being wrapped, even if
1926
that function also had its <code class="docutils literal"><span class="pre">__wrapped__</span></code> attribute set. This means
1927
<code class="docutils literal"><span class="pre">__wrapped__</span></code> attributes now correctly link a stack of decorated
1928
functions rather than every <code class="docutils literal"><span class="pre">__wrapped__</span></code> attribute in the chain
1929
referring to the innermost function. Introspection libraries that
1930
assumed the previous behaviour was intentional can use
1931
<a class="reference internal" href="../library/inspect.html#inspect.unwrap" title="inspect.unwrap"><code class="xref py py-func docutils literal"><span class="pre">inspect.unwrap()</span></code></a> to access the first function in the chain that has
1932
no <code class="docutils literal"><span class="pre">__wrapped__</span></code> attribute.</li>
1933
<li><a class="reference internal" href="../library/inspect.html#inspect.getfullargspec" title="inspect.getfullargspec"><code class="xref py py-func docutils literal"><span class="pre">inspect.getfullargspec()</span></code></a> has been reimplemented on top of
1934
<a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal"><span class="pre">inspect.signature()</span></code></a> and hence handles a much wider variety of callable
1935
objects than it did in the past. It is expected that additional builtin and
1936
extension module callables will gain signature metadata over the course of
1937
the Python 3.4 series. Code that assumes that
1938
<a class="reference internal" href="../library/inspect.html#inspect.getfullargspec" title="inspect.getfullargspec"><code class="xref py py-func docutils literal"><span class="pre">inspect.getfullargspec()</span></code></a> will fail on non-Python callables may need
1939
to be adjusted accordingly.</li>
1940
<li><a class="reference internal" href="../library/importlib.html#importlib.machinery.PathFinder" title="importlib.machinery.PathFinder"><code class="xref py py-class docutils literal"><span class="pre">importlib.machinery.PathFinder</span></code></a> now passes on the current working
1941
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"><span class="pre">sys.path_hooks</span></code></a> for the empty string. This
1942
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"><span class="pre">sys.path_importer_cache</span></code></a> never containing <code class="docutils literal"><span class="pre">''</span></code>, thus
1943
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"><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"><span class="pre">sys.path</span></code></a>
1944
will not find all keys. A module’s <code class="docutils literal"><span class="pre">__file__</span></code> when imported in the current
1945
working directory will also now have an absolute path, including when using
1946
<code class="docutils literal"><span class="pre">-m</span></code> with the interpreter (except for <code class="docutils literal"><span class="pre">__main__.__file__</span></code> when a script
1947
has been executed directly using a relative path) (Contributed by Brett
1948
Cannon in <a class="reference external" href="https://bugs.python.org/issue18416">issue 18416</a>). is specified on the command-line)
1949
(<a class="reference external" href="https://bugs.python.org/issue18416">issue 18416</a>).</li>
1950
<li>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"><span class="pre">HTTPConnection</span></code></a>
1951
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"><span class="pre">HTTPSConnection</span></code></a> changes the meaning of the
1952
remaining arguments if you are specifying them positionally rather than by
1953
keyword. If you’ve been paying attention to deprecation warnings your code
1954
should already be specifying any additional arguments via keywords.</li>
1955
<li>Strings between <code class="docutils literal"><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
1956
a <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal"><span class="pre">SyntaxError</span></code></a>. Previously if there was no leading docstring, an
1957
interstitial string would sometimes be ignored. This brings CPython into
1958
compliance with the language spec; Jython and PyPy already were.
1959
(<a class="reference external" href="https://bugs.python.org/issue17434">issue 17434</a>).</li>
1960
<li><a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.getpeercert" title="ssl.SSLSocket.getpeercert"><code class="xref py py-meth docutils literal"><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"><span class="pre">ssl.SSLSocket.do_handshake()</span></code></a>
1961
now raise an <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal"><span class="pre">OSError</span></code></a> with <code class="docutils literal"><span class="pre">ENOTCONN</span></code> when the <code class="docutils literal"><span class="pre">SSLSocket</span></code> is not
1962
connected, instead of the previous behavior of raising an
1963
<a class="reference internal" href="../library/exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal"><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"><span class="pre">getpeercert()</span></code></a>
1964
will raise a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code></a> if the handshake has not yet been done.</li>
1965
<li><a class="reference internal" href="../library/base64.html#base64.b32decode" title="base64.b32decode"><code class="xref py py-func docutils literal"><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"><span class="pre">binascii.Error</span></code></a> when the
1966
input string contains non-b32-alphabet characters, instead of a
1967
<a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal"><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"><span class="pre">TypeError</span></code></a> was missed when the other
1968
<a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code></a>s were converted. (Contributed by Serhiy Storchaka in
1969
<a class="reference external" href="https://bugs.python.org/issue18011">issue 18011</a>.) Note: this change was also inadvertently applied in Python
1971
<li>The <code class="xref py py-attr docutils literal"><span class="pre">file</span></code> attribute is now automatically closed when
1972
the creating <code class="xref py py-class docutils literal"><span class="pre">cgi.FieldStorage</span></code> instance is garbage collected. If you
1973
were pulling the file object out separately from the <code class="xref py py-class docutils literal"><span class="pre">cgi.FieldStorage</span></code>
1974
instance and not keeping the instance alive, then you should either store the
1975
entire <code class="xref py py-class docutils literal"><span class="pre">cgi.FieldStorage</span></code> instance or read the contents of the file
1976
before the <code class="xref py py-class docutils literal"><span class="pre">cgi.FieldStorage</span></code> instance is garbage collected.</li>
1977
<li>Calling <code class="docutils literal"><span class="pre">read</span></code> or <code class="docutils literal"><span class="pre">write</span></code> on a closed SSL socket now raises an
1978
informative <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code></a> rather than the previous more mysterious
1979
<a class="reference internal" href="../library/exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal"><span class="pre">AttributeError</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue9177">issue 9177</a>).</li>
1980
<li><a class="reference internal" href="../reference/datamodel.html#slice.indices" title="slice.indices"><code class="xref py py-meth docutils literal"><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"><span class="pre">OverflowError</span></code></a> for huge
1981
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"><span class="pre">slice.indices()</span></code></a> now raises a
1982
<a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code></a> if given a negative length; previously it returned nonsense
1983
values (<a class="reference external" href="https://bugs.python.org/issue14794">issue 14794</a>).</li>
1984
<li>The <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal"><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"><span class="pre">cmath</span></code></a> functions, was
1985
incorrectly accepting <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal"><span class="pre">float</span></code></a> values if an object’s <code class="docutils literal"><span class="pre">__complex__</span></code>
1986
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"><span class="pre">TypeError</span></code></a>.
1987
(<a class="reference external" href="https://bugs.python.org/issue16290">issue 16290</a>.)</li>
1988
<li>The <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal"><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"><span class="pre">float</span></code></a>
1989
values for the <em>base</em> parameter. It is unlikely anyone was doing this, but
1990
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"><span class="pre">TypeError</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue16772">issue 16772</a>).</li>
1991
<li>Defaults for keyword-only arguments are now evaluated <em>after</em> defaults for
1992
regular keyword arguments, instead of before. Hopefully no one wrote any
1993
code that depends on the previous buggy behavior (<a class="reference external" href="https://bugs.python.org/issue16967">issue 16967</a>).</li>
1994
<li>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"><span class="pre">fork()</span></code></a>. This may cause
1995
some system resources to be released that previously were incorrectly kept
1996
perpetually alive (for example, database connections kept in thread-local
1997
storage). (<a class="reference external" href="https://bugs.python.org/issue17094">issue 17094</a>.)</li>
1998
<li>Parameter names in <code class="docutils literal"><span class="pre">__annotations__</span></code> dicts are now mangled properly,
1999
similarly to <code class="docutils literal"><span class="pre">__kwdefaults__</span></code>. (Contributed by Yury Selivanov in
2000
<a class="reference external" href="https://bugs.python.org/issue20625">issue 20625</a>.)</li>
2001
<li><a class="reference internal" href="../library/hashlib.html#hashlib.hash.name" title="hashlib.hash.name"><code class="xref py py-attr docutils literal"><span class="pre">hashlib.hash.name</span></code></a> now always returns the identifier in lower case.
2002
Previously some builtin hashes had uppercase names, but now that it is a
2003
formal public interface the naming has been made consistent (<a class="reference external" href="https://bugs.python.org/issue18532">issue 18532</a>).</li>
2004
<li>Because <a class="reference internal" href="../library/unittest.html#unittest.TestSuite" title="unittest.TestSuite"><code class="xref py py-mod docutils literal"><span class="pre">unittest.TestSuite</span></code></a> now drops references to tests after they
2005
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"><span class="pre">TestSuite</span></code></a> to re-run
2006
a set of tests may fail. Test suites should not be re-used in this fashion
2007
since it means state is retained between test runs, breaking the test
2008
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"><span class="pre">unittest</span></code></a> is designed to provide. However, if the lack
2009
of isolation is considered acceptable, the old behavior can be restored by
2010
creating a <a class="reference internal" href="../library/unittest.html#unittest.TestSuite" title="unittest.TestSuite"><code class="xref py py-mod docutils literal"><span class="pre">TestSuite</span></code></a> subclass that defines a
2011
<code class="docutils literal"><span class="pre">_removeTestAtIndex</span></code> method that does nothing (see
2012
<a class="reference internal" href="../library/unittest.html#unittest.TestSuite.__iter__" title="unittest.TestSuite.__iter__"><code class="xref py py-meth docutils literal"><span class="pre">TestSuite.__iter__()</span></code></a>) (<a class="reference external" href="https://bugs.python.org/issue11798">issue 11798</a>).</li>
2013
<li><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"><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"><span class="pre">argparse</span></code></a> for command line parsing. There are
2014
certain invalid command forms that used to work that are no longer allowed;
2015
in theory this should not cause backward compatibility issues since the
2016
disallowed command forms didn’t make any sense and are unlikely to be in use.</li>
2017
<li>The <a class="reference internal" href="../library/re.html#re.split" title="re.split"><code class="xref py py-func docutils literal"><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"><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"><span class="pre">re.sub()</span></code></a> functions, and
2018
the <a class="reference internal" href="../library/re.html#re.match.group" title="re.match.group"><code class="xref py py-meth docutils literal"><span class="pre">group()</span></code></a> and <a class="reference internal" href="../library/re.html#re.match.groups" title="re.match.groups"><code class="xref py py-meth docutils literal"><span class="pre">groups()</span></code></a> methods of
2019
<code class="docutils literal"><span class="pre">match</span></code> objects now always return a <em>bytes</em> object when the string
2020
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
2021
matched the input type, so if your code was depending on the return value
2022
being, say, a <code class="docutils literal"><span class="pre">bytearray</span></code>, you will need to change your code.</li>
2023
<li><a class="reference internal" href="../library/audioop.html#module-audioop" title="audioop: Manipulate raw audio data."><code class="xref py py-mod docutils literal"><span class="pre">audioop</span></code></a> functions now raise an error immediately if passed string
2024
input, instead of failing randomly later on (<a class="reference external" href="https://bugs.python.org/issue16685">issue 16685</a>).</li>
2025
<li>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"><span class="pre">HTMLParser</span></code></a>
2026
currently defaults to <code class="docutils literal"><span class="pre">False</span></code> for backward compatibility, but will
2027
eventually be changed to default to <code class="docutils literal"><span class="pre">True</span></code>. It is recommended that you add
2028
this keyword, with the appropriate value, to any
2029
<a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal"><span class="pre">HTMLParser</span></code></a> calls in your code (<a class="reference external" href="https://bugs.python.org/issue13633">issue 13633</a>).</li>
2030
<li>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"><span class="pre">hmac.new()</span></code></a> function will in the
2031
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"><span class="pre">hmac.new()</span></code></a> should be changed to
2032
explicitly specify a <em>digestmod</em> (<a class="reference external" href="https://bugs.python.org/issue17276">issue 17276</a>).</li>
2033
<li>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"><span class="pre">sysconfig.get_config_var()</span></code></a> with the <code class="docutils literal"><span class="pre">SO</span></code> key, or looking
2034
<code class="docutils literal"><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"><span class="pre">sysconfig.get_config_vars()</span></code></a>
2035
is deprecated. This key should be replaced by <code class="docutils literal"><span class="pre">EXT_SUFFIX</span></code> or
2036
<code class="docutils literal"><span class="pre">SHLIB_SUFFIX</span></code>, depending on the context (<a class="reference external" href="https://bugs.python.org/issue19555">issue 19555</a>).</li>
2037
<li>Any calls to <code class="docutils literal"><span class="pre">open</span></code> functions that specify <code class="docutils literal"><span class="pre">U</span></code> should be modified.
2038
<code class="docutils literal"><span class="pre">U</span></code> is ineffective in Python3 and will eventually raise an error if used.
2039
Depending on the function, the equivalent of its old Python2 behavior can be
2040
achieved using either a <em>newline</em> argument, or if necessary by wrapping the
2041
stream in <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-mod docutils literal"><span class="pre">TextIOWrapper</span></code></a> to use its <em>newline</em> argument
2042
(<a class="reference external" href="https://bugs.python.org/issue15204">issue 15204</a>).</li>
2043
<li>If you use <a class="reference internal" href="../using/scripts.html#scripts-pyvenv"><span>pyvenv</span></a> in a script and desire that pip
2044
<em>not</em> be installed, you must add <code class="docutils literal"><span class="pre">--without-pip</span></code> to your command
2046
<li>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"><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"><span class="pre">json.dumps()</span></code></a> when
2047
an indent is specified has changed: it no longer produces trailing
2048
spaces after the item separating commas at the ends of lines. This
2049
will matter only if you have tests that are doing white-space-sensitive
2050
comparisons of such output (<a class="reference external" href="https://bugs.python.org/issue16333">issue 16333</a>).</li>
2051
<li><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"><span class="pre">doctest</span></code></a> now looks for doctests in extension module <code class="docutils literal"><span class="pre">__doc__</span></code>
2052
strings, so if your doctest test discovery includes extension modules that
2053
have things that look like doctests in them you may see test failures you’ve
2054
never seen before when running your tests (<a class="reference external" href="https://bugs.python.org/issue3158">issue 3158</a>).</li>
2055
<li>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"><span class="pre">collections.abc</span></code></a> module has been slightly refactored as
2056
part of the Python startup improvements. As a consequence of this, it is no
2057
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"><span class="pre">collections</span></code></a> automatically imports
2058
<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"><span class="pre">collections.abc</span></code></a>. If your program depended on the (undocumented)
2059
implicit import, you will need to add an explicit <code class="docutils literal"><span class="pre">import</span> <span class="pre">collections.abc</span></code>
2060
(<a class="reference external" href="https://bugs.python.org/issue20784">issue 20784</a>).</li>
2063
<div class="section" id="changes-in-the-c-api">
2064
<h3>Changes in the C API<a class="headerlink" href="#changes-in-the-c-api" title="Permalink to this headline">¶</a></h3>
2066
<li><a class="reference internal" href="../c-api/veryhigh.html#c.PyEval_EvalFrameEx" title="PyEval_EvalFrameEx"><code class="xref c c-func docutils literal"><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"><span class="pre">PyObject_Repr()</span></code></a>, and
2067
<a class="reference internal" href="../c-api/object.html#c.PyObject_Str" title="PyObject_Str"><code class="xref c c-func docutils literal"><span class="pre">PyObject_Str()</span></code></a>, along with some other internal C APIs, now include
2068
a debugging assertion that ensures they are not used in situations where
2069
they may silently discard a currently active exception. In cases where
2070
discarding the active exception is expected and desired (for example,
2071
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"><span class="pre">PyErr_Fetch()</span></code></a> or
2072
is being deliberately replaced with a different exception), an explicit
2073
<a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Clear" title="PyErr_Clear"><code class="xref c c-func docutils literal"><span class="pre">PyErr_Clear()</span></code></a> call will be needed to avoid triggering the
2074
assertion when invoking these operations (directly or indirectly) and
2075
running against a version of Python that is compiled with assertions
2077
<li><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetImportError" title="PyErr_SetImportError"><code class="xref c c-func docutils literal"><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"><span class="pre">TypeError</span></code></a> when its <strong>msg</strong>
2078
argument is not set. Previously only <code class="docutils literal"><span class="pre">NULL</span></code> was returned with no exception
2080
<li>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"><span class="pre">PyOS_ReadlineFunctionPointer</span></code></a> callback must
2081
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"><span class="pre">PyMem_RawMalloc()</span></code></a> or
2082
<a class="reference internal" href="../c-api/memory.html#c.PyMem_RawRealloc" title="PyMem_RawRealloc"><code class="xref c c-func docutils literal"><span class="pre">PyMem_RawRealloc()</span></code></a>, or <em>NULL</em> if an error occurred, instead of a
2083
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"><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"><span class="pre">PyMem_Realloc()</span></code></a>
2084
(<a class="reference external" href="https://bugs.python.org/issue16742">issue 16742</a>)</li>
2085
<li><code class="xref c c-func docutils literal"><span class="pre">PyThread_set_key_value()</span></code> now always set the value. In Python
2086
3.3, the function did nothing if the key already exists (if the current
2087
value is a non-NULL pointer).</li>
2088
<li>The <code class="docutils literal"><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"><span class="pre">PyFrameObject</span></code></a>
2089
structure has been removed to fix a bug: see <a class="reference external" href="https://bugs.python.org/issue14432">issue 14432</a> for the
2094
<div class="section" id="changed-in-3-4-3">
2095
<h2>Changed in 3.4.3<a class="headerlink" href="#changed-in-3-4-3" title="Permalink to this headline">¶</a></h2>
2096
<div class="section" id="pep-476-enabling-certificate-verification-by-default-for-stdlib-http-clients">
2097
<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>
2098
<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"><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"><span class="pre">urllib.request</span></code></a> and
2099
<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"><span class="pre">xmlrpc.client</span></code></a>, will now verify that the server presents a certificate
2100
which is signed by a CA in the platform trust store and whose hostname matches
2101
the hostname being requested by default, significantly improving security for
2102
many applications.</p>
2103
<p>For applications which require the old previous behavior, they can pass an
2104
alternate context:</p>
2105
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">urllib.request</span>
2106
<span class="kn">import</span> <span class="nn">ssl</span>
2108
<span class="c1"># This disables all verification</span>
2109
<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>
2111
<span class="c1"># This allows using a specific certificate for the host, which doesn't need</span>
2112
<span class="c1"># to be in the trust store</span>
2113
<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>
2115
<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>
2126
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
2127
<div class="sphinxsidebarwrapper">
2128
<h3><a href="../contents.html">Table Of Contents</a></h3>
2130
<li><a class="reference internal" href="#">What’s New In Python 3.4</a><ul>
2131
<li><a class="reference internal" href="#summary-release-highlights">Summary – Release Highlights</a></li>
2132
<li><a class="reference internal" href="#new-features">New Features</a><ul>
2133
<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>
2134
<li><a class="reference internal" href="#bootstrapping-pip-by-default">Bootstrapping pip By Default</a></li>
2135
<li><a class="reference internal" href="#documentation-changes">Documentation Changes</a></li>
2138
<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>
2139
<li><a class="reference internal" href="#improvements-to-codec-handling">Improvements to Codec Handling</a></li>
2140
<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>
2141
<li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
2144
<li><a class="reference internal" href="#new-modules">New Modules</a><ul>
2145
<li><a class="reference internal" href="#asyncio">asyncio</a></li>
2146
<li><a class="reference internal" href="#ensurepip">ensurepip</a></li>
2147
<li><a class="reference internal" href="#enum">enum</a></li>
2148
<li><a class="reference internal" href="#pathlib">pathlib</a></li>
2149
<li><a class="reference internal" href="#selectors">selectors</a></li>
2150
<li><a class="reference internal" href="#statistics">statistics</a></li>
2151
<li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
2154
<li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
2155
<li><a class="reference internal" href="#abc">abc</a></li>
2156
<li><a class="reference internal" href="#aifc">aifc</a></li>
2157
<li><a class="reference internal" href="#argparse">argparse</a></li>
2158
<li><a class="reference internal" href="#audioop">audioop</a></li>
2159
<li><a class="reference internal" href="#base64">base64</a></li>
2160
<li><a class="reference internal" href="#collections">collections</a></li>
2161
<li><a class="reference internal" href="#colorsys">colorsys</a></li>
2162
<li><a class="reference internal" href="#contextlib">contextlib</a></li>
2163
<li><a class="reference internal" href="#dbm">dbm</a></li>
2164
<li><a class="reference internal" href="#dis">dis</a></li>
2165
<li><a class="reference internal" href="#doctest">doctest</a></li>
2166
<li><a class="reference internal" href="#email">email</a></li>
2167
<li><a class="reference internal" href="#filecmp">filecmp</a></li>
2168
<li><a class="reference internal" href="#functools">functools</a></li>
2169
<li><a class="reference internal" href="#gc">gc</a></li>
2170
<li><a class="reference internal" href="#glob">glob</a></li>
2171
<li><a class="reference internal" href="#hashlib">hashlib</a></li>
2172
<li><a class="reference internal" href="#hmac">hmac</a></li>
2173
<li><a class="reference internal" href="#html">html</a></li>
2174
<li><a class="reference internal" href="#http">http</a></li>
2175
<li><a class="reference internal" href="#idlelib-and-idle">idlelib and IDLE</a></li>
2176
<li><a class="reference internal" href="#importlib">importlib</a></li>
2177
<li><a class="reference internal" href="#inspect">inspect</a></li>
2178
<li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
2179
<li><a class="reference internal" href="#logging">logging</a></li>
2180
<li><a class="reference internal" href="#marshal">marshal</a></li>
2181
<li><a class="reference internal" href="#mmap">mmap</a></li>
2182
<li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
2183
<li><a class="reference internal" href="#operator">operator</a></li>
2184
<li><a class="reference internal" href="#os">os</a></li>
2185
<li><a class="reference internal" href="#pdb">pdb</a></li>
2186
<li><a class="reference internal" href="#pickle">pickle</a></li>
2187
<li><a class="reference internal" href="#plistlib">plistlib</a></li>
2188
<li><a class="reference internal" href="#poplib">poplib</a></li>
2189
<li><a class="reference internal" href="#pprint">pprint</a></li>
2190
<li><a class="reference internal" href="#pty">pty</a></li>
2191
<li><a class="reference internal" href="#pydoc">pydoc</a></li>
2192
<li><a class="reference internal" href="#re">re</a></li>
2193
<li><a class="reference internal" href="#resource">resource</a></li>
2194
<li><a class="reference internal" href="#select">select</a></li>
2195
<li><a class="reference internal" href="#shelve">shelve</a></li>
2196
<li><a class="reference internal" href="#shutil">shutil</a></li>
2197
<li><a class="reference internal" href="#smtpd">smtpd</a></li>
2198
<li><a class="reference internal" href="#smtplib">smtplib</a></li>
2199
<li><a class="reference internal" href="#socket">socket</a></li>
2200
<li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
2201
<li><a class="reference internal" href="#ssl">ssl</a></li>
2202
<li><a class="reference internal" href="#stat">stat</a></li>
2203
<li><a class="reference internal" href="#struct">struct</a></li>
2204
<li><a class="reference internal" href="#subprocess">subprocess</a></li>
2205
<li><a class="reference internal" href="#sunau">sunau</a></li>
2206
<li><a class="reference internal" href="#sys">sys</a></li>
2207
<li><a class="reference internal" href="#tarfile">tarfile</a></li>
2208
<li><a class="reference internal" href="#textwrap">textwrap</a></li>
2209
<li><a class="reference internal" href="#threading">threading</a></li>
2210
<li><a class="reference internal" href="#traceback">traceback</a></li>
2211
<li><a class="reference internal" href="#types">types</a></li>
2212
<li><a class="reference internal" href="#urllib">urllib</a></li>
2213
<li><a class="reference internal" href="#unittest">unittest</a></li>
2214
<li><a class="reference internal" href="#venv">venv</a></li>
2215
<li><a class="reference internal" href="#wave">wave</a></li>
2216
<li><a class="reference internal" href="#weakref">weakref</a></li>
2217
<li><a class="reference internal" href="#xml-etree">xml.etree</a></li>
2218
<li><a class="reference internal" href="#zipfile">zipfile</a></li>
2221
<li><a class="reference internal" href="#cpython-implementation-changes">CPython Implementation Changes</a><ul>
2222
<li><a class="reference internal" href="#pep-445-customization-of-cpython-memory-allocators">PEP 445: Customization of CPython Memory Allocators</a></li>
2223
<li><a class="reference internal" href="#pep-442-safe-object-finalization">PEP 442: Safe Object Finalization</a></li>
2224
<li><a class="reference internal" href="#pep-456-secure-and-interchangeable-hash-algorithm">PEP 456: Secure and Interchangeable Hash Algorithm</a></li>
2225
<li><a class="reference internal" href="#pep-436-argument-clinic">PEP 436: Argument Clinic</a></li>
2226
<li><a class="reference internal" href="#other-build-and-c-api-changes">Other Build and C API Changes</a></li>
2227
<li><a class="reference internal" href="#other-improvements">Other Improvements</a></li>
2228
<li><a class="reference internal" href="#significant-optimizations">Significant Optimizations</a></li>
2231
<li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
2232
<li><a class="reference internal" href="#deprecations-in-the-python-api">Deprecations in the Python API</a></li>
2233
<li><a class="reference internal" href="#deprecated-features">Deprecated Features</a></li>
2236
<li><a class="reference internal" href="#removed">Removed</a><ul>
2237
<li><a class="reference internal" href="#operating-systems-no-longer-supported">Operating Systems No Longer Supported</a></li>
2238
<li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
2239
<li><a class="reference internal" href="#code-cleanups">Code Cleanups</a></li>
2242
<li><a class="reference internal" href="#porting-to-python-3-4">Porting to Python 3.4</a><ul>
2243
<li><a class="reference internal" href="#changes-in-python-command-behavior">Changes in ‘python’ Command Behavior</a></li>
2244
<li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
2245
<li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
2248
<li><a class="reference internal" href="#changed-in-3-4-3">Changed in 3.4.3</a><ul>
2249
<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>
2256
<h4>Previous topic</h4>
2257
<p class="topless"><a href="3.5.html"
2258
title="previous chapter">What’s New In Python 3.5</a></p>
2260
<p class="topless"><a href="3.3.html"
2261
title="next chapter">What’s New In Python 3.3</a></p>
2262
<div role="note" aria-label="source link">
2264
<ul class="this-page-menu">
2265
<li><a href="../bugs.html">Report a Bug</a></li>
2266
<li><a href="../_sources/whatsnew/3.4.txt"
2267
rel="nofollow">Show Source</a></li>
2272
<div class="clearer"></div>
2274
<div class="related" role="navigation" aria-label="related navigation">
2277
<li class="right" style="margin-right: 10px">
2278
<a href="../genindex.html" title="General Index"
2281
<a href="../py-modindex.html" title="Python Module Index"
2284
<a href="3.3.html" title="What’s New In Python 3.3"
2287
<a href="3.5.html" title="What’s New In Python 3.5"
2288
>previous</a> |</li>
2289
<li><img src="../_static/py.png" alt=""
2290
style="vertical-align: middle; margin-top: -1px"/></li>
2291
<li><a href="https://www.python.org/">Python</a> »</li>
2293
<span class="version_switcher_placeholder">3.5.2</span>
2294
<a href="../index.html">Documentation </a> »
2297
<li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> »</li>
2301
<div class="inline-search" style="display: none" role="search">
2302
<form class="inline-search" action="../search.html" method="get">
2303
<input placeholder="Quick search" type="text" name="q" />
2304
<input type="submit" value="Go" />
2305
<input type="hidden" name="check_keywords" value="yes" />
2306
<input type="hidden" name="area" value="default" />
2309
<script type="text/javascript">$('.inline-search').show(0);</script>
2315
<div class="footer">
2316
© <a href="../copyright.html">Copyright</a> 2001-2016, Python Software Foundation.
2318
The Python Software Foundation is a non-profit corporation.
2319
<a href="https://www.python.org/psf/donations/">Please donate.</a>
2321
Last updated on Oct 19, 2016.
2322
<a href="../bugs.html">Found a bug</a>?
2324
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
b'\\ No newline at end of file'