blob: 9cf51bdc777f95b64a6e6a0aabebd9e252833881 [file] [log] [blame]
Georg Brandlb80f5112012-09-30 09:11:58 +02001****************************
2 What's New In Python 3.4
3****************************
4
Larry Hastings3732ed22014-03-15 21:13:56 -07005:Author: R. David Murray <rdmurray@bitdance.com> (Editor)
Georg Brandlb80f5112012-09-30 09:11:58 +02006
7.. Rules for maintenance:
8
Nick Coghlan03074fd2012-09-30 18:51:53 +05309 * Anyone can add text to this document, but the maintainer reserves the
10 right to rewrite any additions. In particular, for obscure or esoteric
11 features, the maintainer may reduce any addition to a simple reference to
12 the new documentation rather than explaining the feature inline.
Georg Brandlb80f5112012-09-30 09:11:58 +020013
Nick Coghlan03074fd2012-09-30 18:51:53 +053014 * While the maintainer will periodically go through Misc/NEWS
15 and add changes, it's best not to rely on this. We know from experience
16 that any changes that aren't in the What's New documentation around the
17 time of the original release will remain largely unknown to the community
18 for years, even if they're added later. We also know from experience that
19 other priorities can arise, and the maintainer will run out of time to do
R David Murray061efb12013-12-24 12:35:59 -050020 updates -- in such cases, end users will be much better served by partial
Nick Coghlan03074fd2012-09-30 18:51:53 +053021 notifications that at least give a hint about new features to
22 investigate.
Georg Brandlb80f5112012-09-30 09:11:58 +020023
24 * This is not a complete list of every single change; completeness
Nick Coghlan03074fd2012-09-30 18:51:53 +053025 is the purpose of Misc/NEWS. The What's New should focus on changes that
26 are visible to Python *users* and that *require* a feature release (i.e.
27 most bug fixes should only be recorded in Misc/NEWS)
28
29 * PEPs should not be marked Final until they have an entry in What's New.
30 A placeholder entry that is just a section header and a link to the PEP
31 (e.g ":pep:`397` has been implemented") is acceptable. If a PEP has been
32 implemented and noted in What's New, don't forget to mark it as Final!
Georg Brandlb80f5112012-09-30 09:11:58 +020033
34 * If you want to draw your new text to the attention of the
35 maintainer, add 'XXX' to the beginning of the paragraph or
36 section.
37
Nick Coghlan03074fd2012-09-30 18:51:53 +053038 * It's OK to add just a very brief note about a change. For
39 example: "The :ref:`~socket.transmogrify()` function was added to the
40 :mod:`socket` module." The maintainer will research the change and
41 write the necessary text (if appropriate). The advantage of doing this
42 is that even if no more descriptive text is ever added, readers will at
43 least have a notification that the new feature exists and a link to the
44 relevant documentation.
Georg Brandlb80f5112012-09-30 09:11:58 +020045
46 * You can comment out your additions if you like, but it's not
47 necessary (especially when a final release is some months away).
48
49 * Credit the author of a patch or bugfix. Just the name is
50 sufficient; the e-mail address isn't necessary.
51
52 * It's helpful to add the bug/patch number as a comment:
53
Nick Coghlan03074fd2012-09-30 18:51:53 +053054 The :ref:`~socket.transmogrify()` function was added to the
55 :mod:`socket` module. (Contributed by P.Y. Developer in :issue:`12345`.)
Georg Brandlb80f5112012-09-30 09:11:58 +020056
57 This saves the maintainer the effort of going through the Mercurial log
58 when researching a change.
59
Nick Coghlan03074fd2012-09-30 18:51:53 +053060 * Cross referencing tip: :ref:`mod.attr` will display as ``mod.attr``,
61 while :ref:`~mod.attr` will display as ``attr``.
62
Georg Brandlb80f5112012-09-30 09:11:58 +020063This article explains the new features in Python 3.4, compared to 3.3.
64
Nick Coghlan03074fd2012-09-30 18:51:53 +053065.. Python 3.4 was released on TBD.
Georg Brandlb80f5112012-09-30 09:11:58 +020066
Ezio Melotti25bbe5e2012-11-17 19:30:48 +020067For full details, see the
68`changelog <http://docs.python.org/3.4/whatsnew/changelog.html>`_.
Georg Brandlb80f5112012-09-30 09:11:58 +020069
Georg Brandlb80f5112012-09-30 09:11:58 +020070
71.. seealso::
72
R David Murray061efb12013-12-24 12:35:59 -050073 :pep:`429` -- Python 3.4 Release Schedule
Georg Brandlb80f5112012-09-30 09:11:58 +020074
75
R David Murraye6082552014-01-03 16:15:45 -050076
R David Murraye7cf6782013-12-24 14:51:25 -050077Summary -- Release Highlights
Georg Brandlb80f5112012-09-30 09:11:58 +020078=============================
79
Kristjan Valur Jonssona1e82442013-03-26 13:56:14 +000080.. This section singles out the most important changes in Python 3.4.
Georg Brandlb80f5112012-09-30 09:11:58 +020081 Brevity is key.
82
83New syntax features:
84
R David Murraye0f7a782013-12-20 16:04:29 -050085* No new syntax features were added in Python 3.4.
Georg Brandlb80f5112012-09-30 09:11:58 +020086
Larry Hastings3732ed22014-03-15 21:13:56 -070087Other new features:
R David Murray809487e2013-12-22 20:49:40 -050088
Larry Hastings3732ed22014-03-15 21:13:56 -070089* :ref:`pip should always be available <whatsnew-pep-453>` (:pep:`453`).
90* :ref:`Newly created file descriptors are non-inheritable <whatsnew-pep-446>`
R David Murray809487e2013-12-22 20:49:40 -050091 (:pep:`446`).
Larry Hastings3732ed22014-03-15 21:13:56 -070092* command line option for :ref:`isolated mode <whatsnew-isolated-mode>`
R David Murray809487e2013-12-22 20:49:40 -050093 (:issue:`16499`).
R David Murray8d856782013-12-23 10:28:57 -050094* :ref:`improvements in the handling of codecs <codec-handling-improvements>`
95 that are not text encodings (multiple issues).
R David Murray809487e2013-12-22 20:49:40 -050096* :ref:`A ModuleSpec Type <whatsnew-pep-451>` for the Import System
R David Murraye9b74d42013-12-22 21:05:04 -050097 (:pep:`451`). (Affects importer authors.)
Larry Hastings3732ed22014-03-15 21:13:56 -070098* The :mod:`marshal` format has been made :ref:`more compact and efficient
99 <whatsnew-marshal-3>` (:issue:`16475`).
R David Murray809487e2013-12-22 20:49:40 -0500100
Georg Brandlb80f5112012-09-30 09:11:58 +0200101New library modules:
102
R David Murray9217dad2013-12-23 21:08:28 -0500103* :mod:`asyncio`: :ref:`New provisional API for asynchronous IO
104 <whatsnew-asyncio>` (:pep:`3156`).
105* :mod:`ensurepip`: :ref:`Bootstrapping the pip installer <whatsnew-ensurepip>`
106 (:pep:`453`).
107* :mod:`enum`: :ref:`Support for enumeration types <whatsnew-enum>`
108 (:pep:`435`).
109* :mod:`pathlib`: :ref:`Object-oriented filesystem paths <whatsnew-pathlib>`
110 (:pep:`428`).
R David Murrayf9976e72013-12-23 10:32:02 -0500111* :mod:`selectors`: :ref:`High-level and efficient I/O multiplexing
112 <whatsnew-selectors>`, built upon the :mod:`select` module primitives (part
113 of :pep:`3156`).
R David Murray9217dad2013-12-23 21:08:28 -0500114* :mod:`statistics`: A basic :ref:`numerically stable statistics library
115 <whatsnew-statistics>` (:pep:`450`).
116* :mod:`tracemalloc`: :ref:`Trace Python memory allocations
117 <whatsnew-tracemalloc>` (:pep:`454`).
Georg Brandlb80f5112012-09-30 09:11:58 +0200118
Larry Hastings3732ed22014-03-15 21:13:56 -0700119Significantly improved library modules:
Georg Brandlb80f5112012-09-30 09:11:58 +0200120
R David Murray0a102162013-12-20 15:00:54 -0500121* :ref:`Single-dispatch generic functions <whatsnew-singledispatch>` in
R David Murray8d856782013-12-23 10:28:57 -0500122 :mod:`functools` (:pep:`443`).
123* New :mod:`pickle` :ref:`protocol 4 <whatsnew-protocol-4>` (:pep:`3154`).
R David Murrayac186222013-12-20 17:23:57 -0500124* :mod:`multiprocessing` now has :ref:`an option to avoid using os.fork
125 on Unix <whatsnew-multiprocessing-no-fork>` (:issue:`8713`).
R David Murray6adb4542013-12-20 13:10:43 -0500126* :mod:`email` has a new submodule, :mod:`~email.contentmanager`, and
127 a new :mod:`~email.message.Message` subclass
R David Murray26b80cfd2013-12-20 17:26:52 -0500128 (:class:`~email.contentmanager.EmailMessage`) that :ref:`simplify MIME
R David Murray8d856782013-12-23 10:28:57 -0500129 handling <whatsnew_email_contentmanager>` (:issue:`18891`).
Larry Hastings3732ed22014-03-15 21:13:56 -0700130* The :mod:`inspect` and :mod:`pydoc` modules are now capable of
131 correct introspection of a much wider variety of callable objects,
132 which improves the output of the Python :func:`help` system.
Nick Coghlan96bb4372014-02-09 09:18:26 +1000133* The :mod:`ipaddress` module API has been declared stable
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200134
Larry Hastings3732ed22014-03-15 21:13:56 -0700135Security improvements:
136
137* :ref:`Secure and interchangeable hash algorithm <whatsnew-pep-456>`
138 (:pep:`456`).
139* :ref:`Make newly created file descriptors non-inheritable <whatsnew-pep-446>`
140 (:pep:`446`) to avoid leaking file descriptors to child processes.
141* New command line option for :ref:`isolated mode <whatsnew-isolated-mode>`,
142 (:issue:`16499`).
143* :mod:`multiprocessing` now has :ref:`an option to avoid using os.fork
144 on Unix <whatsnew-multiprocessing-no-fork>`. *spawn* and *forkserver* are
145 more secure because they avoid sharing data with child processes.
146* :mod:`multiprocessing` child processes on Windows no longer inherit
147 all of the parent's inheritable handles, only the necessary ones.
148* A new :func:`hashlib.pbkdf2_hmac` function provides
149 the `PKCS#5 password-based key derivation function 2
150 <http://en.wikipedia.org/wiki/PBKDF2>`_.
151* :ref:`TLSv1.1 and TLSv1.2 support <whatsnew-tls-11-12>` for :mod:`ssl`.
152* :ref:`Retrieving certificates from the Windows system cert store support
153 <whatsnew34-win-cert-store>` for :mod:`ssl`.
154* :ref:`Server-side SNI (Server Name Indication) support
155 <whatsnew34-sni>` for :mod:`ssl`.
156* The :class:`ssl.SSLContext` class has a :ref:`lot of improvements
157 <whatsnew34-sslcontext>`.
158* All modules in the standard library that support SSL now support server
159 certificate verification, including hostname matching
160 (:func:`ssl.match_hostname`) and CRLs (Certificate Revocation lists, see
161 :func:`ssl.SSLContext.load_verify_locations`).
Nick Coghlanaa029da2014-02-09 10:10:24 +1000162
Nick Coghlan367df122013-10-27 01:57:34 +1000163CPython implementation improvements:
Georg Brandlb80f5112012-09-30 09:11:58 +0200164
R David Murraya93ca972013-12-22 14:10:21 -0500165* :ref:`Safe object finalization <whatsnew-pep-442>` (:pep:`442`).
Larry Hastings3732ed22014-03-15 21:13:56 -0700166* Leveraging :pep:`442`, in most cases :ref:`module globals are no longer set
167 to None during finalization <whatsnew-pep-442>` (:issue:`18214`).
R David Murraya93ca972013-12-22 14:10:21 -0500168* :ref:`Configurable memory allocators <whatsnew-pep-445>` (:pep:`445`).
R David Murraya93ca972013-12-22 14:10:21 -0500169* :ref:`Argument Clinic <whatsnew-pep-436>` (:pep:`436`).
Georg Brandlb80f5112012-09-30 09:11:58 +0200170
R David Murray347f9c72013-12-23 21:30:06 -0500171Please read on for a comprehensive list of user-facing changes, including many
172other smaller improvements, CPython optimizations, deprecations, and potential
173porting issues.
Georg Brandlb80f5112012-09-30 09:11:58 +0200174
Nick Coghland0cf0632013-11-11 22:11:55 +1000175
R David Murraye6082552014-01-03 16:15:45 -0500176
Larry Hastings3732ed22014-03-15 21:13:56 -0700177New Features
178============
R David Murray809487e2013-12-22 20:49:40 -0500179
R David Murray68790662013-12-23 11:17:51 -0500180.. _whatsnew-pep-453:
181
R David Murraye7cf6782013-12-24 14:51:25 -0500182PEP 453: Explicit Bootstrapping of PIP in Python Installations
R David Murray809487e2013-12-22 20:49:40 -0500183--------------------------------------------------------------
Nick Coghland0cf0632013-11-11 22:11:55 +1000184
Larry Hastings3732ed22014-03-15 21:13:56 -0700185Bootstrapping pip By Default
186~~~~~~~~~~~~~~~~~~~~~~~~~~~~
187
Nick Coghland0cf0632013-11-11 22:11:55 +1000188The new :mod:`ensurepip` module (defined in :pep:`453`) provides a standard
Nick Coghlanaa029da2014-02-09 10:10:24 +1000189cross-platform mechanism to bootstrap the pip installer into Python
Larry Hastings3732ed22014-03-15 21:13:56 -0700190installations and virtual environments. The version of ``pip`` included
191with Python 3.4.0 is ``pip`` 1.5.4, and future 3.4.x maintenance releases
192will update the bundled version to the latest version of ``pip`` that is
193available at the time of creating the release candidate.
Nick Coghland0cf0632013-11-11 22:11:55 +1000194
Larry Hastings3732ed22014-03-15 21:13:56 -0700195By default, the commands ``pipX`` and ``pipX.Y`` will be installed on all
196platforms (where X.Y stands for the version of the Python installation),
197along with the ``pip`` Python package and its dependencies. On Windows and
198in virtual environments on all platforms, the unversioned ``pip`` command
199will also be installed. On other platforms, the system wide unversioned
200``pip`` command typically refers to the separately installed Python 2
201version.
Nick Coghlanaa029da2014-02-09 10:10:24 +1000202
Larry Hastings3732ed22014-03-15 21:13:56 -0700203The :ref:`pyvenv <scripts-pyvenv>` command line utility and the :mod:`venv`
204module make use of the :mod:`ensurepip` module to make ``pip`` readily
205available in virtual environments. When using the command line utility,
206``pip`` is installed by default, while when using the :mod:`venv` module
207:ref:`venv-api` installation of ``pip`` must be requested explicitly.
Nick Coghlan7bc4b3b2013-11-23 11:59:40 +1000208
Larry Hastings3732ed22014-03-15 21:13:56 -0700209For CPython :ref:`source builds on POSIX systems <building-python-on-unix>`,
210the ``make install`` and ``make altinstall`` commands bootstrap ``pip`` by
211default. This behaviour can be controlled through configure options, and
212overridden through Makefile options.
Nick Coghlan7bc4b3b2013-11-23 11:59:40 +1000213
Larry Hastings3732ed22014-03-15 21:13:56 -0700214On Windows and Mac OS X, the CPython installers now default to installing
215``pip`` along with CPython itself (users may opt out of installing it
216during the installation process). Window users will need to opt in to the
217automatic ``PATH`` modifications to have ``pip`` available from the command
218line by default, otherwise it can still be accessed through the Python
219launcher for Windows as ``py -m pip``.
Nick Coghlan7bc4b3b2013-11-23 11:59:40 +1000220
R David Murray68790662013-12-23 11:17:51 -0500221As `discussed in the PEP`__, platform packagers may choose not to install
Larry Hastings3732ed22014-03-15 21:13:56 -0700222these commands by default, as long as, when invoked, they provide clear and
223simple directions on how to install them on that platform (usually using
224the system package manager).
R David Murray68790662013-12-23 11:17:51 -0500225
226__ http://www.python.org/dev/peps/pep-0453/#recommendations-for-downstream-distributors
227
Nick Coghland0cf0632013-11-11 22:11:55 +1000228.. note::
229
Nick Coghlanaa029da2014-02-09 10:10:24 +1000230 To avoid conflicts between parallel Python 2 and Python 3 installations,
231 only the versioned ``pip3`` and ``pip3.4`` commands are bootstrapped by
Larry Hastings3732ed22014-03-15 21:13:56 -0700232 default when ``ensurepip`` is invoked directly - the ``--default-pip``
233 option is needed to also request the unversioned ``pip`` command.
234 ``pyvenv`` and the Windows installer ensure that the unqualified ``pip``
235 command is made available in those environments, and ``pip`` can always be
Nick Coghlanaa029da2014-02-09 10:10:24 +1000236 invoked via the ``-m`` switch rather than directly to avoid ambiguity on
237 systems with multiple Python installations.
Nick Coghland0cf0632013-11-11 22:11:55 +1000238
Larry Hastings3732ed22014-03-15 21:13:56 -0700239
240Documentation Changes
241~~~~~~~~~~~~~~~~~~~~~
242
243As part of this change, the :ref:`installing-index` and
244:ref:`distributing-index` sections of the documentation have been
245completely redesigned as short getting started and FAQ documents. Most
246packaging documentation has now been moved out to the Python Packaging
247Authority maintained `Python Packaging User Guide
248<http://packaging.python.org>`__ and the documentation of the individual
249projects.
250
251However, as this migration is currently still incomplete, the legacy
252versions of those guides remaining available as :ref:`install-index`
253and :ref:`distutils-index`.
254
Nick Coghland0cf0632013-11-11 22:11:55 +1000255.. seealso::
256
R David Murray061efb12013-12-24 12:35:59 -0500257 :pep:`453` -- Explicit bootstrapping of pip in Python installations
Nick Coghland0cf0632013-11-11 22:11:55 +1000258 PEP written by Donald Stufft and Nick Coghlan, implemented by
Nick Coghlan7bc4b3b2013-11-23 11:59:40 +1000259 Donald Stufft, Nick Coghlan, Martin von Löwis and Ned Deily.
Nick Coghland0cf0632013-11-11 22:11:55 +1000260
261
R David Murrayf9909c22013-12-20 14:50:12 -0500262.. _whatsnew-pep-446:
Victor Stinnerdaf45552013-08-28 00:53:59 +0200263
Larry Hastings3732ed22014-03-15 21:13:56 -0700264PEP 446: Newly Created File Descriptors Are Non-Inheritable
265-----------------------------------------------------------
Victor Stinnerdaf45552013-08-28 00:53:59 +0200266
Nick Coghlan367df122013-10-27 01:57:34 +1000267:pep:`446` makes newly created file descriptors :ref:`non-inheritable
Larry Hastings3732ed22014-03-15 21:13:56 -0700268<fd_inheritance>`. In general, this is the behavior an application will
269want: when launching a new process, having currently open files also
270open in the new process can lead to all sorts of hard to find bugs,
271and potentially to security issues.
272
273However, there are occasions when inheritance is desired. To support
274these cases, the following new functions and methods are available:
Victor Stinnerdaf45552013-08-28 00:53:59 +0200275
276* :func:`os.get_inheritable`, :func:`os.set_inheritable`
277* :func:`os.get_handle_inheritable`, :func:`os.set_handle_inheritable`
278* :meth:`socket.socket.get_inheritable`, :meth:`socket.socket.set_inheritable`
279
Antoine Pitrou796564c2013-07-30 19:59:21 +0200280.. seealso::
281
R David Murray061efb12013-12-24 12:35:59 -0500282 :pep:`446` -- Make newly created file descriptors non-inheritable
Nick Coghlan367df122013-10-27 01:57:34 +1000283 PEP written and implemented by Victor Stinner.
Antoine Pitrou796564c2013-07-30 19:59:21 +0200284
Georg Brandlb80f5112012-09-30 09:11:58 +0200285
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000286.. _codec-handling-improvements:
287
R David Murraye7cf6782013-12-24 14:51:25 -0500288Improvements to Codec Handling
R David Murray809487e2013-12-22 20:49:40 -0500289------------------------------
Nick Coghlan8b097b42013-11-13 23:49:21 +1000290
291Since it was first introduced, the :mod:`codecs` module has always been
292intended to operate as a type-neutral dynamic encoding and decoding
293system. However, its close coupling with the Python text model, especially
294the type restricted convenience methods on the builtin :class:`str`,
295:class:`bytes` and :class:`bytearray` types, has historically obscured that
296fact.
297
298As a key step in clarifying the situation, the :meth:`codecs.encode` and
299:meth:`codecs.decode` convenience functions are now properly documented in
300Python 2.7, 3.3 and 3.4. These functions have existed in the :mod:`codecs`
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000301module (and have been covered by the regression test suite) since Python 2.4,
Nick Coghlan8b097b42013-11-13 23:49:21 +1000302but were previously only discoverable through runtime introspection.
303
304Unlike the convenience methods on :class:`str`, :class:`bytes` and
Larry Hastings3732ed22014-03-15 21:13:56 -0700305:class:`bytearray`, the :mod:`codecs` convenience functions support arbitrary
306codecs in both Python 2 and Python 3, rather than being limited to Unicode text
307encodings (in Python 3) or ``basestring`` <-> ``basestring`` conversions (in
308Python 2).
Nick Coghlan8b097b42013-11-13 23:49:21 +1000309
Nick Coghlan8afc8f62013-11-22 23:00:22 +1000310In Python 3.4, the interpreter is able to identify the known non-text
311encodings provided in the standard library and direct users towards these
312general purpose convenience functions when appropriate::
Nick Coghlan8b097b42013-11-13 23:49:21 +1000313
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000314 >>> b"abcdef".decode("hex")
Nick Coghlan8b097b42013-11-13 23:49:21 +1000315 Traceback (most recent call last):
316 File "<stdin>", line 1, in <module>
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000317 LookupError: 'hex' is not a text encoding; use codecs.decode() to handle arbitrary codecs
Nick Coghlan8b097b42013-11-13 23:49:21 +1000318
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000319 >>> "hello".encode("rot13")
Nick Coghlan8b097b42013-11-13 23:49:21 +1000320 Traceback (most recent call last):
321 File "<stdin>", line 1, in <module>
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000322 LookupError: 'rot13' is not a text encoding; use codecs.encode() to handle arbitrary codecs
Nick Coghlan8b097b42013-11-13 23:49:21 +1000323
Nick Coghlanaa029da2014-02-09 10:10:24 +1000324 >>> open("foo.txt", encoding="hex")
325 Traceback (most recent call last):
326 File "<stdin>", line 1, in <module>
327 LookupError: 'hex' is not a text encoding; use codecs.open() to handle arbitrary codecs
328
Nick Coghlan8b097b42013-11-13 23:49:21 +1000329In a related change, whenever it is feasible without breaking backwards
330compatibility, exceptions raised during encoding and decoding operations
Larry Hastings3732ed22014-03-15 21:13:56 -0700331are wrapped in a chained exception of the same type that mentions the
Nick Coghlan8b097b42013-11-13 23:49:21 +1000332name of the codec responsible for producing the error::
333
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000334 >>> import codecs
335
336 >>> codecs.decode(b"abcdefgh", "hex")
Nick Coghlan77b286b2014-01-27 00:53:38 +1000337 Traceback (most recent call last):
338 File "/usr/lib/python3.4/encodings/hex_codec.py", line 20, in hex_decode
339 return (binascii.a2b_hex(input), len(input))
Nick Coghlan8afc8f62013-11-22 23:00:22 +1000340 binascii.Error: Non-hexadecimal digit found
Nick Coghlan8b097b42013-11-13 23:49:21 +1000341
342 The above exception was the direct cause of the following exception:
343
344 Traceback (most recent call last):
345 File "<stdin>", line 1, in <module>
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000346 binascii.Error: decoding with 'hex' codec failed (Error: Non-hexadecimal digit found)
Nick Coghlan8b097b42013-11-13 23:49:21 +1000347
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000348 >>> codecs.encode("hello", "bz2")
Nick Coghlan77b286b2014-01-27 00:53:38 +1000349 Traceback (most recent call last):
350 File "/usr/lib/python3.4/encodings/bz2_codec.py", line 17, in bz2_encode
351 return (bz2.compress(input), len(input))
352 File "/usr/lib/python3.4/bz2.py", line 498, in compress
353 return comp.compress(data) + comp.flush()
Nick Coghlan8b097b42013-11-13 23:49:21 +1000354 TypeError: 'str' does not support the buffer interface
355
356 The above exception was the direct cause of the following exception:
357
358 Traceback (most recent call last):
359 File "<stdin>", line 1, in <module>
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000360 TypeError: encoding with 'bz2' codec failed (TypeError: 'str' does not support the buffer interface)
Nick Coghlan8b097b42013-11-13 23:49:21 +1000361
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000362Finally, as the examples above show, these improvements have permitted
363the restoration of the convenience aliases for the non-Unicode codecs that
364were themselves restored in Python 3.2. This means that encoding binary data
365to and from its hexadecimal representation (for example) can now be written
366as::
367
368 >>> from codecs import encode, decode
369 >>> encode(b"hello", "hex")
370 b'68656c6c6f'
371 >>> decode(b"68656c6c6f", "hex")
372 b'hello'
373
374The binary and text transforms provided in the standard library are detailed
375in :ref:`binary-transforms` and :ref:`text-transforms`.
376
Larry Hastings3732ed22014-03-15 21:13:56 -0700377(Contributed by Nick Coghlan in :issue:`7475`, :issue:`17827`,
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000378:issue:`17828` and :issue:`19619`)
Nick Coghlan8b097b42013-11-13 23:49:21 +1000379
Nick Coghlanaa029da2014-02-09 10:10:24 +1000380
R David Murray809487e2013-12-22 20:49:40 -0500381.. _whatsnew-pep-451:
Eric Snowb523f842013-11-22 09:05:39 -0700382
383PEP 451: A ModuleSpec Type for the Import System
R David Murray809487e2013-12-22 20:49:40 -0500384------------------------------------------------
Eric Snowb523f842013-11-22 09:05:39 -0700385
R David Murrayf85b2a82013-12-22 21:06:13 -0500386:pep:`451` provides an encapsulation of the information about a module that the
387import machinery will use to load it (that is, a module specification). This
388helps simplify both the import implementation and several import-related APIs.
389The change is also a stepping stone for `several future import-related
390improvements`__.
Eric Snowb523f842013-11-22 09:05:39 -0700391
R David Murraye9b74d42013-12-22 21:05:04 -0500392__ https://mail.python.org/pipermail/python-dev/2013-November/130111.html
Eric Snowb523f842013-11-22 09:05:39 -0700393
394The public-facing changes from the PEP are entirely backward-compatible.
R David Murrayf85b2a82013-12-22 21:06:13 -0500395Furthermore, they should be transparent to everyone but importer authors. Key
396finder and loader methods have been deprecated, but they will continue working.
397New importers should use the new methods described in the PEP. Existing
Larry Hastings3732ed22014-03-15 21:13:56 -0700398importers should be updated to implement the new methods. See the
399:ref:`deprecated-3.4` section for a list of methods that should be replaced and
400their replacements.
Eric Snowb523f842013-11-22 09:05:39 -0700401
Nick Coghlan8b097b42013-11-13 23:49:21 +1000402
Georg Brandlb80f5112012-09-30 09:11:58 +0200403Other Language Changes
R David Murray809487e2013-12-22 20:49:40 -0500404----------------------
Georg Brandlb80f5112012-09-30 09:11:58 +0200405
406Some smaller changes made to the core Python language are:
407
Ezio Melotti34808e22013-10-12 16:36:13 +0300408* Unicode database updated to UCD version 6.3.
Georg Brandlb80f5112012-09-30 09:11:58 +0200409
Larry Hastings3732ed22014-03-15 21:13:56 -0700410* :func:`min` and :func:`max` now accept a *default* keyword-only argument that
411 can be used to specify the value they return if the iterable they are
412 evaluating has no elements. (Contributed by Julian Berman in
413 :issue:`18111`.)
Georg Brandlb80f5112012-09-30 09:11:58 +0200414
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200415* Module objects are now :mod:`weakref`'able.
416
Nick Coghlan0acceb72013-10-20 13:22:21 +1000417* Module ``__file__`` attributes (and related values) should now always
418 contain absolute paths by default, with the sole exception of
419 ``__main__.__file__`` when a script has been executed directly using
420 a relative path (Contributed by Brett Cannon in :issue:`18416`).
421
Larry Hastings3732ed22014-03-15 21:13:56 -0700422* All the UTF-\* codecs (except UTF-7) now reject surrogates during both
Serhiy Storchaka58cf6072013-11-19 11:32:41 +0200423 encoding and decoding unless the ``surrogatepass`` error handler is used,
Larry Hastings3732ed22014-03-15 21:13:56 -0700424 with the exception of the UTF-16 decoder (which accepts valid surrogate pairs)
425 and the UTF-16 encoder (which produces them while encoding non-BMP characters).
Serhiy Storchaka58cf6072013-11-19 11:32:41 +0200426 Contributed by Victor Stinner, Kang-Hao (Kenny) Lu and Serhiy Storchaka in
427 :issue:`12892`.
428
Larry Hastings3732ed22014-03-15 21:13:56 -0700429* New German EBCDIC :ref:`codec <standard-encodings>` ``cp273``. (Contributed
430 by Michael Bierenfeld and Andrew Kuchling in :issue:`1097797`.)
R David Murrayc4c7b1c2014-03-07 21:00:34 -0500431
Larry Hastings3732ed22014-03-15 21:13:56 -0700432* New Ukrainian :ref:`codec <standard-encodings>` ``cp1125``. (Contributed by
433 Serhiy Storchaka in :issue:`19668`.)
434
435* :class:`bytes`.join() and :class:`bytearray`.join() now accept arbitrary
436 buffer objects as arguments. (Contributed by Antoine Pitrou in
437 :issue:`15958`.)
438
439* The :class:`int` constructor now accepts any object that has an ``__index__``
440 method for its *base* argument. (Contributed by Mark Dickinson in
441 :issue:`16772`.)
442
443* Frame objects now have a :func:`~frame.clear` method that clears all
444 references to local variables from the frame. (Contributed by Antoine Pitrou
445 in :issue:`17934`.)
446
447* :class:`memoryview` is now registered as a :class:`Sequence <collections.abc>`,
448 and supports the :func:`reversed` builtin. (Contributed by Nick Coghlan
449 and Claudiu Popa in :issue:`18690` and :issue:`19078`.)
450
451* Signatures reported by :func:`help` have been modified and improved in
452 several cases as a result of the introduction of Argument Clinic and other
453 changes to the :mod:`inspect` and :mod:`pydoc` modules.
454
455* :meth:`~object.__length_hint__` is now part of the formal language
456 specification (see :pep:`424`). (Contributed by Armin Ronacher in
457 :issue:`16148`.)
Georg Brandlb80f5112012-09-30 09:11:58 +0200458
R David Murraye6082552014-01-03 16:15:45 -0500459
Georg Brandlb80f5112012-09-30 09:11:58 +0200460New Modules
461===========
462
Nick Coghlan0acceb72013-10-20 13:22:21 +1000463
R David Murray9217dad2013-12-23 21:08:28 -0500464.. _whatsnew-asyncio:
465
Nick Coghlan0acceb72013-10-20 13:22:21 +1000466asyncio
467-------
468
469The new :mod:`asyncio` module (defined in :pep:`3156`) provides a standard
470pluggable event loop model for Python, providing solid asynchronous IO
471support in the standard library, and making it easier for other event loop
472implementations to interoperate with the standard library and each other.
473
474For Python 3.4, this module is considered a :term:`provisional API`.
475
Nick Coghlan367df122013-10-27 01:57:34 +1000476.. seealso::
477
R David Murray061efb12013-12-24 12:35:59 -0500478 :pep:`3156` -- Asynchronous IO Support Rebooted: the "asyncio" Module
Nick Coghlan367df122013-10-27 01:57:34 +1000479 PEP written and implementation led by Guido van Rossum.
480
R David Murray68790662013-12-23 11:17:51 -0500481
R David Murray9217dad2013-12-23 21:08:28 -0500482.. _whatsnew-ensurepip:
R David Murray68790662013-12-23 11:17:51 -0500483
484ensurepip
485---------
486
487The new :mod:`ensurepip` module is the primary infrastructure for the
488:pep:`453` implementation. In the normal course of events end users will not
489need to interact with this module, but it can be used to manually bootstrap
490``pip`` if the automated bootstrapping into an installation or virtual
491environment was declined.
492
493:mod:`ensurepip` includes a bundled copy of ``pip``, up-to-date as of the first
494release candidate of the release of CPython with which it ships (this applies
495to both maintenance releases and feature releases). ``ensurepip`` does not
Larry Hastings3732ed22014-03-15 21:13:56 -0700496access the internet. If the installation has Internet access, after
497``ensurepip`` is run the bundled ``pip`` can be used to upgrade ``pip`` to a
498more recent release than the bundled one. (Note that such an upgraded version
499of ``pip`` is considered to be a separately installed package and will not be
500removed if Python is uninstalled.)
R David Murray68790662013-12-23 11:17:51 -0500501
502The module is named *ensure*\ pip because if called when ``pip`` is already
503installed, it does nothing. It also has an ``--upgrade`` option that will
504cause it to install the bundled copy of ``pip`` if the existing installed
505version of ``pip`` is older than the bundled copy.
506
507
R David Murray9217dad2013-12-23 21:08:28 -0500508.. _whatsnew-enum:
509
Nick Coghlan0acceb72013-10-20 13:22:21 +1000510enum
511----
512
Nick Coghlan367df122013-10-27 01:57:34 +1000513The new :mod:`enum` module (defined in :pep:`435`) provides a standard
514implementation of enumeration types, allowing other modules (such as
515:mod:`socket`) to provide more informative error messages and better
516debugging support by replacing opaque integer constants with backwards
517compatible enumeration values.
518
519.. seealso::
520
R David Murray061efb12013-12-24 12:35:59 -0500521 :pep:`435` -- Adding an Enum type to the Python standard library
Nick Coghlan367df122013-10-27 01:57:34 +1000522 PEP written by Barry Warsaw, Eli Bendersky and Ethan Furman,
523 implemented by Ethan Furman.
Nick Coghlan0acceb72013-10-20 13:22:21 +1000524
525
R David Murray9217dad2013-12-23 21:08:28 -0500526.. _whatsnew-pathlib:
527
Antoine Pitrou31119e42013-11-22 17:38:12 +0100528pathlib
529-------
530
531The new :mod:`pathlib` module offers classes representing filesystem paths
532with semantics appropriate for different operating systems. Path classes are
533divided between *pure paths*, which provide purely computational operations
534without I/O, and *concrete paths*, which inherit from pure paths but also
535provide I/O operations.
536
537For Python 3.4, this module is considered a :term:`provisional API`.
538
539.. seealso::
540
R David Murray061efb12013-12-24 12:35:59 -0500541 :pep:`428` -- The pathlib module -- object-oriented filesystem paths
Antoine Pitrou31119e42013-11-22 17:38:12 +0100542 PEP written and implemented by Antoine Pitrou.
543
544
R David Murrayf9976e72013-12-23 10:32:02 -0500545.. _whatsnew-selectors:
546
Charles-François Natali243d8d82013-09-04 19:02:49 +0200547selectors
548---------
Georg Brandlb80f5112012-09-30 09:11:58 +0200549
Nick Coghlan0acceb72013-10-20 13:22:21 +1000550The new :mod:`selectors` module (created as part of implementing :pep:`3156`)
551allows high-level and efficient I/O multiplexing, built upon the
552:mod:`select` module primitives.
553
554
R David Murray9217dad2013-12-23 21:08:28 -0500555.. _whatsnew-statistics:
556
Nick Coghlan0acceb72013-10-20 13:22:21 +1000557statistics
558----------
559
560The new :mod:`statistics` module (defined in :pep:`450`) offers some core
561statistics functionality directly in the standard library. This module
562supports calculation of the mean, median, mode, variance and standard
563deviation of a data series.
Georg Brandlb80f5112012-09-30 09:11:58 +0200564
Nick Coghlan367df122013-10-27 01:57:34 +1000565.. seealso::
566
R David Murray061efb12013-12-24 12:35:59 -0500567 :pep:`450` -- Adding A Statistics Module To The Standard Library
Nick Coghlan367df122013-10-27 01:57:34 +1000568 PEP written and implemented by Steven D'Aprano
569
R David Murray9217dad2013-12-23 21:08:28 -0500570.. _whatsnew-tracemalloc:
Georg Brandlb80f5112012-09-30 09:11:58 +0200571
R David Murray8b2d6822013-12-31 15:06:05 -0500572
Victor Stinnerd2736af2013-11-25 09:40:27 +0100573tracemalloc
574-----------
575
576The new :mod:`tracemalloc` module (defined in :pep:`454`) is a debug tool to
577trace memory blocks allocated by Python. It provides the following information:
578
Larry Hastings3732ed22014-03-15 21:13:56 -0700579* Trace where an object was allocated
Victor Stinnerd2736af2013-11-25 09:40:27 +0100580* Statistics on allocated memory blocks per filename and per line number:
581 total size, number and average size of allocated memory blocks
582* Compute the differences between two snapshots to detect memory leaks
583
584.. seealso::
585
R David Murray061efb12013-12-24 12:35:59 -0500586 :pep:`454` -- Add a new tracemalloc module to trace Python memory allocations
Victor Stinnerd2736af2013-11-25 09:40:27 +0100587 PEP written and implemented by Victor Stinner
588
589
R David Murraye6082552014-01-03 16:15:45 -0500590
Georg Brandlb80f5112012-09-30 09:11:58 +0200591Improved Modules
592================
593
R David Murray6e390152013-12-24 22:28:04 -0500594
R David Murray3edcc782013-12-24 16:13:32 -0500595abc
596---
597
598New function :func:`abc.get_cache_token` can be used to know when to invalidate
599caches that are affected by changes in the object graph. (Contributed
600by Łukasz Langa in :issue:`16832`.)
R David Murray72420ff2013-12-24 10:46:44 -0500601
R David Murray2691ee62013-12-28 23:15:12 -0500602New class :class:`~abc.ABC` has :class:`~abc.ABCMeta` as its meta class.
603Using ``ABC`` as a base class has essentially the same effect as specifying
604``metaclass=abc.ABCMeta``, but is simpler to type and easier to read.
605(Contributed by Bruno Dupuis in :issue:`16049`.)
606
607
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200608aifc
609----
610
Larry Hastings3732ed22014-03-15 21:13:56 -0700611The :meth:`~aifc.aifc.getparams` method now returns a namedtuple rather than a
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200612plain tuple. (Contributed by Claudiu Popa in :issue:`17818`.)
613
R David Murrayd592bb22013-12-31 13:45:38 -0500614:func:`aifc.open` now supports the context manager protocol: when used in a
615:keyword:`with` block, the :meth:`~aifc.aifc.close` method of the returned
616object will be called automatically at the end of the block. (Contributed by
617Serhiy Storchacha in :issue:`16486`.)
618
Larry Hastings3732ed22014-03-15 21:13:56 -0700619The :meth:`~aifc.aifc.writeframesraw` and :meth:`~aifc.aifc.writeframes`
620methods now accept any :term:`bytes-like object`. (Contributed by Serhiy
621Storchaka in :issue:`8311`.)
622
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200623
R David Murrayfced3ec2013-12-31 11:18:01 -0500624argparse
625--------
626
627The :class:`~argparse.FileType` class now accepts *encoding* and
628*errors* arguments, which are passed through to :func:`open`. (Contributed
629by Lucas Maystre in :issue:`11175`.)
630
631
Serhiy Storchakaeaea5e92013-10-19 21:10:46 +0300632audioop
633-------
634
Larry Hastings3732ed22014-03-15 21:13:56 -0700635:mod:`audioop` now supports 24-bit samples. (Contributed by Serhiy Storchaka
636in :issue:`12866`.)
Serhiy Storchakaeaea5e92013-10-19 21:10:46 +0300637
Larry Hastings3732ed22014-03-15 21:13:56 -0700638New :func:`~audioop.byteswap` function converts big-endian samples to
639little-endian and vice versa (Contributed by Serhiy Storchaka in
640:issue:`19641`).
641
642All :mod:`audioop` functions now accept any :term:`bytes-like object`. Strings
643are not accepted: they didn't work before, now they raise an error right away.
644(Contributed by Serhiy Storchaka in :issue:`16685`.)
Serhiy Storchaka3062c9a2013-11-23 22:26:01 +0200645
Serhiy Storchakaeaea5e92013-10-19 21:10:46 +0300646
Nick Coghland4fdbcc2013-11-14 00:24:31 +1000647base64
648------
649
650The encoding and decoding functions in :mod:`base64` now accept any
651:term:`bytes-like object` in cases where it previously required a
Larry Hastings3732ed22014-03-15 21:13:56 -0700652:class:`bytes` or :class:`bytearray` instance. (Contributed by Nick Coghlan in
653:issue:`17839`.)
654
655New functions :func:`~base64.a85encode`, :func:`~base64.a85decode`,
656:func:`~base64.b85encode`, and :func:`~base64.b85decode` provide the ability to
657encode and decode binary data from and to ``Ascii85`` and the git/mercurial
658``Base85`` formats, respectively. The ``a85`` functions have options that can
659be used to make them compatible with the variants of the ``Ascii85`` encoding,
660including the Adobe variant. (Contributed by Martin Morrison, the Mercurial
661project, Serhiy Storchaka, and Antoine Pitrou in :issue:`17618`.)
662
663
664collections
665-----------
666
667The :meth:`.ChainMap.new_child` method now accepts an *m* argument specifying
668the child map to add to the chain. This allows an existing mapping and/or a
669custom mapping type to be used for the child. (Contributed by Vinay Sajip in
670:issue:`16613`.)
Nick Coghland4fdbcc2013-11-14 00:24:31 +1000671
672
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200673colorsys
674--------
675
676The number of digits in the coefficients for the RGB --- YIQ conversions have
677been expanded so that they match the FCC NTSC versions. The change in
678results should be less than 1% and may better match results found elsewhere.
R David Murray45e732d2014-02-03 01:33:39 -0500679(Contributed by Brian Landers and Serhiy Storchaka in :issue:`14323`.)
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200680
R David Murray8e37d5d2013-04-13 14:49:48 -0400681
Nick Coghlanb4534ae2013-10-13 23:23:08 +1000682contextlib
683----------
684
Nick Coghlan240f86d2013-10-17 23:40:57 +1000685The new :class:`contextlib.suppress` context manager helps to clarify the
686intent of code that deliberately suppresses exceptions from a single
687statement. (Contributed by Raymond Hettinger in :issue:`15806` and
688Zero Piraeus in :issue:`19266`)
689
Victor Stinner6633c392013-10-21 13:27:11 +0200690The new :func:`contextlib.redirect_stdout` context manager makes it easier
Larry Hastings3732ed22014-03-15 21:13:56 -0700691for utility scripts to handle inflexible APIs that write their output to
692:data:`sys.stdout` and don't provide any options to redirect it. Using the
693context manager, the :data:`sys.stdout` output can be redirected to any
694other stream or, in conjunction with :class:`io.StringIO`, to a string.
695The latter can be especially useful, for example, to capture output
696from a function that was written to implement a command line interface.
697It is recommended only for utility scripts because it affects the
698global state of :data:`sys.stdout`. (Contributed by Raymond Hettinger
699in :issue:`15805`)
Nick Coghlan0acceb72013-10-20 13:22:21 +1000700
701The :mod:`contextlib` documentation has also been updated to include a
702:ref:`discussion <single-use-reusable-and-reentrant-cms>` of the
703differences between single use, reusable and reentrant context managers.
Nick Coghlanb4534ae2013-10-13 23:23:08 +1000704
705
Larry Hastings3732ed22014-03-15 21:13:56 -0700706dbm
707---
708
709:func:`dbm.open` objects now support the context management protocol. When
710used in a :keyword:`with` statement, the ``close`` method of the database
711object will be called automatically at the end of the block. (Contributed by
712Claudiu Popa and Nick Coghlan in :issue:`19282`.)
713
714
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000715dis
716---
717
R David Murray0bce6e72014-01-07 14:30:17 -0500718Functions :func:`~dis.show_code`, :func:`~dis.dis`, :func:`~dis.distb`, and
719:func:`~dis.disassemble` now accept a keyword-only *file* argument that
720controls where they write their output.
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000721
R David Murray0bce6e72014-01-07 14:30:17 -0500722The :mod:`dis` module is now built around an :class:`~dis.Instruction` class
723that provides object oriented access to the details of each individual bytecode
724operation.
725
726A new method, :func:`~dis.get_instructions`, provides an iterator that emits
727the Instruction stream for a given piece of Python code. Thus it is now
728possible to write a program that inspects and manipulates a bytecode
729object in ways different from those provided by the :mod:`~dis` module
730itself. For example::
731
732 >>> import dis
733 >>> for instr in dis.get_instructions(lambda x: x + 1):
734 ... print(instr.opname)
735 LOAD_FAST
736 LOAD_CONST
737 BINARY_ADD
738 RETURN_VALUE
739
740The various display tools in the :mod:`dis` module have been rewritten to use
741these new components.
742
743In addition, a new application-friendly class :class:`~dis.Bytecode` provides
744an object-oriented API for inspecting bytecode in both in human-readable form
745and for iterating over instructions. The :class:`~dis.Bytecode` constructor
746takes the same arguments that :func:`~dis.get_instruction` does (plus an
747optional *current_offset*), and the resulting object can be iterated to produce
748:class:`~dis.Instruction` objects. But it also has a :mod:`~dis.Bytecode.dis`
749method, equivalent to calling :mod:`~dis.dis` on the constructor argument, but
750returned as a multi-line string::
751
752 >>> bytecode = dis.Bytecode(lambda x: x +1, current_offset=3)
753 >>> for instr in bytecode:
754 ... print('{} ({})'.format(instr.opname, instr.opcode))
755 LOAD_FAST (124)
756 LOAD_CONST (100)
757 BINARY_ADD (23)
758 RETURN_VALUE (83)
759 >>> bytecode.dis().splitlines() # doctest: +NORMALIZE_WHITESPACE
760 [' 1 0 LOAD_FAST 0 (x)',
761 ' --> 3 LOAD_CONST 1 (1)',
762 ' 6 BINARY_ADD',
763 ' 7 RETURN_VALUE']
764
765:class:`~dis.Bytecode` also has a class method,
766:meth:`~dis.Bytecode.from_traceback`, that provides the ability to manipulate a
767traceback (that is, ``print(Bytecode.from_traceback(tb).dis())`` is equivalent
768to ``distb(tb)``).
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000769
Nick Coghlan50c48b82013-11-23 00:57:00 +1000770(Contributed by Nick Coghlan, Ryan Kelly and Thomas Kluyver in :issue:`11816`
771and Claudiu Popa in :issue:`17916`)
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000772
Larry Hastings3732ed22014-03-15 21:13:56 -0700773New function :func:`~dis.stack_effect` computes the effect on the Python stack
774of a given opcode and argument, information that is not otherwise available.
775(Contributed by Larry Hastings in :issue:`19722`.)
776
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200777
R David Murray5a9d7062012-11-21 15:09:21 -0500778doctest
779-------
780
R David Murray473f45b2013-12-27 17:01:16 -0500781A new :ref:`option flag <doctest-options>`, :data:`~doctest.FAIL_FAST`, halts
782test running as soon as the first failure is detected. (Contributed by R.
783David Murray and Daniel Urban in :issue:`16522`.)
R David Murray5707d502013-06-23 14:24:13 -0400784
R David Murray473f45b2013-12-27 17:01:16 -0500785The :mod:`doctest` command line interface now uses :mod:`argparse`, and has two
786new options, ``-o`` and ``-f``. ``-o`` allows :ref:`doctest options
787<doctest-options>` to be specified on the command line, and ``-f`` is a
788shorthand for ``-o FAIL_FAST`` (to parallel the similar option supported by the
789:mod:`unittest` CLI). (Contributed by R. David Murray in :issue:`11390`.)
Georg Brandlb80f5112012-09-30 09:11:58 +0200790
Larry Hastings3732ed22014-03-15 21:13:56 -0700791:mod:`doctest` will now find doctests in extension module ``__doc__`` strings.
792(Contributed by Zachary Ware in :issue:`3158`.)
793
R David Murray8e37d5d2013-04-13 14:49:48 -0400794
R David Murraybb17d2b2013-08-09 16:15:28 -0400795email
796-----
797
798:meth:`~email.message.Message.as_string` now accepts a *policy* argument to
799override the default policy of the message when generating a string
800representation of it. This means that ``as_string`` can now be used in more
801circumstances, instead of having to create and use a :mod:`~email.generator` in
Larry Hastings3732ed22014-03-15 21:13:56 -0700802order to pass formatting parameters to its ``flatten`` method. (Contributed by
803R. David Murray in :issue:`18600`.)
R David Murraybb17d2b2013-08-09 16:15:28 -0400804
805New method :meth:`~email.message.Message.as_bytes` added to produce a bytes
806representation of the message in a fashion similar to how ``as_string``
807produces a string representation. It does not accept the *maxheaderlen*
808argument, but does accept the *unixfrom* and *policy* arguments. The
809:class:`~email.message.Message` :meth:`~email.message.Message.__bytes__` method
810calls it, meaning that ``bytes(mymsg)`` will now produce the intuitive
Larry Hastings3732ed22014-03-15 21:13:56 -0700811result: a bytes object containing the fully formatted message. (Contributed
812by R. David Murray in :issue:`18600`.)
R David Murraybb17d2b2013-08-09 16:15:28 -0400813
Larry Hastings3732ed22014-03-15 21:13:56 -0700814The :meth:`.Message.set_param` message now accepts a *replace* keyword argument.
815When specified, the associated header will be updated without changing
816its location in the list of headers. For backward compatibility, the default
817is ``False``. (Contributed by R. David Murray in :issue:`18891`.)
818
R David Murraybb17d2b2013-08-09 16:15:28 -0400819
R David Murray26b80cfd2013-12-20 17:26:52 -0500820.. _whatsnew_email_contentmanager:
821
Larry Hastings3732ed22014-03-15 21:13:56 -0700822A pair of new subclasses of :class:`~email.message.Message` have been added
823(:class:`.EmailMessage` and :class:`.MIMEPart`), along with a new sub-module,
824:mod:`~email.contentmanager` and a new :mod:`~email.policy` attribute
825:attr:`~email.policy.EmailPolicy.content_manager`. All documentation is
826currently in the new module, which is being added as part of email's new
827:term:`provisional API`. These classes provide a number of new methods that
828make extracting content from and inserting content into email messages much
829easier. For details, see the :mod:`~email.contentmanager` documentation and
830the :ref:`email-contentmanager-api-examples`. These API additions complete the
831bulk of the work that was planned as part of the email6 project. The currently
832provisional API is scheduled to become final in Python 3.5 (possibly with a few
833minor additions in the area of error handling). (Contributed by R. David
834Murray in :issue:`18891`.)
R David Murray3da240f2013-10-16 22:48:40 -0400835
R David Murraybb17d2b2013-08-09 16:15:28 -0400836
R David Murray4885f492014-02-02 11:11:01 -0500837filecmp
838-------
839
840A new :func:`~filecmp.clear_cache` function provides the ability to clear the
841:mod:`filecmp` comparison cache, which uses :func:`os.stat` information to
842determine if the file has changed since the last compare. This can be used,
843for example, if the file might have been changed and re-checked in less time
844than the resolution of a particular filesystem's file modification time field.
845(Contributed by Mark Levitt in :issue:`18149`.)
846
Larry Hastings3732ed22014-03-15 21:13:56 -0700847New module attribute :data:`~filecmp.DEFAULT_IGNORES` provides the list of
848directories that are used as the default value for the *ignore* parameter of
849the :func:`~filecmp.dircmp` function. (Contributed by Eli Bendersky in
850:issue:`15442`.)
851
R David Murray4885f492014-02-02 11:11:01 -0500852
Victor Stinner854ffcb2013-06-21 00:36:30 +0200853functools
854---------
855
Andrew Kuchlingfe0f0b02014-01-31 12:17:53 -0500856The new :func:`~functools.partialmethod` descriptor brings partial argument
Nick Coghlanf4cb48a2013-11-03 16:41:46 +1000857application to descriptors, just as :func:`~functools.partial` provides
858for normal callables. The new descriptor also makes it easier to get
859arbitrary callables (including :func:`~functools.partial` instances)
860to behave like normal instance methods when included in a class definition.
Nick Coghlanf4cb48a2013-11-03 16:41:46 +1000861(Contributed by Alon Horev and Nick Coghlan in :issue:`4331`)
862
R David Murray0a102162013-12-20 15:00:54 -0500863.. _whatsnew-singledispatch:
864
Nick Coghlanf4cb48a2013-11-03 16:41:46 +1000865The new :func:`~functools.singledispatch` decorator brings support for
866single-dispatch generic functions to the Python standard library. Where
867object oriented programming focuses on grouping multiple operations on a
868common set of data into a class, a generic function focuses on grouping
869multiple implementations of an operation that allows it to work with
870*different* kinds of data.
871
872.. seealso::
873
R David Murray061efb12013-12-24 12:35:59 -0500874 :pep:`443` -- Single-dispatch generic functions
Nick Coghlanf4cb48a2013-11-03 16:41:46 +1000875 PEP written and implemented by Łukasz Langa.
Victor Stinner854ffcb2013-06-21 00:36:30 +0200876
Larry Hastings3732ed22014-03-15 21:13:56 -0700877:func:`~functools.total_ordering` now supports a return value of
878:const:`NotImplemented` from the underlying comparison function. (Contributed
879by Katie Miller in :issue:`10042`.)
880
R David Murrayd2653812013-12-27 14:06:15 -0500881A pure-python version of the :func:`~functools.partial` function is now in the
882stdlib; in CPython it is overridden by the C accelerated version, but it is
883available for other implementations to use. (Contributed by Brian Thorne in
884:issue:`12428`.)
885
Nick Coghlane8c45d62013-07-28 20:00:01 +1000886
R David Murray0e814632013-12-26 15:11:28 -0500887gc
888--
889
R David Murraya101bdb2014-01-06 16:32:05 -0500890New function :func:`~gc.get_stats` returns a list of three per-generation
891dictionaries containing the collections statistics since interpreter startup.
892(Contributed by Antoine Pitrou in :issue:`16351`.)
R David Murray0e814632013-12-26 15:11:28 -0500893
894
Larry Hastings3732ed22014-03-15 21:13:56 -0700895glob
896----
897
898A new function :func:`~glob.escape` provides a way to escape special characters
899in a filename so that they do not become part of the globbing expansion but are
900instead matched literally. (Contributed by Serhiy Storchaka in :issue:`8402`.)
901
902
Christian Heimese92ef132013-10-13 00:52:43 +0200903hashlib
904-------
905
Larry Hastings3732ed22014-03-15 21:13:56 -0700906A new :func:`hashlib.pbkdf2_hmac` function provides
907the `PKCS#5 password-based key derivation function 2
908<http://en.wikipedia.org/wiki/PBKDF2>`_. (Contributed by Christian
909Heimes in :issue:`18582`)
910
911The :attr:`~hashlib.hash.name` attribute of :mod:`hashlib` hash objects is now
912a formally supported interface. It has always existed in CPython's
913:mod:`hashlib` (although it did not return lower case names for all supported
914hashes), but it was not a public interface and so some other Python
915implementations have not previously supported it. (Contributed by Jason R.
916Coombs in :issue:`18532`.)
Christian Heimese92ef132013-10-13 00:52:43 +0200917
918
R David Murraya56d4e82014-02-02 12:50:48 -0500919hmac
920----
921
922:mod:`hmac` now accepts ``bytearray`` as well as ``bytes`` for the *key*
923argument to the :func:`~hmac.new` function, and the *msg* parameter to both the
924:func:`~hmac.new` function and the :meth:`~hmac.HMAC.update` method now
925accepts any type supported by the :mod:`hashlib` module. (Contributed
926by Jonas Borgström in :issue:`18240`.)
927
Larry Hastings3732ed22014-03-15 21:13:56 -0700928The *digestmod* argument to the :func:`hmac.new` function may now be any hash
929digest name recognized by :mod:`hashlib`. In addition, the current behavior in
930which the value of *digestmod* defaults to ``MD5`` is deprecated: in a
931future version of Python there will be no default value. (Contributed by
932Christian Heimes in :issue:`17276`.)
933
934With the addition of :attr:`~hmac.HMAC.block_size` and :attr:`~hmac.HMAC.name`
935attributes (and the formal documentation of the :attr:`~hmac.HMAC.digest_size`
936attribute), the :mod:`hmac` module now conforms fully to the :pep:`247` API.
937(Contributed by Christian Heimes in :issue:`18775`.)
938
R David Murraya56d4e82014-02-02 12:50:48 -0500939
Ezio Melotti250a06c2013-11-25 06:18:47 +0200940html
941----
942
Larry Hastings3732ed22014-03-15 21:13:56 -0700943New function :func:`~html.unescape` function converts HTML5 character references to
944the corresponding Unicode characters. (Contributed by Ezio Melotti in
945:issue:`2927`)
Ezio Melotti250a06c2013-11-25 06:18:47 +0200946
Larry Hastings3732ed22014-03-15 21:13:56 -0700947:class:`~html.parser.HTMLParser` accepts a new keyword argument
948*convert_charrefs* that, when ``True``, automatically converts all character
949references. For backward-compatibility, its value defaults to ``False``, but
950it will change to ``True`` in a future version of Python, so you are invited to
951set it explicitly and update your code to use this new feature. (Contributed
952by Ezio Melotti in :issue:`13633`)
Ezio Melotti250a06c2013-11-25 06:18:47 +0200953
954The *strict* argument of :class:`~html.parser.HTMLParser` is now deprecated.
Ezio Melotti250a06c2013-11-25 06:18:47 +0200955(Contributed by Ezio Melotti in :issue:`15114`)
956
957
R David Murraya475a8d2014-01-03 13:03:00 -0500958http
959----
960
961:meth:`~http.server.BaseHTTPRequestHandler.send_error` now accepts an
Zachary Ware335957e2014-01-13 16:08:54 -0600962optional additional *explain* parameter which can be used to provide an
R David Murraya475a8d2014-01-03 13:03:00 -0500963extended error description, overriding the hardcoded default if there is one.
964This extended error description will be formatted using the
965:attr:`~http.server.HTTP.error_message_format` attribute and sent as the body
966of the error response. (Contributed by Karl Cow in :issue:`12921`.)
967
Larry Hastings3732ed22014-03-15 21:13:56 -0700968The :mod:`http.server` :ref:`command line interface <http-server-cli>` now has
969a ``-b/--bind`` option that causes the server to listen on a specific address.
970(Contributed by Malte Swart in :issue:`17764`.)
971
R David Murraya475a8d2014-01-03 13:03:00 -0500972
R David Murrayd2653812013-12-27 14:06:15 -0500973importlib
974---------
975
976The :class:`~importlib.abc.InspectLoader` ABC defines a new method,
977:meth:`~importlib.abc.InspectLoader.source_to_code` that accepts source
978data and a path and returns a code object. The default implementation
979is equivalent to ``compile(data, path, 'exec', dont_inherit=True)``.
980(Contributed by Eric Snow and Brett Cannon in :issue:`15627`.)
981
R David Murray0ae7ae12014-01-08 18:16:02 -0500982:class:`~importlib.abc.InspectLoader` also now has a default implementation
983for the :meth:`~importlib.abc.InspectLoader.get_code` method. However,
984it will normally be desirable to override the default implementation
985for performance reasons. (Contributed by Brett Cannon in :issue:`18072`.)
986
R David Murray70e04f52014-02-02 10:50:17 -0500987The :func:`~importlib.reload` function has been moved from :mod:`imp` to
988:mod:`importlib` as part of the :mod:`imp` module deprecation. (Contributed by
989Berker Peksag in :issue:`18193`.)
R David Murray8c561b52014-02-01 12:27:07 -0500990
R David Murray900aeb72014-02-02 11:32:31 -0500991:mod:`importlib.util` now has a :data:`~importlib.util.MAGIC_NUMBER` attribute
992providing access to the bytecode version number. This replaces the
993:func:`~imp.get_magic` function in the deprecated :mod:`imp` module.
994(Contributed by Brett Cannon in :issue:`18192`.)
995
996New :mod:`importlib.util` functions :func:`~importlib.util.cache_from_source`
997and :func:`~importlib.util.source_from_cache` replace the same-named functions
998in the deprecated :mod:`imp` module. (Contributed by Brett Cannon in
999:issue:`18194`.)
1000
R David Murray5147e002014-02-02 12:19:57 -05001001The :mod:`importlib` bootstrap :class:`.NamespaceLoader` now conforms to
1002the :class:`.InspectLoader` ABC, which means that ``runpy`` and
1003``python -m`` can now be used with namespace packages. (Contributed
1004by Brett Cannon in :issue:`18058`.)
1005
R David Murraya56d4e82014-02-02 12:50:48 -05001006:mod:`importlib.util` has a new function :func:`~importlib.util.decode_source`
1007that decodes source from bytes using universal newline processing. This is
1008useful for implementing :meth:`.InspectLoader.get_source` methods.
1009
Larry Hastings3732ed22014-03-15 21:13:56 -07001010:class:`importlib.machinery.ExtensionFileLoader` now has a
1011:meth:`~importlib.machinery.ExtensionFileLoader.get_filename` method. This was
1012inadvertently omitted in the original implementation. (Contributed by Eric
1013Snow in :issue:`19152`.)
1014
R David Murrayd2653812013-12-27 14:06:15 -05001015
Antoine Pitroud6cbd342013-08-12 20:48:15 +02001016inspect
1017-------
1018
Larry Hastings3732ed22014-03-15 21:13:56 -07001019The :mod:`inspect` module now offers a basic :ref:`command line interface
Nick Coghlan367df122013-10-27 01:57:34 +10001020<inspect-module-cli>` to quickly display source code and other
1021information for modules, classes and functions. (Contributed by Claudiu Popa
1022and Nick Coghlan in :issue:`18626`)
Nick Coghlanf94a16b2013-09-22 22:46:49 +10001023
Antoine Pitroud6cbd342013-08-12 20:48:15 +02001024:func:`~inspect.unwrap` makes it easy to unravel wrapper function chains
1025created by :func:`functools.wraps` (and any other API that sets the
Nick Coghlan367df122013-10-27 01:57:34 +10001026``__wrapped__`` attribute on a wrapper function). (Contributed by
1027Daniel Urban, Aaron Iles and Nick Coghlan in :issue:`13266`)
1028
1029As part of the implementation of the new :mod:`enum` module, the
1030:mod:`inspect` module now has substantially better support for custom
1031``__dir__`` methods and dynamic class attributes provided through
1032metaclasses (Contributed by Ethan Furman in :issue:`18929` and
1033:issue:`19030`)
1034
Yury Selivanovd82eddc2014-01-29 11:24:39 -05001035:func:`~inspect.getfullargspec` and :func:`~inspect.getargspec`
1036now use the :func:`~inspect.signature` API. This allows them to
Larry Hastings3732ed22014-03-15 21:13:56 -07001037support a much broader range of callables, including those with
1038``__signature__`` attributes, those with metadata provided by argument
1039clinic, :func:`functools.partial` objects and more. Note that, unlike
1040:func:`~inspect.signature`, these functions still ignore ``__wrapped__``
1041attributes, and report the already bound first argument for bound methods,
1042so it is still necessary to update your code to use
1043:func:`~inspect.signature` directly if those features are desired.
1044(Contributed by Yury Selivanov in :issue:`17481`)
Yury Selivanovd82eddc2014-01-29 11:24:39 -05001045
Yury Selivanov63da7c72014-01-31 14:48:37 -05001046:func:`~inspect.signature` now supports duck types of CPython functions,
1047which adds support for functions compiled with Cython. (Contributed
1048by Stefan Behnel and Yury Selivanov in :issue:`17159`)
1049
Antoine Pitroud6cbd342013-08-12 20:48:15 +02001050
Nick Coghlan96bb4372014-02-09 09:18:26 +10001051ipaddress
1052---------
1053
1054:mod:`ipaddress` was added to the standard library in Python 3.3 as a
1055:term:`provisional API`. With the release of Python 3.4, this qualification
1056has been removed: :mod:`ipaddress` is now considered a stable API, covered
1057by the normal standard library requirements to maintain backwards
1058compatibility.
1059
Larry Hastings3732ed22014-03-15 21:13:56 -07001060A new :attr:`~ipaddress.IPv4Address.is_global` property is ``True`` if
1061an address is globally routeable. (Contributed by Peter Moody in
1062:issue:`17400`.)
1063
Nick Coghlan96bb4372014-02-09 09:18:26 +10001064
R David Murray9cf617b2014-01-04 18:55:01 -05001065logging
1066-------
1067
1068The :class:`~logging.handlers.TimedRotatingFileHandler` has a new *atTime*
1069parameter that can be used to specify the time of day when rollover should
1070happen. (Contributed by Ronald Oussoren in :issue:`9556`.)
1071
Larry Hastings3732ed22014-03-15 21:13:56 -07001072:class:`~logging.handlers.SocketHandler` and
1073:class:`~logging.handlers.DatagramHandler` now support Unix domain sockets (by
1074setting *port* to ``None``). (Contributed by Vinay Sajip in commit
1075ce46195b56a9.)
1076
1077:func:`~logging.config.fileConfig` now accepts a
1078:class:`configparser.RawConfigParser` subclass instance for the *fname*
1079parameter. This facilitates using a configuration file when logging
1080configuration is just a part of the overall application configuration, or where
1081the application modifies the configuration before passing it to
1082:func:`~logging.config.fileConfig`. (Contributed by Vinay Sajip in
1083:issue:`16110`.)
1084
1085Logging configuration data received from a socket via the
1086:func:`logging.config.listen` function can now be validated before being
1087processed by supplying a verification function as the argument to the new
1088*verify* keyword argument. (Contributed by Vinay Sajip in :issue:`15452`.)
1089
R David Murray9cf617b2014-01-04 18:55:01 -05001090
R David Murray8f7664a2013-12-22 20:40:11 -05001091.. _whatsnew-marshal-3:
1092
1093marshal
1094-------
1095
1096The default :mod:`marshal` version has been bumped to 3. The code implementing
1097the new version restores the Python2 behavior of recording only one copy of
1098interned strings and preserving the interning on deserialization, and extends
1099this "one copy" ability to any object type (including handling recursive
1100references). This reduces both the size of ``.pyc`` files and the amount of
1101memory a module occupies in memory when it is loaded from a ``.pyc`` (or
Larry Hastings3732ed22014-03-15 21:13:56 -07001102``.pyo``) file. (Contributed by Kristján Valur Jónsson in :issue:`16475`,
1103with additional speedups by Antoine Pitrou in :issue:`19219`.)
R David Murray8f7664a2013-12-22 20:40:11 -05001104
1105
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001106mmap
1107----
1108
Larry Hastings3732ed22014-03-15 21:13:56 -07001109mmap objects can now be :mod:`weakref`\ ed. (Contributed by Valerie Lambert in
1110:issue:`4885`.)
R David Murray57fcf762014-01-03 23:31:54 -05001111
R David Murray33ef1ae2013-12-31 16:04:50 -05001112
Richard Oudkerk84ed9a62013-08-14 15:35:41 +01001113multiprocessing
1114---------------
1115
R David Murrayac186222013-12-20 17:23:57 -05001116.. _whatsnew-multiprocessing-no-fork:
1117
Larry Hastings3732ed22014-03-15 21:13:56 -07001118On Unix two new :ref:`start methods <multiprocessing-start-methods>`,
1119(``spawn`` and ``forkserver``, have been added for starting processes using
R David Murrayac186222013-12-20 17:23:57 -05001120:mod:`multiprocessing`. These make the mixing of processes with threads more
1121robust, and the ``spawn`` method matches the semantics that multiprocessing has
Larry Hastings3732ed22014-03-15 21:13:56 -07001122always used on Windows. New function
1123:func:`~multiprocessing.get_all_start_methods` reports all start methods
1124available on the platform, :func:`~multiprocessing.get_start_method` reports
1125the current start method, and :func:`~multiprocessing.set_start_method` sets
1126the start method. (Contributed by Richard Oudkerk in :issue:`8713`).
Richard Oudkerk84ed9a62013-08-14 15:35:41 +01001127
Larry Hastings3732ed22014-03-15 21:13:56 -07001128:mod:`multiprocessing` also now has the concept of a ``context``, which
1129determines how child processes are created. New function
1130:func:`~multiprocessing.get_context` returns a context that uses a specified
1131start method. It has the same API as the :mod:`multiprocessing` module itself,
1132so you can use it to create :class:`~multiprocessing.pool.Pool`\ s and other
1133objects that will operate within that context. This allows a framework and an
1134application or different parts of the same application to use multiprocessing
1135without interfering with each other. (Contributed by Richard Oudkerk in
1136:issue:`18999`.)
1137
1138Except when using the old *fork* start method, child processes no longer
1139inherit unneeded handles/file descriptors from their parents (part of
1140:issue:`8713`).
Richard Oudkerk84ed9a62013-08-14 15:35:41 +01001141
Nick Coghlan9a767352013-12-17 22:17:26 +10001142:mod:`multiprocessing` now relies on :mod:`runpy` (which implements the
1143``-m`` switch) to initialise ``__main__`` appropriately in child processes
1144when using the ``spawn`` or ``forkserver`` start methods. This resolves some
Larry Hastings3732ed22014-03-15 21:13:56 -07001145edge cases where combining multiprocessing, the ``-m`` command line switch,
Nick Coghlan9a767352013-12-17 22:17:26 +10001146and explicit relative imports could cause obscure failures in child
1147processes. (Contributed by Nick Coghlan in :issue:`19946`)
1148
Richard Oudkerk84ed9a62013-08-14 15:35:41 +01001149
R David Murray98358272014-01-05 20:52:06 -05001150operator
1151--------
1152
Larry Hastings3732ed22014-03-15 21:13:56 -07001153New function :func:`~operator.length_hint` provides an implementation of the
1154specification for how the :meth:`~object.__length_hint__` special method should
1155be used, as part of the :pep:`424` formal specification of this language
1156feature. (Contributed by Armin Ronacher in :issue:`16148`.)
1157
R David Murray98358272014-01-05 20:52:06 -05001158There is now a pure-python version of the :mod:`operator` module available for
1159reference and for use by alternate implementations of Python. (Contributed by
1160Zachary Ware in :issue:`16694`.)
1161
1162
Victor Stinnerdaf45552013-08-28 00:53:59 +02001163os
1164--
1165
Larry Hastings3732ed22014-03-15 21:13:56 -07001166There are new functions to get and set the :ref:`inheritable flag
1167<fd_inheritance>` of a file descriptor (:func:`os.get_inheritable`,
1168:func:`os.set_inheritable`) or a Windows handle
1169(:func:`os.get_handle_inheritable`, :func:`os.set_handle_inheritable`).
Victor Stinnerdaf45552013-08-28 00:53:59 +02001170
Larry Hastings3732ed22014-03-15 21:13:56 -07001171New function :func:`~os.cpu_count` reports the number of CPUs available on the
1172platform on which Python is running (or ``None`` if the count can't be
1173determined). The :func:`multiprocessing.cpu_count` function is now implemented
1174in terms of this function). (Contributed by Trent Nelson, Yogesh Chaudhari,
1175Victor Stinner, and Charles-François Natali in :issue:`17914`.)
Victor Stinnerdaf45552013-08-28 00:53:59 +02001176
Larry Hastings3732ed22014-03-15 21:13:56 -07001177:func:`os.path.samestat` is now available on the Windows platform (and the
1178:func:`os.path.samefile` implementation is now shared between Unix and
1179Windows). (Contributed by Brian Curtin in :issue:`11939`.)
1180
1181:func:`os.path.ismount` now recognizes volumes mounted below a drive
1182root on Windows. (Contributed by Tim Golden in :issue:`9035`.)
1183
1184:func:`os.open` supports two new flags on platforms that provide them,
1185:data:`~os.O_PATH` (un-opened file descriptor), and :data:`~os.O_TMPFILE`
1186(unnamed temporary file; as of 3.4.0 release available only on Linux systems
1187with a kernel version of 3.11 or newer that have uapi headers). (Contributed
1188by Christian Heimes in :issue:`18673` and Benjamin Peterson, respectively.)
R David Murray66bf12a2014-01-08 17:21:22 -05001189
Victor Stinnerdaf45552013-08-28 00:53:59 +02001190
R David Murray78d692f2013-10-10 17:23:26 -04001191pdb
1192---
1193
Larry Hastings3732ed22014-03-15 21:13:56 -07001194:mod:`pdb` has been enhanced to handle generators, :keyword:`yield`, and
1195``yield from`` in a more useful fashion. This is especially helpful when
1196debugging :mod:`asyncio` based programs. (Contributed by Andrew Svetlov and
1197Xavier de Gaye in :issue:`16596`.)
1198
R David Murray78d692f2013-10-10 17:23:26 -04001199The ``print`` command has been removed from :mod:`pdb`, restoring access to the
Larry Hastings3732ed22014-03-15 21:13:56 -07001200Python :func:`print` function from the pdb command line. Python2's ``pdb`` did
1201not have a ``print`` command; instead, entering ``print`` executed the
1202``print`` statement. In Python3 ``print`` was mistakenly made an alias for the
1203pdb :pdbcmd:`p` command. ``p``, however, prints the ``repr`` of its argument,
1204not the ``str`` like the Python2 ``print`` command did. Worse, the Python3
1205``pdb print`` command shadowed the Python3 ``print`` function, making it
1206inaccessible at the ``pdb`` prompt. (Contributed by Connor Osborn in
1207:issue:`18764`.)
R David Murray78d692f2013-10-10 17:23:26 -04001208
1209
R David Murray809487e2013-12-22 20:49:40 -05001210.. _whatsnew-protocol-4:
1211
R David Murray5ea95242013-12-24 15:59:57 -05001212pickle
R David Murray809487e2013-12-22 20:49:40 -05001213------
1214
R David Murray809487e2013-12-22 20:49:40 -05001215:mod:`pickle` now supports (but does not use by default) a new pickle protocol,
1216protocol 4. This new protocol addresses a number of issues that were present
1217in previous protocols, such as the serialization of nested classes, very large
Larry Hastings3732ed22014-03-15 21:13:56 -07001218strings and containers, and classes whose :meth:`__new__` method takes
R David Murray809487e2013-12-22 20:49:40 -05001219keyword-only arguments. It also provides some efficiency improvements.
1220
1221.. seealso::
1222
R David Murray061efb12013-12-24 12:35:59 -05001223 :pep:`3154` -- Pickle protocol 4
R David Murray809487e2013-12-22 20:49:40 -05001224 PEP written by Antoine Pitrou and implemented by Alexandre Vassalotti.
1225
1226
Nick Coghlanaa029da2014-02-09 10:10:24 +10001227plistlib
1228--------
1229
Larry Hastings3732ed22014-03-15 21:13:56 -07001230:mod:`plistlib` now has an API that is similar to the standard pattern for
1231stdlib serialization protocols, with new :func:`~plistlib.load`,
1232:func:`~plistlib.dump`, :func:`~plistlib.loads`, and :func:`~plistlib.dumps`
1233functions. (The older API is now deprecated.) In addition to the already
1234supported XML plist format (:data:`~plistlib.FMT_XML`), it also now supports
1235the binary plist format (:data:`~plistlib.FMT_BINARY`). (Contributed by Ronald
1236Oussoren and others in :issue:`14455`).
Nick Coghlanaa029da2014-02-09 10:10:24 +10001237
1238
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001239poplib
1240------
1241
R David Murray473f45b2013-12-27 17:01:16 -05001242Two new methods have been added to :mod:`poplib`: :meth:`~poplib.POP3.capa`,
1243which returns the list of capabilities advertised by the POP server, and
1244:meth:`~poplib.POP3.stls`, which switches a clear-text POP3 session into an
1245encrypted POP3 session if the POP server supports it. (Contributed by Lorenzo
1246Catucci in :issue:`4473`.)
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001247
1248
Serhiy Storchaka7c411a42013-10-02 11:56:18 +03001249pprint
1250------
1251
Larry Hastings3732ed22014-03-15 21:13:56 -07001252The :mod:`pprint` module's :class:`~pprint.PrettyPrinter` class and its
1253:func:`~pprint.pformat`, and :func:`~pprint.pprint` functions have a new
1254option, *compact*, that controls how the output is formatted. Currently
1255setting *compact* to ``True`` means that sequences will be printed with as many
1256sequence elements as will fit within *width* on each (indented) line.
1257(Contributed by Serhiy Storchaka in :issue:`19132`.)
Serhiy Storchaka7c411a42013-10-02 11:56:18 +03001258
R David Murrayb231b2b2014-01-04 17:11:23 -05001259Long strings are now wrapped using Python's normal line continuation
Larry Hastings3732ed22014-03-15 21:13:56 -07001260syntax. (Contributed by Antoine Pitrou in :issue:`17150`).
R David Murrayb231b2b2014-01-04 17:11:23 -05001261
Serhiy Storchaka7c411a42013-10-02 11:56:18 +03001262
R David Murray6e390152013-12-24 22:28:04 -05001263pty
1264---
1265
1266:func:`pty.spawn` now returns the status value from :func:`os.waitpid` on
1267the child process, instead of ``None``. (Contributed by Gregory P. Smith.)
1268
1269
Nick Coghlan367df122013-10-27 01:57:34 +10001270pydoc
1271-----
1272
Larry Hastings3732ed22014-03-15 21:13:56 -07001273The :mod:`pydoc` module is now based directly on the :func:`inspect.signature`
1274introspection API, allowing it to provide signature information for a wider
1275variety of callable objects. This change also means that ``__wrapped__``
1276attributes are now taken into account when displaying help information
1277(Contributed by Larry Hastings in :issue:`19674`)
1278
1279The :mod:`pydoc` module no longer displays the ``self`` parameter for
1280already bound methods. Instead, it aims to always display the exact current
1281signature of the supplied callable (Contributed by Larry Hastings in
1282:issue:`20710`)
1283
1284In addition to the changes that have been made to :mod:`pydoc` directly,
Nick Coghlan367df122013-10-27 01:57:34 +10001285its handling of custom ``__dir__`` methods and various descriptor
Larry Hastings3732ed22014-03-15 21:13:56 -07001286behaviours has also been improved substantially by the underlying changes in
Nick Coghlan367df122013-10-27 01:57:34 +10001287the :mod:`inspect` module.
1288
Larry Hastings3732ed22014-03-15 21:13:56 -07001289As the :func:`help` builtin is based on :mod:`pydoc`, the above changes also
1290affect the behaviour of :func:`help`.
1291
Nick Coghlan367df122013-10-27 01:57:34 +10001292
Serhiy Storchaka32eddc12013-11-23 23:20:30 +02001293re
1294--
1295
Larry Hastings3732ed22014-03-15 21:13:56 -07001296New :func:`~re.fullmatch` function and :meth:`.regex.fullmatch` method anchor
1297the pattern at both ends of the string to match. This provides a way to be
1298explicit about the goal of the match, which avoids a class of subtle bugs where
1299``$`` characters get lost during code changes or the addition of alternatives
1300to an existing regular expression. (Contributed by Matthew Barnett in
1301:issue:`16203`.)
Serhiy Storchaka32eddc12013-11-23 23:20:30 +02001302
Ezio Melottidd7e2912013-11-25 23:20:20 +02001303The repr of :ref:`regex objects <re-objects>` now includes the pattern
1304and the flags; the repr of :ref:`match objects <match-objects>` now
Larry Hastings3732ed22014-03-15 21:13:56 -07001305includes the start, end, and the part of the string that matched. (Contributed
1306by Hugo Lopes Tavares and Serhiy Storchaka in :issue:`13592` and
1307:issue:`17087`.)
Ezio Melottidd7e2912013-11-25 23:20:20 +02001308
1309
Christian Heimesb7bd5df2013-10-22 11:21:54 +02001310resource
1311--------
1312
Larry Hastings3732ed22014-03-15 21:13:56 -07001313New :func:`~resource.prlimit` function, available on Linux platforms with a
1314kernel version of 2.6.36 or later and glibc of 2.13 or later, provides the
1315ability to query or set the resource limits for processes other than the one
1316making the call. (Contributed by Christian Heimes in :issue:`16595`.)
1317
1318On Linux kernel version 2.6.36 or later, there are there are also some new
1319Linux specific constants: :attr:`~resource.RLIMIT_MSGQUEUE`,
1320:attr:`~resource.RLIMIT_NICE`, :attr:`~resource.RLIMIT_RTPRIO`,
1321:attr:`~resource.RLIMIT_RTTIME`, and :attr:`~resource.RLIMIT_SIGPENDING`.
1322(Contributed by Christian Heimes in :issue:`19324`.)
1323
1324On FreeBSD version 9 and later, there some new FreeBSD specific constants:
1325:attr:`~resource.RLIMIT_SBSIZE`, :attr:`~resource.RLIMIT_SWAP`, and
1326:attr:`~resource.RLIMIT_NPTS`. (Contributed by Claudiu Popa in
1327:issue:`19343`.)
Christian Heimesb7bd5df2013-10-22 11:21:54 +02001328
R David Murray575fb312013-12-25 23:21:03 -05001329
R David Murray2bc930f2013-12-31 11:17:21 -05001330select
1331------
1332
1333:class:`~select.epoll` objects now support the context management protocol.
1334When used in a :keyword:`with` statement, the :meth:`~select.epoll.close`
1335method will be called automatically at the end of the block. (Contributed
1336by Serhiy Storchaka in :issue:`16488`.)
1337
Larry Hastings3732ed22014-03-15 21:13:56 -07001338:class:`~select.devpoll` objects now have :meth:`~select.devpoll.fileno` and
1339:meth:`~select.devpoll.close` methods, as well as a new attribute
1340:attr:`~select.devpoll.closed`. (Contributed by Victor Stinner in
1341:issue:`18794`.)
1342
R David Murray2bc930f2013-12-31 11:17:21 -05001343
R David Murray575fb312013-12-25 23:21:03 -05001344shelve
1345------
1346
1347:class:`~shelve.Shelf` instances may now be used in :keyword:`with` statements,
1348and will be automatically closed at the end of the :keyword:`with` block.
1349(Contributed by Filip Gruszczyński in :issue:`13896`.)
1350
1351
Larry Hastings3732ed22014-03-15 21:13:56 -07001352shutil
1353------
1354
1355:func:`~shutil.copyfile` now raises a specific :exc:`~shutil.Error` subclass,
1356:exc:`~shutil.SameFileError`, when the source and destination are the same
1357file, which allows an application to take appropriate action on this specific
1358error. (Contributed by Atsuo Ishimoto and Hynek Schlawack in
1359:issue:`1492704`.)
1360
1361
R David Murrayf1e4fdc2014-01-21 18:30:42 -05001362smtpd
1363-----
1364
1365The :class:`~smtpd.SMTPServer` and :class:`~smtpd.SMTPChannel` classes now
Larry Hastings3732ed22014-03-15 21:13:56 -07001366accept a *map* keyword argument which, if specified, is passed in to
R David Murrayf1e4fdc2014-01-21 18:30:42 -05001367:class:`asynchat.async_chat` as its *map* argument. This allows an application
1368to avoid affecting the global socket map. (Contributed by Vinay Sajip in
1369:issue:`11959`.)
1370
1371
R David Murray8e37d5d2013-04-13 14:49:48 -04001372smtplib
1373-------
1374
R David Murray8a345962013-04-14 06:46:35 -04001375:exc:`~smtplib.SMTPException` is now a subclass of :exc:`OSError`, which allows
R David Murray8e37d5d2013-04-13 14:49:48 -04001376both socket level errors and SMTP protocol level errors to be caught in one
1377try/except statement by code that only cares whether or not an error occurred.
Larry Hastings3732ed22014-03-15 21:13:56 -07001378(Contributed by Ned Jackson Lovely in :issue:`2118`).
R David Murray8e37d5d2013-04-13 14:49:48 -04001379
Antoine Pitroud6cbd342013-08-12 20:48:15 +02001380
Victor Stinnerdaf45552013-08-28 00:53:59 +02001381socket
1382------
1383
R David Murray33ef1ae2013-12-31 16:04:50 -05001384The socket module now supports the :data:`~socket.CAN_BCM` protocol on
1385platforms that support it. (Contributed by Brian Thorne in :issue:`15359`.)
1386
Georg Brandl5642ff92013-09-15 10:37:57 +02001387Socket objects have new methods to get or set their :ref:`inheritable flag
R David Murray33ef1ae2013-12-31 16:04:50 -05001388<fd_inheritance>`, :meth:`~socket.socket.get_inheritable` and
1389:meth:`~socket.socket.set_inheritable`.
Victor Stinnerdaf45552013-08-28 00:53:59 +02001390
R David Murray33ef1ae2013-12-31 16:04:50 -05001391The ``socket.AF_*`` and ``socket.SOCK_*`` constants are now enumeration values
1392using the new :mod:`enum` module. This allows meaningful names to be printed
1393during debugging, instead of integer "magic numbers".
Victor Stinnerdaf45552013-08-28 00:53:59 +02001394
R David Murray66bf12a2014-01-08 17:21:22 -05001395The :data:`~socket.AF_LINK` constant is now available on BSD and OSX.
1396
Larry Hastings3732ed22014-03-15 21:13:56 -07001397:func:`~socket.inet_pton` and :func:`~socket.inet_ntop` are now supported
1398on Windows. (Contributed by Atsuo Ishimoto in :issue:`7171`.)
1399
R David Murray8b2d6822013-12-31 15:06:05 -05001400
R David Murray9025f1c2014-01-02 13:44:18 -05001401sqlite3
1402-------
1403
Larry Hastings3732ed22014-03-15 21:13:56 -07001404A new boolean parameter to the :func:`~sqlite3.connect` function, *uri*, can be
1405used to indicate that the *database* parameter is a ``uri`` (see the `SQLite
1406URI documentation <http://www.sqlite.org/uri.html>`_). (Contributed by poq in
1407:issue:`13773`.)
R David Murray9025f1c2014-01-02 13:44:18 -05001408
1409
Christian Heimes24cd4cf2013-06-22 19:31:58 +02001410ssl
1411---
1412
R David Murray748bad22013-12-20 17:08:39 -05001413.. _whatsnew-tls-11-12:
Christian Heimes24cd4cf2013-06-22 19:31:58 +02001414
R David Murray748bad22013-12-20 17:08:39 -05001415:data:`~ssl.PROTOCOL_TLSv1_1` and :data:`~ssl.PROTOCOL_TLSv1_2` (TLSv1.1 and
1416TLSv1.2 support) have been added; support for these protocols is only available if
1417Python is linked with OpenSSL 1.0.1 or later. (Contributed by Michele Orrù and
1418Antoine Pitrou in :issue:`16692`)
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001419
Larry Hastings3732ed22014-03-15 21:13:56 -07001420.. _whatsnew34-sslcontext:
1421
1422New function :func:`~ssl.create_default_context` provides a standard way to
1423obtain an :class:`~ssl.SSLContext` whose settings are intended to be a
1424reasonable balance between compatibility and security. These settings are
1425more stringent than the defaults provided by the :class:`~ssl.SSLContext`
1426constructor, and may be adjusted in the future, without prior deprecation, if
1427best-practice security requirements change. The new recommended best
1428practice for using stdlib libraries that support SSL is to use
1429:func:`~ssl.create_default_context` to obtain an :class:`~ssl.SSLContext`
1430object, modify it if needed, and then pass it as the *context* argument
1431of the appropriate stdlib API. (Contributed by Christian Heimes
1432in :issue:`19689`.)
1433
1434:class:`~ssl.SSLContext` method :meth:`~ssl.SSLContext.load_verify_locations`
1435accepts a new optional argument *cadata*, which can be used to provide PEM or
1436DER encoded certificates directly via strings or bytes, respectively.
1437(Contributed by Christian Heimes in :issue:`18138`.)
1438
R David Murrayf1e4fdc2014-01-21 18:30:42 -05001439New function :func:`~ssl.get_default_verify_paths` returns
1440a named tuple of the paths and environment variables that the
1441:meth:`~ssl.SSLContext.set_default_verify_paths` method uses to set
1442OpenSSL's default ``cafile`` and ``capath``. This can be an aid in
1443debugging default verification issues. (Contributed by Christian Heimes
1444in :issue:`18143`.)
1445
1446:class:`~ssl.SSLContext` has a new method,
1447:meth:`~ssl.SSLContext.cert_store_stats`, that reports the number of loaded
1448``X.509`` certs, ``X.509 CA`` certs, and certificate revocation lists (``crl``\
1449s), as well as a :meth:`~ssl.SSLContext.get_ca_certs` method that returns a
1450list of the loaded ``CA`` certificates. (Contributed by Christian Heimes in
Larry Hastings3732ed22014-03-15 21:13:56 -07001451:issue:`18147`.)
1452
1453If OpenSSL 0.9.8 or later is available, :class:`~ssl.SSLContext` has an new
1454attribute :attr:`~ssl.SSLContext.verify_flags` that can be used to control the
1455certificate verification process by setting it to some combination of the new
1456constants :data:`~ssl.VERIFY_DEFAULT`, :data:`~ssl.VERIFY_CRL_CHECK_LEAF`,
1457:data:`~ssl.VERIFY_CRL_CHECK_CHAIN`, or :data:`~ssl.VERIFY_X509_STRICT`.
1458OpenSSL does not do any CRL verification by default. (Contributed by
1459Christien Heimes in :issue:`8813`.)
1460
1461New :class:`~ssl.SSLContext` method :meth:`~ssl.SSLContext.load_default_certs`
1462loads a set of dfault "certificate authority" (CA) certificates from default
1463locations, which vary according to the platform. It can be used to load both
1464TLS web server authentication certificates
1465(``purpose=``:data:`~ssl.Purpose.SERVER_AUTH`) for a client to use to verify a
1466server, and certificates for a server to use in verifying client certificates
1467(``purpose=``:data:`~ssl.Purpose.CLIENT_AUTH`). (Contributed by Christian
1468Heimes in :issue:`19292`.)
1469
1470.. _whatsnew34-win-cert-store:
Christian Heimes24cd4cf2013-06-22 19:31:58 +02001471
R David Murray8c561b52014-02-01 12:27:07 -05001472Two new windows-only functions, :func:`~ssl.enum_certificates` and
1473:func:`~ssl.enum_crls` provide the ability to retrieve certificates,
1474certificate information, and CRLs from the Windows cert store. (Contributed
1475by Christian Heimes in :issue:`17134`.)
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001476
Larry Hastings3732ed22014-03-15 21:13:56 -07001477.. _whatsnew34-sni:
1478
1479Support for server-side SNI (Server Name Indication) using the new
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001480:meth:`ssl.SSLContext.set_servername_callback` method.
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001481(Contributed by Daniel Black in :issue:`8109`.)
1482
Larry Hastings3732ed22014-03-15 21:13:56 -07001483The dictionary returned by :meth:`.SSLSocket.getpeercert` contains additional
1484``X509v3`` extension items: ``crlDistributionPoints``, ``calIssuers``, and
1485``OCSP`` URIs. (Contributed by Christian Heimes in :issue:`18379`.)
1486
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001487
Antoine Pitroud6cbd342013-08-12 20:48:15 +02001488stat
1489----
1490
1491The :mod:`stat` module is now backed by a C implementation in :mod:`_stat`. A C
1492implementation is required as most of the values aren't standardized and
Larry Hastings3732ed22014-03-15 21:13:56 -07001493are platform-dependent. (Contributed by Christian Heimes in :issue:`11016`.)
Antoine Pitroud6cbd342013-08-12 20:48:15 +02001494
Larry Hastings3732ed22014-03-15 21:13:56 -07001495The module supports new :mod:`~stat.ST_MODE` flags, :mod:`~stat.S_IFDOOR`,
1496:attr:`~stat.S_IFPORT`, and :attr:`~stat.S_IFWHT`. (Contributed by
1497Christian Hiemes in :issue:`11016`.)
Antoine Pitroud6cbd342013-08-12 20:48:15 +02001498
1499
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001500struct
1501------
1502
Larry Hastings3732ed22014-03-15 21:13:56 -07001503New function :mod:`~struct.iter_unpack` and a new
1504:meth:`struct.Struct.iter_unpack` method on compiled formats provide streamed
1505unpacking of a buffer containing repeated instances of a given format of data.
1506(Contributed by Antoine Pitrou in :issue:`17804`.)
R David Murray98358272014-01-05 20:52:06 -05001507
1508
1509subprocess
1510----------
1511
1512:func:`~subprocess.check_output` now accepts an *input* argument that can
1513be used to provide the contents of ``stdin`` for the command that is run.
1514(Contributed by Zack Weinberg in :issue:`16624`.)
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001515
Larry Hastings3732ed22014-03-15 21:13:56 -07001516:func:`~subprocess.getstatus` and :func:`~subprocess.getstatusoutput` now
1517work on Windows. This change was actually inadvertently made in 3.3.4.
1518(Contributed by Tim Golden in :issue:`10197`.)
1519
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001520
Serhiy Storchakae06a8962013-09-04 00:43:03 +03001521sunau
1522-----
1523
1524The :meth:`~sunau.getparams` method now returns a namedtuple rather than a
1525plain tuple. (Contributed by Claudiu Popa in :issue:`18901`.)
1526
Larry Hastings3732ed22014-03-15 21:13:56 -07001527:meth:`sunau.open` now supports the context manager protocol: when used in a
1528:keyword:`with` block, the ``close`` method of the returned object will be
1529called automatically at the end of the block. (Contributed by Serhiy Storchaka
1530in :issue:`18878`.)
1531
1532:meth:`.AU_write.setsampwidth` now supports 24 bit samples, thus adding
1533support for writing 24 sample using the module. (Contributed by
1534Serhiy Storchaka in :issue:`19261`.)
1535
1536The :meth:`~sunau.AU_write.writeframesraw` and
1537:meth:`~sunau.AU_write.writeframes` methods now accept any :term:`bytes-like
1538object`. (Contributed by Serhiy Storchaka in :issue:`8311`.)
Serhiy Storchaka34d20132013-09-05 17:01:53 +03001539
Serhiy Storchakae06a8962013-09-04 00:43:03 +03001540
R David Murrayd17aba72013-12-24 14:46:23 -05001541sys
1542---
1543
1544New function :func:`sys.getallocatedblocks` returns the current number of
Larry Hastings3732ed22014-03-15 21:13:56 -07001545blocks allocated by the interpreter. (In CPython with the default
R David Murrayd17aba72013-12-24 14:46:23 -05001546``--with-pymalloc`` setting, this is allocations made through the
Larry Hastings3732ed22014-03-15 21:13:56 -07001547:c:func:`PyObject_Malloc` API.) This can be useful for tracking memory leaks,
R David Murrayd17aba72013-12-24 14:46:23 -05001548especially if automated via a test suite. (Contributed by Antoine Pitrou
1549in :issue:`13390`.)
1550
Larry Hastings3732ed22014-03-15 21:13:56 -07001551When the Python interpreter starts in :ref:`interactive mode
1552<tut-interactive>`, it checks for an :data:`~sys.__interactivehook__` attribute
1553on the :mod:`sys` module. If the attribute exists, its value is called with no
1554arguments just before interactive mode is started. The check is made after the
1555:envvar:`PYTHONSTARTUP` file is read, so it can be set there. The :mod:`site`
1556module :ref:`sets it <rlcompleter-config>` to a function that enables tab
1557completion and history saving (in :file:`~/.python-history`) if the platform
1558supports :mod:`readline`. If you do not want this (new) behavior, you can
1559override it in :envvar:`PYTHONSTARTUP`, :mod:`sitecustomize`, or
1560:mod:`usercustomize` by deleting this attribute from :mod:`sys` (or setting it
1561to some other callable). (Contributed by Éric Araujo and Antoine Pitrou in
1562:issue:`5845`.)
1563
1564
1565tarfile
1566-------
1567
1568The :mod:`tarfile` module now supports a simple :ref:`tarfile-commandline` when
1569called as a script directly or via ``-m``. This can be used to create and
1570extract tarfile archives. (Contributed by Berker Peksag in :issue:`13477`.)
1571
1572
1573textwrap
1574--------
1575
1576The :class:`~textwrap.TextWrapper` class has two new attributes/constructor
1577arguments: :attr:`~textwrap.TextWrapper.max_lines`, which limits the number of
1578lines in the output, and :attr:`~textwrap.TextWrapper.placeholder`, which is a
1579string that will appear at the end of the output if it has been truncated
1580because of *max_lines*. Building on these capabilities, a new convenience
1581function :func:`~textwrap.shorten` collapses all of the whitespace in the input
1582to single spaces and produces a single line of a given *width* that ends with
1583the *placeholder* (by default, ``[...]``). (Contributed by Antoine Pitrou and
1584Serhiy Storchaka in :issue:`18585` and :issue:`18725`.)
1585
1586
1587threading
1588---------
1589
1590The :class:`~threading.Thread` object representing the main thread can be
1591obtained from the new :func:`~threading.main_thread` function. In normal
1592conditions this will be the thread from which the Python interpreter was
1593started. (Contributed by Andrew Svetlov in :issue:`18882`.)
1594
R David Murrayd17aba72013-12-24 14:46:23 -05001595
Andrew Kuchling173a1572013-09-15 18:15:56 -04001596traceback
1597---------
1598
1599A new :func:`traceback.clear_frames` function takes a traceback object
1600and clears the local variables in all of the frames it references,
Larry Hastings3732ed22014-03-15 21:13:56 -07001601reducing the amount of memory consumed. (Contributed by Andrew Kuchling in
1602:issue:`1565525`).
1603
1604
1605types
1606-----
1607
1608A new :func:`~types.DynamicClassAttribute` descriptor provides a way to define
1609an attribute that acts normally when looked up through an instance object, but
1610which is routed to the *class* ``__getattr__`` when looked up through the
1611class. This allows one to have properties active on a class, and have virtual
1612attributes on the class with the same name (see :mod:`Enum` for an example).
1613(Contributed by Ethan Furman in :issue:`19030`.)
Andrew Kuchling173a1572013-09-15 18:15:56 -04001614
1615
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001616urllib
1617------
1618
R David Murray473f45b2013-12-27 17:01:16 -05001619:mod:`urllib.request` now supports ``data:`` URLs via the
1620:class:`~urllib.request.DataHandler` class. (Contributed by Mathias Panzenböck
1621in :issue:`16423`.)
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001622
Larry Hastings3732ed22014-03-15 21:13:56 -07001623The http method that will be used by a :class:`~urllib.request.Request` class
1624can now be specified by setting a :class:`~urllib.request.Request.method`
1625class attribute on the subclass. (Contributed by Jason R Coombs in
1626:issue:`18978`.)
1627
1628:class:`~urllib.request.Request` objects are now reusable: if the
1629:attr:`~urllib.request.Request.full_url` or :attr:`~urllib.request.Request.data`
1630attributes are modified, all relevant internal properties are updated. This
1631means, for example, that it is now possible to use the same
1632:class:`~urllib.request.Request` object in more than one
1633:meth:`.OpenerDirector.open` call with different *data* arguments, or to
1634modify a :class:`~urllib.request.Request`\ 's ``url`` rather than recomputing it
1635from scratch. There is also a new
1636:meth:`~urllib.request.Request.remove_header` method that can be used to remove
1637headers from a :class:`~urllib.request.Request`. (Contributed by Alexey
1638Kachayev in :issue:`16464`, Daniel Wozniak in :issue:`17485`, and Damien Brecht
1639and Senthil Kumaran in :issue:`17272`.)
1640
1641:class:`~urllib.error.HTTPError` objects now have a
1642:attr:`~urllib.error.HTTPError.headers` attribute that provides access to the
1643HTTP response headers associated with the error. (Contributed by
1644Berker Peksag in :issue:`15701`.)
1645
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001646
1647unittest
1648--------
1649
R David Murray57fcf762014-01-03 23:31:54 -05001650The :class:`~unittest.TestCase` class has a new method,
1651:meth:`~unittest.TestCase.subTest`, that produces a context manager whose
1652:keyword:`with` block becomes a "sub-test". This context manager allows a test
1653method to dynamically generate subtests by, say, calling the ``subTest``
1654context manager inside a loop. A single test method can thereby produce an
1655indefinite number of separately-identified and separately-counted tests, all of
1656which will run even if one or more of them fail. For example::
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001657
R David Murray57fcf762014-01-03 23:31:54 -05001658 class NumbersTest(unittest.TestCase):
1659 def test_even(self):
1660 for i in range(6):
Larry Hastings3732ed22014-03-15 21:13:56 -07001661 with self.subTest(i=i):
R David Murray57fcf762014-01-03 23:31:54 -05001662 self.assertEqual(i % 2, 0)
1663
1664will result in six subtests, each identified in the unittest verbose output
1665with a label consisting of the variable name ``i`` and a particular value for
1666that variable (``i=0``, ``i=1``, etc). See :ref:`subtests` for the full
1667version of this example. (Contributed by Antoine Pitrou in :issue:`16997`.)
1668
1669:func:`unittest.main` now accepts an iterable of test names for
R David Murray9025f1c2014-01-02 13:44:18 -05001670*defaultTest*, where previously it only accepted a single test name as a
1671string. (Contributed by Jyrki Pulliainen in :issue:`15132`.)
1672
R David Murray42fa1102014-01-03 13:03:36 -05001673If :class:`~unittest.SkipTest` is raised during test discovery (that is, at the
1674module level in the test file), it is now reported as a skip instead of an
1675error. (Contributed by Zach Ware in :issue:`16935`.)
1676
R David Murraydb085f52014-01-03 15:46:24 -05001677:meth:`~unittest.TestLoader.discover` now sorts the discovered files to provide
1678consistent test ordering. (Contributed by Martin Melin and Jeff Ramnani in
1679:issue:`16709`.)
1680
Larry Hastings3732ed22014-03-15 21:13:56 -07001681:class:`~unittest.TestSuite` now drops references to tests as soon as the test
1682has been run, if the test is successful. On Python interpreters that do
1683garbage collection, this allows the tests to be garbage collected if nothing
1684else is holding a reference to the test. It is possible to override this
1685behavior by creating a :class:`~unittest.TestSuite` subclass that defines a
1686custom ``_removeTestAtIndex`` method. (Contributed by Tom Wardill, Matt
1687McClure, and Andrew Svetlov in :issue:`11798`.)
1688
1689A new test assertion context-manager, :meth:`~unittest.TestCase.assertLogs`,
1690will ensure that a given block of code emits a log message using the
1691:mod:`logging` module. By default the message can come from any logger and
1692have a priority of ``INFO`` or higher, but both the logger name and an
1693alternative minimum logging level may be specified. The object returned by the
1694context manager can be queried for the :class:`~logging.LogRecord`\ s and/or
1695formatted messages that were logged. (Contributed by Antoine Pitrou in
1696:issue:`18937`.)
1697
1698Test discovery now works with namespace packages (Contributed by Claudiu Popa
1699in :issue:`17457`.)
1700
1701:mod:`unittest.mock` objects now inspect their specification signatures when
1702matching calls, which means an argument can now be matched by either position
1703or name, instead of only by position. (Contributed by Antoine Pitrou in
1704:issue:`17015`.)
1705
1706:func:`~mock.mock_open` objects now have ``readline`` and ``readlines``
1707methods. (Contributed by Toshio Kuratomi in :issue:`17467`.)
1708
R David Murray8e37d5d2013-04-13 14:49:48 -04001709
R David Murray575fb312013-12-25 23:21:03 -05001710venv
1711----
1712
1713:mod:`venv` now includes activation scripts for the ``csh`` and ``fish``
1714shells (Contributed by Andrew Svetlov in :issue:`15417`.)
1715
Larry Hastings3732ed22014-03-15 21:13:56 -07001716:class:`~venv.EnvBuilder` and the :func:`~venv.create` convenience function
1717take a new keyword argument *with_pip*, which defaults to ``False``, that
1718controls whether or not :class:`~venv.EnvBuilder` ensures that ``pip`` is
1719installed in the virtual environment. (Contributed by Nick Coghlan in
1720:issue:`19552` as part of the :pep:`453` implementation.)
1721
R David Murray575fb312013-12-25 23:21:03 -05001722
R David Murray671cd322013-04-10 12:31:43 -04001723wave
1724----
1725
1726The :meth:`~wave.getparams` method now returns a namedtuple rather than a
1727plain tuple. (Contributed by Claudiu Popa in :issue:`17487`.)
1728
R David Murrayc91d5ee2013-07-31 13:46:08 -04001729:meth:`wave.open` now supports the context manager protocol. (Contributed
1730by Claudiu Popa in :issue:`17616`.)
1731
Larry Hastings3732ed22014-03-15 21:13:56 -07001732:mod:`wave` can now :ref:`write output to unseekable files
1733<wave-write-objects>`. (Contributed by David Jones, Guilherme Polo, and Serhiy
1734Storchaka in :issue:`5202`.)
1735
1736The :meth:`~wave.Wave_write.writeframesraw` and
1737:meth:`~wave.Wave_write.writeframes` methods now accept any :term:`bytes-like
1738object`. (Contributed by Serhiy Storchaka in :issue:`8311`.)
1739
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001740
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001741weakref
1742-------
1743
1744New :class:`~weakref.WeakMethod` class simulates weak references to bound
Nick Coghlanbe57ab82013-09-22 21:26:30 +10001745methods. (Contributed by Antoine Pitrou in :issue:`14631`.)
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001746
Nick Coghlanbe57ab82013-09-22 21:26:30 +10001747New :class:`~weakref.finalize` class makes it possible to register a callback
1748to be invoked when an object is garbage collected, without needing to
1749carefully manage the lifecycle of the weak reference itself. (Contributed by
1750Richard Oudkerk in :issue:`15528`)
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001751
R David Murraya101bdb2014-01-06 16:32:05 -05001752The callback, if any, associated with a :class:`~weakref.ref` is now
1753exposed via the :attr:`~weakref.ref.__callback__` attribute. (Contributed
1754by Mark Dickinson in :issue:`17643`.)
1755
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001756
1757xml.etree
1758---------
1759
R David Murray410d3202014-01-04 23:52:50 -05001760A new parser, :class:`~xml.etree.ElementTree.XMLPullParser`, allows a
1761non-blocking applications to parse XML documents. An example can be
1762seen at :ref:`elementtree-pull-parsing`. (Contributed by Antoine
1763Pitrou in :issue:`17741`.)
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +02001764
R David Murray575fb312013-12-25 23:21:03 -05001765The :mod:`xml.etree.ElementTree` :func:`~xml.etree.ElementTree.tostring` and
1766:func:`~xml.etree.ElementTree.tostringlist` functions, and the
1767:class:`~xml.etree.ElementTree.ElementTree`
1768:meth:`~xml.etree.ElementTree.ElementTree.write` method, now have a
1769*short_empty_elements* :ref:`keyword-only parameter <keyword-only_parameter>`
1770providing control over whether elements with no content are written in
1771abbreviated (``<tag />``) or expanded (``<tag></tag>``) form. (Contributed by
1772Ariel Poliak and Serhiy Storchaka in :issue:`14377`.)
1773
Christian Tismer59202e52013-10-21 03:59:23 +02001774
Larry Hastings3732ed22014-03-15 21:13:56 -07001775zipfile
1776-------
Christian Tismer59202e52013-10-21 03:59:23 +02001777
Larry Hastings3732ed22014-03-15 21:13:56 -07001778The :meth:`~zipfile.PyZipFile.writepy` method of the
1779:class:`~zipfile.PyZipFile` class has a new *filterfunc* option that can be
1780used to control which directories and files are added to the archive. For
1781example, this could be used to exclude test files from the archive.
Christian Tismer59202e52013-10-21 03:59:23 +02001782(Contributed by Christian Tismer in :issue:`19274`.)
1783
Larry Hastings3732ed22014-03-15 21:13:56 -07001784The *allowZip64* parameter to :class:`~zipfile.ZipFile` and
1785:class:`~zipfile.PyZipfile` is now ``True`` by default. (Contributed by
1786William Mallard in :issue:`17201`.)
1787
Christian Tismer59202e52013-10-21 03:59:23 +02001788
R David Murraye6082552014-01-03 16:15:45 -05001789
Nick Coghlan367df122013-10-27 01:57:34 +10001790CPython Implementation Changes
1791==============================
1792
1793
R David Murrayc16dfe12013-12-21 12:32:10 -05001794.. _whatsnew-pep-445:
Nick Coghlan367df122013-10-27 01:57:34 +10001795
R David Murraye7cf6782013-12-24 14:51:25 -05001796PEP 445: Customization of CPython Memory Allocators
Nick Coghlan367df122013-10-27 01:57:34 +10001797---------------------------------------------------
1798
1799:pep:`445` adds new C level interfaces to customize memory allocation in
1800the CPython interpreter.
1801
1802.. seealso::
1803
R David Murray061efb12013-12-24 12:35:59 -05001804 :pep:`445` -- Add new APIs to customize Python memory allocators
Nick Coghlan367df122013-10-27 01:57:34 +10001805 PEP written and implemented by Victor Stinner.
1806
1807
R David Murrayc16dfe12013-12-21 12:32:10 -05001808.. _whatsnew-pep-442:
Nick Coghlan367df122013-10-27 01:57:34 +10001809
R David Murraye7cf6782013-12-24 14:51:25 -05001810PEP 442: Safe Object Finalization
Nick Coghlan367df122013-10-27 01:57:34 +10001811---------------------------------
1812
1813:pep:`442` removes the current limitations and quirks of object finalization
1814in CPython. With it, objects with :meth:`__del__` methods, as well as
1815generators with :keyword:`finally` clauses, can be finalized when they are
1816part of a reference cycle.
1817
1818As part of this change, module globals are no longer forcibly set to
1819:const:`None` during interpreter shutdown in most cases, instead relying
R David Murrayca794612013-12-22 14:05:11 -05001820on the normal operation of the cyclic garbage collector. This avoids a
1821whole class of interpreter-shutdown-time errors, usually involving
1822``__del__`` methods, that have plagued Python since the cyclic GC
1823was first introduced.
Nick Coghlan367df122013-10-27 01:57:34 +10001824
1825.. seealso::
1826
R David Murray061efb12013-12-24 12:35:59 -05001827 :pep:`442` -- Safe object finalization
Nick Coghlan367df122013-10-27 01:57:34 +10001828 PEP written and implemented by Antoine Pitrou.
1829
1830
R David Murrayc16dfe12013-12-21 12:32:10 -05001831.. _whatsnew-pep-456:
1832
1833PEP 456: Secure and Interchangeable Hash Algorithm
1834--------------------------------------------------
1835
1836:pep:`456` follows up on earlier security fix work done on Python's hash
1837algorithm to address certain DOS attacks to which public facing APIs backed by
1838dictionary lookups may be subject. (See :issue:`14621` for the start of the
1839current round of improvements.) The PEP unifies CPython's hash code to make it
1840easier for a packager to substitute a different hash algorithm, and switches
1841Python's default implementation to a SipHash implementation on platforms that
1842have a 64 bit data type. Any performance differences in comparison with the
1843older FNV algorithm are trivial.
1844
1845The PEP adds additional fields to the :func:`sys.hash_info` struct sequence to
1846describe the hash algorithm in use by the currently executing binary. Otherwise,
1847the PEP does not alter any existing CPython APIs.
1848
1849
R David Murray6dd18302013-12-24 12:23:56 -05001850.. _whatsnew-pep-436:
1851
1852PEP 436: Argument Clinic
1853------------------------
1854
1855"Argument Clinic" (:pep:`436`) is now part of the CPython build process
1856and can be used to simplify the process of defining and maintaining
1857accurate signatures for builtins and standard library extension modules
1858implemented in C.
1859
Nick Coghlanaa029da2014-02-09 10:10:24 +10001860Some standard library extension modules have been converted to use Argument
Larry Hastings3732ed22014-03-15 21:13:56 -07001861Clinic in Python 3.4, and :mod:`pydoc` and :mod:`inspect` have been updated
1862accordingly.
1863
1864It is expected that signature metadata for programmatic introspection will
1865be added to additional callables implemented in C as part of Python 3.4
1866maintenance releases.
Nick Coghlanaa029da2014-02-09 10:10:24 +10001867
R David Murray6dd18302013-12-24 12:23:56 -05001868.. note::
1869 The Argument Clinic PEP is not fully up to date with the state of the
1870 implementation. This has been deemed acceptable by the release manager
1871 and core development team in this case, as Argument Clinic will not
1872 be made available as a public API for third party use in Python 3.4.
1873
1874.. seealso::
1875
R David Murray061efb12013-12-24 12:35:59 -05001876 :pep:`436` -- The Argument Clinic DSL
R David Murray6dd18302013-12-24 12:23:56 -05001877 PEP written and implemented by Larry Hastings.
1878
1879
R David Murraye7cf6782013-12-24 14:51:25 -05001880Other Build and C API Changes
Nick Coghlan367df122013-10-27 01:57:34 +10001881-----------------------------
Georg Brandlb80f5112012-09-30 09:11:58 +02001882
Nick Coghlanaa029da2014-02-09 10:10:24 +10001883* The new :c:func:`PyType_GetSlot` function has been added to the stable ABI,
1884 allowing retrieval of function pointers from named type slots when using
1885 the limited API. (Contributed by Martin von Löwis in :issue:`17162`)
1886
Nick Coghlan7d270ee2013-10-17 22:35:35 +10001887* The new :c:func:`Py_SetStandardStreamEncoding` pre-initialization API
1888 allows applications embedding the CPython interpreter to reliably force
1889 a particular encoding and error handler for the standard streams
1890 (Contributed by Bastien Montagne and Nick Coghlan in :issue:`16129`)
Georg Brandlb80f5112012-09-30 09:11:58 +02001891
Nick Coghlan0acceb72013-10-20 13:22:21 +10001892* Most Python C APIs that don't mutate string arguments are now correctly
1893 marked as accepting ``const char *`` rather than ``char *`` (Contributed
1894 by Serhiy Storchaka in :issue:`1772673`).
1895
Larry Hastings3732ed22014-03-15 21:13:56 -07001896* A new shell version of ``python-config`` can be used even when a python
R David Murrayd91ba202013-12-24 12:13:44 -05001897 interpreter is not available (for example, in cross compilation scenarios).
1898
Larry Hastings3732ed22014-03-15 21:13:56 -07001899* :c:func:`PyUnicode_FromFormat` now supports width and precision
1900 specifications for ``%s``, ``%A``, ``%U``, ``%V``, ``%S``, and ``%R``.
1901 (Contributed by Ysj Ray and Victor Stinner in :issue:`7330`.)
Georg Brandlb80f5112012-09-30 09:11:58 +02001902
Larry Hastings3732ed22014-03-15 21:13:56 -07001903* New function :c:func:`PyStructSequence_InitType2` supplements the
1904 existing :c:func:`PyStructSequence_InitType` function. The difference
1905 is that it returns ``0`` on success and ``-1`` on failure.
1906
1907* The CPython source can now be compiled using the address sanity checking
1908 features of recent versions of GCC and clang: the false alarms in the small
1909 object allocator have been silenced. (Contributed by Dhiru Kholia in
1910 :issue:`18596`.)
1911
1912* The Windows build now uses `Address Space Layout Randomization
1913 <http://en.wikipedia.org/wiki/ASLR>`_ and `Data Execution Prevention
1914 <http://en.wikipedia.org/wiki/Data_Execution_Prevention>`_. (Contributed by
1915 Christian Heimes in :issue:`16632`.)
1916
1917* New function :c:func:`PyObject_LengthHint` is the C API equivalent
1918 of :func:`operator.length_hint`. (Contributed by Armin Ronacher in
1919 :issue:`16148`.)
1920
1921
1922.. _other-improvements-3.4:
R David Murraye6082552014-01-03 16:15:45 -05001923
R David Murraye7cf6782013-12-24 14:51:25 -05001924Other Improvements
Larry Hastings3732ed22014-03-15 21:13:56 -07001925------------------
R David Murraybcaaecf2013-12-23 21:23:36 -05001926
Larry Hastings3732ed22014-03-15 21:13:56 -07001927.. _whatsnew-isolated-mode:
1928
1929* The :ref:`python <using-on-cmdline>` command has a new :ref:`option
1930 <using-on-misc-options>`, ``-I``, which causes it to run in "isolated mode",
1931 which means that :data:`sys.path` contains neither the script's directory nor
1932 the user's ``site-packages`` directory, and all :envvar:`PYTHON*` environment
1933 variables are ignored (it implies both ``-s`` and ``-E``). Other
1934 restrictions may also be applied in the future, with the goal being to
1935 isolate the execution of a script from the user's environment. This is
1936 appropriate, for example, when Python is used to run a system script. On
1937 most POSIX systems it can and should be used in the ``#!`` line of system
1938 scripts. (Contributed by Christian Heimes in :issue:`16499`.)
1939
1940* Tab-completion is now enabled by default in the interactive interpreter
1941 on systems that support :mod:`readline`. History is also enabled by default,
1942 and is written to (and read from) the file :file:`~/.python-history`.
R David Murraybcaaecf2013-12-23 21:23:36 -05001943 (Contributed by Antoine Pitrou and Éric Araujo in :issue:`5845`.)
1944
1945* Invoking the Python interpreter with ``--version`` now outputs the version to
1946 standard output instead of standard error (:issue:`18338`). Similar changes
1947 were made to :mod:`argparse` (:issue:`18920`) and other modules that have
1948 script-like invocation capabilities (:issue:`18922`).
1949
R David Murray72420ff2013-12-24 10:46:44 -05001950* The CPython Windows installer now adds ``.py`` to the :envvar:`PATHEXT`
1951 variable when extensions are registered, allowing users to run a python
1952 script at the windows command prompt by just typing its name without the
1953 ``.py`` extension. (Contributed by Paul Moore in :issue:`18569`.)
1954
R David Murrayd17aba72013-12-24 14:46:23 -05001955* A new ``make`` target `coverage-report
1956 <http://docs.python.org/devguide/coverage.html#measuring-coverage-of-c-code-with-gcov-and-lcov>`_
1957 will build python, run the test suite, and generate an HTML coverage report
1958 for the C codebase using ``gcov`` and `lcov
1959 <http://ltp.sourceforge.net/coverage/lcov.php>`_.
1960
1961* The ``-R`` option to the :ref:`python regression test suite <regrtest>` now
1962 also checks for memory allocation leaks, using
1963 :func:`sys.getallocatedblocks()`. (Contributed by Antoine Pitrou in
1964 :issue:`13390`).
1965
R David Murray5147e002014-02-02 12:19:57 -05001966* ``python -m`` now works with namespace packages.
1967
R David Murraya56d4e82014-02-02 12:50:48 -05001968* The :mod:`stat` module is now implemented in C, which means it gets the
1969 values for its constants from the C header files, instead of having the
1970 values hard-coded in the python module as was previously the case.
1971
Larry Hastings3732ed22014-03-15 21:13:56 -07001972* Loading multiple python modules from a single OS module (``.so``, ``.dll``)
1973 now works correctly (previously it silently returned the first python
1974 module in the file). (Contributed by Václav Šmilauer in :issue:`16421`.)
1975
1976* A new opcode, :opcode:`LOAD_CLASSDEREF`, has been added to fix a bug in the
1977 loading of free variables in class bodies that could be triggered by certain
1978 uses of :ref:`__prepare__ <prepare>`. (Contributed by Benjamin Peterson in
1979 :issue:`17853`.)
1980
1981* A number of MemoryError-related crashes were identified and fixed by Victor
1982 Stinner using his :pep:`445`-based ``pyfailmalloc`` tool (:issue:`18408`,
1983 :issue:`18520`).
1984
1985* The :ref:`pyvenv <scripts-pyvenv>` command now accepts a ``--copies`` option
1986 to use copies rather than symlinks even on systems where symlinks are the
1987 default. (Contributed by Vinay Sajip in :issue:`18807`.)
1988
1989* The :ref:`pyvenv <scripts-pyvenv>` command also accepts a ``--without-pip``
1990 option to suppress the otherwise-automatic bootstrapping of pip into
1991 the virtual environment. (Contributed by Nick Coghlan in :issue:`19552`
1992 as part of the :pep:`453` implementation.)
1993
1994* The encoding name is now optional in the value set for the
1995 :envvar:`PYTHONIOENCODING` environment variable. This makes it possible to
1996 set just the error handler, without changing the default encoding.
1997 (Contributed by Serhiy Storchaka in :issue:`18818`.)
1998
1999* The :mod:`bz2`, :mod:`lzma`, and :mod:`gzip` module ``open`` functions now
2000 support ``x`` (exclusive creation) mode. (Contributed by Tim Heaney and
2001 Vajrasky Kok in :issue:`19201`, :issue:`19222`, and :issue:`19223`.)
R David Murraybcaaecf2013-12-23 21:23:36 -05002002
R David Murraye6082552014-01-03 16:15:45 -05002003
R David Murrayd74d09a2013-12-24 15:33:02 -05002004Significant Optimizations
Larry Hastings3732ed22014-03-15 21:13:56 -07002005-------------------------
R David Murraybcaaecf2013-12-23 21:23:36 -05002006
R David Murray4908f4a2014-01-04 18:07:20 -05002007* The UTF-32 decoder is now 3x to 4x faster. (Contributed by Serhiy Storchaka
2008 in :issue:`14625`.)
R David Murraybcaaecf2013-12-23 21:23:36 -05002009
2010* The cost of hash collisions for sets is now reduced. Each hash table
2011 probe now checks a series of consecutive, adjacent key/hash pairs before
2012 continuing to make random probes through the hash table. This exploits
2013 cache locality to make collision resolution less expensive.
R David Murraybcaaecf2013-12-23 21:23:36 -05002014 The collision resolution scheme can be described as a hybrid of linear
2015 probing and open addressing. The number of additional linear probes
2016 defaults to nine. This can be changed at compile-time by defining
2017 LINEAR_PROBES to be any value. Set LINEAR_PROBES=0 to turn-off
R David Murray59171722014-01-03 15:52:22 -05002018 linear probing entirely. (Contributed by Raymond Hettinger in
2019 :issue:`18771`.)
R David Murraybcaaecf2013-12-23 21:23:36 -05002020
2021* The interpreter starts about 30% faster. A couple of measures lead to the
2022 speedup. The interpreter loads fewer modules on startup, e.g. the :mod:`re`,
2023 :mod:`collections` and :mod:`locale` modules and their dependencies are no
2024 longer imported by default. The marshal module has been improved to load
R David Murray59171722014-01-03 15:52:22 -05002025 compiled Python code faster. (Contributed by Antoine Pitrou, Christian
2026 Heimes and Victor Stinner in :issue:`19219`, :issue:`19218`, :issue:`19209`,
2027 :issue:`19205` and :issue:`9548`)
R David Murraybcaaecf2013-12-23 21:23:36 -05002028
R David Murray6e390152013-12-24 22:28:04 -05002029* :class:`bz2.BZ2File` is now as fast or faster than the Python2 version for
2030 most cases. :class:`lzma.LZMAFile` has also been optimized. (Contributed by
2031 Serhiy Storchaka and Nadeem Vawda in :issue:`16034`.)
2032
R David Murray8b2d6822013-12-31 15:06:05 -05002033* :func:`random.getrandbits` is 20%-40% faster for small integers (the most
2034 common use case). (Contributed by Serhiy Storchaka in :issue:`16674`).
2035
R David Murrayb231b2b2014-01-04 17:11:23 -05002036* By taking advantage of the new storage format for strings, pickling of
2037 strings is now significantly faster. (Contributed by Victor Stinner and
2038 Antoine Pitrou in :issue:`15596`.)
2039
R David Murray66bf12a2014-01-08 17:21:22 -05002040* A performance issue in :meth:`io.FileIO.readall` has been solved. This
2041 particularly affects Windows, and significantly speeds up the case of piping
2042 significant amounts of data through :mod:`subprocess`. (Contributed
2043 by Richard Oudkerk in :issue:`15758`.)
2044
R David Murraybf0ab832014-02-03 01:14:03 -05002045* :func:`html.escape` is now 10x faster. (Contributed by Matt Bryant in
2046 :issue:`18020`.)
R David Murraybcaaecf2013-12-23 21:23:36 -05002047
Larry Hastings3732ed22014-03-15 21:13:56 -07002048* On Windows, the native ``VirtualAlloc`` is now used instead of the CRT
2049 ``malloc`` in ``obmalloc``. Artificial benchmarks show about a 3% memory
2050 savings.
2051
2052* :func:`os.urandom` now uses a lazily-opened persistent file descriptor
2053 so as to avoid using many file descriptors when run in parallel from
2054 multiple threads. (Contributed by Antoine Pitrou in :issue:`18756`.)
2055
2056
2057.. _deprecated-3.4:
R David Murraye6082552014-01-03 16:15:45 -05002058
Georg Brandlb80f5112012-09-30 09:11:58 +02002059Deprecated
2060==========
2061
R David Murrayd74d09a2013-12-24 15:33:02 -05002062This section covers various APIs and other features that have been deprecated
2063in Python 3.4, and will be removed in Python 3.5 or later. In most (but not
2064all) cases, using the deprecated APIs will produce a :exc:`DeprecationWarning`
2065when the interpreter is run with deprecation warnings enabled (for example, by
2066using ``-Wd``).
2067
Georg Brandlb80f5112012-09-30 09:11:58 +02002068
Larry Hastings3732ed22014-03-15 21:13:56 -07002069Deprecations in the Python API
2070------------------------------
Georg Brandlb80f5112012-09-30 09:11:58 +02002071
R David Murrayb79b7852014-02-22 14:28:46 -05002072* As mentioned in :ref:`whatsnew-pep-451`, a number of :mod:`importilb`
2073 methods and functions are deprecated: :meth:`importlib.find_loader` is
2074 replaced by :func:`importlib.util.find_spec`;
2075 :meth:`importlib.machinery.PathFinder.find_module` is replaced by
2076 :meth:`importlib.machinery.PathFinder.find_spec`;
2077 :meth:`importlib.abc.MetaPathFinder.find_module` is replaced by
2078 :meth:`importlib.abc.MetaPathFinder.find_spec`;
2079 :meth:`importlib.abc.PathEntryFinder.find_loader` and
2080 :meth:`~importlib.abc.PathEntryFinder.find_module` are replaced by
2081 :meth:`importlib.abc.PathEntryFinder.find_spec`; all of the ``xxxLoader`` ABC
2082 ``load_module`` methods (:meth:`importlib.abc.Loader.load_module`,
2083 :meth:`importlib.abc.InspectLoader.load_module`,
2084 :meth:`importlib.abc.FileLoader.load_module`,
2085 :meth:`importlib.abc.SourceLoader.load_module`) should no longer be
2086 implemented, instead loaders should implement an
2087 ``exec_module`` method
2088 (:meth:`importlib.abc.Loader.exec_module`,
2089 :meth:`importlib.abc.InspectLoader.exec_module`
2090 :meth:`importlib.abc.SourceLoader.exec_module`) and let the import system
2091 take care of the rest; and
2092 :meth:`importlib.abc.Loader.module_repr`,
2093 :meth:`importlib.util.module_for_loader`, :meth:`importlib.util.set_loader`,
2094 and :meth:`importlib.util.set_package` are no longer needed because their
2095 functions are now handled automatically by the import system.
Brett Cannon82b3d6a2013-06-14 22:37:11 -04002096
Brett Cannone4f41de2013-06-16 13:13:40 -04002097* The :mod:`imp` module is pending deprecation. To keep compatibility with
2098 Python 2/3 code bases, the module's removal is currently not scheduled.
2099
Brett Cannon1448ecf2013-10-04 11:38:59 -04002100* The :mod:`formatter` module is pending deprecation and is slated for removal
2101 in Python 3.6.
2102
Larry Hastings3732ed22014-03-15 21:13:56 -07002103* ``MD5`` as the default *digestmod* for the :func:`hmac.new` function is
2104 deprecated. Python 3.6 will require an explicit digest name or constructor as
2105 *digestmod* argument.
Christian Heimes634919a2013-11-20 17:23:06 +01002106
R David Murray9025f1c2014-01-02 13:44:18 -05002107* The internal ``Netrc`` class in the :mod:`ftplib` module has been documented
2108 as deprecated in its docstring for quite some time. It now emits a
2109 :exc:`DeprecationWarning` and will be removed completely in Python 3.5.
2110
Larry Hastings3732ed22014-03-15 21:13:56 -07002111* The undocumented *endtime* argument to :meth:`subprocess.Popen.wait` should
2112 not have been exposed and is hopefully not in use; it is deprecated and
2113 will mostly likely be removed in Python 3.5.
Georg Brandlb80f5112012-09-30 09:11:58 +02002114
Larry Hastings3732ed22014-03-15 21:13:56 -07002115* The *strict* argument of :class:`~html.parser.HTMLParser` is deprecated.
Georg Brandlb80f5112012-09-30 09:11:58 +02002116
Larry Hastings3732ed22014-03-15 21:13:56 -07002117* The :mod:`plistlib` :func:`~plistlib.readPlist`,
2118 :func:`~plistlib.writePlist`, :func:`~plistlib.readPlistFromBytes`, and
2119 :func:`~plistlib.writePlistToBytes` functions are deprecated in favor of the
2120 corresponding new functions :func:`~plistlib.load`, :func:`~plistlib.dump`,
2121 :func:`~plistlib.loads`, and :func:`~plistlib.dumps`. :func:`~plistlib.Data`
2122 is deprecated in favor of just using the :class:`bytes` constructor.
2123
2124* The :mod:`sysconfig` key ``SO`` is deprecated, it has been replaced by
2125 ``EXT_SUFFIX``.
2126
2127* The ``U`` mode accepted by various ``open`` functions is deprecated.
2128 In Python3 it does not do anything useful, and should be replaced by
2129 appropriate uses of :class:`io.TextIOWrapper` (if needed) and its *newline*
2130 argument.
2131
2132* The *parser* argument of :func:`xml.etree.ElementTree.iterparse` has
2133 been deprecated, as has the *html* argument of
2134 :func:`~xml.etree.ElementTree.XMLParser`. To prepare for the removal of the
2135 latter, all arguments to ``XMLParser`` should be passed by keyword.
Georg Brandlb80f5112012-09-30 09:11:58 +02002136
2137
R David Murraye7cf6782013-12-24 14:51:25 -05002138Deprecated Features
Georg Brandlb80f5112012-09-30 09:11:58 +02002139-------------------
2140
R David Murray5ea95242013-12-24 15:59:57 -05002141* Running :ref:`idle` with the ``-n`` flag (no subprocess) is deprecated.
2142 However, the feature will not be removed until :issue:`18823` is resolved.
2143
Antoine Pitrou3b2f0f02013-10-25 21:39:26 +02002144* The site module adding a "site-python" directory to sys.path, if it
2145 exists, is deprecated (:issue:`19375`).
Georg Brandlb80f5112012-09-30 09:11:58 +02002146
2147
R David Murray59171722014-01-03 15:52:22 -05002148
R David Murray72420ff2013-12-24 10:46:44 -05002149Removed
2150=======
2151
R David Murray59171722014-01-03 15:52:22 -05002152
2153Operating Systems No Longer Supported
2154-------------------------------------
2155
2156Support for the following operating systems has been removed from the source
2157and build tools:
2158
2159* OS/2 (:issue:`16135`).
2160* Windows 2000 (changeset e52df05b496a).
Larry Hastings3732ed22014-03-15 21:13:56 -07002161* Windows systems where ``COMSPEC`` points to ``command.com`` (:issue:`14470`).
R David Murray59171722014-01-03 15:52:22 -05002162* VMS (:issue:`16136`).
2163
2164
2165API and Feature Removals
2166------------------------
2167
R David Murrayd2653812013-12-27 14:06:15 -05002168The following obsolete and previously deprecated APIs and features have been
R David Murray59171722014-01-03 15:52:22 -05002169removed:
R David Murray076dead2013-12-24 14:59:50 -05002170
R David Murray72420ff2013-12-24 10:46:44 -05002171* The unmaintained ``Misc/TextMate`` and ``Misc/vim`` directories have been
R David Murrayd91ba202013-12-24 12:13:44 -05002172 removed (see the `devguide <http://docs.python.org/devguide>`_
R David Murray00569362014-01-03 13:04:25 -05002173 for suggestions on what to use instead).
R David Murray72420ff2013-12-24 10:46:44 -05002174
R David Murrayd17aba72013-12-24 14:46:23 -05002175* The ``SO`` makefile macro is removed (it was replaced by the
2176 ``SHLIB_SUFFIX`` and ``EXT_SUFFIX`` macros) (:issue:`16754`).
2177
R David Murrayd74d09a2013-12-24 15:33:02 -05002178* The ``PyThreadState.tick_counter`` field has been removed; its value has
Larry Hastings3732ed22014-03-15 21:13:56 -07002179 been meaningless since Python 3.2, when the "new GIL" was introduced
2180 (:issue:`19199`).
R David Murrayd74d09a2013-12-24 15:33:02 -05002181
R David Murrayd2653812013-12-27 14:06:15 -05002182* ``PyLoader`` and ``PyPycLoader`` have been removed from :mod:`importlib`.
2183 (Contributed by Taras Lyapun in :issue:`15641`.)
2184
R David Murraya2924ca2014-01-03 14:06:01 -05002185* The *strict* argument to :class:`~http.client.HTTPConnection` and
2186 :class:`~http.client.HTTPSConnection` has been removed. HTTP 0.9-style
2187 "Simple Responses" are no longer supported.
R David Murray00569362014-01-03 13:04:25 -05002188
R David Murraydb085f52014-01-03 15:46:24 -05002189* The deprecated :mod:`urllib.request.Request` getter and setter methods
2190 ``add_data``, ``has_data``, ``get_data``, ``get_type``, ``get_host``,
2191 ``get_selector``, ``set_proxy``, ``get_origin_req_host``, and
2192 ``is_unverifiable`` have been removed (use direct attribute access instead).
2193
R David Murray244ad602014-01-04 21:17:52 -05002194* Support for loading the deprecated ``TYPE_INT64`` has been removed from
2195 :mod:`marshal`. (Contributed by Dan Riti in :issue:`15480`.)
2196
Yury Selivanov2393dca2014-01-27 15:07:58 -05002197* :class:`inspect.Signature`: positional-only parameters are now required
2198 to have a valid name.
2199
Larry Hastings3732ed22014-03-15 21:13:56 -07002200* :meth:`object.__format__` no longer accepts non-empty format strings, it now
2201 raises a :exc:`TypeError` instead. Using a non-empty string has been
2202 deprecated since Python 3.2. This change has been made to prevent a
2203 situation where previously working (but incorrect) code would start failing
2204 if an object gained a __format__ method, which means that your code may now
2205 raise a :exc:`TypeError` if you are using an ``'s'`` format code with objects
2206 that do not have a __format__ method that handles it. See :issue:`7994` for
2207 background.
2208
R David Murray6dfc6322014-03-13 21:34:54 -04002209* :meth:`difflib.SequenceMatcher.isbjunk` and
2210 :meth:`difflib.SequenceMatcher.isbpopular` were deprecated in 3.2, and have
2211 now been removed: use ``x in sm.bjunk`` and
2212 ``x in sm.bpopular``, where *sm* is a :class:`~difflib.SequenceMatcher` object
2213 (:issue:`13248`).
2214
R David Murray72420ff2013-12-24 10:46:44 -05002215
R David Murray98358272014-01-05 20:52:06 -05002216Code Cleanups
2217-------------
2218
2219* The unused and undocumented internal ``Scanner`` class has been removed from
2220 the :mod:`pydoc` module.
2221
R David Murraybf0ab832014-02-03 01:14:03 -05002222* The private and effectively unused ``_gestalt`` module has been removed,
2223 along with the private :mod:`platform` functions ``_mac_ver_lookup``,
2224 ``_mac_ver_gstalt``, and ``_bcd2str``, which would only have ever been called
2225 on badly broken OSX systems (see :issue:`18393`).
2226
Larry Hastings3732ed22014-03-15 21:13:56 -07002227* The hardcoded copies of certain :mod:`stat` constants that were included in
2228 the :mod:`tarfile` module namespace have been removed.
2229
R David Murray98358272014-01-05 20:52:06 -05002230
R David Murraye6082552014-01-03 16:15:45 -05002231
Benjamin Peterson88f3b232012-10-04 12:45:10 -04002232Porting to Python 3.4
Georg Brandlb80f5112012-09-30 09:11:58 +02002233=====================
2234
2235This section lists previously described changes and other bugfixes
2236that may require changes to your code.
2237
Larry Hastings3732ed22014-03-15 21:13:56 -07002238
2239Changes in 'python' Command Behavior
2240------------------------------------
2241
2242* In a posix shell, setting the :envvar:`PATH` environment variable to
2243 an empty value is equivalent to not setting it at all. However, setting
2244 :envvar:`PYTHONPATH` to an empty value was *not* equivalent to not setting it
2245 at all: setting :envvar:`PYTHONPATH` to an empty value was equivalent to
2246 setting it to ``.``, which leads to confusion when reasoning by analogy to
2247 how :envvar:`PATH` works. The behavior now conforms to the posix convention
2248 for :envvar:`PATH`.
2249
2250* The [X refs, Y blocks] output of a debug (``--with-pydebug``) build of the
2251 CPython interpreter is now off by default. It can be re-enabled using the
2252 ``-X showrefcount`` option. (Contributed by Ezio Melotti in :issue:`17323`.)
2253
2254* The python command and most stdlib scripts (as well as :mod:`argparse`) now
2255 output ``--version`` information to ``stdout`` instead of ``stderr`` (for
2256 issue list see :ref:`other-improvements-3.4` above).
2257
2258
R David Murrayd74d09a2013-12-24 15:33:02 -05002259Changes in the Python API
2260-------------------------
2261
Brett Cannon777622b2013-04-09 17:03:10 -04002262* The ABCs defined in :mod:`importlib.abc` now either raise the appropriate
2263 exception or return a default value instead of raising
2264 :exc:`NotImplementedError` blindly. This will only affect code calling
2265 :func:`super` and falling through all the way to the ABCs. For compatibility,
2266 catch both :exc:`NotImplementedError` or the appropriate exception as needed.
Brett Cannon4c14b5d2013-05-04 13:56:58 -04002267
2268* The module type now initializes the :attr:`__package__` and :attr:`__loader__`
2269 attributes to ``None`` by default. To determine if these attributes were set
2270 in a backwards-compatible fashion, use e.g.
Larry Hastings3732ed22014-03-15 21:13:56 -07002271 ``getattr(module, '__loader__', None) is not None``. (:issue:`17115`.)
Brett Cannon3dc48d62013-05-28 18:35:54 -04002272
2273* :meth:`importlib.util.module_for_loader` now sets ``__loader__`` and
2274 ``__package__`` unconditionally to properly support reloading. If this is not
2275 desired then you will need to set these attributes manually. You can use
Brett Cannon028d5122013-05-31 18:02:11 -04002276 :func:`importlib.util.module_to_load` for module management.
Brett Cannon3e0651b2013-05-31 23:18:39 -04002277
2278* Import now resets relevant attributes (e.g. ``__name__``, ``__loader__``,
2279 ``__package__``, ``__file__``, ``__cached__``) unconditionally when reloading.
Larry Hastings3732ed22014-03-15 21:13:56 -07002280 Note that this restores a pre-3.3 behavior in that it means a module is
2281 re-found when re-loaded (:issue:`19413`).
Brett Cannon3e0651b2013-05-31 23:18:39 -04002282
Brett Cannon1448ecf2013-10-04 11:38:59 -04002283* Frozen packages no longer set ``__path__`` to a list containing the package
Larry Hastings3732ed22014-03-15 21:13:56 -07002284 name, they now set it to an empty list. The previous behavior could cause
2285 the import system to do the wrong thing on submodule imports if there was
2286 also a directory with the same name as the frozen package. The correct way
2287 to determine if a module is a package or not is to use``hasattr(module,
2288 '__path__')`` (:issue:`18065`).
2289
2290* Frozen modules no longer define a ``__file__`` attribute. It's semantically
2291 incorrect for frozen modules to set the attribute as they are not loaded from
2292 any explicit location. If you must know that a module comes from frozen code
2293 then you can see if the module's ``__spec__.location`` is set to ``'frozen'``,
2294 check if the loader is a subclass of
2295 :class:`importlib.machinery.FrozenImporter`,
2296 or if Python 2 compatibility is necessary you can use :func:`imp.is_frozen`.
Brett Cannon8f5ac512013-06-12 23:29:18 -04002297
Brett Cannon33915eb2013-06-14 18:33:00 -04002298* :func:`py_compile.compile` now raises :exc:`FileExistsError` if the file path
2299 it would write to is a symlink or a non-regular file. This is to act as a
2300 warning that import will overwrite those files with a regular file regardless
2301 of what type of file path they were originally.
Brett Cannonf4375ef2013-06-16 18:05:54 -04002302
2303* :meth:`importlib.abc.SourceLoader.get_source` no longer raises
2304 :exc:`ImportError` when the source code being loaded triggers a
2305 :exc:`SyntaxError` or :exc:`UnicodeDecodeError`. As :exc:`ImportError` is
2306 meant to be raised only when source code cannot be found but it should, it was
2307 felt to be over-reaching/overloading of that meaning when the source code is
2308 found but improperly structured. If you were catching ImportError before and
2309 wish to continue to ignore syntax or decoding issues, catch all three
Victor Stinner84e33c82013-06-21 00:31:55 +02002310 exceptions now.
Nick Coghlan24c05bc2013-07-15 21:13:08 +10002311
2312* :func:`functools.update_wrapper` and :func:`functools.wraps` now correctly
R David Murraybf0ab832014-02-03 01:14:03 -05002313 set the ``__wrapped__`` attribute to the function being wrapped, even if
Nick Coghlan367df122013-10-27 01:57:34 +10002314 that function also had its ``__wrapped__`` attribute set. This means
2315 ``__wrapped__`` attributes now correctly link a stack of decorated
2316 functions rather than every ``__wrapped__`` attribute in the chain
2317 referring to the innermost function. Introspection libraries that
2318 assumed the previous behaviour was intentional can use
2319 :func:`inspect.unwrap` to access the first function in the chain that has
2320 no ``__wrapped__`` attribute.
Victor Stinner2fe9bac2013-10-10 16:18:20 +02002321
Larry Hastings3732ed22014-03-15 21:13:56 -07002322* :func:`inspect.getfullargspec` has been reimplemented on top of
2323 :func:`inspect.signature` and hence handles a much wider variety of callable
2324 objects than it did in the past. It is expected that additional builtin and
2325 extension module callables will gain signature metadata over the course of
2326 the Python 3.4 series. Code that assumes that
2327 :func:`inspect.getfullargspec` will fail on non-Python callables may need
2328 to be adjusted accordingly.
2329
Georg Brandl0f5bff22013-10-19 17:46:38 +02002330* :class:`importlib.machinery.PathFinder` now passes on the current working
Brett Cannon27e27f72013-10-18 11:39:04 -04002331 directory to objects in :data:`sys.path_hooks` for the empty string. This
2332 results in :data:`sys.path_importer_cache` never containing ``''``, thus
2333 iterating through :data:`sys.path_importer_cache` based on :data:`sys.path`
2334 will not find all keys. A module's ``__file__`` when imported in the current
2335 working directory will also now have an absolute path, including when using
Larry Hastings3732ed22014-03-15 21:13:56 -07002336 ``-m`` with the interpreter (except for ``__main__.__file__`` when a script
2337 has been executed directly using a relative path) (Contributed by Brett
2338 Cannon in :issue:`18416`). is specified on the command-line)
2339 (:issue:`18416`).
Victor Stinner2748bc72013-12-13 10:57:04 +01002340
R David Murraya2924ca2014-01-03 14:06:01 -05002341* The removal of the *strict* argument to :class:`~http.client.HTTPConnection`
2342 and :class:`~http.client.HTTPSConnection` changes the meaning of the
2343 remaining arguments if you are specifying them positionally rather than by
2344 keyword. If you've been paying attention to deprecation warnings your code
2345 should already be specifying any additional arguments via keywords.
2346
R David Murray4908f4a2014-01-04 18:07:20 -05002347* Strings between ``from __future__ import ...`` statements now *always* raise
2348 a :exc:`SyntaxError`. Previously if there was no leading docstring, an
2349 interstitial string would sometimes be ignored. This brings CPython into
2350 compliance with the language spec; Jython and PyPy already were.
2351 (:issue:`17434`).
2352
R David Murraya101bdb2014-01-06 16:32:05 -05002353* :meth:`ssl.SSLSocket.getpeercert` and :meth:`ssl.SSLSocket.do_handshake`
2354 now raise an :exc:`OSError` with ``ENOTCONN`` when the ``SSLSocket`` is not
2355 connected, instead of the previous behavior of raising an
2356 :exc:`AttributError`. In addition, :meth:`~ssl.SSLSocket.getpeercert`
2357 will raise a :exc:`ValueError` if the handshake has not yet been done.
2358
R David Murray0ae7ae12014-01-08 18:16:02 -05002359* :func:`base64.b32decode` now raises a :exc:`binascii.Error` when the
2360 input string contains non-b32-alphabet characters, instead of a
2361 :exc:`TypeError`. This particular :exc:`TypeError` was missed when the other
2362 :exc:`TypeError`\ s were converted. (Contributed by Serhiy Storchaka in
2363 :issue:`18011`.) Note: this change was also inadvertently applied in Python
2364 3.3.3.
2365
Brett Cannonc089f702014-01-17 11:03:19 -05002366* The :attr:`~cgi.FieldStorage.file` attribute is now automatically closed when
2367 the creating :class:`cgi.FieldStorage` instance is garbage collected. If you
2368 were pulling the file object out separately from the :class:`cgi.FieldStorage`
2369 instance and not keeping the instance alive, then you should either store the
2370 entire :class:`cgi.FieldStorage` instance or read the contents of the file
2371 before the :class:`cgi.FieldStorage` instance is garbage collected.
2372
R David Murray45e732d2014-02-03 01:33:39 -05002373* Calling ``read`` or ``write`` on a closed SSL socket now raises an
2374 informative :exc:`ValueError` rather than the previous more mysterious
2375 :exc:`AttributeError` (:issue:`9177`).
2376
Larry Hastings3732ed22014-03-15 21:13:56 -07002377* :meth:`slice.indices` no longer produces an :exc:`OverflowError` for huge
2378 values. As a consequence of this fix, :meth:`slice.indices` now raises a
2379 :exc:`ValueError` if given a negative length; previously it returned nonsense
2380 values (:issue:`14794`).
2381
2382* The :class:`complex` constructor, unlike the :mod:`cmath` functions, was
2383 incorrectly accepting :class:`float` values if an object's ``__complex__``
2384 special method returned one. This now raises a :exc:`TypeError`.
2385 (:issue:`16290`.)
2386
2387* The :class:`int` constructor in 3.2 and 3.3 erroneously accepts :class:`float`
2388 values for the *base* parameter. It is unlikely anyone was doing this, but
2389 if so, it will now raise a :exc:`TypeError` (:issue:`16772`).
2390
2391* Defaults for keyword-only arguments are now evaluated *after* defaults for
2392 regular keyword arguments, instead of before. Hopefully no one wrote any
2393 code that depends on the previous buggy behavior (:issue:`16967`).
2394
2395* Stale thread states are now cleared after :func:`~os.fork`. This may cause
2396 some system resources to be released that previously were incorrectly kept
2397 perpetually alive (for example, database connections kept in thread-local
2398 storage). (:issue:`17094`.)
2399
2400* Parameter names in ``__annotations__`` dicts are now mangled properly,
Yury Selivanov026019f2014-02-18 12:49:41 -05002401 similarly to ``__kwdefaults__``. (Contributed by Yury Selivanov in
2402 :issue:`20625`).
2403
Larry Hastings3732ed22014-03-15 21:13:56 -07002404* :attr:`hashlib.hash.name` now always returns the identifier in lower case.
2405 Previously some builtin hashes had uppercase names, but now that it is a
2406 formal public interface the naming has been made consistent (:issue:`18532`).
2407
2408* Because :mod:`unittest.TestSuite` now drops references to tests after they
2409 are run, test harnesses that re-use a :class:`~unittest.TestSuite` to re-run
2410 a set of tests may fail. Test suites should not be re-used in this fashion
2411 since it means state is retained between test runs, breaking the test
2412 isolation that :mod:`unittest` is designed to provide. However, if the lack
2413 of isolation is considered acceptable, the old behavior can be restored by
2414 creating a :mod:`~unittest.TestSuite` subclass that defines a
2415 ``_removeTestAtIndex`` method that does nothing (see
2416 :meth:`.TestSuite.__iter__`) (:issue:`11798`).
2417
2418* :mod:`unittest` now uses :mod:`argparse` for command line parsing. There are
2419 certain invalid command forms that used to work that are no longer allowed;
2420 in theory this should not cause backward compatibility issues since the
2421 disallowed command forms didn't make any sense and are unlikely to be in use.
2422
2423* The :func:`re.split`, :func:`re.findall`, and :func:`re.sub` functions, and
2424 the :meth:`~re.match.group` and :meth:`~re.match.groups` methods of
2425 ``match`` objects now always return a *bytes* object when the string
2426 to be matched is a :term:`bytes-like object`. Previously the return type
2427 matched the input type, so if your code was depending on the return value
2428 being, say, a ``bytearray``, you will need to change your code.
2429
2430* :mod:`audioop` functions now raise an error immediately if passed string
2431 input, instead of failing randomly later on (:issue:`16685`).
2432
2433* The new *convert_charrefs* argument to :class:`~html.parser.HTMLParser`
2434 currently defaults to ``False`` for backward compatibility, but will
2435 eventually be changed to default to ``True``. It is recommended that you add
2436 this keyword, with the appropriate value, to any
2437 :class:`~html.parser.HTMLParser` calls in your code (:issue:`13633`).
2438
2439* Since the *digestmod* argument to the :func:`hmac.new` function will in the
2440 future have no default, all calls to :func:`hmac.new` should be changed to
2441 explicitly specify a *digestmod* (:issue:`17276`).
2442
2443* Calling :func:`sysconfig.get_config_var` with the ``SO`` key, or looking
2444 ``SO`` up in the results of a call to :func:`sysconfig.get_config_vars`
2445 is deprecated. This key should be replaced by ``EXT_SUFFIX`` or
2446 ``SHLIB_SUFFIX``, depending on the context (:issue:`19555`).
2447
2448* Any calls to ``open`` functions that specify ``U`` should be modified.
2449 ``U`` is ineffective in Python3 and will eventually raise an error if used.
2450 Depending on the function, the equivalent of its old Python2 behavior can be
2451 achieved using either a *newline* argument, or if necessary by wrapping the
2452 stream in :mod:`~io.TextIOWrapper` to use its *newline* argument
2453 (:issue:`15204`).
2454
2455* If you use :ref:`pyvenv <scripts-pyvenv>` in a script and desire that pip
2456 *not* be installed, you must add ``--without-pip`` to your command
2457 invocation.
2458
2459* The default behavior of :func:`json.dump` and :func:`json.dumps` when
2460 an indent is specified has changed: it no longer produces trailing
2461 spaces after the item separating commas at the ends of lines. This
2462 will matter only if you have tests that are doing white-space-sensitive
2463 comparisons of such output (:issue:`16333`).
2464
2465* :mod:`doctest` now looks for doctests in extension module ``__doc__``
2466 strings, so if your doctest test discovery includes extension modules that
2467 have things that look like doctests in them you may see test failures you've
2468 never seen before when running your tests (:issue:`3158`).
2469
2470* The :mod:`collections.abc` module has been slightly refactored as
2471 part of the Python startup improvements. As a consequence of this, it is no
2472 longer the case that importing :mod:`collections` automatically imports
2473 :mod:`collections.abc`. If your program depended on the (undocumented)
2474 implicit import, you will need to add an explicit ``import collections.abc``
2475 (:issue:`20784`).
2476
R David Murrayd2653812013-12-27 14:06:15 -05002477
Victor Stinner774b2e02013-12-13 14:33:01 +01002478Changes in the C API
2479--------------------
2480
Larry Hastingsad88d7a2014-02-10 04:26:10 -08002481* :c:func:`PyEval_EvalFrameEx`, :c:func:`PyObject_Repr`, and
Nick Coghlanc0bc0b42014-02-09 12:00:01 +10002482 :c:func:`PyObject_Str`, along with some other internal C APIs, now include
2483 a debugging assertion that ensures they are not used in situations where
2484 they may silently discard a currently active exception. In cases where
Nick Coghlan3d7b3642014-02-09 10:57:34 +10002485 discarding the active exception is expected and desired (for example,
Nick Coghlanc0bc0b42014-02-09 12:00:01 +10002486 because it has already been saved locally with :c:func:`PyErr_Fetch` or
2487 is being deliberately replaced with a different exception), an explicit
2488 :c:func:`PyErr_Clear` call will be needed to avoid triggering the
Nick Coghlan72318b92014-02-09 12:05:13 +10002489 assertion when invoking these operations (directly or indirectly) and
2490 running against a version of Python that is compiled with assertions
2491 enabled.
Nick Coghlan3d7b3642014-02-09 10:57:34 +10002492
Victor Stinner774b2e02013-12-13 14:33:01 +01002493* :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg**
2494 argument is not set. Previously only ``NULL`` was returned with no exception
2495 set.
2496
2497* The result of the :c:data:`PyOS_ReadlineFunctionPointer` callback must
2498 now be a string allocated by :c:func:`PyMem_RawMalloc` or
2499 :c:func:`PyMem_RawRealloc`, or *NULL* if an error occurred, instead of a
Larry Hastings3732ed22014-03-15 21:13:56 -07002500 string allocated by :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`
2501 (:issue:`16742`)
Victor Stinner774b2e02013-12-13 14:33:01 +01002502
2503* :c:func:`PyThread_set_key_value` now always set the value. In Python
Victor Stinner2748bc72013-12-13 10:57:04 +01002504 3.3, the function did nothing if the key already exists (if the current
2505 value is a non-NULL pointer).
2506
Victor Stinner774b2e02013-12-13 14:33:01 +01002507* The ``f_tstate`` (thread state) field of the :c:type:`PyFrameObject`
2508 structure has been removed to fix a bug: see :issue:`14432` for the
2509 rationale.