blob: af3c35f9ade118c8f91cf8a15eeb0470316309d7 [file] [log] [blame]
Georg Brandlb80f5112012-09-30 09:11:58 +02001****************************
2 What's New In Python 3.4
3****************************
4
Georg Brandl3b80d342012-10-28 13:37:54 +01005.. :Author: Someone <email>
6 (uncomment if there is a principal author)
Georg Brandlb80f5112012-09-30 09:11:58 +02007
8.. Rules for maintenance:
9
Nick Coghlan03074fd2012-09-30 18:51:53 +053010 * Anyone can add text to this document, but the maintainer reserves the
11 right to rewrite any additions. In particular, for obscure or esoteric
12 features, the maintainer may reduce any addition to a simple reference to
13 the new documentation rather than explaining the feature inline.
Georg Brandlb80f5112012-09-30 09:11:58 +020014
Nick Coghlan03074fd2012-09-30 18:51:53 +053015 * While the maintainer will periodically go through Misc/NEWS
16 and add changes, it's best not to rely on this. We know from experience
17 that any changes that aren't in the What's New documentation around the
18 time of the original release will remain largely unknown to the community
19 for years, even if they're added later. We also know from experience that
20 other priorities can arise, and the maintainer will run out of time to do
21 updates - in such cases, end users will be much better served by partial
22 notifications that at least give a hint about new features to
23 investigate.
Georg Brandlb80f5112012-09-30 09:11:58 +020024
25 * This is not a complete list of every single change; completeness
Nick Coghlan03074fd2012-09-30 18:51:53 +053026 is the purpose of Misc/NEWS. The What's New should focus on changes that
27 are visible to Python *users* and that *require* a feature release (i.e.
28 most bug fixes should only be recorded in Misc/NEWS)
29
30 * PEPs should not be marked Final until they have an entry in What's New.
31 A placeholder entry that is just a section header and a link to the PEP
32 (e.g ":pep:`397` has been implemented") is acceptable. If a PEP has been
33 implemented and noted in What's New, don't forget to mark it as Final!
Georg Brandlb80f5112012-09-30 09:11:58 +020034
35 * If you want to draw your new text to the attention of the
36 maintainer, add 'XXX' to the beginning of the paragraph or
37 section.
38
Nick Coghlan03074fd2012-09-30 18:51:53 +053039 * It's OK to add just a very brief note about a change. For
40 example: "The :ref:`~socket.transmogrify()` function was added to the
41 :mod:`socket` module." The maintainer will research the change and
42 write the necessary text (if appropriate). The advantage of doing this
43 is that even if no more descriptive text is ever added, readers will at
44 least have a notification that the new feature exists and a link to the
45 relevant documentation.
Georg Brandlb80f5112012-09-30 09:11:58 +020046
47 * You can comment out your additions if you like, but it's not
48 necessary (especially when a final release is some months away).
49
50 * Credit the author of a patch or bugfix. Just the name is
51 sufficient; the e-mail address isn't necessary.
52
53 * It's helpful to add the bug/patch number as a comment:
54
Nick Coghlan03074fd2012-09-30 18:51:53 +053055 The :ref:`~socket.transmogrify()` function was added to the
56 :mod:`socket` module. (Contributed by P.Y. Developer in :issue:`12345`.)
Georg Brandlb80f5112012-09-30 09:11:58 +020057
58 This saves the maintainer the effort of going through the Mercurial log
59 when researching a change.
60
Nick Coghlan03074fd2012-09-30 18:51:53 +053061 * Cross referencing tip: :ref:`mod.attr` will display as ``mod.attr``,
62 while :ref:`~mod.attr` will display as ``attr``.
63
Georg Brandlb80f5112012-09-30 09:11:58 +020064This article explains the new features in Python 3.4, compared to 3.3.
65
Nick Coghlan03074fd2012-09-30 18:51:53 +053066.. Python 3.4 was released on TBD.
Georg Brandlb80f5112012-09-30 09:11:58 +020067
Ezio Melotti25bbe5e2012-11-17 19:30:48 +020068For full details, see the
69`changelog <http://docs.python.org/3.4/whatsnew/changelog.html>`_.
Georg Brandlb80f5112012-09-30 09:11:58 +020070
71.. note:: Prerelease users should be aware that this document is currently in
72 draft form. It will be updated substantially as Python 3.4 moves towards
73 release, so it's worth checking back even after reading earlier versions.
74
75
76.. seealso::
77
Nick Coghlan367df122013-10-27 01:57:34 +100078 :pep:`429` - Python 3.4 Release Schedule
Georg Brandlb80f5112012-09-30 09:11:58 +020079
80
81Summary -- Release highlights
82=============================
83
Kristjan Valur Jonssona1e82442013-03-26 13:56:14 +000084.. This section singles out the most important changes in Python 3.4.
Georg Brandlb80f5112012-09-30 09:11:58 +020085 Brevity is key.
86
87New syntax features:
88
Nick Coghlan0acceb72013-10-20 13:22:21 +100089* No new syntax features are planned for Python 3.4.
Georg Brandlb80f5112012-09-30 09:11:58 +020090
91New library modules:
92
Nick Coghlan0acceb72013-10-20 13:22:21 +100093* :mod:`asyncio`: New provisonal API for asynchronous IO (:pep:`3156`).
94* :mod:`enum`: Support for enumeration types (:pep:`435`).
Nick Coghland0cf0632013-11-11 22:11:55 +100095* :mod:`ensurepip`: Bootstrapping the pip installer (:pep:`453`).
Antoine Pitrou31119e42013-11-22 17:38:12 +010096* :mod:`pathlib`: Object-oriented filesystem paths (:pep:`428`).
Victor Stinner4aea4a02013-09-04 20:30:34 +020097* :mod:`selectors`: High-level and efficient I/O multiplexing, built upon the
98 :mod:`select` module primitives.
Nick Coghlan0acceb72013-10-20 13:22:21 +100099* :mod:`statistics`: A basic numerically stable statistics library (:pep:`450`).
Georg Brandlb80f5112012-09-30 09:11:58 +0200100
Nick Coghlan367df122013-10-27 01:57:34 +1000101New expected features for Python implementations:
Georg Brandlb80f5112012-09-30 09:11:58 +0200102
Victor Stinnerdaf45552013-08-28 00:53:59 +0200103* :ref:`PEP 446: Make newly created file descriptors non-inheritable <pep-446>`.
Nick Coghlan367df122013-10-27 01:57:34 +1000104* command line option for :ref:`isolated mode <using-on-misc-options>`,
105 (:issue:`16499`).
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000106* :ref:`improvements <codec-handling-improvements>` in the handling of
107 codecs that are not text encodings
Georg Brandlb80f5112012-09-30 09:11:58 +0200108
109Significantly Improved Library Modules:
110
Nick Coghlan367df122013-10-27 01:57:34 +1000111* Single-dispatch generic functions in :mod:`functoools` (:pep:`443`)
Antoine Pitrouc9dc4a22013-11-23 18:59:12 +0100112* New :mod:`pickle` protocol 4 (:pep:`3154`)
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200113* SHA-3 (Keccak) support for :mod:`hashlib`.
114* TLSv1.1 and TLSv1.2 support for :mod:`ssl`.
Richard Oudkerk84ed9a62013-08-14 15:35:41 +0100115* :mod:`multiprocessing` now has option to avoid using :func:`os.fork`
116 on Unix (:issue:`8713`).
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200117
Nick Coghlan367df122013-10-27 01:57:34 +1000118CPython implementation improvements:
Georg Brandlb80f5112012-09-30 09:11:58 +0200119
Nick Coghlan367df122013-10-27 01:57:34 +1000120* :ref:`PEP 442: Safe object finalization <pep-442>`
121* :ref:`PEP 445: Configurable memory allocators <pep-445>`
Christian Heimes985ecdc2013-11-20 11:46:18 +0100122* :pep:`456` Secure and interchangeable hash algorithm
Nick Coghlan367df122013-10-27 01:57:34 +1000123* Improve finalization of Python modules to avoid setting their globals
124 to None, in most cases (:issue:`18214`).
125* A more efficient :mod:`marshal` format (:issue:`16475`).
126* "Argument Clinic", an initial step towards providing improved introspection
127 support for builtin and standard library extension types implemented in C
128 (:pep:`436`)
Georg Brandlb80f5112012-09-30 09:11:58 +0200129
130Please read on for a comprehensive list of user-facing changes.
131
Nick Coghland0cf0632013-11-11 22:11:55 +1000132
133PEP 453: Explicit bootstrapping of pip in Python installations
134==============================================================
135
136The new :mod:`ensurepip` module (defined in :pep:`453`) provides a standard
137cross-platform mechanism to boostrap the pip installer into Python
138installations and virtual environments.
139
Nick Coghlan7bc4b3b2013-11-23 11:59:40 +1000140The :mod:`venv` module and the :command:`pyvenv` utility make use of this
141module to make ``pip`` readily available in virtual environments. When
142using the command line interface, ``pip`` is installed by default, while
143for the module API installation of ``pip`` must be requested explicitly.
144
145For CPython source builds on POSIX systems, the ``make install`` and
146``make altinstall`` commands bootstrap ``pip`` by default. This behaviour
147can be controlled through configure options, and overridden through
148Makefile options.
149
Ned Deily44a0db02013-11-22 22:39:09 -0800150On Windows and Mac OS X, the CPython installers now offer the option to
151install ``pip`` along with CPython itself.
Nick Coghlan7bc4b3b2013-11-23 11:59:40 +1000152
Nick Coghland0cf0632013-11-11 22:11:55 +1000153.. note::
154
Nick Coghlan7bc4b3b2013-11-23 11:59:40 +1000155 The implementation of PEP 453 is still a work in progress. Refer to
156 :issue:`19347` for the progress on additional steps:
Nick Coghland0cf0632013-11-11 22:11:55 +1000157
Nick Coghlan7bc4b3b2013-11-23 11:59:40 +1000158 * Having the binary installers install ``pip`` by default
159 * Recommending the use of ``pip`` in the "Installing Python Module"
160 documentation.
Nick Coghland0cf0632013-11-11 22:11:55 +1000161
162.. seealso::
163
164 :pep:`453` - Explicit bootstrapping of pip in Python installations
165 PEP written by Donald Stufft and Nick Coghlan, implemented by
Nick Coghlan7bc4b3b2013-11-23 11:59:40 +1000166 Donald Stufft, Nick Coghlan, Martin von Löwis and Ned Deily.
Nick Coghland0cf0632013-11-11 22:11:55 +1000167
168
Victor Stinnerdaf45552013-08-28 00:53:59 +0200169.. _pep-446:
170
171PEP 446: Make newly created file descriptors non-inheritable
172============================================================
173
Nick Coghlan367df122013-10-27 01:57:34 +1000174:pep:`446` makes newly created file descriptors :ref:`non-inheritable
Georg Brandl5642ff92013-09-15 10:37:57 +0200175<fd_inheritance>`. New functions and methods:
Victor Stinnerdaf45552013-08-28 00:53:59 +0200176
177* :func:`os.get_inheritable`, :func:`os.set_inheritable`
178* :func:`os.get_handle_inheritable`, :func:`os.set_handle_inheritable`
179* :meth:`socket.socket.get_inheritable`, :meth:`socket.socket.set_inheritable`
180
Antoine Pitrou796564c2013-07-30 19:59:21 +0200181.. seealso::
182
Nick Coghlan367df122013-10-27 01:57:34 +1000183 :pep:`446` - Make newly created file descriptors non-inheritable
184 PEP written and implemented by Victor Stinner.
Antoine Pitrou796564c2013-07-30 19:59:21 +0200185
Georg Brandlb80f5112012-09-30 09:11:58 +0200186
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000187.. _codec-handling-improvements:
188
189Improvements to codec handling
190==============================
Nick Coghlan8b097b42013-11-13 23:49:21 +1000191
192Since it was first introduced, the :mod:`codecs` module has always been
193intended to operate as a type-neutral dynamic encoding and decoding
194system. However, its close coupling with the Python text model, especially
195the type restricted convenience methods on the builtin :class:`str`,
196:class:`bytes` and :class:`bytearray` types, has historically obscured that
197fact.
198
199As a key step in clarifying the situation, the :meth:`codecs.encode` and
200:meth:`codecs.decode` convenience functions are now properly documented in
201Python 2.7, 3.3 and 3.4. These functions have existed in the :mod:`codecs`
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000202module (and have been covered by the regression test suite) since Python 2.4,
Nick Coghlan8b097b42013-11-13 23:49:21 +1000203but were previously only discoverable through runtime introspection.
204
205Unlike the convenience methods on :class:`str`, :class:`bytes` and
206:class:`bytearray`, these convenience functions support arbitrary codecs
207in both Python 2 and Python 3, rather than being limited to Unicode text
208encodings (in Python 3) or ``basestring`` <-> ``basestring`` conversions
209(in Python 2).
210
Nick Coghlan8afc8f62013-11-22 23:00:22 +1000211In Python 3.4, the interpreter is able to identify the known non-text
212encodings provided in the standard library and direct users towards these
213general purpose convenience functions when appropriate::
Nick Coghlan8b097b42013-11-13 23:49:21 +1000214
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000215 >>> b"abcdef".decode("hex")
Nick Coghlan8b097b42013-11-13 23:49:21 +1000216 Traceback (most recent call last):
217 File "<stdin>", line 1, in <module>
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000218 LookupError: 'hex' is not a text encoding; use codecs.decode() to handle arbitrary codecs
Nick Coghlan8b097b42013-11-13 23:49:21 +1000219
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000220 >>> "hello".encode("rot13")
Nick Coghlan8b097b42013-11-13 23:49:21 +1000221 Traceback (most recent call last):
222 File "<stdin>", line 1, in <module>
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000223 LookupError: 'rot13' is not a text encoding; use codecs.encode() to handle arbitrary codecs
Nick Coghlan8b097b42013-11-13 23:49:21 +1000224
225In a related change, whenever it is feasible without breaking backwards
226compatibility, exceptions raised during encoding and decoding operations
227will be wrapped in a chained exception of the same type that mentions the
228name of the codec responsible for producing the error::
229
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000230 >>> import codecs
231
232 >>> codecs.decode(b"abcdefgh", "hex")
Nick Coghlan8afc8f62013-11-22 23:00:22 +1000233 binascii.Error: Non-hexadecimal digit found
Nick Coghlan8b097b42013-11-13 23:49:21 +1000234
235 The above exception was the direct cause of the following exception:
236
237 Traceback (most recent call last):
238 File "<stdin>", line 1, in <module>
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000239 binascii.Error: decoding with 'hex' codec failed (Error: Non-hexadecimal digit found)
Nick Coghlan8b097b42013-11-13 23:49:21 +1000240
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000241 >>> codecs.encode("hello", "bz2")
Nick Coghlan8b097b42013-11-13 23:49:21 +1000242 TypeError: 'str' does not support the buffer interface
243
244 The above exception was the direct cause of the following exception:
245
246 Traceback (most recent call last):
247 File "<stdin>", line 1, in <module>
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000248 TypeError: encoding with 'bz2' codec failed (TypeError: 'str' does not support the buffer interface)
Nick Coghlan8b097b42013-11-13 23:49:21 +1000249
Nick Coghlan9c1aed82013-11-23 11:13:36 +1000250Finally, as the examples above show, these improvements have permitted
251the restoration of the convenience aliases for the non-Unicode codecs that
252were themselves restored in Python 3.2. This means that encoding binary data
253to and from its hexadecimal representation (for example) can now be written
254as::
255
256 >>> from codecs import encode, decode
257 >>> encode(b"hello", "hex")
258 b'68656c6c6f'
259 >>> decode(b"68656c6c6f", "hex")
260 b'hello'
261
262The binary and text transforms provided in the standard library are detailed
263in :ref:`binary-transforms` and :ref:`text-transforms`.
264
265(Contributed by Nick Coghlan in :issue:`7475`, , :issue:`17827`,
266:issue:`17828` and :issue:`19619`)
Nick Coghlan8b097b42013-11-13 23:49:21 +1000267
Eric Snowb523f842013-11-22 09:05:39 -0700268.. _pep-451:
269
270PEP 451: A ModuleSpec Type for the Import System
271================================================
272
273:pep:`451` provides an encapsulation of the information about a module
274that the import machinery will use to load it, (i.e. a module spec).
275This helps simplify both the import implementation and several
276import-related APIs. The change is also a stepping stone for several
277future import-related improvements.
278
279https://mail.python.org/pipermail/python-dev/2013-November/130111.html
280
281The public-facing changes from the PEP are entirely backward-compatible.
282Furthermore, they should be transparent to everyone but importer
283authors. Key finder and loader methods have been deprecated, but they
284will continue working. New importers should use the new methods
285described in the PEP. Existing importers should be updated to implement
286the new methods.
287
Nick Coghlan8b097b42013-11-13 23:49:21 +1000288
Antoine Pitrouc9dc4a22013-11-23 18:59:12 +0100289Pickle protocol 4
290=================
291
292The new :mod:`pickle` protocol addresses a number of issues that were present
293in previous protocols, such as the serialization of nested classes, very
294large strings and containers, or classes whose :meth:`__new__` method takes
295keyword-only arguments. It also brings a couple efficiency improvements.
296
297.. seealso::
298
299 :pep:`3154` - Pickle protocol 4
300 PEP written by Antoine Pitrou and implemented by Alexandre Vassalotti.
301
302
Georg Brandlb80f5112012-09-30 09:11:58 +0200303Other Language Changes
304======================
305
306Some smaller changes made to the core Python language are:
307
Ezio Melotti34808e22013-10-12 16:36:13 +0300308* Unicode database updated to UCD version 6.3.
Georg Brandlb80f5112012-09-30 09:11:58 +0200309
R David Murray9a2f1392013-06-28 13:31:19 -0400310* :func:`min` and :func:`max` now accept a *default* argument that can be used
311 to specify the value they return if the iterable they are evaluating has no
312 elements. Contributed by Julian Berman in :issue:`18111`.
Georg Brandlb80f5112012-09-30 09:11:58 +0200313
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200314* Module objects are now :mod:`weakref`'able.
315
Nick Coghlan0acceb72013-10-20 13:22:21 +1000316* Module ``__file__`` attributes (and related values) should now always
317 contain absolute paths by default, with the sole exception of
318 ``__main__.__file__`` when a script has been executed directly using
319 a relative path (Contributed by Brett Cannon in :issue:`18416`).
320
Serhiy Storchaka58cf6072013-11-19 11:32:41 +0200321* Now all the UTF-\* codecs (except UTF-7) reject surrogates during both
322 encoding and decoding unless the ``surrogatepass`` error handler is used,
323 with the exception of the UTF-16 decoder that accepts valid surrogate pairs,
324 and the UTF-16 encoder that produces them while encoding non-BMP characters.
325 Contributed by Victor Stinner, Kang-Hao (Kenny) Lu and Serhiy Storchaka in
326 :issue:`12892`.
327
Georg Brandlb80f5112012-09-30 09:11:58 +0200328
329New Modules
330===========
331
Nick Coghlan0acceb72013-10-20 13:22:21 +1000332
333asyncio
334-------
335
336The new :mod:`asyncio` module (defined in :pep:`3156`) provides a standard
337pluggable event loop model for Python, providing solid asynchronous IO
338support in the standard library, and making it easier for other event loop
339implementations to interoperate with the standard library and each other.
340
341For Python 3.4, this module is considered a :term:`provisional API`.
342
Nick Coghlan367df122013-10-27 01:57:34 +1000343.. seealso::
344
345 :pep:`3156` - Asynchronous IO Support Rebooted: the "asyncio" Module
346 PEP written and implementation led by Guido van Rossum.
347
Nick Coghlan0acceb72013-10-20 13:22:21 +1000348enum
349----
350
Nick Coghlan367df122013-10-27 01:57:34 +1000351The new :mod:`enum` module (defined in :pep:`435`) provides a standard
352implementation of enumeration types, allowing other modules (such as
353:mod:`socket`) to provide more informative error messages and better
354debugging support by replacing opaque integer constants with backwards
355compatible enumeration values.
356
357.. seealso::
358
359 :pep:`435` - Adding an Enum type to the Python standard library
360 PEP written by Barry Warsaw, Eli Bendersky and Ethan Furman,
361 implemented by Ethan Furman.
Nick Coghlan0acceb72013-10-20 13:22:21 +1000362
363
Antoine Pitrou31119e42013-11-22 17:38:12 +0100364pathlib
365-------
366
367The new :mod:`pathlib` module offers classes representing filesystem paths
368with semantics appropriate for different operating systems. Path classes are
369divided between *pure paths*, which provide purely computational operations
370without I/O, and *concrete paths*, which inherit from pure paths but also
371provide I/O operations.
372
373For Python 3.4, this module is considered a :term:`provisional API`.
374
375.. seealso::
376
377 :pep:`428` - The pathlib module -- object-oriented filesystem paths
378 PEP written and implemented by Antoine Pitrou.
379
380
Charles-François Natali243d8d82013-09-04 19:02:49 +0200381selectors
382---------
Georg Brandlb80f5112012-09-30 09:11:58 +0200383
Nick Coghlan0acceb72013-10-20 13:22:21 +1000384The new :mod:`selectors` module (created as part of implementing :pep:`3156`)
385allows high-level and efficient I/O multiplexing, built upon the
386:mod:`select` module primitives.
387
388
389statistics
390----------
391
392The new :mod:`statistics` module (defined in :pep:`450`) offers some core
393statistics functionality directly in the standard library. This module
394supports calculation of the mean, median, mode, variance and standard
395deviation of a data series.
Georg Brandlb80f5112012-09-30 09:11:58 +0200396
Nick Coghlan367df122013-10-27 01:57:34 +1000397.. seealso::
398
399 :pep:`450` - Adding A Statistics Module To The Standard Library
400 PEP written and implemented by Steven D'Aprano
401
Georg Brandlb80f5112012-09-30 09:11:58 +0200402
403Improved Modules
404================
405
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200406aifc
407----
408
409The :meth:`~aifc.getparams` method now returns a namedtuple rather than a
410plain tuple. (Contributed by Claudiu Popa in :issue:`17818`.)
411
412
Serhiy Storchakaeaea5e92013-10-19 21:10:46 +0300413audioop
414-------
415
416Added support for 24-bit samples (:issue:`12866`).
417
Serhiy Storchaka3062c9a2013-11-23 22:26:01 +0200418Added the :func:`~audioop.byteswap` function to convert big-endian samples
419to little-endian and vice versa (:issue:`19641`).
420
Serhiy Storchakaeaea5e92013-10-19 21:10:46 +0300421
Nick Coghland4fdbcc2013-11-14 00:24:31 +1000422base64
423------
424
425The encoding and decoding functions in :mod:`base64` now accept any
426:term:`bytes-like object` in cases where it previously required a
Georg Brandled007d52013-11-24 16:09:26 +0100427:class:`bytes` or :class:`bytearray` instance (:issue:`17839`).
Nick Coghland4fdbcc2013-11-14 00:24:31 +1000428
429
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200430colorsys
431--------
432
433The number of digits in the coefficients for the RGB --- YIQ conversions have
434been expanded so that they match the FCC NTSC versions. The change in
435results should be less than 1% and may better match results found elsewhere.
436
R David Murray8e37d5d2013-04-13 14:49:48 -0400437
Nick Coghlanb4534ae2013-10-13 23:23:08 +1000438contextlib
439----------
440
Nick Coghlan240f86d2013-10-17 23:40:57 +1000441The new :class:`contextlib.suppress` context manager helps to clarify the
442intent of code that deliberately suppresses exceptions from a single
443statement. (Contributed by Raymond Hettinger in :issue:`15806` and
444Zero Piraeus in :issue:`19266`)
445
Victor Stinner6633c392013-10-21 13:27:11 +0200446The new :func:`contextlib.redirect_stdout` context manager makes it easier
Nick Coghlanb4534ae2013-10-13 23:23:08 +1000447for utility scripts to handle inflexible APIs that don't provide any
448options to retrieve their output as a string or direct it to somewhere
Nick Coghlan0acceb72013-10-20 13:22:21 +1000449other than :data:`sys.stdout`. In conjunction with :class:`io.StringIO`,
450this context manager is also useful for checking expected output from
451command line utilities. (Contribute by Raymond Hettinger in :issue:`15805`)
452
453The :mod:`contextlib` documentation has also been updated to include a
454:ref:`discussion <single-use-reusable-and-reentrant-cms>` of the
455differences between single use, reusable and reentrant context managers.
Nick Coghlanb4534ae2013-10-13 23:23:08 +1000456
457
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000458dis
459---
460
Serhiy Storchaka98b28fd2013-10-13 23:12:09 +0300461The :mod:`dis` module is now built around an :class:`~dis.Instruction` class
462that provides details of individual bytecode operations and a
463:func:`~dis.get_instructions` iterator that emits the Instruction stream for a
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000464given piece of Python code. The various display tools in the :mod:`dis`
465module have been updated to be based on these new components.
466
467The new :class:`dis.Bytecode` class provides an object-oriented API for
468inspecting bytecode, both in human-readable form and for iterating over
469instructions.
470
Nick Coghlan50c48b82013-11-23 00:57:00 +1000471(Contributed by Nick Coghlan, Ryan Kelly and Thomas Kluyver in :issue:`11816`
472and Claudiu Popa in :issue:`17916`)
Nick Coghlanb39fd0c2013-05-06 23:59:20 +1000473
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200474
R David Murray5a9d7062012-11-21 15:09:21 -0500475doctest
476-------
477
R David Murray5707d502013-06-23 14:24:13 -0400478Added :data:`~doctest.FAIL_FAST` flag to halt test running as soon as the first
479failure is detected. (Contributed by R. David Murray and Daniel Urban in
480:issue:`16522`.)
481
482Updated the doctest command line interface to use :mod:`argparse`, and added
483``-o`` and ``-f`` options to the interface. ``-o`` allows doctest options to
484be specified on the command line, and ``-f`` is a shorthand for ``-o
485FAIL_FAST`` (to parallel the similar option supported by the :mod:`unittest`
486CLI). (Contributed by R. David Murray in :issue:`11390`.)
Georg Brandlb80f5112012-09-30 09:11:58 +0200487
R David Murray8e37d5d2013-04-13 14:49:48 -0400488
R David Murraybb17d2b2013-08-09 16:15:28 -0400489email
490-----
491
492:meth:`~email.message.Message.as_string` now accepts a *policy* argument to
493override the default policy of the message when generating a string
494representation of it. This means that ``as_string`` can now be used in more
495circumstances, instead of having to create and use a :mod:`~email.generator` in
496order to pass formatting parameters to its ``flatten`` method.
497
498New method :meth:`~email.message.Message.as_bytes` added to produce a bytes
499representation of the message in a fashion similar to how ``as_string``
500produces a string representation. It does not accept the *maxheaderlen*
501argument, but does accept the *unixfrom* and *policy* arguments. The
502:class:`~email.message.Message` :meth:`~email.message.Message.__bytes__` method
503calls it, meaning that ``bytes(mymsg)`` will now produce the intuitive
504result: a bytes object containing the fully formatted message.
505
506(Contributed by R. David Murray in :issue:`18600`.)
507
R David Murray3da240f2013-10-16 22:48:40 -0400508A pair of new subclasses of :class:`~email.message.Message` have been added,
509along with a new sub-module, :mod:`~email.contentmanager`. All documentation
510is currently in the new module, which is being added as part of the new
Nick Coghlan240f86d2013-10-17 23:40:57 +1000511:term:`provisional <provisional package>` email API. These classes provide a
R David Murray3da240f2013-10-16 22:48:40 -0400512number of new methods that make extracting content from and inserting content
513into email messages much easier. See the :mod:`~email.contentmanager`
514documentation for details.
515
516These API additions complete the bulk of the work that was planned as part of
517the email6 project. The currently provisional API is scheduled to become final
518in Python 3.5 (possibly with a few minor additions in the area of error
519handling).
520
521(Contributed by R. David Murray in :issue:`18891`.)
522
R David Murraybb17d2b2013-08-09 16:15:28 -0400523
Victor Stinner854ffcb2013-06-21 00:36:30 +0200524functools
525---------
526
Nick Coghlanf4cb48a2013-11-03 16:41:46 +1000527The new :func:`~functools.partialmethod` descriptor bring partial argument
528application to descriptors, just as :func:`~functools.partial` provides
529for normal callables. The new descriptor also makes it easier to get
530arbitrary callables (including :func:`~functools.partial` instances)
531to behave like normal instance methods when included in a class definition.
532
533(Contributed by Alon Horev and Nick Coghlan in :issue:`4331`)
534
535The new :func:`~functools.singledispatch` decorator brings support for
536single-dispatch generic functions to the Python standard library. Where
537object oriented programming focuses on grouping multiple operations on a
538common set of data into a class, a generic function focuses on grouping
539multiple implementations of an operation that allows it to work with
540*different* kinds of data.
541
542.. seealso::
543
544 :pep:`443` - Single-dispatch generic functions
545 PEP written and implemented by Łukasz Langa.
Victor Stinner854ffcb2013-06-21 00:36:30 +0200546
Nick Coghlane8c45d62013-07-28 20:00:01 +1000547
Christian Heimese92ef132013-10-13 00:52:43 +0200548hashlib
549-------
550
551New :func:`hashlib.pbkdf2_hmac` function.
552
553(Contributed by Christian Heimes in :issue:`18582`)
554
555
Ezio Melotti250a06c2013-11-25 06:18:47 +0200556html
557----
558
559Added a new :func:`html.unescape` function that converts HTML5 character
560references to the corresponding Unicode characters.
561
562(Contributed by Ezio Melotti in :issue:`2927`)
563
564Added a new *convert_charrefs* keyword argument to
565:class:`~html.parser.HTMLParser` that, when ``True``, automatically converts
566all character references. For backward-compatibility, its value defaults
567to ``False``, but it will change to ``True`` in future versions, so you
568are invited to set it explicitly and update your code to use this new feature.
569
570(Contributed by Ezio Melotti in :issue:`13633`)
571
572The *strict* argument of :class:`~html.parser.HTMLParser` is now deprecated.
573
574(Contributed by Ezio Melotti in :issue:`15114`)
575
576
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200577inspect
578-------
579
Nick Coghlanf94a16b2013-09-22 22:46:49 +1000580
Nick Coghlan367df122013-10-27 01:57:34 +1000581The inspect module now offers a basic :ref:`command line interface
582<inspect-module-cli>` to quickly display source code and other
583information for modules, classes and functions. (Contributed by Claudiu Popa
584and Nick Coghlan in :issue:`18626`)
Nick Coghlanf94a16b2013-09-22 22:46:49 +1000585
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200586:func:`~inspect.unwrap` makes it easy to unravel wrapper function chains
587created by :func:`functools.wraps` (and any other API that sets the
Nick Coghlan367df122013-10-27 01:57:34 +1000588``__wrapped__`` attribute on a wrapper function). (Contributed by
589Daniel Urban, Aaron Iles and Nick Coghlan in :issue:`13266`)
590
591As part of the implementation of the new :mod:`enum` module, the
592:mod:`inspect` module now has substantially better support for custom
593``__dir__`` methods and dynamic class attributes provided through
594metaclasses (Contributed by Ethan Furman in :issue:`18929` and
595:issue:`19030`)
596
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200597
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200598mmap
599----
600
601mmap objects can now be weakref'ed.
602
603(Contributed by Valerie Lambert in :issue:`4885`.)
604
605
Richard Oudkerk84ed9a62013-08-14 15:35:41 +0100606multiprocessing
607---------------
608
609On Unix two new *start methods* have been added for starting processes
610using :mod:`multiprocessing`. These make the mixing of processes with
611threads more robust. See :issue:`8713`.
612
613Also, except when using the old *fork* start method, child processes
614will no longer inherit unneeded handles/file descriptors from their parents.
615
616
Victor Stinnerdaf45552013-08-28 00:53:59 +0200617os
618--
619
Georg Brandlc6ebbef2013-09-16 04:03:12 +0200620New functions to get and set the :ref:`inheritable flag <fd_inheritance>` of a file
Victor Stinnerdaf45552013-08-28 00:53:59 +0200621descriptors or a Windows handle:
622
623* :func:`os.get_inheritable`, :func:`os.set_inheritable`
624* :func:`os.get_handle_inheritable`, :func:`os.set_handle_inheritable`
625
626
R David Murray78d692f2013-10-10 17:23:26 -0400627pdb
628---
629
630The ``print`` command has been removed from :mod:`pdb`, restoring access to the
631``print`` function.
632
633Rationale: Python2's ``pdb`` did not have a ``print`` command; instead,
634entering ``print`` executed the ``print`` statement. In Python3 ``print`` was
635mistakenly made an alias for the pdb :pdbcmd:`p` command. ``p``, however,
636prints the ``repr`` of its argument, not the ``str`` like the Python2 ``print``
637command did. Worse, the Python3 ``pdb print`` command shadowed the Python3
638``print`` function, making it inaccessible at the ``pdb`` prompt.
639
640(Contributed by Connor Osborn in :issue:`18764`.)
641
642
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200643poplib
644------
645
646New :meth:`~poplib.POP3.stls` method to switch a clear-text POP3 session into
647an encrypted POP3 session.
648
649New :meth:`~poplib.POP3.capa` method to query the capabilities advertised by the
650POP3 server.
651
652(Contributed by Lorenzo Catucci in :issue:`4473`.)
653
654
Serhiy Storchaka7c411a42013-10-02 11:56:18 +0300655pprint
656------
657
Christian Heimese1bfd3e2013-10-21 12:32:21 +0200658The :mod:`pprint` module now supports *compact* mode for formatting long
Serhiy Storchaka7c411a42013-10-02 11:56:18 +0300659sequences (:issue:`19132`).
660
661
Nick Coghlan367df122013-10-27 01:57:34 +1000662pydoc
663-----
664
665While significant changes have not been made to :mod:`pydoc` directly,
666its handling of custom ``__dir__`` methods and various descriptor
667behaviours has been improved substantially by the underlying changes in
668the :mod:`inspect` module.
669
670
Serhiy Storchaka32eddc12013-11-23 23:20:30 +0200671re
672--
673
674Added :func:`re.fullmatch` function and :meth:`regex.fullmatch` method,
675which anchor the pattern at both ends of the string to match.
676(Contributed by Matthew Barnett in :issue:`16203`.)
677
Christian Heimesb7bd5df2013-10-22 11:21:54 +0200678resource
679--------
680
681New :func:`resource.prlimit` function and Linux specific constants.
682(Contributed by Christian Heimes in :issue:`16595` and :issue:`19324`.)
683
R David Murray8e37d5d2013-04-13 14:49:48 -0400684smtplib
685-------
686
R David Murray8a345962013-04-14 06:46:35 -0400687:exc:`~smtplib.SMTPException` is now a subclass of :exc:`OSError`, which allows
R David Murray8e37d5d2013-04-13 14:49:48 -0400688both socket level errors and SMTP protocol level errors to be caught in one
689try/except statement by code that only cares whether or not an error occurred.
690(:issue:`2118`).
691
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200692
Victor Stinnerdaf45552013-08-28 00:53:59 +0200693socket
694------
695
Georg Brandl5642ff92013-09-15 10:37:57 +0200696Socket objects have new methods to get or set their :ref:`inheritable flag
697<fd_inheritance>`:
Victor Stinnerdaf45552013-08-28 00:53:59 +0200698
699* :meth:`socket.socket.get_inheritable`, :meth:`socket.socket.set_inheritable`
700
Eli Bendersky34567ec2013-08-31 15:18:48 -0700701The ``socket.AF_*`` and ``socket.SOCK_*`` constants are enumeration values,
702using the new :mod:`enum` module. This allows descriptive reporting during
703debugging, instead of seeing integer "magic numbers".
Victor Stinnerdaf45552013-08-28 00:53:59 +0200704
Christian Heimes24cd4cf2013-06-22 19:31:58 +0200705ssl
706---
707
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200708TLSv1.1 and TLSv1.2 support.
Christian Heimes70833a82013-06-22 19:34:17 +0200709
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200710(Contributed by Michele Orrù and Antoine Pitrou in :issue:`16692`)
Christian Heimes24cd4cf2013-06-22 19:31:58 +0200711
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200712* New diagnostic functions :func:`~ssl.get_default_verify_paths`,
713 :meth:`~ssl.SSLContext.cert_store_stats` and
714 :meth:`~ssl.SSLContext.get_ca_certs`
715
716* Add :func:`ssl.enum_cert_store` to retrieve certificates and CRL from Windows'
717 cert store.
Christian Heimes24cd4cf2013-06-22 19:31:58 +0200718
719(Contributed by Christian Heimes in :issue:`18143`, :issue:`18147` and
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200720 :issue:`17134`.)
721
722Support for server-side SNI using the new
723:meth:`ssl.SSLContext.set_servername_callback` method.
724
725(Contributed by Daniel Black in :issue:`8109`.)
726
727
Antoine Pitroud6cbd342013-08-12 20:48:15 +0200728stat
729----
730
731The :mod:`stat` module is now backed by a C implementation in :mod:`_stat`. A C
732implementation is required as most of the values aren't standardized and
733platform-dependent. (Contributed by Christian Heimes in :issue:`11016`.)
734
735The module supports new file types: door, event port and whiteout.
736
737
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200738struct
739------
740
741Streaming struct unpacking using :func:`struct.iter_unpack`.
742
743(Contributed by Antoine Pitrou in :issue:`17804`.)
744
745
Serhiy Storchakae06a8962013-09-04 00:43:03 +0300746sunau
747-----
748
749The :meth:`~sunau.getparams` method now returns a namedtuple rather than a
750plain tuple. (Contributed by Claudiu Popa in :issue:`18901`.)
751
Serhiy Storchaka34d20132013-09-05 17:01:53 +0300752:meth:`sunau.open` now supports the context manager protocol (:issue:`18878`).
753
Serhiy Storchakae06a8962013-09-04 00:43:03 +0300754
Andrew Kuchling173a1572013-09-15 18:15:56 -0400755traceback
756---------
757
758A new :func:`traceback.clear_frames` function takes a traceback object
759and clears the local variables in all of the frames it references,
760reducing the amount of memory consumed (:issue:`1565525`).
761
762
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200763urllib
764------
765
766Add support.for ``data:`` URLs in :mod:`urllib.request`.
767
768(Contributed by Mathias Panzenböck in :issue:`16423`.)
769
770
771unittest
772--------
773
774Support for easy dynamically-generated subtests using the
775:meth:`~unittest.TestCase.subTest` context manager.
776
777(Contributed by Antoine Pitrou in :issue:`16997`.)
778
R David Murray8e37d5d2013-04-13 14:49:48 -0400779
R David Murray671cd322013-04-10 12:31:43 -0400780wave
781----
782
783The :meth:`~wave.getparams` method now returns a namedtuple rather than a
784plain tuple. (Contributed by Claudiu Popa in :issue:`17487`.)
785
R David Murrayc91d5ee2013-07-31 13:46:08 -0400786:meth:`wave.open` now supports the context manager protocol. (Contributed
787by Claudiu Popa in :issue:`17616`.)
788
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200789
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200790weakref
791-------
792
793New :class:`~weakref.WeakMethod` class simulates weak references to bound
Nick Coghlanbe57ab82013-09-22 21:26:30 +1000794methods. (Contributed by Antoine Pitrou in :issue:`14631`.)
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200795
Nick Coghlanbe57ab82013-09-22 21:26:30 +1000796New :class:`~weakref.finalize` class makes it possible to register a callback
797to be invoked when an object is garbage collected, without needing to
798carefully manage the lifecycle of the weak reference itself. (Contributed by
799Richard Oudkerk in :issue:`15528`)
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200800
801
802xml.etree
803---------
804
805Add an event-driven parser for non-blocking applications,
Eli Benderskyb5869342013-08-30 05:51:20 -0700806:class:`~xml.etree.ElementTree.XMLPullParser`.
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200807
Eli Benderskyb5869342013-08-30 05:51:20 -0700808(Contributed by Antoine Pitrou in :issue:`17741`.)
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200809
Christian Tismer59202e52013-10-21 03:59:23 +0200810
811zipfile.PyZipfile
812-----------------
813
814Add a filter function to ignore some packages (tests for instance),
815:meth:`~zipfile.PyZipFile.writepy`.
816
817(Contributed by Christian Tismer in :issue:`19274`.)
818
819
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200820Other improvements
821==================
822
823Tab-completion is now enabled by default in the interactive interpreter.
824
825(Contributed by Antoine Pitrou and Éric Araujo in :issue:`5845`.)
826
Eli Bendersky96d848a2013-09-06 06:55:58 -0700827Python invocation changes
828=========================
829
830Invoking the Python interpreter with ``--version`` now outputs the version to
831standard output instead of standard error (:issue:`18338`). Similar changes
832were made to :mod:`argparse` (:issue:`18920`) and other modules that have
833script-like invocation capabilities (:issue:`18922`).
Antoine Pitrouf89aa9a2013-08-12 20:46:47 +0200834
Georg Brandlb80f5112012-09-30 09:11:58 +0200835Optimizations
836=============
837
838Major performance enhancements have been added:
839
Victor Stinnere64322e2012-10-30 23:12:47 +0100840* The UTF-32 decoder is now 3x to 4x faster.
Georg Brandlb80f5112012-09-30 09:11:58 +0200841
Raymond Hettingerc301b552013-08-19 09:12:20 -0700842* The cost of hash collisions for sets is now reduced. Each hash table
Raymond Hettinger8408dc52013-09-15 14:57:15 -0700843 probe now checks a series of consecutive, adjacent key/hash pairs before
844 continuing to make random probes through the hash table. This exploits
845 cache locality to make collision resolution less expensive.
846
847 The collision resolution scheme can be described as a hybrid of linear
848 probing and open addressing. The number of additional linear probes
849 defaults to nine. This can be changed at compile-time by defining
850 LINEAR_PROBES to be any value. Set LINEAR_PROBES=0 to turn-off
851 linear probing entirely.
Raymond Hettingerc301b552013-08-19 09:12:20 -0700852
Christian Heimes086b1af2013-10-22 11:49:34 +0200853 (Contributed by Raymond Hettinger in :issue:`18771`.)
Raymond Hettingerc301b552013-08-19 09:12:20 -0700854
Christian Heimes17ecd1d2013-10-13 03:10:06 +0200855* The interpreter starts about 30% faster. A couple of measures lead to the
Eric V. Smith57841dd2013-10-13 00:36:08 -0400856 speedup. The interpreter loads fewer modules on startup, e.g. the :mod:`re`,
Christian Heimes17ecd1d2013-10-13 03:10:06 +0200857 :mod:`collections` and :mod:`locale` modules and their dependencies are no
858 longer imported by default. The marshal module has been improved to load
859 compiled Python code faster.
860
861 (Contributed by Antoine Pitrou, Christian Heimes and Victor Stinner in
862 :issue:`19219`, :issue:`19218`, :issue:`19209`, :issue:`19205` and
863 :issue:`9548`)
864
865
Nick Coghlan367df122013-10-27 01:57:34 +1000866CPython Implementation Changes
867==============================
868
869
870.. _pep-445:
871
872PEP 445: Customization of CPython memory allocators
873---------------------------------------------------
874
875:pep:`445` adds new C level interfaces to customize memory allocation in
876the CPython interpreter.
877
878.. seealso::
879
880 :pep:`445` - Add new APIs to customize Python memory allocators
881 PEP written and implemented by Victor Stinner.
882
883
884.. _pep-442:
885
886PEP 442: Safe object finalization
887---------------------------------
888
889:pep:`442` removes the current limitations and quirks of object finalization
890in CPython. With it, objects with :meth:`__del__` methods, as well as
891generators with :keyword:`finally` clauses, can be finalized when they are
892part of a reference cycle.
893
894As part of this change, module globals are no longer forcibly set to
895:const:`None` during interpreter shutdown in most cases, instead relying
896on the normal operation of the cyclic garbage collector.
897
898.. seealso::
899
900 :pep:`442` - Safe object finalization
901 PEP written and implemented by Antoine Pitrou.
902
903
904Other build and C API changes
905-----------------------------
Georg Brandlb80f5112012-09-30 09:11:58 +0200906
907Changes to Python's build process and to the C API include:
908
Nick Coghlan7d270ee2013-10-17 22:35:35 +1000909* The new :c:func:`Py_SetStandardStreamEncoding` pre-initialization API
910 allows applications embedding the CPython interpreter to reliably force
911 a particular encoding and error handler for the standard streams
912 (Contributed by Bastien Montagne and Nick Coghlan in :issue:`16129`)
Georg Brandlb80f5112012-09-30 09:11:58 +0200913
Nick Coghlan0acceb72013-10-20 13:22:21 +1000914* Most Python C APIs that don't mutate string arguments are now correctly
915 marked as accepting ``const char *`` rather than ``char *`` (Contributed
916 by Serhiy Storchaka in :issue:`1772673`).
917
918* "Argument Clinic" (:pep:`436`) is now part of the CPython build process
919 and can be used to simplify the process of defining and maintaining
920 accurate signatures for builtins and standard library extension modules
921 implemented in C.
922
Nick Coghlan367df122013-10-27 01:57:34 +1000923 .. note::
924 The Argument Clinic PEP is not fully up to date with the state of the
925 implementation. This has been deemed acceptable by the release manager
926 and core development team in this case, as Argument Clinic will not
927 be made available as a public API for third party use in Python 3.4.
928
Georg Brandlb80f5112012-09-30 09:11:58 +0200929
930Deprecated
931==========
932
933Unsupported Operating Systems
934-----------------------------
935
Victor Stinnerf3fd13b2013-08-04 10:30:57 +0200936* OS/2
Victor Stinnerf3fd13b2013-08-04 10:30:57 +0200937* Windows 2000
Georg Brandlb80f5112012-09-30 09:11:58 +0200938
939
940Deprecated Python modules, functions and methods
941------------------------------------------------
942
Terry Jan Reedy2b6c26e2013-03-21 19:36:26 -0400943* :meth:`difflib.SequenceMatcher.isbjunk` and
Andrew Kuchling0d0813a2013-06-15 13:29:09 -0400944 :meth:`difflib.SequenceMatcher.isbpopular` were removed: use ``x in sm.bjunk`` and
945 ``x in sm.bpopular``, where *sm* is a :class:`~difflib.SequenceMatcher` object.
Georg Brandlb80f5112012-09-30 09:11:58 +0200946
Brett Cannon82b3d6a2013-06-14 22:37:11 -0400947* :func:`importlib.util.module_for_loader` is pending deprecation. Using
948 :func:`importlib.util.module_to_load` and
949 :meth:`importlib.abc.Loader.init_module_attrs` allows subclasses of a loader
950 to more easily customize module loading.
951
Brett Cannone4f41de2013-06-16 13:13:40 -0400952* The :mod:`imp` module is pending deprecation. To keep compatibility with
953 Python 2/3 code bases, the module's removal is currently not scheduled.
954
Brett Cannon1448ecf2013-10-04 11:38:59 -0400955* The :mod:`formatter` module is pending deprecation and is slated for removal
956 in Python 3.6.
957
Christian Heimes634919a2013-11-20 17:23:06 +0100958* MD5 as default digestmod for :mod:`hmac` is deprecated. Python 3.6 will
959 require an explicit digest name or constructor as *digestmod* argument.
960
Georg Brandlb80f5112012-09-30 09:11:58 +0200961
962Deprecated functions and types of the C API
963-------------------------------------------
964
Victor Stinner3dd263f2013-10-23 18:54:43 +0200965* The ``PyThreadState.tick_counter`` field has been removed: its value was
966 meaningless since Python 3.2 ("new GIL").
Georg Brandlb80f5112012-09-30 09:11:58 +0200967
968
969Deprecated features
970-------------------
971
Antoine Pitrou3b2f0f02013-10-25 21:39:26 +0200972* The site module adding a "site-python" directory to sys.path, if it
973 exists, is deprecated (:issue:`19375`).
Georg Brandlb80f5112012-09-30 09:11:58 +0200974
975
Benjamin Peterson88f3b232012-10-04 12:45:10 -0400976Porting to Python 3.4
Georg Brandlb80f5112012-09-30 09:11:58 +0200977=====================
978
979This section lists previously described changes and other bugfixes
980that may require changes to your code.
981
Brett Cannon777622b2013-04-09 17:03:10 -0400982* The ABCs defined in :mod:`importlib.abc` now either raise the appropriate
983 exception or return a default value instead of raising
984 :exc:`NotImplementedError` blindly. This will only affect code calling
985 :func:`super` and falling through all the way to the ABCs. For compatibility,
986 catch both :exc:`NotImplementedError` or the appropriate exception as needed.
Brett Cannon4c14b5d2013-05-04 13:56:58 -0400987
988* The module type now initializes the :attr:`__package__` and :attr:`__loader__`
989 attributes to ``None`` by default. To determine if these attributes were set
990 in a backwards-compatible fashion, use e.g.
Brett Cannon3dc48d62013-05-28 18:35:54 -0400991 ``getattr(module, '__loader__', None) is not None``.
992
993* :meth:`importlib.util.module_for_loader` now sets ``__loader__`` and
994 ``__package__`` unconditionally to properly support reloading. If this is not
995 desired then you will need to set these attributes manually. You can use
Brett Cannon028d5122013-05-31 18:02:11 -0400996 :func:`importlib.util.module_to_load` for module management.
Brett Cannon3e0651b2013-05-31 23:18:39 -0400997
998* Import now resets relevant attributes (e.g. ``__name__``, ``__loader__``,
999 ``__package__``, ``__file__``, ``__cached__``) unconditionally when reloading.
1000
Brett Cannon1448ecf2013-10-04 11:38:59 -04001001* Frozen packages no longer set ``__path__`` to a list containing the package
1002 name but an empty list instead. Determing if a module is a package should be
1003 done using ``hasattr(module, '__path__')``.
Brett Cannon8f5ac512013-06-12 23:29:18 -04001004
1005* :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg**
Brett Cannon82da8882013-07-04 17:48:16 -04001006 argument is not set. Previously only ``NULL`` was returned with no exception
1007 set.
Brett Cannon33915eb2013-06-14 18:33:00 -04001008
1009* :func:`py_compile.compile` now raises :exc:`FileExistsError` if the file path
1010 it would write to is a symlink or a non-regular file. This is to act as a
1011 warning that import will overwrite those files with a regular file regardless
1012 of what type of file path they were originally.
Brett Cannonf4375ef2013-06-16 18:05:54 -04001013
1014* :meth:`importlib.abc.SourceLoader.get_source` no longer raises
1015 :exc:`ImportError` when the source code being loaded triggers a
1016 :exc:`SyntaxError` or :exc:`UnicodeDecodeError`. As :exc:`ImportError` is
1017 meant to be raised only when source code cannot be found but it should, it was
1018 felt to be over-reaching/overloading of that meaning when the source code is
1019 found but improperly structured. If you were catching ImportError before and
1020 wish to continue to ignore syntax or decoding issues, catch all three
Victor Stinner84e33c82013-06-21 00:31:55 +02001021 exceptions now.
Nick Coghlan24c05bc2013-07-15 21:13:08 +10001022
1023* :func:`functools.update_wrapper` and :func:`functools.wraps` now correctly
Nick Coghlan367df122013-10-27 01:57:34 +10001024 set the ``__wrapped__`` attribute to the function being wrapper, even if
1025 that function also had its ``__wrapped__`` attribute set. This means
1026 ``__wrapped__`` attributes now correctly link a stack of decorated
1027 functions rather than every ``__wrapped__`` attribute in the chain
1028 referring to the innermost function. Introspection libraries that
1029 assumed the previous behaviour was intentional can use
1030 :func:`inspect.unwrap` to access the first function in the chain that has
1031 no ``__wrapped__`` attribute.
Victor Stinner2fe9bac2013-10-10 16:18:20 +02001032
Georg Brandlc2228c82013-10-12 13:24:55 +02001033* (C API) The result of the :c:data:`PyOS_ReadlineFunctionPointer` callback must
Victor Stinner2fe9bac2013-10-10 16:18:20 +02001034 now be a string allocated by :c:func:`PyMem_RawMalloc` or
1035 :c:func:`PyMem_RawRealloc`, or *NULL* if an error occurred, instead of a
1036 string allocated by :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`.
1037
Georg Brandl0f5bff22013-10-19 17:46:38 +02001038* :class:`importlib.machinery.PathFinder` now passes on the current working
Brett Cannon27e27f72013-10-18 11:39:04 -04001039 directory to objects in :data:`sys.path_hooks` for the empty string. This
1040 results in :data:`sys.path_importer_cache` never containing ``''``, thus
1041 iterating through :data:`sys.path_importer_cache` based on :data:`sys.path`
1042 will not find all keys. A module's ``__file__`` when imported in the current
1043 working directory will also now have an absolute path, including when using
1044 ``-m`` with the interpreter (this does not influence when the path to a file
1045 is specified on the command-line).