blob: 779f7f4ddbe236370a0ff44c538e971a467b2e7f [file] [log] [blame]
Giampaolo Rodolà3108f982011-02-24 20:59:48 +00001****************************
2 What's New In Python 3.3
3****************************
4
Éric Araujob07b97f2011-10-05 01:03:34 +02005.. Rules for maintenance:
Giampaolo Rodolà3108f982011-02-24 20:59:48 +00006
7 * Anyone can add text to this document. Do not spend very much time
8 on the wording of your changes, because your text will probably
9 get rewritten to some degree.
10
11 * The maintainer will go through Misc/NEWS periodically and add
12 changes; it's therefore more important to add your changes to
13 Misc/NEWS than to this file.
14
15 * This is not a complete list of every single change; completeness
16 is the purpose of Misc/NEWS. Some changes I consider too small
17 or esoteric to include. If such a change is added to the text,
18 I'll just remove it. (This is another reason you shouldn't spend
19 too much time on writing your addition.)
20
21 * If you want to draw your new text to the attention of the
22 maintainer, add 'XXX' to the beginning of the paragraph or
23 section.
24
25 * It's OK to just add a fragmentary note about a change. For
26 example: "XXX Describe the transmogrify() function added to the
27 socket module." The maintainer will research the change and
28 write the necessary text.
29
30 * You can comment out your additions if you like, but it's not
31 necessary (especially when a final release is some months away).
32
33 * Credit the author of a patch or bugfix. Just the name is
34 sufficient; the e-mail address isn't necessary.
35
36 * It's helpful to add the bug/patch number as a comment:
37
Giampaolo Rodolà3108f982011-02-24 20:59:48 +000038 XXX Describe the transmogrify() function added to the socket
39 module.
Éric Araujob07b97f2011-10-05 01:03:34 +020040 (Contributed by P.Y. Developer in :issue:`12345`.)
Giampaolo Rodolà3108f982011-02-24 20:59:48 +000041
Éric Araujob07b97f2011-10-05 01:03:34 +020042 This saves the maintainer the effort of going through the Mercurial log
Giampaolo Rodolà3108f982011-02-24 20:59:48 +000043 when researching a change.
44
45This article explains the new features in Python 3.3, compared to 3.2.
R David Murrayf23e2b62012-09-29 19:41:26 -040046Python 3.3 was released on September 29, 2012. For full details,
Georg Brandle73778c2014-10-29 08:36:35 +010047see the `changelog <https://docs.python.org/3.3/whatsnew/changelog.html>`_.
R David Murrayf23e2b62012-09-29 19:41:26 -040048
49.. seealso::
50
Nick Coghlancfb18182012-09-30 12:08:13 +053051 :pep:`398` - Python 3.3 Release Schedule
Giampaolo Rodolà3108f982011-02-24 20:59:48 +000052
Nick Coghlanb47b5392012-05-26 01:31:25 +100053
Antoine Pitrouc907de92012-08-21 00:53:06 +020054Summary -- Release highlights
55=============================
Victor Stinner636130e2012-08-05 16:37:12 +020056
Antoine Pitrouc907de92012-08-21 00:53:06 +020057.. This section singles out the most important changes in Python 3.3.
58 Brevity is key.
Victor Stinner636130e2012-08-05 16:37:12 +020059
Antoine Pitrouc907de92012-08-21 00:53:06 +020060New syntax features:
Victor Stinner636130e2012-08-05 16:37:12 +020061
Antoine Pitrouc907de92012-08-21 00:53:06 +020062* New ``yield from`` expression for :ref:`generator delegation <pep-380>`.
63* The ``u'unicode'`` syntax is accepted again for :class:`str` objects.
Victor Stinner636130e2012-08-05 16:37:12 +020064
Antoine Pitrouc907de92012-08-21 00:53:06 +020065New library modules:
66
67* :mod:`faulthandler` (helps debugging low-level crashes)
68* :mod:`ipaddress` (high-level objects representing IP addresses and masks)
69* :mod:`lzma` (compress data using the XZ / LZMA algorithm)
Victor Stinner1da769a2012-09-18 22:40:03 +020070* :mod:`unittest.mock` (replace parts of your system under test with mock objects)
Antoine Pitrouc907de92012-08-21 00:53:06 +020071* :mod:`venv` (Python :ref:`virtual environments <pep-405>`, as in the
72 popular ``virtualenv`` package)
73
74New built-in features:
75
76* Reworked :ref:`I/O exception hierarchy <pep-3151>`.
77
78Implementation improvements:
79
80* Rewritten :ref:`import machinery <importlib>` based on :mod:`importlib`.
81* More compact :ref:`unicode strings <pep-393>`.
82* More compact :ref:`attribute dictionaries <pep-412>`.
83
R David Murrayf23e2b62012-09-29 19:41:26 -040084Significantly Improved Library Modules:
85
86* C Accelerator for the :ref:`decimal <new-decimal>` module.
87* Better unicode handling in the :ref:`email <new-email>` module
88 (:term:`provisional <provisional package>`).
89
Antoine Pitrouc907de92012-08-21 00:53:06 +020090Security improvements:
91
92* Hash randomization is switched on by default.
93
94Please read on for a comprehensive list of user-facing changes.
95
96
97.. _pep-405:
Victor Stinner636130e2012-08-05 16:37:12 +020098
Éric Araujo859aad62012-06-24 00:07:41 -040099PEP 405: Virtual Environments
100=============================
Nick Coghlanb47b5392012-05-26 01:31:25 +1000101
Antoine Pitroua5e57972012-08-21 01:08:17 +0200102Virtual environments help create separate Python setups while sharing a
103system-wide base install, for ease of maintenance. Virtual environments
104have their own set of private site packages (i.e. locally-installed
105libraries), and are optionally segregated from the system-wide site
106packages. Their concept and implementation are inspired by the popular
107``virtualenv`` third-party package, but benefit from tighter integration
108with the interpreter core.
Éric Araujo859aad62012-06-24 00:07:41 -0400109
Antoine Pitroua5e57972012-08-21 01:08:17 +0200110This PEP adds the :mod:`venv` module for programmatic access, and the
111:ref:`pyvenv <scripts-pyvenv>` script for command-line access and
Ezio Melottiad626802012-10-16 21:50:33 +0300112administration. The Python interpreter checks for a ``pyvenv.cfg``,
Antoine Pitroua5e57972012-08-21 01:08:17 +0200113file whose existence signals the base of a virtual environment's directory
114tree.
Nick Coghlanb47b5392012-05-26 01:31:25 +1000115
R David Murrayf23e2b62012-09-29 19:41:26 -0400116.. seealso::
117
118 :pep:`405` - Python Virtual Environments
Ezio Melotti36e01df2012-10-20 16:26:18 +0300119 PEP written by Carl Meyer; implementation by Carl Meyer and Vinay Sajip
R David Murrayf23e2b62012-09-29 19:41:26 -0400120
Giampaolo Rodolà3108f982011-02-24 20:59:48 +0000121
Ezio Melotti8cd45bd2012-10-21 07:36:58 +0300122PEP 420: Implicit Namespace Packages
123====================================
Éric Araujo859aad62012-06-24 00:07:41 -0400124
125Native support for package directories that don't require ``__init__.py``
126marker files and can automatically span multiple path segments (inspired by
127various third party approaches to namespace packages, as described in
128:pep:`420`)
129
R David Murrayf23e2b62012-09-29 19:41:26 -0400130.. seealso::
131
Ezio Melotti8cd45bd2012-10-21 07:36:58 +0300132 :pep:`420` - Implicit Namespace Packages
R David Murrayf23e2b62012-09-29 19:41:26 -0400133 PEP written by Eric V. Smith; implementation by Eric V. Smith
134 and Barry Warsaw
135
Éric Araujo859aad62012-06-24 00:07:41 -0400136
137.. _pep-3118-update:
Nick Coghlan98e20702012-03-06 21:50:13 +1000138
Stefan Krah9a2d99e2012-02-25 12:24:21 +0100139PEP 3118: New memoryview implementation and buffer protocol documentation
140=========================================================================
141
R David Murrayf23e2b62012-09-29 19:41:26 -0400142The implementation of :pep:`3118` has been significantly improved.
Stefan Krah9a2d99e2012-02-25 12:24:21 +0100143
144The new memoryview implementation comprehensively fixes all ownership and
145lifetime issues of dynamically allocated fields in the Py_buffer struct
146that led to multiple crash reports. Additionally, several functions that
147crashed or returned incorrect results for non-contiguous or multi-dimensional
148input have been fixed.
149
150The memoryview object now has a PEP-3118 compliant getbufferproc()
151that checks the consumer's request type. Many new features have been
152added, most of them work in full generality for non-contiguous arrays
153and arrays with suboffsets.
154
155The documentation has been updated, clearly spelling out responsibilities
156for both exporters and consumers. Buffer request flags are grouped into
157basic and compound flags. The memory layout of non-contiguous and
158multi-dimensional NumPy-style arrays is explained.
159
160Features
161--------
162
163* All native single character format specifiers in struct module syntax
164 (optionally prefixed with '@') are now supported.
165
166* With some restrictions, the cast() method allows changing of format and
167 shape of C-contiguous arrays.
168
169* Multi-dimensional list representations are supported for any array type.
170
171* Multi-dimensional comparisons are supported for any array type.
172
Stefan Krah9e31d362012-09-08 15:35:01 +0200173* One-dimensional memoryviews of hashable (read-only) types with formats B,
Serhiy Storchakae5cf4862014-11-02 19:18:52 +0200174 b or c are now hashable. (Contributed by Antoine Pitrou in :issue:`13411`.)
Nick Coghlan98e20702012-03-06 21:50:13 +1000175
Stefan Krah9a2d99e2012-02-25 12:24:21 +0100176* Arbitrary slicing of any 1-D arrays type is supported. For example, it
177 is now possible to reverse a memoryview in O(1) by using a negative step.
178
179API changes
180-----------
181
182* The maximum number of dimensions is officially limited to 64.
183
184* The representation of empty shape, strides and suboffsets is now
185 an empty tuple instead of None.
186
187* Accessing a memoryview element with format 'B' (unsigned bytes)
188 now returns an integer (in accordance with the struct module syntax).
189 For returning a bytes object the view must be cast to 'c' first.
190
Nick Coghlan06e1ab02012-08-25 17:59:50 +1000191* memoryview comparisons now use the logical structure of the operands
192 and compare all array elements by value. All format strings in struct
193 module syntax are supported. Views with unrecognised format strings
194 are still permitted, but will always compare as unequal, regardless
195 of view contents.
196
Serhiy Storchakaa4d170d2013-12-23 18:20:51 +0200197* For further changes see `Build and C API Changes`_ and `Porting C code`_.
Stefan Krah9a2d99e2012-02-25 12:24:21 +0100198
Serhiy Storchakae5cf4862014-11-02 19:18:52 +0200199(Contributed by Stefan Krah in :issue:`10181`.)
R David Murrayf23e2b62012-09-29 19:41:26 -0400200
201.. seealso::
202
203 :pep:`3118` - Revising the Buffer Protocol
204
205
Antoine Pitrou037ffbf2011-10-24 00:25:41 +0200206.. _pep-393:
207
Ezio Melotti48a2f8f2011-09-29 00:18:19 +0300208PEP 393: Flexible String Representation
209=======================================
210
Antoine Pitroufd9b4162011-10-24 00:14:43 +0200211The Unicode string type is changed to support multiple internal
212representations, depending on the character with the largest Unicode ordinal
213(1, 2, or 4 bytes) in the represented string. This allows a space-efficient
214representation in common cases, but gives access to full UCS-4 on all
215systems. For compatibility with existing APIs, several representations may
216exist in parallel; over time, this compatibility should be phased out.
Ezio Melotti397546a2011-09-29 08:34:36 +0300217
Antoine Pitroufd9b4162011-10-24 00:14:43 +0200218On the Python side, there should be no downside to this change.
Ezio Melotti397546a2011-09-29 08:34:36 +0300219
Antoine Pitroufd9b4162011-10-24 00:14:43 +0200220On the C API side, PEP 393 is fully backward compatible. The legacy API
221should remain available at least five years. Applications using the legacy
222API will not fully benefit of the memory reduction, or - worse - may use
223a bit more memory, because Python may have to maintain two versions of each
224string (in the legacy format and in the new efficient storage).
225
Antoine Pitrou0599b5b2011-11-29 22:45:07 +0100226Functionality
227-------------
228
Antoine Pitroufd9b4162011-10-24 00:14:43 +0200229Changes introduced by :pep:`393` are the following:
Ezio Melotti48a2f8f2011-09-29 00:18:19 +0300230
Serhiy Storchakad3faf432015-01-18 11:28:37 +0200231* Python now always supports the full range of Unicode code points, including
Ezio Melotti397546a2011-09-29 08:34:36 +0300232 non-BMP ones (i.e. from ``U+0000`` to ``U+10FFFF``). The distinction between
233 narrow and wide builds no longer exists and Python now behaves like a wide
Antoine Pitroufd9b4162011-10-24 00:14:43 +0200234 build, even under Windows.
Ezio Melotti397546a2011-09-29 08:34:36 +0300235
Antoine Pitroufd9b4162011-10-24 00:14:43 +0200236* With the death of narrow builds, the problems specific to narrow builds have
237 also been fixed, for example:
Ezio Melotti397546a2011-09-29 08:34:36 +0300238
239 * :func:`len` now always returns 1 for non-BMP characters,
240 so ``len('\U0010FFFF') == 1``;
241
242 * surrogate pairs are not recombined in string literals,
243 so ``'\uDBFF\uDFFF' != '\U0010FFFF'``;
244
Antoine Pitroufd9b4162011-10-24 00:14:43 +0200245 * indexing or slicing non-BMP characters returns the expected value,
Ezio Melotti397546a2011-09-29 08:34:36 +0300246 so ``'\U0010FFFF'[0]`` now returns ``'\U0010FFFF'`` and not ``'\uDBFF'``;
247
Antoine Pitroud136aec2011-11-17 01:48:06 +0100248 * all other functions in the standard library now correctly handle
Serhiy Storchakad3faf432015-01-18 11:28:37 +0200249 non-BMP code points.
Ezio Melotti397546a2011-09-29 08:34:36 +0300250
Ezio Melotti48a2f8f2011-09-29 00:18:19 +0300251* The value of :data:`sys.maxunicode` is now always ``1114111`` (``0x10FFFF``
252 in hexadecimal). The :c:func:`PyUnicode_GetMax` function still returns
253 either ``0xFFFF`` or ``0x10FFFF`` for backward compatibility, and it should
254 not be used with the new Unicode API (see :issue:`13054`).
255
Ezio Melotti397546a2011-09-29 08:34:36 +0300256* The :file:`./configure` flag ``--with-wide-unicode`` has been removed.
Victor Stinner7d637ab2011-09-29 02:56:16 +0200257
Antoine Pitrou0599b5b2011-11-29 22:45:07 +0100258Performance and resource usage
259------------------------------
260
Serhiy Storchakad3faf432015-01-18 11:28:37 +0200261The storage of Unicode strings now depends on the highest code point in the string:
Antoine Pitrou0599b5b2011-11-29 22:45:07 +0100262
Serhiy Storchakad3faf432015-01-18 11:28:37 +0200263* pure ASCII and Latin1 strings (``U+0000-U+00FF``) use 1 byte per code point;
Antoine Pitrou0599b5b2011-11-29 22:45:07 +0100264
Serhiy Storchakad3faf432015-01-18 11:28:37 +0200265* BMP strings (``U+0000-U+FFFF``) use 2 bytes per code point;
Antoine Pitrou0599b5b2011-11-29 22:45:07 +0100266
Serhiy Storchakad3faf432015-01-18 11:28:37 +0200267* non-BMP strings (``U+10000-U+10FFFF``) use 4 bytes per code point.
Antoine Pitrou0599b5b2011-11-29 22:45:07 +0100268
Martin v. Löwisde157cc2012-03-06 08:42:17 +0100269The net effect is that for most applications, memory usage of string
270storage should decrease significantly - especially compared to former
271wide unicode builds - as, in many cases, strings will be pure ASCII
272even in international contexts (because many strings store non-human
273language data, such as XML fragments, HTTP headers, JSON-encoded data,
274etc.). We also hope that it will, for the same reasons, increase CPU
275cache efficiency on non-trivial applications. The memory usage of
276Python 3.3 is two to three times smaller than Python 3.2, and a little
277bit better than Python 2.7, on a Django benchmark (see the PEP for
278details).
Antoine Pitrou0599b5b2011-11-29 22:45:07 +0100279
R David Murrayf23e2b62012-09-29 19:41:26 -0400280.. seealso::
281
282 :pep:`393` - Flexible String Representation
283 PEP written by Martin von Löwis; implementation by Torsten Becker
284 and Martin von Löwis.
285
Éric Araujob07b97f2011-10-05 01:03:34 +0200286
Nick Coghlan349c8022012-09-30 13:00:43 +0530287.. _pep-397:
288
289PEP 397: Python Launcher for Windows
290====================================
291
292The Python 3.3 Windows installer now includes a ``py`` launcher application
293that can be used to launch Python applications in a version independent
294fashion.
295
296This launcher is invoked implicitly when double-clicking ``*.py`` files.
297If only a single Python version is installed on the system, that version
298will be used to run the file. If multiple versions are installed, the most
299recent version is used by default, but this can be overridden by including
300a Unix-style "shebang line" in the Python script.
301
302The launcher can also be used explicitly from the command line as the ``py``
303application. Running ``py`` follows the same version selection rules as
304implicitly launching scripts, but a more specific version can be selected
305by passing appropriate arguments (such as ``-3`` to request Python 3 when
306Python 2 is also installed, or ``-2.6`` to specifclly request an earlier
307Python version when a more recent version is installed).
308
309In addition to the launcher, the Windows installer now includes an
Serhiy Storchakae5cf4862014-11-02 19:18:52 +0200310option to add the newly installed Python to the system PATH. (Contributed
311by Brian Curtin in :issue:`3561`.)
Nick Coghlan349c8022012-09-30 13:00:43 +0530312
313.. seealso::
314
315 :pep:`397` - Python Launcher for Windows
316 PEP written by Mark Hammond and Martin v. Löwis; implementation by
317 Vinay Sajip.
318
319 Launcher documentation: :ref:`launcher`
320
321 Installer PATH modification: :ref:`windows-path-mod`
322
323
Antoine Pitrouc907de92012-08-21 00:53:06 +0200324.. _pep-3151:
325
Victor Stinnera1bf2982011-10-12 20:35:02 +0200326PEP 3151: Reworking the OS and IO exception hierarchy
327=====================================================
328
Antoine Pitrou01fd26c2011-10-24 00:07:02 +0200329The hierarchy of exceptions raised by operating system errors is now both
330simplified and finer-grained.
Victor Stinnera1bf2982011-10-12 20:35:02 +0200331
Antoine Pitrou01fd26c2011-10-24 00:07:02 +0200332You don't have to worry anymore about choosing the appropriate exception
333type between :exc:`OSError`, :exc:`IOError`, :exc:`EnvironmentError`,
334:exc:`WindowsError`, :exc:`mmap.error`, :exc:`socket.error` or
335:exc:`select.error`. All these exception types are now only one:
336:exc:`OSError`. The other names are kept as aliases for compatibility
337reasons.
Victor Stinnera1bf2982011-10-12 20:35:02 +0200338
Antoine Pitrou01fd26c2011-10-24 00:07:02 +0200339Also, it is now easier to catch a specific error condition. Instead of
340inspecting the ``errno`` attribute (or ``args[0]``) for a particular
341constant from the :mod:`errno` module, you can catch the adequate
342:exc:`OSError` subclass. The available subclasses are the following:
Victor Stinnera1bf2982011-10-12 20:35:02 +0200343
Antoine Pitrou01fd26c2011-10-24 00:07:02 +0200344* :exc:`BlockingIOError`
345* :exc:`ChildProcessError`
346* :exc:`ConnectionError`
347* :exc:`FileExistsError`
348* :exc:`FileNotFoundError`
349* :exc:`InterruptedError`
350* :exc:`IsADirectoryError`
351* :exc:`NotADirectoryError`
352* :exc:`PermissionError`
353* :exc:`ProcessLookupError`
354* :exc:`TimeoutError`
Victor Stinnera1bf2982011-10-12 20:35:02 +0200355
Antoine Pitrou01fd26c2011-10-24 00:07:02 +0200356And the :exc:`ConnectionError` itself has finer-grained subclasses:
Victor Stinnera1bf2982011-10-12 20:35:02 +0200357
Antoine Pitrou01fd26c2011-10-24 00:07:02 +0200358* :exc:`BrokenPipeError`
359* :exc:`ConnectionAbortedError`
360* :exc:`ConnectionRefusedError`
361* :exc:`ConnectionResetError`
Victor Stinnera1bf2982011-10-12 20:35:02 +0200362
363Thanks to the new exceptions, common usages of the :mod:`errno` can now be
Antoine Pitrou01fd26c2011-10-24 00:07:02 +0200364avoided. For example, the following code written for Python 3.2::
Victor Stinnera1bf2982011-10-12 20:35:02 +0200365
366 from errno import ENOENT, EACCES, EPERM
367
368 try:
369 with open("document.txt") as f:
370 content = f.read()
371 except IOError as err:
372 if err.errno == ENOENT:
373 print("document.txt file is missing")
374 elif err.errno in (EACCES, EPERM):
375 print("You are not allowed to read document.txt")
376 else:
377 raise
378
Antoine Pitrou01fd26c2011-10-24 00:07:02 +0200379can now be written without the :mod:`errno` import and without manual
380inspection of exception attributes::
Victor Stinnera1bf2982011-10-12 20:35:02 +0200381
382 try:
383 with open("document.txt") as f:
384 content = f.read()
385 except FileNotFoundError:
386 print("document.txt file is missing")
387 except PermissionError:
388 print("You are not allowed to read document.txt")
389
R David Murrayf23e2b62012-09-29 19:41:26 -0400390.. seealso::
391
392 :pep:`3151` - Reworking the OS and IO Exception Hierarchy
393 PEP written and implemented by Antoine Pitrou
394
Victor Stinnera1bf2982011-10-12 20:35:02 +0200395
Chris Jerdonek2654b862012-12-23 15:31:57 -0800396.. index::
397 single: yield; yield from (in What's New)
398
Antoine Pitrouc907de92012-08-21 00:53:06 +0200399.. _pep-380:
400
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000401PEP 380: Syntax for Delegating to a Subgenerator
402================================================
403
Chris Jerdonek2654b862012-12-23 15:31:57 -0800404PEP 380 adds the ``yield from`` expression, allowing a :term:`generator` to
405delegate
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000406part of its operations to another generator. This allows a section of code
Chris Jerdonek2654b862012-12-23 15:31:57 -0800407containing :keyword:`yield` to be factored out and placed in another generator.
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000408Additionally, the subgenerator is allowed to return with a value, and the
409value is made available to the delegating generator.
Nick Coghlanb9b281b2012-03-06 22:31:12 +1000410
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000411While designed primarily for use in delegating to a subgenerator, the ``yield
412from`` expression actually allows delegation to arbitrary subiterators.
413
Nick Coghlanb9b281b2012-03-06 22:31:12 +1000414For simple iterators, ``yield from iterable`` is essentially just a shortened
415form of ``for item in iterable: yield item``::
416
417 >>> def g(x):
418 ... yield from range(x, 0, -1)
419 ... yield from range(x)
420 ...
421 >>> list(g(5))
422 [5, 4, 3, 2, 1, 0, 1, 2, 3, 4]
423
424However, unlike an ordinary loop, ``yield from`` allows subgenerators to
425receive sent and thrown values directly from the calling scope, and
426return a final value to the outer generator::
427
Chris Jerdonek2654b862012-12-23 15:31:57 -0800428 >>> def accumulate():
429 ... tally = 0
Nick Coghlanb9b281b2012-03-06 22:31:12 +1000430 ... while 1:
431 ... next = yield
432 ... if next is None:
433 ... return tally
434 ... tally += next
435 ...
Chris Jerdonek2654b862012-12-23 15:31:57 -0800436 >>> def gather_tallies(tallies):
Nick Coghlanb9b281b2012-03-06 22:31:12 +1000437 ... while 1:
438 ... tally = yield from accumulate()
439 ... tallies.append(tally)
440 ...
441 >>> tallies = []
442 >>> acc = gather_tallies(tallies)
443 >>> next(acc) # Ensure the accumulator is ready to accept values
Chris Jerdonek2654b862012-12-23 15:31:57 -0800444 >>> for i in range(4):
Nick Coghlanb9b281b2012-03-06 22:31:12 +1000445 ... acc.send(i)
446 ...
447 >>> acc.send(None) # Finish the first tally
448 >>> for i in range(5):
449 ... acc.send(i)
450 ...
451 >>> acc.send(None) # Finish the second tally
452 >>> tallies
Chris Jerdonek2654b862012-12-23 15:31:57 -0800453 [6, 10]
Nick Coghlanb9b281b2012-03-06 22:31:12 +1000454
455The main principle driving this change is to allow even generators that are
456designed to be used with the ``send`` and ``throw`` methods to be split into
457multiple subgenerators as easily as a single large function can be split into
458multiple subfunctions.
459
R David Murrayf23e2b62012-09-29 19:41:26 -0400460.. seealso::
461
462 :pep:`380` - Syntax for Delegating to a Subgenerator
463 PEP written by Greg Ewing; implementation by Greg Ewing, integrated into
Ezio Melotti76e7ea52012-10-20 22:53:47 +0300464 3.3 by Renaud Blanch, Ryan Kelly and Nick Coghlan; documentation by
465 Zbigniew Jędrzejewski-Szmek and Nick Coghlan
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000466
467
Nick Coghlanab7bf212012-02-26 17:49:52 +1000468PEP 409: Suppressing exception context
469======================================
470
Nick Coghlanab7bf212012-02-26 17:49:52 +1000471PEP 409 introduces new syntax that allows the display of the chained
472exception context to be disabled. This allows cleaner error messages in
473applications that convert between exception types::
474
475 >>> class D:
476 ... def __init__(self, extra):
477 ... self._extra_attributes = extra
478 ... def __getattr__(self, attr):
479 ... try:
480 ... return self._extra_attributes[attr]
481 ... except KeyError:
482 ... raise AttributeError(attr) from None
483 ...
484 >>> D({}).x
485 Traceback (most recent call last):
486 File "<stdin>", line 1, in <module>
487 File "<stdin>", line 8, in __getattr__
488 AttributeError: x
489
490Without the ``from None`` suffix to suppress the cause, the original
491exception would be displayed by default::
492
493 >>> class C:
494 ... def __init__(self, extra):
495 ... self._extra_attributes = extra
496 ... def __getattr__(self, attr):
497 ... try:
498 ... return self._extra_attributes[attr]
499 ... except KeyError:
500 ... raise AttributeError(attr)
501 ...
502 >>> C({}).x
503 Traceback (most recent call last):
504 File "<stdin>", line 6, in __getattr__
505 KeyError: 'x'
506
507 During handling of the above exception, another exception occurred:
508
509 Traceback (most recent call last):
510 File "<stdin>", line 1, in <module>
511 File "<stdin>", line 8, in __getattr__
512 AttributeError: x
513
514No debugging capability is lost, as the original exception context remains
515available if needed (for example, if an intervening library has incorrectly
516suppressed valuable underlying details)::
517
518 >>> try:
519 ... D({}).x
520 ... except AttributeError as exc:
521 ... print(repr(exc.__context__))
522 ...
523 KeyError('x',)
524
R David Murrayf23e2b62012-09-29 19:41:26 -0400525.. seealso::
526
527 :pep:`409` - Suppressing exception context
528 PEP written by Ethan Furman; implemented by Ethan Furman and Nick
529 Coghlan.
530
Nick Coghlanab7bf212012-02-26 17:49:52 +1000531
Nick Coghlan98e20702012-03-06 21:50:13 +1000532PEP 414: Explicit Unicode literals
533======================================
534
Nick Coghlan98e20702012-03-06 21:50:13 +1000535To ease the transition from Python 2 for Unicode aware Python applications
536that make heavy use of Unicode literals, Python 3.3 once again supports the
537"``u``" prefix for string literals. This prefix has no semantic significance
538in Python 3, it is provided solely to reduce the number of purely mechanical
539changes in migrating to Python 3, making it easier for developers to focus on
540the more significant semantic changes (such as the stricter default
541separation of binary and text data).
542
R David Murrayf23e2b62012-09-29 19:41:26 -0400543.. seealso::
544
545 :pep:`414` - Explicit Unicode literals
546 PEP written by Armin Ronacher.
547
Nick Coghlan98e20702012-03-06 21:50:13 +1000548
Antoine Pitrou6bbd76b2011-11-25 19:10:05 +0100549PEP 3155: Qualified name for classes and functions
550==================================================
551
Antoine Pitrou6bbd76b2011-11-25 19:10:05 +0100552Functions and class objects have a new ``__qualname__`` attribute representing
553the "path" from the module top-level to their definition. For global functions
554and classes, this is the same as ``__name__``. For other functions and classes,
555it provides better information about where they were actually defined, and
556how they might be accessible from the global scope.
557
558Example with (non-bound) methods::
Nick Coghlan2dfe6b02012-01-14 14:19:49 +1000559
Antoine Pitrou6bbd76b2011-11-25 19:10:05 +0100560 >>> class C:
561 ... def meth(self):
562 ... pass
563 >>> C.meth.__name__
564 'meth'
565 >>> C.meth.__qualname__
566 'C.meth'
567
568Example with nested classes::
569
570 >>> class C:
571 ... class D:
572 ... def meth(self):
573 ... pass
574 ...
575 >>> C.D.__name__
576 'D'
577 >>> C.D.__qualname__
578 'C.D'
579 >>> C.D.meth.__name__
580 'meth'
581 >>> C.D.meth.__qualname__
582 'C.D.meth'
583
584Example with nested functions::
585
586 >>> def outer():
587 ... def inner():
588 ... pass
589 ... return inner
590 ...
591 >>> outer().__name__
592 'inner'
593 >>> outer().__qualname__
594 'outer.<locals>.inner'
595
Antoine Pitroue7ede062011-11-25 19:11:26 +0100596The string representation of those objects is also changed to include the
Antoine Pitrou6bbd76b2011-11-25 19:10:05 +0100597new, more precise information::
598
599 >>> str(C.D)
600 "<class '__main__.C.D'>"
601 >>> str(C.D.meth)
602 '<function C.D.meth at 0x7f46b9fe31e0>'
603
R David Murrayf23e2b62012-09-29 19:41:26 -0400604.. seealso::
605
606 :pep:`3155` - Qualified name for classes and functions
607 PEP written and implemented by Antoine Pitrou.
608
Antoine Pitrou6bbd76b2011-11-25 19:10:05 +0100609
Antoine Pitrouc907de92012-08-21 00:53:06 +0200610.. _pep-412:
611
Antoine Pitroud94adb72012-07-07 17:33:42 +0200612PEP 412: Key-Sharing Dictionary
613===============================
614
Antoine Pitroud94adb72012-07-07 17:33:42 +0200615Dictionaries used for the storage of objects' attributes are now able to
616share part of their internal storage between each other (namely, the part
617which stores the keys and their respective hashes). This reduces the memory
618consumption of programs creating many instances of non-builtin types.
619
R David Murrayf23e2b62012-09-29 19:41:26 -0400620.. seealso::
621
622 :pep:`412` - Key-Sharing Dictionary
623 PEP written and implemented by Mark Shannon.
624
Antoine Pitroud94adb72012-07-07 17:33:42 +0200625
Andrew Svetlovac23c9e2012-08-13 21:27:56 +0300626PEP 362: Function Signature Object
627==================================
628
Andrew Svetlovac23c9e2012-08-13 21:27:56 +0300629A new function :func:`inspect.signature` makes introspection of python
630callables easy and straightforward. A broad range of callables is supported:
631python functions, decorated or not, classes, and :func:`functools.partial`
632objects. New classes :class:`inspect.Signature`, :class:`inspect.Parameter`
633and :class:`inspect.BoundArguments` hold information about the call signatures,
634such as, annotations, default values, parameters kinds, and bound arguments,
635which considerably simplifies writing decorators and any code that validates
636or amends calling signatures or arguments.
637
R David Murrayf23e2b62012-09-29 19:41:26 -0400638.. seealso::
639
640 :pep:`362`: - Function Signature Object
641 PEP written by Brett Cannon, Yury Selivanov, Larry Hastings, Jiwon Seo;
642 implemented by Yury Selivanov.
643
Andrew Svetlovac23c9e2012-08-13 21:27:56 +0300644
Eric Snowb2a61e12012-09-05 22:19:38 -0700645PEP 421: Adding sys.implementation
646==================================
647
Eric Snowb2a61e12012-09-05 22:19:38 -0700648A new attribute on the :mod:`sys` module exposes details specific to the
649implementation of the currently running interpreter. The initial set of
650attributes on :attr:`sys.implementation` are ``name``, ``version``,
651``hexversion``, and ``cache_tag``.
652
653The intention of ``sys.implementation`` is to consolidate into one namespace
654the implementation-specific data used by the standard library. This allows
655different Python implementations to share a single standard library code base
656much more easily. In its initial state, ``sys.implementation`` holds only a
657small portion of the implementation-specific data. Over time that ratio will
658shift in order to make the standard library more portable.
659
660One example of improved standard library portability is ``cache_tag``. As of
661Python 3.3, ``sys.implementation.cache_tag`` is used by :mod:`importlib` to
662support :pep:`3147` compliance. Any Python implementation that uses
663``importlib`` for its built-in import system may use ``cache_tag`` to control
664the caching behavior for modules.
665
666SimpleNamespace
667---------------
668
669The implementation of ``sys.implementation`` also introduces a new type to
670Python: :class:`types.SimpleNamespace`. In contrast to a mapping-based
671namespace, like :class:`dict`, ``SimpleNamespace`` is attribute-based, like
672:class:`object`. However, unlike ``object``, ``SimpleNamespace`` instances
673are writable. This means that you can add, remove, and modify the namespace
674through normal attribute access.
675
R David Murrayf23e2b62012-09-29 19:41:26 -0400676.. seealso::
677
678 :pep:`421` - Adding sys.implementation
679 PEP written and implemented by Eric Snow.
680
Eric Snowb2a61e12012-09-05 22:19:38 -0700681
Antoine Pitrouc907de92012-08-21 00:53:06 +0200682.. _importlib:
683
Brett Cannonc2043482012-04-29 20:59:41 -0400684Using importlib as the Implementation of Import
685===============================================
686:issue:`2377` - Replace __import__ w/ importlib.__import__
687:issue:`13959` - Re-implement parts of :mod:`imp` in pure Python
688:issue:`14605` - Make import machinery explicit
689:issue:`14646` - Require loaders set __loader__ and __package__
690
Brett Cannonc2043482012-04-29 20:59:41 -0400691The :func:`__import__` function is now powered by :func:`importlib.__import__`.
692This work leads to the completion of "phase 2" of :pep:`302`. There are
693multiple benefits to this change. First, it has allowed for more of the
694machinery powering import to be exposed instead of being implicit and hidden
695within the C code. It also provides a single implementation for all Python VMs
696supporting Python 3.3 to use, helping to end any VM-specific deviations in
697import semantics. And finally it eases the maintenance of import, allowing for
698future growth to occur.
699
R David Murraycff1c6f2012-09-29 14:34:43 -0400700For the common user, there should be no visible change in semantics. For
701those whose code currently manipulates import or calls import
702programmatically, the code changes that might possibly be required are covered
703in the `Porting Python code`_ section of this document.
Brett Cannonc2043482012-04-29 20:59:41 -0400704
705New APIs
706--------
707One of the large benefits of this work is the exposure of what goes into
708making the import statement work. That means the various importers that were
709once implicit are now fully exposed as part of the :mod:`importlib` package.
710
Brett Cannon077ef452012-08-02 17:50:06 -0400711The abstract base classes defined in :mod:`importlib.abc` have been expanded
712to properly delineate between :term:`meta path finders <meta path finder>`
713and :term:`path entry finders <path entry finder>` by introducing
714:class:`importlib.abc.MetaPathFinder` and
715:class:`importlib.abc.PathEntryFinder`, respectively. The old ABC of
716:class:`importlib.abc.Finder` is now only provided for backwards-compatibility
717and does not enforce any method requirements.
718
719In terms of finders, :class:`importlib.machinery.FileFinder` exposes the
Brett Cannonc2043482012-04-29 20:59:41 -0400720mechanism used to search for source and bytecode files of a module. Previously
721this class was an implicit member of :attr:`sys.path_hooks`.
722
723For loaders, the new abstract base class :class:`importlib.abc.FileLoader` helps
724write a loader that uses the file system as the storage mechanism for a module's
725code. The loader for source files
726(:class:`importlib.machinery.SourceFileLoader`), sourceless bytecode files
727(:class:`importlib.machinery.SourcelessFileLoader`), and extension modules
728(:class:`importlib.machinery.ExtensionFileLoader`) are now available for
729direct use.
730
731:exc:`ImportError` now has ``name`` and ``path`` attributes which are set when
732there is relevant data to provide. The message for failed imports will also
733provide the full name of the module now instead of just the tail end of the
734module's name.
735
736The :func:`importlib.invalidate_caches` function will now call the method with
737the same name on all finders cached in :attr:`sys.path_importer_cache` to help
738clean up any stored state as necessary.
739
740Visible Changes
741---------------
R David Murrayf23e2b62012-09-29 19:41:26 -0400742
743For potential required changes to code, see the `Porting Python code`_
744section.
Brett Cannonc2043482012-04-29 20:59:41 -0400745
746Beyond the expanse of what :mod:`importlib` now exposes, there are other
747visible changes to import. The biggest is that :attr:`sys.meta_path` and
Brett Cannon077ef452012-08-02 17:50:06 -0400748:attr:`sys.path_hooks` now store all of the meta path finders and path entry
749hooks used by import. Previously the finders were implicit and hidden within
750the C code of import instead of being directly exposed. This means that one can
751now easily remove or change the order of the various finders to fit one's needs.
Brett Cannonc2043482012-04-29 20:59:41 -0400752
753Another change is that all modules have a ``__loader__`` attribute, storing the
754loader used to create the module. :pep:`302` has been updated to make this
755attribute mandatory for loaders to implement, so in the future once 3rd-party
756loaders have been updated people will be able to rely on the existence of the
757attribute. Until such time, though, import is setting the module post-load.
758
759Loaders are also now expected to set the ``__package__`` attribute from
760:pep:`366`. Once again, import itself is already setting this on all loaders
761from :mod:`importlib` and import itself is setting the attribute post-load.
762
763``None`` is now inserted into :attr:`sys.path_importer_cache` when no finder
764can be found on :attr:`sys.path_hooks`. Since :class:`imp.NullImporter` is not
765directly exposed on :attr:`sys.path_hooks` it could no longer be relied upon to
766always be available to use as a value representing no finder found.
767
768All other changes relate to semantic changes which should be taken into
769consideration when updating code for Python 3.3, and thus should be read about
770in the `Porting Python code`_ section of this document.
771
R David Murrayf23e2b62012-09-29 19:41:26 -0400772(Implementation by Brett Cannon)
773
Brett Cannonc2043482012-04-29 20:59:41 -0400774
Giampaolo Rodolà3108f982011-02-24 20:59:48 +0000775Other Language Changes
776======================
777
778Some smaller changes made to the core Python language are:
779
Antoine Pitrou7b578b32011-11-29 22:47:11 +0100780* Added support for Unicode name aliases and named sequences.
781 Both :func:`unicodedata.lookup()` and ``'\N{...}'`` now resolve name aliases,
782 and :func:`unicodedata.lookup()` resolves named sequences too.
Giampaolo Rodolà3108f982011-02-24 20:59:48 +0000783
Serhiy Storchakae5cf4862014-11-02 19:18:52 +0200784 (Contributed by Ezio Melotti in :issue:`12753`.)
Ezio Melotti931b8aa2011-10-21 21:57:36 +0300785
Nick Coghlanc4bacd32012-09-27 19:58:31 +1000786* Unicode database updated to UCD version 6.1.0
787
Antoine Pitrou7b578b32011-11-29 22:47:11 +0100788* Equality comparisons on :func:`range` objects now return a result reflecting
789 the equality of the underlying sequences generated by those range objects.
Sandro Tosicd899122012-01-22 12:16:04 +0100790 (:issue:`13201`)
Giampaolo Rodolà3108f982011-02-24 20:59:48 +0000791
Antoine Pitrou7b578b32011-11-29 22:47:11 +0100792* The ``count()``, ``find()``, ``rfind()``, ``index()`` and ``rindex()``
793 methods of :class:`bytes` and :class:`bytearray` objects now accept an
794 integer between 0 and 255 as their first argument.
Mark Dickinson36645682011-10-23 19:53:01 +0100795
Serhiy Storchakae5cf4862014-11-02 19:18:52 +0200796 (Contributed by Petri Lehtinen in :issue:`12170`.)
Mark Dickinson36645682011-10-23 19:53:01 +0100797
R David Murraye54c7182012-10-16 21:52:24 -0400798* The ``rjust()``, ``ljust()``, and ``center()`` methods of :class:`bytes`
799 and :class:`bytearray` now accept a :class:`bytearray` for the ``fill``
800 argument. (Contributed by Petri Lehtinen in :issue:`12380`.)
801
Eli Bendersky7add4ea2012-03-17 15:14:35 +0200802* New methods have been added to :class:`list` and :class:`bytearray`:
R David Murrayd2489cf2012-09-30 17:28:54 -0400803 ``copy()`` and ``clear()`` (:issue:`10516`). Consequently,
804 :class:`~collections.abc.MutableSequence` now also defines a
805 :meth:`~collections.abc.MutableSequence.clear` method (:issue:`11388`).
Petri Lehtinen61ea8a02011-11-24 22:00:46 +0200806
Antoine Pitrou9a864472012-05-04 23:15:47 +0200807* Raw bytes literals can now be written ``rb"..."`` as well as ``br"..."``.
R David Murrayf23e2b62012-09-29 19:41:26 -0400808
Antoine Pitrou9a864472012-05-04 23:15:47 +0200809 (Contributed by Antoine Pitrou in :issue:`13748`.)
810
811* :meth:`dict.setdefault` now does only one lookup for the given key, making
812 it atomic when used with built-in types.
R David Murrayf23e2b62012-09-29 19:41:26 -0400813
Antoine Pitrou9a864472012-05-04 23:15:47 +0200814 (Contributed by Filip Gruszczyński in :issue:`13521`.)
815
R David Murrayf23e2b62012-09-29 19:41:26 -0400816* The error messages produced when a function call does not match the function
817 signature have been significantly improved.
Antoine Pitrou9a864472012-05-04 23:15:47 +0200818
R David Murrayf23e2b62012-09-29 19:41:26 -0400819 (Contributed by Benjamin Peterson.)
Benjamin Petersone50d6ab2012-04-03 00:52:18 -0400820
Antoine Pitrou9a864472012-05-04 23:15:47 +0200821
Antoine Pitrou79341e72012-05-17 21:13:45 +0200822A Finer-Grained Import Lock
823===========================
824
825Previous versions of CPython have always relied on a global import lock.
826This led to unexpected annoyances, such as deadlocks when importing a module
827would trigger code execution in a different thread as a side-effect.
828Clumsy workarounds were sometimes employed, such as the
829:c:func:`PyImport_ImportModuleNoBlock` C API function.
830
831In Python 3.3, importing a module takes a per-module lock. This correctly
832serializes importation of a given module from multiple threads (preventing
833the exposure of incompletely initialized modules), while eliminating the
834aforementioned annoyances.
835
R David Murrayf23e2b62012-09-29 19:41:26 -0400836(Contributed by Antoine Pitrou in :issue:`9260`.)
Antoine Pitrou79341e72012-05-17 21:13:45 +0200837
838
Victor Stinner8f17c1c2012-08-05 16:31:32 +0200839Builtin functions and types
840===========================
Victor Stinnerfa0d6282012-08-05 15:56:51 +0200841
Victor Stinner8f17c1c2012-08-05 16:31:32 +0200842* :func:`open` gets a new *opener* parameter: the underlying file descriptor
843 for the file object is then obtained by calling *opener* with (*file*,
844 *flags*). It can be used to use custom flags like :data:`os.O_CLOEXEC` for
845 example. The ``'x'`` mode was added: open for exclusive creation, failing if
846 the file already exists.
847* :func:`print`: added the *flush* keyword argument. If the *flush* keyword
848 argument is true, the stream is forcibly flushed.
849* :func:`hash`: hash randomization is enabled by default, see
850 :meth:`object.__hash__` and :envvar:`PYTHONHASHSEED`.
851* The :class:`str` type gets a new :meth:`~str.casefold` method: return a
852 casefolded copy of the string, casefolded strings may be used for caseless
853 matching. For example, ``'ß'.casefold()`` returns ``'ss'``.
Nick Coghlan273069c2012-08-20 17:14:07 +1000854* The sequence documentation has been substantially rewritten to better
855 explain the binary/text sequence distinction and to provide specific
856 documentation sections for the individual builtin sequence types
Serhiy Storchakae5cf4862014-11-02 19:18:52 +0200857 (:issue:`4966`).
Victor Stinnerfa0d6282012-08-05 15:56:51 +0200858
R David Murrayf23e2b62012-09-29 19:41:26 -0400859
Victor Stinner636130e2012-08-05 16:37:12 +0200860New Modules
861===========
862
863faulthandler
864------------
865
Victor Stinner1da769a2012-09-18 22:40:03 +0200866This new debug module :mod:`faulthandler` contains functions to dump Python tracebacks explicitly,
Victor Stinner636130e2012-08-05 16:37:12 +0200867on a fault (a crash like a segmentation fault), after a timeout, or on a user
868signal. Call :func:`faulthandler.enable` to install fault handlers for the
869:const:`SIGSEGV`, :const:`SIGFPE`, :const:`SIGABRT`, :const:`SIGBUS`, and
870:const:`SIGILL` signals. You can also enable them at startup by setting the
871:envvar:`PYTHONFAULTHANDLER` environment variable or by using :option:`-X`
872``faulthandler`` command line option.
873
874Example of a segmentation fault on Linux: ::
875
876 $ python -q -X faulthandler
877 >>> import ctypes
878 >>> ctypes.string_at(0)
879 Fatal Python error: Segmentation fault
880
881 Current thread 0x00007fb899f39700:
882 File "/home/python/cpython/Lib/ctypes/__init__.py", line 486 in string_at
883 File "<stdin>", line 1 in <module>
884 Segmentation fault
885
886
887ipaddress
888---------
889
890The new :mod:`ipaddress` module provides tools for creating and manipulating
891objects representing IPv4 and IPv6 addresses, networks and interfaces (i.e.
892an IP address associated with a specific IP subnet).
893
Serhiy Storchakae5cf4862014-11-02 19:18:52 +0200894(Contributed by Google and Peter Moody in :pep:`3144`.)
Victor Stinner636130e2012-08-05 16:37:12 +0200895
896lzma
897----
898
899The newly-added :mod:`lzma` module provides data compression and decompression
900using the LZMA algorithm, including support for the ``.xz`` and ``.lzma``
901file formats.
902
Serhiy Storchakae5cf4862014-11-02 19:18:52 +0200903(Contributed by Nadeem Vawda and Per Øyvind Karlsen in :issue:`6715`.)
Victor Stinner636130e2012-08-05 16:37:12 +0200904
905
906Improved Modules
907================
Giampaolo Rodolà3108f982011-02-24 20:59:48 +0000908
Victor Stinnerf4c54ff2012-02-08 01:48:34 +0100909abc
910---
911
912Improved support for abstract base classes containing descriptors composed with
913abstract methods. The recommended approach to declaring abstract descriptors is
914now to provide :attr:`__isabstractmethod__` as a dynamically updated
915property. The built-in descriptors have been updated accordingly.
916
917 * :class:`abc.abstractproperty` has been deprecated, use :class:`property`
918 with :func:`abc.abstractmethod` instead.
919 * :class:`abc.abstractclassmethod` has been deprecated, use
920 :class:`classmethod` with :func:`abc.abstractmethod` instead.
921 * :class:`abc.abstractstaticmethod` has been deprecated, use
922 :class:`staticmethod` with :func:`abc.abstractmethod` instead.
923
Serhiy Storchakae5cf4862014-11-02 19:18:52 +0200924(Contributed by Darren Dale in :issue:`11610`.)
Victor Stinnerf4c54ff2012-02-08 01:48:34 +0100925
R David Murrayd2489cf2012-09-30 17:28:54 -0400926:meth:`abc.ABCMeta.register` now returns the registered subclass, which means
927it can now be used as a class decorator (:issue:`10868`).
928
929
Meador Ingec5dbb3d2011-09-20 21:48:16 -0500930array
931-----
932
933The :mod:`array` module supports the :c:type:`long long` type using ``q`` and
934``Q`` type codes.
935
Serhiy Storchakae5cf4862014-11-02 19:18:52 +0200936(Contributed by Oren Tirosh and Hirokazu Yamamoto in :issue:`1172711`.)
Meador Ingec5dbb3d2011-09-20 21:48:16 -0500937
938
R David Murrayf4c27572012-10-06 23:19:17 -0400939base64
940------
Victor Stinner8f17c1c2012-08-05 16:31:32 +0200941
942ASCII-only Unicode strings are now accepted by the decoding functions of the
R David Murrayf4c27572012-10-06 23:19:17 -0400943:mod:`base64` modern interface. For example, ``base64.b64decode('YWJj')``
944returns ``b'abc'``. (Contributed by Catalin Iacob in :issue:`13641`.)
Victor Stinner8f17c1c2012-08-05 16:31:32 +0200945
946
R David Murrayfd740962012-10-06 22:08:08 -0400947binascii
948--------
949
950In addition to the binary objects they normally accept, the ``a2b_`` functions
951now all also accept ASCII-only strings as input. (Contributed by Antoine
952Pitrou in :issue:`13637`.)
953
954
Nadeem Vawdad7e5c6e2012-02-12 01:34:18 +0200955bz2
956---
957
958The :mod:`bz2` module has been rewritten from scratch. In the process, several
959new features have been added:
960
Victor Stinner8f17c1c2012-08-05 16:31:32 +0200961* New :func:`bz2.open` function: open a bzip2-compressed file in binary or
962 text mode.
963
Nadeem Vawdad7e5c6e2012-02-12 01:34:18 +0200964* :class:`bz2.BZ2File` can now read from and write to arbitrary file-like
965 objects, by means of its constructor's *fileobj* argument.
966
Serhiy Storchakae5cf4862014-11-02 19:18:52 +0200967 (Contributed by Nadeem Vawda in :issue:`5863`.)
Nadeem Vawdad7e5c6e2012-02-12 01:34:18 +0200968
969* :class:`bz2.BZ2File` and :func:`bz2.decompress` can now decompress
970 multi-stream inputs (such as those produced by the :program:`pbzip2` tool).
971 :class:`bz2.BZ2File` can now also be used to create this type of file, using
972 the ``'a'`` (append) mode.
973
Serhiy Storchakae5cf4862014-11-02 19:18:52 +0200974 (Contributed by Nir Aides in :issue:`1625`.)
Nadeem Vawdad7e5c6e2012-02-12 01:34:18 +0200975
976* :class:`bz2.BZ2File` now implements all of the :class:`io.BufferedIOBase` API,
977 except for the :meth:`detach` and :meth:`truncate` methods.
978
979
Victor Stinner2cded9c2011-07-08 01:45:13 +0200980codecs
981------
982
Antoine Pitrou4f863432012-02-12 02:12:47 +0100983The :mod:`~encodings.mbcs` codec has been rewritten to handle correctly
Georg Brandlff962c52012-02-04 08:55:56 +0100984``replace`` and ``ignore`` error handlers on all Windows versions. The
985:mod:`~encodings.mbcs` codec now supports all error handlers, instead of only
986``replace`` to encode and ``ignore`` to decode.
Victor Stinner3a50e702011-10-18 21:21:00 +0200987
Georg Brandlff962c52012-02-04 08:55:56 +0100988A new Windows-only codec has been added: ``cp65001`` (:issue:`13216`). It is the
989Windows code page 65001 (Windows UTF-8, ``CP_UTF8``). For example, it is used
990by ``sys.stdout`` if the console output code page is set to cp65001 (e.g., using
991``chcp 65001`` command).
Victor Stinner2f3ca9f2011-10-27 01:38:56 +0200992
Georg Brandlff962c52012-02-04 08:55:56 +0100993Multibyte CJK decoders now resynchronize faster. They only ignore the first
Georg Brandl6c0929b2011-07-09 11:43:33 +0200994byte of an invalid byte sequence. For example, ``b'\xff\n'.decode('gb2312',
995'replace')`` now returns a ``\n`` after the replacement character.
Victor Stinner2cded9c2011-07-08 01:45:13 +0200996
Georg Brandl6c0929b2011-07-09 11:43:33 +0200997(:issue:`12016`)
Victor Stinner2cded9c2011-07-08 01:45:13 +0200998
Georg Brandlff962c52012-02-04 08:55:56 +0100999Incremental CJK codec encoders are no longer reset at each call to their
1000encode() methods. For example::
Victor Stinner2cded9c2011-07-08 01:45:13 +02001001
1002 $ ./python -q
1003 >>> import codecs
1004 >>> encoder = codecs.getincrementalencoder('hz')('strict')
1005 >>> b''.join(encoder.encode(x) for x in '\u52ff\u65bd\u65bc\u4eba\u3002 Bye.')
1006 b'~{NpJ)l6HK!#~} Bye.'
1007
Georg Brandl6c0929b2011-07-09 11:43:33 +02001008This example gives ``b'~{Np~}~{J)~}~{l6~}~{HK~}~{!#~} Bye.'`` with older Python
Victor Stinner2cded9c2011-07-08 01:45:13 +02001009versions.
1010
Georg Brandl6c0929b2011-07-09 11:43:33 +02001011(:issue:`12100`)
Victor Stinner2cded9c2011-07-08 01:45:13 +02001012
Victor Stinner9f4b1e92011-11-10 20:56:30 +01001013The ``unicode_internal`` codec has been deprecated.
1014
Éric Araujo4f61a2d2012-04-04 23:01:01 -04001015
1016collections
1017-----------
1018
1019Addition of a new :class:`~collections.ChainMap` class to allow treating a
R David Murraya21e5152012-10-06 16:29:14 -04001020number of mappings as a single unit. (Written by Raymond Hettinger for
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001021:issue:`11089`, made public in :issue:`11297`.)
Éric Araujo4f61a2d2012-04-04 23:01:01 -04001022
1023The abstract base classes have been moved in a new :mod:`collections.abc`
1024module, to better differentiate between the abstract and the concrete
1025collections classes. Aliases for ABCs are still present in the
R David Murraya21e5152012-10-06 16:29:14 -04001026:mod:`collections` module to preserve existing imports. (:issue:`11085`)
Éric Araujo4f61a2d2012-04-04 23:01:01 -04001027
1028.. XXX addition of __slots__ to ABCs not recorded here: internal detail
1029
R David Murraya21e5152012-10-06 16:29:14 -04001030The :class:`~collections.Counter` class now supports the unary ``+`` and ``-``
1031operators, as well as the in-place operators ``+=``, ``-=``, ``|=``, and
1032``&=``. (Contributed by Raymond Hettinger in :issue:`13121`.)
1033
Éric Araujo4f61a2d2012-04-04 23:01:01 -04001034
Nick Coghlan3267a302012-05-21 22:54:43 +10001035contextlib
1036----------
1037
Giampaolo Rodola'15c88492012-09-25 12:00:04 -07001038:class:`~contextlib.ExitStack` now provides a solid foundation for
Nick Coghlan3267a302012-05-21 22:54:43 +10001039programmatic manipulation of context managers and similar cleanup
1040functionality. Unlike the previous ``contextlib.nested`` API (which was
1041deprecated and removed), the new API is designed to work correctly
1042regardless of whether context managers acquire their resources in
Nick Coghlan161ea6a2012-05-22 23:04:42 +10001043their ``__init__`` method (for example, file objects) or in their
Nick Coghlan3267a302012-05-21 22:54:43 +10001044``__enter__`` method (for example, synchronisation objects from the
1045:mod:`threading` module).
1046
1047(:issue:`13585`)
1048
1049
Éric Araujo84b8ed82011-08-29 21:42:47 +02001050crypt
1051-----
1052
Victor Stinner8f17c1c2012-08-05 16:31:32 +02001053Addition of salt and modular crypt format (hashing method) and the :func:`~crypt.mksalt`
Victor Stinnerc78fb332011-09-21 03:35:44 +02001054function to the :mod:`crypt` module.
Éric Araujo84b8ed82011-08-29 21:42:47 +02001055
1056(:issue:`10924`)
1057
Victor Stinnera7878b72011-07-14 23:07:44 +02001058curses
1059------
1060
Victor Stinner0fdfceb2011-11-25 22:10:02 +01001061 * If the :mod:`curses` module is linked to the ncursesw library, use Unicode
1062 functions when Unicode strings or characters are passed (e.g.
1063 :c:func:`waddwstr`), and bytes functions otherwise (e.g. :c:func:`waddstr`).
1064 * Use the locale encoding instead of ``utf-8`` to encode Unicode strings.
1065 * :class:`curses.window` has a new :attr:`curses.window.encoding` attribute.
Victor Stinnerc78fb332011-09-21 03:35:44 +02001066 * The :class:`curses.window` class has a new :meth:`~curses.window.get_wch`
1067 method to get a wide character
1068 * The :mod:`curses` module has a new :meth:`~curses.unget_wch` function to
1069 push a wide character so the next :meth:`~curses.window.get_wch` will return
1070 it
Victor Stinnera7878b72011-07-14 23:07:44 +02001071
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001072(Contributed by Iñigo Serna in :issue:`6755`.)
Victor Stinnera7878b72011-07-14 23:07:44 +02001073
Victor Stinner8f17c1c2012-08-05 16:31:32 +02001074datetime
1075--------
1076
1077 * Equality comparisons between naive and aware :class:`~datetime.datetime`
R David Murrayd2489cf2012-09-30 17:28:54 -04001078 instances now return :const:`False` instead of raising :exc:`TypeError`
1079 (:issue:`15006`).
Victor Stinner8f17c1c2012-08-05 16:31:32 +02001080 * New :meth:`datetime.datetime.timestamp` method: Return POSIX timestamp
1081 corresponding to the :class:`~datetime.datetime` instance.
1082 * The :meth:`datetime.datetime.strftime` method supports formatting years
1083 older than 1000.
R David Murraydefdb162012-09-29 10:53:31 -04001084 * The :meth:`datetime.datetime.astimezone` method can now be
Alexander Belopolsky35d600c2012-08-22 23:14:29 -04001085 called without arguments to convert datetime instance to the system
1086 timezone.
Victor Stinner8f17c1c2012-08-05 16:31:32 +02001087
R David Murrayf23e2b62012-09-29 19:41:26 -04001088
1089.. _new-decimal:
1090
Stefan Krah1919b7e2012-03-21 18:25:23 +01001091decimal
1092-------
1093
1094:issue:`7652` - integrate fast native decimal arithmetic.
1095 C-module and libmpdec written by Stefan Krah.
1096
1097The new C version of the decimal module integrates the high speed libmpdec
Stefan Krahbf803082012-04-01 13:07:24 +02001098library for arbitrary precision correctly-rounded decimal floating point
1099arithmetic. libmpdec conforms to IBM's General Decimal Arithmetic Specification.
Stefan Krah1919b7e2012-03-21 18:25:23 +01001100
Stefan Krah0c0914e2012-04-09 20:31:15 +02001101Performance gains range from 10x for database applications to 100x for
Stefan Krahbf803082012-04-01 13:07:24 +02001102numerically intensive applications. These numbers are expected gains
1103for standard precisions used in decimal floating point arithmetic. Since
1104the precision is user configurable, the exact figures may vary. For example,
1105in integer bignum arithmetic the differences can be significantly higher.
1106
1107The following table is meant as an illustration. Benchmarks are available
Georg Brandl204e7892012-04-01 13:10:58 +02001108at http://www.bytereef.org/mpdecimal/quickstart.html.
Stefan Krah1919b7e2012-03-21 18:25:23 +01001109
1110 +---------+-------------+--------------+-------------+
1111 | | decimal.py | _decimal | speedup |
1112 +=========+=============+==============+=============+
Stefan Kraha3f4a162012-09-01 14:27:51 +02001113 | pi | 42.02s | 0.345s | 120x |
Stefan Krah1919b7e2012-03-21 18:25:23 +01001114 +---------+-------------+--------------+-------------+
1115 | telco | 172.19s | 5.68s | 30x |
1116 +---------+-------------+--------------+-------------+
1117 | psycopg | 3.57s | 0.29s | 12x |
1118 +---------+-------------+--------------+-------------+
1119
1120Features
1121~~~~~~~~
1122
1123* The :exc:`~decimal.FloatOperation` signal optionally enables stricter
1124 semantics for mixing floats and Decimals.
1125
1126* If Python is compiled without threads, the C version automatically
1127 disables the expensive thread local context machinery. In this case,
Serhiy Storchakafbc1c262013-11-29 12:17:13 +02001128 the variable :data:`~decimal.HAVE_THREADS` is set to ``False``.
Stefan Krah1919b7e2012-03-21 18:25:23 +01001129
1130API changes
1131~~~~~~~~~~~
1132
1133* The C module has the following context limits, depending on the machine
1134 architecture:
1135
1136 +-------------------+---------------------+------------------------------+
1137 | | 32-bit | 64-bit |
1138 +===================+=====================+==============================+
1139 | :const:`MAX_PREC` | :const:`425000000` | :const:`999999999999999999` |
1140 +-------------------+---------------------+------------------------------+
1141 | :const:`MAX_EMAX` | :const:`425000000` | :const:`999999999999999999` |
1142 +-------------------+---------------------+------------------------------+
1143 | :const:`MIN_EMIN` | :const:`-425000000` | :const:`-999999999999999999` |
1144 +-------------------+---------------------+------------------------------+
1145
1146* In the context templates (:class:`~decimal.DefaultContext`,
1147 :class:`~decimal.BasicContext` and :class:`~decimal.ExtendedContext`)
1148 the magnitude of :attr:`~decimal.Context.Emax` and
1149 :attr:`~decimal.Context.Emin` has changed to :const:`999999`.
1150
1151* The :class:`~decimal.Decimal` constructor in decimal.py does not observe
1152 the context limits and converts values with arbitrary exponents or precision
1153 exactly. Since the C version has internal limits, the following scheme is
1154 used: If possible, values are converted exactly, otherwise
1155 :exc:`~decimal.InvalidOperation` is raised and the result is NaN. In the
1156 latter case it is always possible to use :meth:`~decimal.Context.create_decimal`
1157 in order to obtain a rounded or inexact value.
1158
1159
1160* The power function in decimal.py is always correctly-rounded. In the
1161 C version, it is defined in terms of the correctly-rounded
1162 :meth:`~decimal.Decimal.exp` and :meth:`~decimal.Decimal.ln` functions,
1163 but the final result is only "almost always correctly rounded".
1164
1165
1166* In the C version, the context dictionary containing the signals is a
1167 :class:`~collections.abc.MutableMapping`. For speed reasons,
1168 :attr:`~decimal.Context.flags` and :attr:`~decimal.Context.traps` always
1169 refer to the same :class:`~collections.abc.MutableMapping` that the context
1170 was initialized with. If a new signal dictionary is assigned,
1171 :attr:`~decimal.Context.flags` and :attr:`~decimal.Context.traps`
1172 are updated with the new values, but they do not reference the RHS
1173 dictionary.
1174
1175
1176* Pickling a :class:`~decimal.Context` produces a different output in order
1177 to have a common interchange format for the Python and C versions.
1178
1179
1180* The order of arguments in the :class:`~decimal.Context` constructor has been
1181 changed to match the order displayed by :func:`repr`.
1182
1183
Stefan Krahaf3f3a72012-08-30 12:33:55 +02001184* The ``watchexp`` parameter in the :meth:`~decimal.Decimal.quantize` method
1185 is deprecated.
1186
1187
R David Murrayf23e2b62012-09-29 19:41:26 -04001188.. _new-email:
1189
R David Murray77ac3512012-09-29 15:43:33 -04001190email
1191-----
1192
1193Policy Framework
1194~~~~~~~~~~~~~~~~
1195
1196The email package now has a :mod:`~email.policy` framework. A
1197:class:`~email.policy.Policy` is an object with several methods and properties
1198that control how the email package behaves. The primary policy for Python 3.3
1199is the :class:`~email.policy.Compat32` policy, which provides backward
1200compatibility with the email package in Python 3.2. A ``policy`` can be
1201specified when an email message is parsed by a :mod:`~email.parser`, or when a
1202:class:`~email.message.Message` object is created, or when an email is
1203serialized using a :mod:`~email.generator`. Unless overridden, a policy passed
1204to a ``parser`` is inherited by all the ``Message`` object and sub-objects
1205created by the ``parser``. By default a ``generator`` will use the policy of
1206the ``Message`` object it is serializing. The default policy is
1207:data:`~email.policy.compat32`.
1208
1209The minimum set of controls implemented by all ``policy`` objects are:
1210
Georg Brandl44ea77b2013-03-28 13:28:44 +01001211 .. tabularcolumns:: |l|L|
1212
R David Murray77ac3512012-09-29 15:43:33 -04001213 =============== =======================================================
1214 max_line_length The maximum length, excluding the linesep character(s),
1215 individual lines may have when a ``Message`` is
1216 serialized. Defaults to 78.
1217
1218 linesep The character used to separate individual lines when a
1219 ``Message`` is serialized. Defaults to ``\n``.
1220
1221 cte_type ``7bit`` or ``8bit``. ``8bit`` applies only to a
1222 ``Bytes`` ``generator``, and means that non-ASCII may
1223 be used where allowed by the protocol (or where it
1224 exists in the original input).
1225
1226 raise_on_defect Causes a ``parser`` to raise error when defects are
1227 encountered instead of adding them to the ``Message``
1228 object's ``defects`` list.
1229 =============== =======================================================
1230
1231A new policy instance, with new settings, is created using the
1232:meth:`~email.policy.Policy.clone` method of policy objects. ``clone`` takes
1233any of the above controls as keyword arguments. Any control not specified in
1234the call retains its default value. Thus you can create a policy that uses
1235``\r\n`` linesep characters like this::
1236
1237 mypolicy = compat32.clone(linesep='\r\n')
1238
1239Policies can be used to make the generation of messages in the format needed by
1240your application simpler. Instead of having to remember to specify
1241``linesep='\r\n'`` in all the places you call a ``generator``, you can specify
1242it once, when you set the policy used by the ``parser`` or the ``Message``,
1243whichever your program uses to create ``Message`` objects. On the other hand,
1244if you need to generate messages in multiple forms, you can still specify the
1245parameters in the appropriate ``generator`` call. Or you can have custom
1246policy instances for your different cases, and pass those in when you create
1247the ``generator``.
1248
1249
1250Provisional Policy with New Header API
1251~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1252
1253While the policy framework is worthwhile all by itself, the main motivation for
1254introducing it is to allow the creation of new policies that implement new
1255features for the email package in a way that maintains backward compatibility
1256for those who do not use the new policies. Because the new policies introduce a
1257new API, we are releasing them in Python 3.3 as a :term:`provisional policy
1258<provisional package>`. Backwards incompatible changes (up to and including
1259removal of the code) may occur if deemed necessary by the core developers.
1260
1261The new policies are instances of :class:`~email.policy.EmailPolicy`,
1262and add the following additional controls:
1263
Georg Brandl44ea77b2013-03-28 13:28:44 +01001264 .. tabularcolumns:: |l|L|
1265
R David Murray77ac3512012-09-29 15:43:33 -04001266 =============== =======================================================
1267 refold_source Controls whether or not headers parsed by a
1268 :mod:`~email.parser` are refolded by the
1269 :mod:`~email.generator`. It can be ``none``, ``long``,
1270 or ``all``. The default is ``long``, which means that
1271 source headers with a line longer than
1272 ``max_line_length`` get refolded. ``none`` means no
1273 line get refolded, and ``all`` means that all lines
1274 get refolded.
1275
1276 header_factory A callable that take a ``name`` and ``value`` and
1277 produces a custom header object.
1278 =============== =======================================================
1279
1280The ``header_factory`` is the key to the new features provided by the new
1281policies. When one of the new policies is used, any header retrieved from
1282a ``Message`` object is an object produced by the ``header_factory``, and any
1283time you set a header on a ``Message`` it becomes an object produced by
1284``header_factory``. All such header objects have a ``name`` attribute equal
1285to the header name. Address and Date headers have additional attributes
1286that give you access to the parsed data of the header. This means you can now
1287do things like this::
1288
1289 >>> m = Message(policy=SMTP)
1290 >>> m['To'] = 'Éric <foo@example.com>'
1291 >>> m['to']
1292 'Éric <foo@example.com>'
1293 >>> m['to'].addresses
1294 (Address(display_name='Éric', username='foo', domain='example.com'),)
1295 >>> m['to'].addresses[0].username
1296 'foo'
1297 >>> m['to'].addresses[0].display_name
1298 'Éric'
1299 >>> m['Date'] = email.utils.localtime()
1300 >>> m['Date'].datetime
1301 datetime.datetime(2012, 5, 25, 21, 39, 24, 465484, tzinfo=datetime.timezone(datetime.timedelta(-1, 72000), 'EDT'))
1302 >>> m['Date']
1303 'Fri, 25 May 2012 21:44:27 -0400'
1304 >>> print(m)
1305 To: =?utf-8?q?=C3=89ric?= <foo@example.com>
1306 Date: Fri, 25 May 2012 21:44:27 -0400
1307
1308You will note that the unicode display name is automatically encoded as
1309``utf-8`` when the message is serialized, but that when the header is accessed
1310directly, you get the unicode version. This eliminates any need to deal with
1311the :mod:`email.header` :meth:`~email.header.decode_header` or
1312:meth:`~email.header.make_header` functions.
1313
1314You can also create addresses from parts::
1315
1316 >>> m['cc'] = [Group('pals', [Address('Bob', 'bob', 'example.com'),
1317 ... Address('Sally', 'sally', 'example.com')]),
1318 ... Address('Bonzo', addr_spec='bonz@laugh.com')]
1319 >>> print(m)
1320 To: =?utf-8?q?=C3=89ric?= <foo@example.com>
1321 Date: Fri, 25 May 2012 21:44:27 -0400
1322 cc: pals: Bob <bob@example.com>, Sally <sally@example.com>;, Bonzo <bonz@laugh.com>
1323
1324Decoding to unicode is done automatically::
1325
1326 >>> m2 = message_from_string(str(m))
1327 >>> m2['to']
1328 'Éric <foo@example.com>'
1329
1330When you parse a message, you can use the ``addresses`` and ``groups``
1331attributes of the header objects to access the groups and individual
1332addresses::
1333
1334 >>> m2['cc'].addresses
1335 (Address(display_name='Bob', username='bob', domain='example.com'), Address(display_name='Sally', username='sally', domain='example.com'), Address(display_name='Bonzo', username='bonz', domain='laugh.com'))
1336 >>> m2['cc'].groups
1337 (Group(display_name='pals', addresses=(Address(display_name='Bob', username='bob', domain='example.com'), Address(display_name='Sally', username='sally', domain='example.com')), Group(display_name=None, addresses=(Address(display_name='Bonzo', username='bonz', domain='laugh.com'),))
1338
1339In summary, if you use one of the new policies, header manipulation works the
1340way it ought to: your application works with unicode strings, and the email
1341package transparently encodes and decodes the unicode to and from the RFC
1342standard Content Transfer Encodings.
1343
R David Murray445d69c2012-09-30 21:59:56 -04001344Other API Changes
1345~~~~~~~~~~~~~~~~~
1346
R David Murray3430fb82012-10-02 18:24:56 -04001347New :class:`~email.parser.BytesHeaderParser`, added to the :mod:`~email.parser`
1348module to complement :class:`~email.parser.HeaderParser` and complete the Bytes
1349API.
1350
1351New utility functions:
1352
1353 * :func:`~email.utils.format_datetime`: given a :class:`~datetime.datetime`,
1354 produce a string formatted for use in an email header.
1355
1356 * :func:`~email.utils.parsedate_to_datetime`: given a date string from
1357 an email header, convert it into an aware :class:`~datetime.datetime`,
1358 or a naive :class:`~datetime.datetime` if the offset is ``-0000``.
1359
1360 * :func:`~email.utils.localtime`: With no argument, returns the
1361 current local time as an aware :class:`~datetime.datetime` using the local
1362 :class:`~datetime.timezone`. Given an aware :class:`~datetime.datetime`,
1363 converts it into an aware :class:`~datetime.datetime` using the
1364 local :class:`~datetime.timezone`.
R David Murray445d69c2012-09-30 21:59:56 -04001365
R David Murray77ac3512012-09-29 15:43:33 -04001366
Victor Stinner811db3b2011-09-21 03:20:03 +02001367ftplib
1368------
1369
R David Murrayd2489cf2012-09-30 17:28:54 -04001370* :class:`ftplib.FTP` now accepts a ``source_address`` keyword argument to
1371 specify the ``(host, port)`` to use as the source address in the bind call
1372 when creating the outgoing socket. (Contributed by Giampaolo Rodolà
1373 in :issue:`8594`.)
1374
Giampaolo Rodola'49379c02012-09-25 12:32:46 -07001375* The :class:`~ftplib.FTP_TLS` class now provides a new
1376 :func:`~ftplib.FTP_TLS.ccc` function to revert control channel back to
R David Murrayd2489cf2012-09-30 17:28:54 -04001377 plaintext. This can be useful to take advantage of firewalls that know how
1378 to handle NAT with non-secure FTP without opening fixed ports. (Contributed
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001379 by Giampaolo Rodolà in :issue:`12139`.)
Victor Stinner811db3b2011-09-21 03:20:03 +02001380
Giampaolo Rodola'49379c02012-09-25 12:32:46 -07001381* Added :meth:`ftplib.FTP.mlsd` method which provides a parsable directory
1382 listing format and deprecates :meth:`ftplib.FTP.nlst` and
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001383 :meth:`ftplib.FTP.dir`. (Contributed by Giampaolo Rodolà in :issue:`11072`.)
Victor Stinner811db3b2011-09-21 03:20:03 +02001384
R David Murray1e218c92012-10-06 18:18:55 -04001385
1386functools
1387---------
1388
1389The :func:`functools.lru_cache` decorator now accepts a ``typed`` keyword
1390argument (that defaults to ``False`` to ensure that it caches values of
1391different types that compare equal in separate cache slots. (Contributed
1392by Raymond Hettinger in :issue:`13227`.)
1393
1394
Victor Stinner8f17c1c2012-08-05 16:31:32 +02001395gc
1396--
1397
1398It is now possible to register callbacks invoked by the garbage collector
Georg Brandla81b4812012-08-11 08:43:59 +02001399before and after collection using the new :data:`~gc.callbacks` list.
Victor Stinner8f17c1c2012-08-05 16:31:32 +02001400
1401
Christian Heimes31940372012-06-26 10:16:55 +02001402hmac
1403----
1404
R David Murray1e218c92012-10-06 18:18:55 -04001405A new :func:`~hmac.compare_digest` function has been added to prevent side
1406channel attacks on digests through timing analysis. (Contributed by Nick
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001407Coghlan and Christian Heimes in :issue:`15061`.)
Ezio Melotti461f41d2012-09-26 17:43:23 +03001408
1409
R David Murray445d69c2012-09-30 21:59:56 -04001410http
1411----
1412
1413:class:`http.server.BaseHTTPRequestHandler` now buffers the headers and writes
1414them all at once when :meth:`~http.server.BaseHTTPRequestHandler.end_headers` is
1415called. A new method :meth:`~http.server.BaseHTTPRequestHandler.flush_headers`
1416can be used to directly manage when the accumlated headers are sent.
1417(Contributed by Andrew Schaaf in :issue:`3709`.)
1418
R David Murray1e218c92012-10-06 18:18:55 -04001419:class:`http.server` now produces valid ``HTML 4.01 strict`` output.
1420(Contributed by Ezio Melotti in :issue:`13295`.)
R David Murray445d69c2012-09-30 21:59:56 -04001421
R David Murrayfd740962012-10-06 22:08:08 -04001422:class:`http.client.HTTPResponse` now has a
1423:meth:`~http.client.HTTPResponse.readinto` method, which means it can be used
Martin Panter7462b6492015-11-02 03:37:02 +00001424as an :class:`io.RawIOBase` class. (Contributed by John Kuhn in
R David Murrayfd740962012-10-06 22:08:08 -04001425:issue:`13464`.)
1426
Ezio Melotti461f41d2012-09-26 17:43:23 +03001427
R David Murray1e218c92012-10-06 18:18:55 -04001428html
1429----
1430
1431:class:`html.parser.HTMLParser` is now able to parse broken markup without
Ezio Melotti461f41d2012-09-26 17:43:23 +03001432raising errors, therefore the *strict* argument of the constructor and the
1433:exc:`~html.parser.HTMLParseError` exception are now deprecated.
1434The ability to parse broken markup is the result of a number of bug fixes that
1435are also available on the latest bug fix releases of Python 2.7/3.2.
Ezio Melotti461f41d2012-09-26 17:43:23 +03001436(Contributed by Ezio Melotti in :issue:`15114`, and :issue:`14538`,
1437:issue:`13993`, :issue:`13960`, :issue:`13358`, :issue:`1745761`,
1438:issue:`755670`, :issue:`13357`, :issue:`12629`, :issue:`1200313`,
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001439:issue:`670664`, :issue:`13273`, :issue:`12888`, :issue:`7311`.)
Ezio Melotti461f41d2012-09-26 17:43:23 +03001440
R David Murray1e218c92012-10-06 18:18:55 -04001441A new :data:`~html.entities.html5` dictionary that maps HTML5 named character
1442references to the equivalent Unicode character(s) (e.g. ``html5['gt;'] ==
1443'>'``) has been added to the :mod:`html.entities` module. The dictionary is
1444now also used by :class:`~html.parser.HTMLParser`. (Contributed by Ezio
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001445Melotti in :issue:`11113` and :issue:`15156`.)
R David Murray1e218c92012-10-06 18:18:55 -04001446
R David Murray445d69c2012-09-30 21:59:56 -04001447
Antoine Pitrou5a8bc6f2011-11-17 02:20:48 +01001448imaplib
1449-------
1450
1451The :class:`~imaplib.IMAP4_SSL` constructor now accepts an SSLContext
1452parameter to control parameters of the secure channel.
1453
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001454(Contributed by Sijin Joseph in :issue:`8808`.)
Antoine Pitrou5a8bc6f2011-11-17 02:20:48 +01001455
1456
Nick Coghlan2f92e542012-06-23 19:39:55 +10001457inspect
1458-------
1459
1460A new :func:`~inspect.getclosurevars` function has been added. This function
1461reports the current binding of all names referenced from the function body and
1462where those names were resolved, making it easier to verify correct internal
1463state when testing code that relies on stateful closures.
1464
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001465(Contributed by Meador Inge and Nick Coghlan in :issue:`13062`.)
Nick Coghlan2f92e542012-06-23 19:39:55 +10001466
Nick Coghlan04e2e3f2012-06-23 19:52:05 +10001467A new :func:`~inspect.getgeneratorlocals` function has been added. This
1468function reports the current binding of local variables in the generator's
1469stack frame, making it easier to verify correct internal state when testing
1470generators.
1471
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001472(Contributed by Meador Inge in :issue:`15153`.)
Nick Coghlan04e2e3f2012-06-23 19:52:05 +10001473
Charles-François Natalidc3044c2012-01-09 22:40:02 +01001474io
1475--
1476
Charles-François Natalid612de12012-01-14 11:51:00 +01001477The :func:`~io.open` function has a new ``'x'`` mode that can be used to
1478exclusively create a new file, and raise a :exc:`FileExistsError` if the file
1479already exists. It is based on the C11 'x' mode to fopen().
Charles-François Natalidc3044c2012-01-09 22:40:02 +01001480
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001481(Contributed by David Townshend in :issue:`12760`.)
Charles-François Natalidc3044c2012-01-09 22:40:02 +01001482
Victor Stinner8f17c1c2012-08-05 16:31:32 +02001483The constructor of the :class:`~io.TextIOWrapper` class has a new
1484*write_through* optional argument. If *write_through* is ``True``, calls to
1485:meth:`~io.TextIOWrapper.write` are guaranteed not to be buffered: any data
1486written on the :class:`~io.TextIOWrapper` object is immediately handled to its
1487underlying binary buffer.
1488
Charles-François Natalidc3044c2012-01-09 22:40:02 +01001489
R David Murray445d69c2012-09-30 21:59:56 -04001490itertools
1491---------
1492
1493:func:`~itertools.accumulate` now takes an optional ``func`` argument for
1494providing a user-supplied binary function.
1495
1496
1497logging
1498-------
1499
R David Murray3430fb82012-10-02 18:24:56 -04001500The :func:`~logging.basicConfig` function now supports an optional ``handlers``
1501argument taking an iterable of handlers to be added to the root logger.
1502
1503A class level attribute :attr:`~logging.handlers.SysLogHandler.append_nul` has
1504been added to :class:`~logging.handlers.SysLogHandler` to allow control of the
1505appending of the ``NUL`` (``\000``) byte to syslog records, since for some
1506deamons it is required while for others it is passed through to the log.
1507
R David Murray445d69c2012-09-30 21:59:56 -04001508
1509
Victor Stinnerfa0e3d52011-05-09 01:01:09 +02001510math
1511----
1512
R David Murray26d15bf2012-09-29 15:13:35 -04001513The :mod:`math` module has a new function, :func:`~math.log2`, which returns
1514the base-2 logarithm of *x*.
Victor Stinnerfa0e3d52011-05-09 01:01:09 +02001515
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001516(Written by Mark Dickinson in :issue:`11888`.)
Victor Stinnerfa0e3d52011-05-09 01:01:09 +02001517
1518
R David Murray3430fb82012-10-02 18:24:56 -04001519mmap
1520----
1521
1522The :meth:`~mmap.mmap.read` method is now more compatible with other file-like
1523objects: if the argument is omitted or specified as ``None``, it returns the
1524bytes from the current file position to the end of the mapping. (Contributed
1525by Petri Lehtinen in :issue:`12021`.)
1526
1527
Antoine Pitrou9a864472012-05-04 23:15:47 +02001528multiprocessing
1529---------------
1530
Martin Panterc04fb562016-02-10 05:44:01 +00001531The new :func:`multiprocessing.connection.wait` function allows polling
Antoine Pitrou9a864472012-05-04 23:15:47 +02001532multiple objects (such as connections, sockets and pipes) with a timeout.
1533(Contributed by Richard Oudkerk in :issue:`12328`.)
1534
1535:class:`multiprocessing.Connection` objects can now be transferred over
1536multiprocessing connections.
1537(Contributed by Richard Oudkerk in :issue:`4892`.)
1538
R David Murrayd2489cf2012-09-30 17:28:54 -04001539:class:`multiprocessing.Process` now accepts a ``daemon`` keyword argument
1540to override the default behavior of inheriting the ``daemon`` flag from
1541the parent process (:issue:`6064`).
1542
Serhiy Storchaka56a6d852014-12-01 18:28:43 +02001543New attribute :data:`multiprocessing.Process.sentinel` allows a
R David Murray994ce1a2012-10-02 10:19:08 -04001544program to wait on multiple :class:`~multiprocessing.Process` objects at one
1545time using the appropriate OS primitives (for example, :mod:`select` on
1546posix systems).
1547
R David Murrayace51622012-10-06 22:26:52 -04001548New methods :meth:`multiprocessing.pool.Pool.starmap` and
1549:meth:`~multiprocessing.pool.Pool.starmap_async` provide
1550:func:`itertools.starmap` equivalents to the existing
1551:meth:`multiprocessing.pool.Pool.map` and
1552:meth:`~multiprocessing.pool.Pool.map_async` functions. (Contributed by Hynek
1553Schlawack in :issue:`12708`.)
1554
Antoine Pitrou9a864472012-05-04 23:15:47 +02001555
Victor Stinnerfa0e3d52011-05-09 01:01:09 +02001556nntplib
1557-------
1558
Serhiy Storchaka14867992014-09-10 23:43:41 +03001559The :class:`nntplib.NNTP` class now supports the context management protocol to
Victor Stinnerfa0e3d52011-05-09 01:01:09 +02001560unconditionally consume :exc:`socket.error` exceptions and to close the NNTP
1561connection when done::
1562
1563 >>> from nntplib import NNTP
Ezio Melotti3c14b4e2011-07-13 11:44:44 +03001564 >>> with NNTP('news.gmane.org') as n:
Victor Stinnerfa0e3d52011-05-09 01:01:09 +02001565 ... n.group('gmane.comp.python.committers')
1566 ...
Ezio Melotti04f648c2011-07-26 09:37:46 +03001567 ('211 1755 1 1755 gmane.comp.python.committers', 1755, 1, 1755, 'gmane.comp.python.committers')
Victor Stinnerfa0e3d52011-05-09 01:01:09 +02001568 >>>
1569
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001570(Contributed by Giampaolo Rodolà in :issue:`9795`.)
Victor Stinnerfa0e3d52011-05-09 01:01:09 +02001571
1572
Giampaolo Rodolàc9c2c8b2011-02-25 14:39:16 +00001573os
1574--
1575
Charles-François Natalia003af12011-06-01 20:30:52 +02001576* The :mod:`os` module has a new :func:`~os.pipe2` function that makes it
1577 possible to create a pipe with :data:`~os.O_CLOEXEC` or
1578 :data:`~os.O_NONBLOCK` flags set atomically. This is especially useful to
1579 avoid race conditions in multi-threaded programs.
1580
Giampaolo Rodolà18e8bcb2011-02-25 20:57:54 +00001581* The :mod:`os` module has a new :func:`~os.sendfile` function which provides
Senthil Kumaranb4760ef2015-06-14 17:35:37 -07001582 an efficient "zero-copy" way for copying data from one file (or socket)
Giampaolo Rodolà18e8bcb2011-02-25 20:57:54 +00001583 descriptor to another. The phrase "zero-copy" refers to the fact that all of
1584 the copying of data between the two descriptors is done entirely by the
1585 kernel, with no copying of data into userspace buffers. :func:`~os.sendfile`
1586 can be used to efficiently copy data from a file on disk to a network socket,
1587 e.g. for downloading a file.
Giampaolo Rodolàc9c2c8b2011-02-25 14:39:16 +00001588
Giampaolo Rodolà18e8bcb2011-02-25 20:57:54 +00001589 (Patch submitted by Ross Lagerwall and Giampaolo Rodolà in :issue:`10882`.)
1590
Victor Stinnerfa0d6282012-08-05 15:56:51 +02001591* To avoid race conditions like symlink attacks and issues with temporary
1592 files and directories, it is more reliable (and also faster) to manipulate
1593 file descriptors instead of file names. Python 3.3 enhances existing functions
Victor Stinner8f17c1c2012-08-05 16:31:32 +02001594 and introduces new functions to work on file descriptors (:issue:`4761`,
Larry Hastings94717972012-09-21 09:30:19 -07001595 :issue:`10755` and :issue:`14626`).
Victor Stinnerfa0d6282012-08-05 15:56:51 +02001596
1597 - The :mod:`os` module has a new :func:`~os.fwalk` function similar to
1598 :func:`~os.walk` except that it also yields file descriptors referring to the
1599 directories visited. This is especially useful to avoid symlink races.
1600
1601 - The following functions get new optional *dir_fd* (:ref:`paths relative to
1602 directory descriptors <dir_fd>`) and/or *follow_symlinks* (:ref:`not
1603 following symlinks <follow_symlinks>`):
1604 :func:`~os.access`, :func:`~os.chflags`, :func:`~os.chmod`, :func:`~os.chown`,
1605 :func:`~os.link`, :func:`~os.lstat`, :func:`~os.mkdir`, :func:`~os.mkfifo`,
1606 :func:`~os.mknod`, :func:`~os.open`, :func:`~os.readlink`, :func:`~os.remove`,
1607 :func:`~os.rename`, :func:`~os.replace`, :func:`~os.rmdir`, :func:`~os.stat`,
R David Murrayc652ce62012-09-30 20:07:42 -04001608 :func:`~os.symlink`, :func:`~os.unlink`, :func:`~os.utime`. Platform
1609 support for using these parameters can be checked via the sets
1610 :data:`os.supports_dir_fd` and :data:`os.supports_follows_symlinks`.
Victor Stinnerfa0d6282012-08-05 15:56:51 +02001611
1612 - The following functions now support a file descriptor for their path argument:
1613 :func:`~os.chdir`, :func:`~os.chmod`, :func:`~os.chown`,
Victor Stinner8f17c1c2012-08-05 16:31:32 +02001614 :func:`~os.execve`, :func:`~os.listdir`, :func:`~os.pathconf`, :func:`~os.path.exists`,
R David Murrayc652ce62012-09-30 20:07:42 -04001615 :func:`~os.stat`, :func:`~os.statvfs`, :func:`~os.utime`. Platform support
1616 for this can be checked via the :data:`os.supports_fd` set.
1617
1618* :func:`~os.access` accepts an ``effective_ids`` keyword argument to turn on
1619 using the effective uid/gid rather than the real uid/gid in the access check.
1620 Platform support for this can be checked via the
1621 :data:`~os.supports_effective_ids` set.
Victor Stinnerfa0d6282012-08-05 15:56:51 +02001622
Giampaolo Rodolà18e8bcb2011-02-25 20:57:54 +00001623* The :mod:`os` module has two new functions: :func:`~os.getpriority` and
1624 :func:`~os.setpriority`. They can be used to get or set process
1625 niceness/priority in a fashion similar to :func:`os.nice` but extended to all
1626 processes instead of just the current one.
1627
1628 (Patch submitted by Giampaolo Rodolà in :issue:`10784`.)
Giampaolo Rodolà3108f982011-02-24 20:59:48 +00001629
Antoine Pitrou9a864472012-05-04 23:15:47 +02001630* The new :func:`os.replace` function allows cross-platform renaming of a
1631 file with overwriting the destination. With :func:`os.rename`, an existing
1632 destination file is overwritten under POSIX, but raises an error under
1633 Windows.
1634 (Contributed by Antoine Pitrou in :issue:`8828`.)
1635
Larry Hastings94717972012-09-21 09:30:19 -07001636* The stat family of functions (:func:`~os.stat`, :func:`~os.fstat`,
1637 and :func:`~os.lstat`) now support reading a file's timestamps
1638 with nanosecond precision. Symmetrically, :func:`~os.utime`
1639 can now write file timestamps with nanosecond precision. (Contributed by
1640 Larry Hastings in :issue:`14127`.)
1641
Antoine Pitrou9a864472012-05-04 23:15:47 +02001642* The new :func:`os.get_terminal_size` function queries the size of the
Victor Stinnerfa0d6282012-08-05 15:56:51 +02001643 terminal attached to a file descriptor. See also
1644 :func:`shutil.get_terminal_size`.
Antoine Pitrou9a864472012-05-04 23:15:47 +02001645 (Contributed by Zbigniew Jędrzejewski-Szmek in :issue:`13609`.)
1646
Georg Brandldba3b5c2012-06-26 09:36:14 +02001647.. XXX sort out this mess after beta1
Victor Stinnere5064372011-10-14 00:08:29 +02001648
Victor Stinner8f17c1c2012-08-05 16:31:32 +02001649* New functions to support Linux extended attributes (:issue:`12720`):
Victor Stinnerfa0d6282012-08-05 15:56:51 +02001650 :func:`~os.getxattr`, :func:`~os.listxattr`, :func:`~os.removexattr`,
1651 :func:`~os.setxattr`.
Victor Stinnere5064372011-10-14 00:08:29 +02001652
Victor Stinnerfa0d6282012-08-05 15:56:51 +02001653* New interface to the scheduler. These functions
1654 control how a process is allocated CPU time by the operating system. New
1655 functions:
1656 :func:`~os.sched_get_priority_max`, :func:`~os.sched_get_priority_min`,
1657 :func:`~os.sched_getaffinity`, :func:`~os.sched_getparam`,
1658 :func:`~os.sched_getscheduler`, :func:`~os.sched_rr_get_interval`,
1659 :func:`~os.sched_setaffinity`, :func:`~os.sched_setparam`,
1660 :func:`~os.sched_setscheduler`, :func:`~os.sched_yield`,
Victor Stinnere5064372011-10-14 00:08:29 +02001661
Victor Stinnerfa0d6282012-08-05 15:56:51 +02001662* New functions to control the file system:
Victor Stinnere5064372011-10-14 00:08:29 +02001663
Victor Stinnerfa0d6282012-08-05 15:56:51 +02001664 * :func:`~os.posix_fadvise`: Announces an intention to access data in a
1665 specific pattern thus allowing the kernel to make optimizations.
1666 * :func:`~os.posix_fallocate`: Ensures that enough disk space is allocated
1667 for a file.
1668 * :func:`~os.sync`: Force write of everything to disk.
Victor Stinnere5064372011-10-14 00:08:29 +02001669
R David Murrayc652ce62012-09-30 20:07:42 -04001670* Additional new posix functions:
Victor Stinnere5064372011-10-14 00:08:29 +02001671
Victor Stinnerfa0d6282012-08-05 15:56:51 +02001672 * :func:`~os.lockf`: Apply, test or remove a POSIX lock on an open file descriptor.
1673 * :func:`~os.pread`: Read from a file descriptor at an offset, the file
1674 offset remains unchanged.
1675 * :func:`~os.pwrite`: Write to a file descriptor from an offset, leaving
1676 the file offset unchanged.
1677 * :func:`~os.readv`: Read from a file descriptor into a number of writable buffers.
1678 * :func:`~os.truncate`: Truncate the file corresponding to *path*, so that
1679 it is at most *length* bytes in size.
1680 * :func:`~os.waitid`: Wait for the completion of one or more child processes.
1681 * :func:`~os.writev`: Write the contents of *buffers* to a file descriptor,
1682 where *buffers* is an arbitrary sequence of buffers.
1683 * :func:`~os.getgrouplist` (:issue:`9344`): Return list of group ids that
1684 specified user belongs to.
Victor Stinnere5064372011-10-14 00:08:29 +02001685
Victor Stinnerfa0d6282012-08-05 15:56:51 +02001686* :func:`~os.times` and :func:`~os.uname`: Return type changed from a tuple to
1687 a tuple-like object with named attributes.
Victor Stinnere5064372011-10-14 00:08:29 +02001688
R David Murrayc652ce62012-09-30 20:07:42 -04001689* Some platforms now support additional constants for the :func:`~os.lseek`
1690 function, such as ``os.SEEK_HOLE`` and ``os.SEEK_DATA``.
1691
R David Murray1e218c92012-10-06 18:18:55 -04001692* New constants :data:`~os.RTLD_LAZY`, :data:`~os.RTLD_NOW`,
1693 :data:`~os.RTLD_GLOBAL`, :data:`~os.RTLD_LOCAL`, :data:`~os.RTLD_NODELETE`,
1694 :data:`~os.RTLD_NOLOAD`, and :data:`~os.RTLD_DEEPBIND` are available on
1695 platforms that support them. These are for use with the
1696 :func:`sys.setdlopenflags` function, and supersede the similar constants
1697 defined in :mod:`ctypes` and :mod:`DLFCN`. (Contributed by Victor Stinner
1698 in :issue:`13226`.)
1699
R David Murrayc652ce62012-09-30 20:07:42 -04001700* :func:`os.symlink` now accepts (and ignores) the ``target_is_directory``
1701 keyword argument on non-Windows platforms, to ease cross-platform support.
1702
Giampaolo Rodolà424298a2011-03-03 18:34:06 +00001703
Georg Brandl4c7c3c52012-03-10 22:36:48 +01001704pdb
1705---
1706
R David Murray26d15bf2012-09-29 15:13:35 -04001707Tab-completion is now available not only for command names, but also their
1708arguments. For example, for the ``break`` command, function and file names
1709are completed.
1710
1711(Contributed by Georg Brandl in :issue:`14210`)
Georg Brandl4c7c3c52012-03-10 22:36:48 +01001712
1713
Antoine Pitrou9a864472012-05-04 23:15:47 +02001714pickle
1715------
1716
1717:class:`pickle.Pickler` objects now have an optional
Martin Panterc04fb562016-02-10 05:44:01 +00001718:attr:`~pickle.Pickler.dispatch_table` attribute allowing per-pickler
1719reduction functions to be set.
R David Murray26d15bf2012-09-29 15:13:35 -04001720
Antoine Pitrou9a864472012-05-04 23:15:47 +02001721(Contributed by Richard Oudkerk in :issue:`14166`.)
1722
1723
Victor Stinner383c3fc2011-05-25 01:35:05 +02001724pydoc
1725-----
1726
Victor Stinner6daa33c2011-05-25 01:41:22 +02001727The Tk GUI and the :func:`~pydoc.serve` function have been removed from the
1728:mod:`pydoc` module: ``pydoc -g`` and :func:`~pydoc.serve` have been deprecated
1729in Python 3.2.
Victor Stinner383c3fc2011-05-25 01:35:05 +02001730
1731
Antoine Pitrouad09b5d2012-06-24 22:41:33 +02001732re
1733--
1734
1735:class:`str` regular expressions now support ``\u`` and ``\U`` escapes.
1736
1737(Contributed by Serhiy Storchaka in :issue:`3665`.)
1738
1739
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001740sched
1741-----
Victor Stinner754851f2011-04-19 23:58:51 +02001742
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001743* :meth:`~sched.scheduler.run` now accepts a *blocking* parameter which when
1744 set to False makes the method execute the scheduled events due to expire
1745 soonest (if any) and then return immediately.
1746 This is useful in case you want to use the :class:`~sched.scheduler` in
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001747 non-blocking applications. (Contributed by Giampaolo Rodolà in :issue:`13449`.)
Victor Stinner754851f2011-04-19 23:58:51 +02001748
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001749* :class:`~sched.scheduler` class can now be safely used in multi-threaded
1750 environments. (Contributed by Josiah Carlson and Giampaolo Rodolà in
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001751 :issue:`8684`.)
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001752
1753* *timefunc* and *delayfunct* parameters of :class:`~sched.scheduler` class
1754 constructor are now optional and defaults to :func:`time.time` and
1755 :func:`time.sleep` respectively. (Contributed by Chris Clark in
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001756 :issue:`13245`.)
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001757
1758* :meth:`~sched.scheduler.enter` and :meth:`~sched.scheduler.enterabs`
1759 *argument* parameter is now optional. (Contributed by Chris Clark in
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001760 :issue:`13245`.)
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001761
1762* :meth:`~sched.scheduler.enter` and :meth:`~sched.scheduler.enterabs`
1763 now accept a *kwargs* parameter. (Contributed by Chris Clark in
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001764 :issue:`13245`.)
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001765
1766
Jesus Ceaaa264882012-10-04 02:51:22 +02001767select
1768------
1769
Eric V. Smithb72e69e2014-01-25 05:11:43 -05001770Solaris and derivative platforms have a new class :class:`select.devpoll`
Jesus Ceab6bb3ad2012-10-04 02:58:48 +02001771for high performance asynchronous sockets via :file:`/dev/poll`.
R David Murray1e218c92012-10-06 18:18:55 -04001772(Contributed by Jesús Cea Avión in :issue:`6397`.)
Jesus Ceaaa264882012-10-04 02:51:22 +02001773
1774
R David Murrayaae25832012-09-29 09:49:05 -04001775shlex
1776-----
1777
R David Murray26d15bf2012-09-29 15:13:35 -04001778The previously undocumented helper function ``quote`` from the
1779:mod:`pipes` modules has been moved to the :mod:`shlex` module and
1780documented. :func:`~shlex.quote` properly escapes all characters in a string
1781that might be otherwise given special meaning by the shell.
R David Murrayaae25832012-09-29 09:49:05 -04001782
1783
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001784shutil
1785------
1786
R David Murrayd2489cf2012-09-30 17:28:54 -04001787* New functions:
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001788
1789 * :func:`~shutil.disk_usage`: provides total, used and free disk space
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001790 statistics. (Contributed by Giampaolo Rodolà in :issue:`12442`.)
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001791 * :func:`~shutil.chown`: allows one to change user and/or group of the given
1792 path also specifying the user/group names and not only their numeric
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001793 ids. (Contributed by Sandro Tosi in :issue:`12191`.)
R David Murrayd2489cf2012-09-30 17:28:54 -04001794 * :func:`shutil.get_terminal_size`: returns the size of the terminal window
1795 to which the interpreter is attached. (Contributed by Zbigniew
1796 Jędrzejewski-Szmek in :issue:`13609`.)
Victor Stinnera9293352011-04-30 15:21:58 +02001797
Larry Hastings94717972012-09-21 09:30:19 -07001798* :func:`~shutil.copy2` and :func:`~shutil.copystat` now preserve file
1799 timestamps with nanosecond precision on platforms that support it.
1800 They also preserve file "extended attributes" on Linux. (Contributed
1801 by Larry Hastings in :issue:`14127` and :issue:`15238`.)
1802
Antoine Pitrou9a864472012-05-04 23:15:47 +02001803* Several functions now take an optional ``symlinks`` argument: when that
1804 parameter is true, symlinks aren't dereferenced and the operation instead
1805 acts on the symlink itself (or creates one, if relevant).
1806 (Contributed by Hynek Schlawack in :issue:`12715`.)
1807
R David Murrayf4c27572012-10-06 23:19:17 -04001808* When copying files to a different file system, :func:`~shutil.move` now
1809 handles symlinks the way the posix ``mv`` command does, recreating the
1810 symlink rather than copying the target file contents. (Contributed by
1811 Jonathan Niehof in :issue:`9993`.) :func:`~shutil.move` now also returns
1812 the ``dst`` argument as its result.
1813
Nick Coghlan5b0eca12012-06-24 16:43:06 +10001814* :func:`~shutil.rmtree` is now resistant to symlink attacks on platforms
1815 which support the new ``dir_fd`` parameter in :func:`os.open` and
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001816 :func:`os.unlink`. (Contributed by Martin von Löwis and Hynek Schlawack
Nick Coghlan5b0eca12012-06-24 16:43:06 +10001817 in :issue:`4489`.)
1818
Antoine Pitrou9a864472012-05-04 23:15:47 +02001819
Victor Stinnera9293352011-04-30 15:21:58 +02001820signal
1821------
1822
Victor Stinnerfa0e3d52011-05-09 01:01:09 +02001823* The :mod:`signal` module has new functions:
Victor Stinnera9293352011-04-30 15:21:58 +02001824
Victor Stinnerb3e72192011-05-08 01:46:11 +02001825 * :func:`~signal.pthread_sigmask`: fetch and/or change the signal mask of the
Serhiy Storchakaf47036c2013-12-24 11:04:36 +02001826 calling thread (Contributed by Jean-Paul Calderone in :issue:`8407`);
1827 * :func:`~signal.pthread_kill`: send a signal to a thread;
1828 * :func:`~signal.sigpending`: examine pending functions;
1829 * :func:`~signal.sigwait`: wait a signal;
Ross Lagerwallbc808222011-06-25 12:13:40 +02001830 * :func:`~signal.sigwaitinfo`: wait for a signal, returning detailed
Serhiy Storchakaf47036c2013-12-24 11:04:36 +02001831 information about it;
Ross Lagerwallbc808222011-06-25 12:13:40 +02001832 * :func:`~signal.sigtimedwait`: like :func:`~signal.sigwaitinfo` but with a
1833 timeout.
Victor Stinnera9293352011-04-30 15:21:58 +02001834
Victor Stinnerd49b1f12011-05-08 02:03:15 +02001835* The signal handler writes the signal number as a single byte instead of
1836 a nul byte into the wakeup file descriptor. So it is possible to wait more
1837 than one signal and know which signals were raised.
1838
Victor Stinner388196e2011-05-10 17:13:00 +02001839* :func:`signal.signal` and :func:`signal.siginterrupt` raise an OSError,
1840 instead of a RuntimeError: OSError has an errno attribute.
1841
R David Murray1764c802012-09-29 11:42:36 -04001842
1843smtpd
1844-----
1845
R David Murray26d15bf2012-09-29 15:13:35 -04001846The :mod:`smtpd` module now supports :rfc:`5321` (extended SMTP) and :rfc:`1870`
1847(size extension). Per the standard, these extensions are enabled if and only
1848if the client initiates the session with an ``EHLO`` command.
R David Murray1764c802012-09-29 11:42:36 -04001849
R David Murray26d15bf2012-09-29 15:13:35 -04001850(Initial ``ELHO`` support by Alberto Trevino. Size extension by Juhana
1851Jauhiainen. Substantial additional work on the patch contributed by Michele
1852Orrù and Dan Boswell. :issue:`8739`)
R David Murray1764c802012-09-29 11:42:36 -04001853
1854
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001855smtplib
1856-------
1857
R David Murraya21e5152012-10-06 16:29:14 -04001858The :class:`~smtplib.SMTP`, :class:`~smtplib.SMTP_SSL`, and
1859:class:`~smtplib.LMTP` classes now accept a ``source_address`` keyword argument
1860to specify the ``(host, port)`` to use as the source address in the bind call
1861when creating the outgoing socket. (Contributed by Paulo Scardine in
1862:issue:`11281`.)
1863
Serhiy Storchaka14867992014-09-10 23:43:41 +03001864:class:`~smtplib.SMTP` now supports the context management protocol, allowing an
R David Murray3430fb82012-10-02 18:24:56 -04001865``SMTP`` instance to be used in a ``with`` statement. (Contributed
1866by Giampaolo Rodolà in :issue:`11289`.)
1867
R David Murray26d15bf2012-09-29 15:13:35 -04001868The :class:`~smtplib.SMTP_SSL` constructor and the :meth:`~smtplib.SMTP.starttls`
1869method now accept an SSLContext parameter to control parameters of the secure
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001870channel. (Contributed by Kasun Herath in :issue:`8809`.)
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001871
1872
Nick Coghlan96fe56a2011-08-22 11:55:57 +10001873socket
1874------
1875
Charles-François Natali47413c12011-10-06 19:47:44 +02001876* The :class:`~socket.socket` class now exposes additional methods to process
1877 ancillary data when supported by the underlying platform:
Nick Coghlan96fe56a2011-08-22 11:55:57 +10001878
Charles-François Natali47413c12011-10-06 19:47:44 +02001879 * :func:`~socket.socket.sendmsg`
1880 * :func:`~socket.socket.recvmsg`
1881 * :func:`~socket.socket.recvmsg_into`
Nick Coghlan96fe56a2011-08-22 11:55:57 +10001882
Charles-François Natali47413c12011-10-06 19:47:44 +02001883 (Contributed by David Watson in :issue:`6560`, based on an earlier patch by
1884 Heiko Wundram)
1885
1886* The :class:`~socket.socket` class now supports the PF_CAN protocol family
Georg Brandl5d941342016-02-26 19:37:12 +01001887 (https://en.wikipedia.org/wiki/Socketcan), on Linux
1888 (https://lwn.net/Articles/253425).
Charles-François Natali47413c12011-10-06 19:47:44 +02001889
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001890 (Contributed by Matthias Fuchs, updated by Tiago Gonçalves in :issue:`10141`.)
Charles-François Natali47413c12011-10-06 19:47:44 +02001891
Charles-François Natali10b8cf42011-11-10 19:21:37 +01001892* The :class:`~socket.socket` class now supports the PF_RDS protocol family
Georg Brandl5d941342016-02-26 19:37:12 +01001893 (https://en.wikipedia.org/wiki/Reliable_Datagram_Sockets and
Georg Brandlb7354a62014-10-29 10:57:37 +01001894 https://oss.oracle.com/projects/rds/).
Victor Stinner754851f2011-04-19 23:58:51 +02001895
R David Murrayf4c27572012-10-06 23:19:17 -04001896* The :class:`~socket.socket` class now supports the ``PF_SYSTEM`` protocol
1897 family on OS X. (Contributed by Michael Goderbauer in :issue:`13777`.)
1898
R David Murrayd2489cf2012-09-30 17:28:54 -04001899* New function :func:`~socket.sethostname` allows the hostname to be set
1900 on unix systems if the calling process has sufficient privileges.
1901 (Contributed by Ross Lagerwall in :issue:`10866`.)
1902
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01001903
R David Murray258fabe2012-10-01 21:43:46 -04001904socketserver
1905------------
1906
1907:class:`~socketserver.BaseServer` now has an overridable method
1908:meth:`~socketserver.BaseServer.service_actions` that is called by the
1909:meth:`~socketserver.BaseServer.serve_forever` method in the service loop.
1910:class:`~socketserver.ForkingMixIn` now uses this to clean up zombie
Senthil Kumaranb4760ef2015-06-14 17:35:37 -07001911child processes. (Contributed by Justin Warkentin in :issue:`11109`.)
R David Murray258fabe2012-10-01 21:43:46 -04001912
1913
R David Murray445d69c2012-09-30 21:59:56 -04001914sqlite3
1915-------
1916
1917New :class:`sqlite3.Connection` method
1918:meth:`~sqlite3.Connection.set_trace_callback` can be used to capture a trace of
1919all sql commands processed by sqlite. (Contributed by Torsten Landschoff
1920in :issue:`11688`.)
1921
1922
Victor Stinner99c8b162011-05-24 12:05:19 +02001923ssl
1924---
1925
Antoine Pitrou2c0a9672011-11-17 02:09:13 +01001926* The :mod:`ssl` module has two new random generation functions:
Victor Stinner99c8b162011-05-24 12:05:19 +02001927
1928 * :func:`~ssl.RAND_bytes`: generate cryptographically strong
1929 pseudo-random bytes.
1930 * :func:`~ssl.RAND_pseudo_bytes`: generate pseudo-random bytes.
1931
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001932 (Contributed by Victor Stinner in :issue:`12049`.)
Antoine Pitrou2c0a9672011-11-17 02:09:13 +01001933
1934* The :mod:`ssl` module now exposes a finer-grained exception hierarchy
1935 in order to make it easier to inspect the various kinds of errors.
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001936 (Contributed by Antoine Pitrou in :issue:`11183`.)
Antoine Pitrou2c0a9672011-11-17 02:09:13 +01001937
1938* :meth:`~ssl.SSLContext.load_cert_chain` now accepts a *password* argument
1939 to be used if the private key is encrypted.
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001940 (Contributed by Adam Simpkins in :issue:`12803`.)
Antoine Pitrou2c0a9672011-11-17 02:09:13 +01001941
Antoine Pitrou73fc8142011-12-23 20:58:36 +01001942* Diffie-Hellman key exchange, both regular and Elliptic Curve-based, is
1943 now supported through the :meth:`~ssl.SSLContext.load_dh_params` and
1944 :meth:`~ssl.SSLContext.set_ecdh_curve` methods.
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001945 (Contributed by Antoine Pitrou in :issue:`13626` and :issue:`13627`.)
Antoine Pitrou73fc8142011-12-23 20:58:36 +01001946
Antoine Pitrou2c0a9672011-11-17 02:09:13 +01001947* SSL sockets have a new :meth:`~ssl.SSLSocket.get_channel_binding` method
1948 allowing the implementation of certain authentication mechanisms such as
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001949 SCRAM-SHA-1-PLUS. (Contributed by Jacek Konieczny in :issue:`12551`.)
Antoine Pitrou2c0a9672011-11-17 02:09:13 +01001950
Antoine Pitrou73fc8142011-12-23 20:58:36 +01001951* You can query the SSL compression algorithm used by an SSL socket, thanks
R David Murrayfd740962012-10-06 22:08:08 -04001952 to its new :meth:`~ssl.SSLSocket.compression` method. The new attribute
1953 :attr:`~ssl.OP_NO_COMPRESSION` can be used to disable compression.
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001954 (Contributed by Antoine Pitrou in :issue:`13634`.)
Antoine Pitrou73fc8142011-12-23 20:58:36 +01001955
Antoine Pitrou9a864472012-05-04 23:15:47 +02001956* Support has been added for the Next Procotol Negotiation extension using
1957 the :meth:`ssl.SSLContext.set_npn_protocols` method.
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001958 (Contributed by Colin Marc in :issue:`14204`.)
Antoine Pitrou9a864472012-05-04 23:15:47 +02001959
Antoine Pitrouad09b5d2012-06-24 22:41:33 +02001960* SSL errors can now be introspected more easily thanks to
1961 :attr:`~ssl.SSLError.library` and :attr:`~ssl.SSLError.reason` attributes.
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001962 (Contributed by Antoine Pitrou in :issue:`14837`.)
Antoine Pitrouad09b5d2012-06-24 22:41:33 +02001963
R David Murray445d69c2012-09-30 21:59:56 -04001964* The :func:`~ssl.get_server_certificate` function now supports IPv6.
1965 (Contributed by Charles-François Natali in :issue:`11811`.)
1966
R David Murrayfd740962012-10-06 22:08:08 -04001967* New attribute :attr:`~ssl.OP_CIPHER_SERVER_PREFERENCE` allows setting
1968 SSLv3 server sockets to use the server's cipher ordering preference rather
1969 than the client's (:issue:`13635`).
1970
R David Murray445d69c2012-09-30 21:59:56 -04001971
Giampaolo Rodola'ffa1d0b2012-05-15 15:30:25 +02001972stat
1973----
1974
R David Murray26d15bf2012-09-29 15:13:35 -04001975The undocumented tarfile.filemode function has been moved to
1976:func:`stat.filemode`. It can be used to convert a file's mode to a string of
1977the form '-rwxrwxrwx'.
Giampaolo Rodola'ffa1d0b2012-05-15 15:30:25 +02001978
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02001979(Contributed by Giampaolo Rodolà in :issue:`14807`.)
Antoine Pitrou73fc8142011-12-23 20:58:36 +01001980
R David Murrayc652ce62012-09-30 20:07:42 -04001981
R David Murray1e218c92012-10-06 18:18:55 -04001982struct
1983------
1984
1985The :mod:`struct` module now supports ``ssize_t`` and ``size_t`` via the
1986new codes ``n`` and ``N``, respectively. (Contributed by Antoine Pitrou
1987in :issue:`3163`.)
1988
1989
R David Murrayc652ce62012-09-30 20:07:42 -04001990subprocess
1991----------
1992
1993Command strings can now be bytes objects on posix platforms. (Contributed by
R David Murray445d69c2012-09-30 21:59:56 -04001994Victor Stinner in :issue:`8513`.)
R David Murrayc652ce62012-09-30 20:07:42 -04001995
1996A new constant :data:`~subprocess.DEVNULL` allows suppressing output in a
1997platform-independent fashion. (Contributed by Ross Lagerwall in
1998:issue:`5870`.)
1999
2000
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01002001sys
2002---
Giampaolo Rodola'210e7ca2011-07-01 13:55:36 +02002003
R David Murray26d15bf2012-09-29 15:13:35 -04002004The :mod:`sys` module has a new :data:`~sys.thread_info` :term:`struct
R David Murray445d69c2012-09-30 21:59:56 -04002005sequence` holding informations about the thread implementation
2006(:issue:`11223`).
Giampaolo Rodola'096dcb12011-06-27 11:17:51 +02002007
R David Murray1e218c92012-10-06 18:18:55 -04002008
R David Murrayfd740962012-10-06 22:08:08 -04002009tarfile
2010-------
2011
2012:mod:`tarfile` now supports ``lzma`` encoding via the :mod:`lzma` module.
2013(Contributed by Lars Gustäbel in :issue:`5689`.)
2014
2015
R David Murrayca76ea12012-10-06 18:32:39 -04002016tempfile
2017--------
2018
2019:class:`tempfile.SpooledTemporaryFile`\'s
R David Murray03b2a1c2013-04-03 06:16:14 -04002020:meth:`~tempfile.SpooledTemporaryFile.truncate` method now accepts
R David Murrayca76ea12012-10-06 18:32:39 -04002021a ``size`` parameter. (Contributed by Ryan Kelly in :issue:`9957`.)
2022
2023
Nick Coghlan4fae8cd2012-06-11 23:07:51 +10002024textwrap
2025--------
2026
R David Murray26d15bf2012-09-29 15:13:35 -04002027The :mod:`textwrap` module has a new :func:`~textwrap.indent` that makes
2028it straightforward to add a common prefix to selected lines in a block
R David Murray445d69c2012-09-30 21:59:56 -04002029of text (:issue:`13857`).
Antoine Pitrou5a8bc6f2011-11-17 02:20:48 +01002030
R David Murrayd2489cf2012-09-30 17:28:54 -04002031
2032threading
2033---------
2034
R David Murrayef4d2862012-10-06 14:35:35 -04002035:class:`threading.Condition`, :class:`threading.Semaphore`,
R David Murray344174d2012-10-06 16:06:16 -04002036:class:`threading.BoundedSemaphore`, :class:`threading.Event`, and
R David Murrayef4d2862012-10-06 14:35:35 -04002037:class:`threading.Timer`, all of which used to be factory functions returning a
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02002038class instance, are now classes and may be subclassed. (Contributed by Éric
2039Araujo in :issue:`10968`.)
R David Murrayef4d2862012-10-06 14:35:35 -04002040
R David Murrayd2489cf2012-09-30 17:28:54 -04002041The :class:`threading.Thread` constructor now accepts a ``daemon`` keyword
2042argument to override the default behavior of inheriting the ``deamon`` flag
2043value from the parent thread (:issue:`6064`).
2044
R David Murray0bbfd6b2012-10-01 22:10:15 -04002045The formerly private function ``_thread.get_ident`` is now available as the
Georg Brandldc704c62012-10-02 10:16:19 +02002046public function :func:`threading.get_ident`. This eliminates several cases of
R David Murray0bbfd6b2012-10-01 22:10:15 -04002047direct access to the ``_thread`` module in the stdlib. Third party code that
2048used ``_thread.get_ident`` should likewise be changed to use the new public
2049interface.
2050
R David Murrayd2489cf2012-09-30 17:28:54 -04002051
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01002052time
2053----
Antoine Pitrou5a8bc6f2011-11-17 02:20:48 +01002054
Victor Stinnerec895392012-04-29 02:41:27 +02002055The :pep:`418` added new functions to the :mod:`time` module:
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01002056
Victor Stinnerec895392012-04-29 02:41:27 +02002057* :func:`~time.get_clock_info`: Get information on a clock.
2058* :func:`~time.monotonic`: Monotonic clock (cannot go backward), not affected
2059 by system clock updates.
2060* :func:`~time.perf_counter`: Performance counter with the highest available
2061 resolution to measure a short duration.
2062* :func:`~time.process_time`: Sum of the system and user CPU time of the
2063 current process.
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01002064
Victor Stinnerec895392012-04-29 02:41:27 +02002065Other new functions:
2066
2067* :func:`~time.clock_getres`, :func:`~time.clock_gettime` and
2068 :func:`~time.clock_settime` functions with ``CLOCK_xxx`` constants.
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02002069 (Contributed by Victor Stinner in :issue:`10278`.)
Victor Stinnerf4c54ff2012-02-08 01:48:34 +01002070
R David Murray3430fb82012-10-02 18:24:56 -04002071To improve cross platform consistency, :func:`~time.sleep` now raises a
2072:exc:`ValueError` when passed a negative sleep value. Previously this was an
2073error on posix, but produced an infinite sleep on Windows.
2074
Antoine Pitrou5a8bc6f2011-11-17 02:20:48 +01002075
Victor Stinner0db176f2012-04-16 00:16:30 +02002076types
2077-----
2078
2079Add a new :class:`types.MappingProxyType` class: Read-only proxy of a mapping.
2080(:issue:`14386`)
2081
2082
Georg Brandl6b4c8472014-10-30 22:26:26 +01002083The new functions :func:`types.new_class` and :func:`types.prepare_class` provide support
Nick Coghlan7fc570a2012-05-20 02:34:13 +10002084for PEP 3115 compliant dynamic type creation. (:issue:`14588`)
2085
2086
Ezio Melotti461f41d2012-09-26 17:43:23 +03002087unittest
2088--------
2089
2090:meth:`.assertRaises`, :meth:`.assertRaisesRegex`, :meth:`.assertWarns`, and
2091:meth:`.assertWarnsRegex` now accept a keyword argument *msg* when used as
R David Murrayc652ce62012-09-30 20:07:42 -04002092context managers. (Contributed by Ezio Melotti and Winston Ewert in
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02002093:issue:`10775`.)
Ezio Melotti461f41d2012-09-26 17:43:23 +03002094
R David Murrayc652ce62012-09-30 20:07:42 -04002095:meth:`unittest.TestCase.run` now returns the :class:`~unittest.TestResult`
2096object.
Ezio Melotti461f41d2012-09-26 17:43:23 +03002097
R David Murray1e218c92012-10-06 18:18:55 -04002098
Senthil Kumarande49d642011-10-16 23:54:44 +08002099urllib
2100------
2101
2102The :class:`~urllib.request.Request` class, now accepts a *method* argument
2103used by :meth:`~urllib.request.Request.get_method` to determine what HTTP method
Senthil Kumarana41c9422011-10-20 02:37:08 +08002104should be used. For example, this will send a ``'HEAD'`` request::
Senthil Kumarande49d642011-10-16 23:54:44 +08002105
Georg Brandle73778c2014-10-29 08:36:35 +01002106 >>> urlopen(Request('https://www.python.org', method='HEAD'))
Senthil Kumarande49d642011-10-16 23:54:44 +08002107
2108(:issue:`1673007`)
Giampaolo Rodola'096dcb12011-06-27 11:17:51 +02002109
Giampaolo Rodola'be55d992011-11-22 13:33:34 +01002110
Éric Araujo4f61a2d2012-04-04 23:01:01 -04002111webbrowser
2112----------
2113
R David Murrayf4c27572012-10-06 23:19:17 -04002114The :mod:`webbrowser` module supports more "browsers": Google Chrome (named
Éric Araujo4f61a2d2012-04-04 23:01:01 -04002115:program:`chrome`, :program:`chromium`, :program:`chrome-browser` or
R David Murrayf4c27572012-10-06 23:19:17 -04002116:program:`chromium-browser` depending on the version and operating system),
2117and the generic launchers :program:`xdg-open`, from the FreeDesktop.org
2118project, and :program:`gvfs-open`, which is the default URI handler for GNOME
21193. (The former contributed by Arnaud Calmettes in :issue:`13620`, the latter
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02002120by Matthias Klose in :issue:`14493`.)
Éric Araujo4f61a2d2012-04-04 23:01:01 -04002121
2122
Eli Benderskyefcaba02012-08-09 08:20:20 +03002123xml.etree.ElementTree
2124---------------------
2125
2126The :mod:`xml.etree.ElementTree` module now imports its C accelerator by
2127default; there is no longer a need to explicitly import
2128:mod:`xml.etree.cElementTree` (this module stays for backwards compatibility,
2129but is now deprecated). In addition, the ``iter`` family of methods of
2130:class:`~xml.etree.ElementTree.Element` has been optimized (rewritten in C).
2131The module's documentation has also been greatly improved with added examples
2132and a more detailed reference.
2133
2134
R David Murray1e218c92012-10-06 18:18:55 -04002135zlib
2136----
2137
2138New attribute :attr:`zlib.Decompress.eof` makes it possible to distinguish
2139between a properly-formed compressed stream and an incomplete or truncated one.
2140(Contributed by Nadeem Vawda in :issue:`12646`.)
2141
2142New attribute :attr:`zlib.ZLIB_RUNTIME_VERSION` reports the version string of
2143the underlying ``zlib`` library that is loaded at runtime. (Contributed by
2144Torsten Landschoff in :issue:`12306`.)
2145
2146
Giampaolo Rodolà3108f982011-02-24 20:59:48 +00002147Optimizations
2148=============
2149
2150Major performance enhancements have been added:
2151
Éric Araujo4f61a2d2012-04-04 23:01:01 -04002152* Thanks to :pep:`393`, some operations on Unicode strings have been optimized:
Victor Stinner46606ce2011-11-20 18:27:55 +01002153
2154 * the memory footprint is divided by 2 to 4 depending on the text
Victor Stinnera996f1e2011-11-21 13:14:43 +01002155 * encode an ASCII string to UTF-8 doesn't need to encode characters anymore,
2156 the UTF-8 representation is shared with the ASCII representation
Victor Stinner6099a032011-12-18 14:22:26 +01002157 * the UTF-8 encoder has been optimized
Serhiy Storchakad65c9492015-11-02 14:10:23 +02002158 * repeating a single ASCII letter and getting a substring of an ASCII string
Victor Stinner6099a032011-12-18 14:22:26 +01002159 is 4 times faster
Giampaolo Rodolà3108f982011-02-24 20:59:48 +00002160
Antoine Pitrou5d7e1d32012-06-24 22:38:23 +02002161* UTF-8 is now 2x to 4x faster. UTF-16 encoding is now up to 10x faster.
Antoine Pitrou5cec9d22012-05-17 17:37:02 +02002162
Serhiy Storchakae5cf4862014-11-02 19:18:52 +02002163 (Contributed by Serhiy Storchaka, :issue:`14624`, :issue:`14738` and
Antoine Pitrouc9092962012-06-15 22:22:18 +02002164 :issue:`15026`.)
Antoine Pitrou5cec9d22012-05-17 17:37:02 +02002165
Giampaolo Rodolà3108f982011-02-24 20:59:48 +00002166
2167Build and C API Changes
2168=======================
2169
2170Changes to Python's build process and to the C API include:
2171
Stefan Krah95b1ba62012-02-29 17:27:21 +01002172* New :pep:`3118` related function:
2173
2174 * :c:func:`PyMemoryView_FromMemory`
2175
Éric Araujo4f61a2d2012-04-04 23:01:01 -04002176* :pep:`393` added new Unicode types, macros and functions:
Victor Stinner46606ce2011-11-20 18:27:55 +01002177
Victor Stinnera996f1e2011-11-21 13:14:43 +01002178 * High-level API:
2179
2180 * :c:func:`PyUnicode_CopyCharacters`
2181 * :c:func:`PyUnicode_FindChar`
2182 * :c:func:`PyUnicode_GetLength`, :c:macro:`PyUnicode_GET_LENGTH`
2183 * :c:func:`PyUnicode_New`
2184 * :c:func:`PyUnicode_Substring`
2185 * :c:func:`PyUnicode_ReadChar`, :c:func:`PyUnicode_WriteChar`
2186
2187 * Low-level API:
2188
2189 * :c:type:`Py_UCS1`, :c:type:`Py_UCS2`, :c:type:`Py_UCS4` types
2190 * :c:type:`PyASCIIObject` and :c:type:`PyCompactUnicodeObject` structures
2191 * :c:macro:`PyUnicode_READY`
2192 * :c:func:`PyUnicode_FromKindAndData`
2193 * :c:func:`PyUnicode_AsUCS4`, :c:func:`PyUnicode_AsUCS4Copy`
2194 * :c:macro:`PyUnicode_DATA`, :c:macro:`PyUnicode_1BYTE_DATA`,
2195 :c:macro:`PyUnicode_2BYTE_DATA`, :c:macro:`PyUnicode_4BYTE_DATA`
2196 * :c:macro:`PyUnicode_KIND` with :c:type:`PyUnicode_Kind` enum:
2197 :c:data:`PyUnicode_WCHAR_KIND`, :c:data:`PyUnicode_1BYTE_KIND`,
2198 :c:data:`PyUnicode_2BYTE_KIND`, :c:data:`PyUnicode_4BYTE_KIND`
2199 * :c:macro:`PyUnicode_READ`, :c:macro:`PyUnicode_READ_CHAR`, :c:macro:`PyUnicode_WRITE`
2200 * :c:macro:`PyUnicode_MAX_CHAR_VALUE`
2201
R David Murraye54c7182012-10-16 21:52:24 -04002202* :c:macro:`PyArg_ParseTuple` now accepts a :class:`bytearray` for the ``c``
2203 format (:issue:`12380`).
2204
Giampaolo Rodolà3108f982011-02-24 20:59:48 +00002205
2206
Victor Stinnerd1be8782011-12-09 00:10:41 +01002207Deprecated
2208==========
2209
Georg Brandl0cd25c92011-04-29 13:45:54 +02002210Unsupported Operating Systems
Victor Stinnerd1be8782011-12-09 00:10:41 +01002211-----------------------------
Victor Stinnerb90db4c2011-04-26 22:48:24 +02002212
Brian Curtin49a40cd2011-05-02 22:30:06 -05002213OS/2 and VMS are no longer supported due to the lack of a maintainer.
2214
2215Windows 2000 and Windows platforms which set ``COMSPEC`` to ``command.com``
2216are no longer supported due to maintenance burden.
Victor Stinnerb90db4c2011-04-26 22:48:24 +02002217
R David Murrayd2489cf2012-09-30 17:28:54 -04002218OSF support, which was deprecated in 3.2, has been completely removed.
2219
Victor Stinnerb90db4c2011-04-26 22:48:24 +02002220
Victor Stinner46606ce2011-11-20 18:27:55 +01002221Deprecated Python modules, functions and methods
Victor Stinnerd1be8782011-12-09 00:10:41 +01002222------------------------------------------------
Victor Stinner19bd0692011-11-16 00:18:57 +01002223
R David Murraye54c7182012-10-16 21:52:24 -04002224* Passing a non-empty string to ``object.__format__()`` is deprecated, and
2225 will produce a :exc:`TypeError` in Python 3.4 (:issue:`9856`).
Victor Stinner19bd0692011-11-16 00:18:57 +01002226* The ``unicode_internal`` codec has been deprecated because of the
Sandro Tosicd899122012-01-22 12:16:04 +01002227 :pep:`393`, use UTF-8, UTF-16 (``utf-16-le`` or ``utf-16-be``), or UTF-32
2228 (``utf-32-le`` or ``utf-32-be``)
Victor Stinner19bd0692011-11-16 00:18:57 +01002229* :meth:`ftplib.FTP.nlst` and :meth:`ftplib.FTP.dir`: use
Victor Stinner46606ce2011-11-20 18:27:55 +01002230 :meth:`ftplib.FTP.mlsd`
Victor Stinner19bd0692011-11-16 00:18:57 +01002231* :func:`platform.popen`: use the :mod:`subprocess` module. Check especially
R David Murrayc652ce62012-09-30 20:07:42 -04002232 the :ref:`subprocess-replacements` section (:issue:`11377`).
Victor Stinner19bd0692011-11-16 00:18:57 +01002233* :issue:`13374`: The Windows bytes API has been deprecated in the :mod:`os`
Victor Stinner46606ce2011-11-20 18:27:55 +01002234 module. Use Unicode filenames, instead of bytes filenames, to not depend on
Victor Stinner19bd0692011-11-16 00:18:57 +01002235 the ANSI code page anymore and to support any filename.
Florent Xiclunaa72a98f2012-02-13 11:03:30 +01002236* :issue:`13988`: The :mod:`xml.etree.cElementTree` module is deprecated. The
2237 accelerator is used automatically whenever available.
Victor Stinner47620a62012-04-29 02:52:39 +02002238* The behaviour of :func:`time.clock` depends on the platform: use the new
2239 :func:`time.perf_counter` or :func:`time.process_time` function instead,
2240 depending on your requirements, to have a well defined behaviour.
Victor Stinnerfa0d6282012-08-05 15:56:51 +02002241* The :func:`os.stat_float_times` function is deprecated.
Victor Stinner8f17c1c2012-08-05 16:31:32 +02002242* :mod:`abc` module:
2243
2244 * :class:`abc.abstractproperty` has been deprecated, use :class:`property`
2245 with :func:`abc.abstractmethod` instead.
2246 * :class:`abc.abstractclassmethod` has been deprecated, use
2247 :class:`classmethod` with :func:`abc.abstractmethod` instead.
2248 * :class:`abc.abstractstaticmethod` has been deprecated, use
2249 :class:`staticmethod` with :func:`abc.abstractmethod` instead.
2250
Georg Brandlfc349212012-09-26 13:11:48 +02002251* :mod:`importlib` package:
Brett Cannon288717a2012-09-25 15:23:07 -04002252
2253 * :meth:`importlib.abc.SourceLoader.path_mtime` is now deprecated in favour of
2254 :meth:`importlib.abc.SourceLoader.path_stats` as bytecode files now store
2255 both the modification time and size of the source file the bytecode file was
2256 compiled from.
2257
2258
2259
Victor Stinner19bd0692011-11-16 00:18:57 +01002260
2261
Victor Stinner46606ce2011-11-20 18:27:55 +01002262Deprecated functions and types of the C API
Victor Stinnerd1be8782011-12-09 00:10:41 +01002263-------------------------------------------
Victor Stinner46606ce2011-11-20 18:27:55 +01002264
Éric Araujo4f61a2d2012-04-04 23:01:01 -04002265The :c:type:`Py_UNICODE` has been deprecated by :pep:`393` and will be
Victor Stinner46606ce2011-11-20 18:27:55 +01002266removed in Python 4. All functions using this type are deprecated:
2267
Victor Stinner46606ce2011-11-20 18:27:55 +01002268Unicode functions and methods using :c:type:`Py_UNICODE` and
2269:c:type:`Py_UNICODE*` types:
2270
R David Murrayf75e65f2012-09-29 15:27:53 -04002271* :c:macro:`PyUnicode_FromUnicode`: use :c:func:`PyUnicode_FromWideChar` or
2272 :c:func:`PyUnicode_FromKindAndData`
2273* :c:macro:`PyUnicode_AS_UNICODE`, :c:func:`PyUnicode_AsUnicode`,
2274 :c:func:`PyUnicode_AsUnicodeAndSize`: use :c:func:`PyUnicode_AsWideCharString`
2275* :c:macro:`PyUnicode_AS_DATA`: use :c:macro:`PyUnicode_DATA` with
2276 :c:macro:`PyUnicode_READ` and :c:macro:`PyUnicode_WRITE`
2277* :c:macro:`PyUnicode_GET_SIZE`, :c:func:`PyUnicode_GetSize`: use
2278 :c:macro:`PyUnicode_GET_LENGTH` or :c:func:`PyUnicode_GetLength`
2279* :c:macro:`PyUnicode_GET_DATA_SIZE`: use
2280 ``PyUnicode_GET_LENGTH(str) * PyUnicode_KIND(str)`` (only work on ready
2281 strings)
2282* :c:func:`PyUnicode_AsUnicodeCopy`: use :c:func:`PyUnicode_AsUCS4Copy` or
2283 :c:func:`PyUnicode_AsWideCharString`
2284* :c:func:`PyUnicode_GetMax`
Victor Stinnerab595942011-12-17 04:59:06 +01002285
Victor Stinner46606ce2011-11-20 18:27:55 +01002286
Victor Stinnera996f1e2011-11-21 13:14:43 +01002287Functions and macros manipulating Py_UNICODE* strings:
2288
R David Murrayf75e65f2012-09-29 15:27:53 -04002289* :c:macro:`Py_UNICODE_strlen`: use :c:func:`PyUnicode_GetLength` or
2290 :c:macro:`PyUnicode_GET_LENGTH`
2291* :c:macro:`Py_UNICODE_strcat`: use :c:func:`PyUnicode_CopyCharacters` or
2292 :c:func:`PyUnicode_FromFormat`
2293* :c:macro:`Py_UNICODE_strcpy`, :c:macro:`Py_UNICODE_strncpy`,
2294 :c:macro:`Py_UNICODE_COPY`: use :c:func:`PyUnicode_CopyCharacters` or
2295 :c:func:`PyUnicode_Substring`
2296* :c:macro:`Py_UNICODE_strcmp`: use :c:func:`PyUnicode_Compare`
2297* :c:macro:`Py_UNICODE_strncmp`: use :c:func:`PyUnicode_Tailmatch`
2298* :c:macro:`Py_UNICODE_strchr`, :c:macro:`Py_UNICODE_strrchr`: use
2299 :c:func:`PyUnicode_FindChar`
2300* :c:macro:`Py_UNICODE_FILL`: use :c:func:`PyUnicode_Fill`
2301* :c:macro:`Py_UNICODE_MATCH`
Victor Stinnera996f1e2011-11-21 13:14:43 +01002302
Victor Stinner46606ce2011-11-20 18:27:55 +01002303Encoders:
2304
R David Murrayf75e65f2012-09-29 15:27:53 -04002305* :c:func:`PyUnicode_Encode`: use :c:func:`PyUnicode_AsEncodedObject`
2306* :c:func:`PyUnicode_EncodeUTF7`
2307* :c:func:`PyUnicode_EncodeUTF8`: use :c:func:`PyUnicode_AsUTF8` or
2308 :c:func:`PyUnicode_AsUTF8String`
2309* :c:func:`PyUnicode_EncodeUTF32`
2310* :c:func:`PyUnicode_EncodeUTF16`
2311* :c:func:`PyUnicode_EncodeUnicodeEscape:` use
2312 :c:func:`PyUnicode_AsUnicodeEscapeString`
2313* :c:func:`PyUnicode_EncodeRawUnicodeEscape:` use
2314 :c:func:`PyUnicode_AsRawUnicodeEscapeString`
2315* :c:func:`PyUnicode_EncodeLatin1`: use :c:func:`PyUnicode_AsLatin1String`
2316* :c:func:`PyUnicode_EncodeASCII`: use :c:func:`PyUnicode_AsASCIIString`
2317* :c:func:`PyUnicode_EncodeCharmap`
2318* :c:func:`PyUnicode_TranslateCharmap`
2319* :c:func:`PyUnicode_EncodeMBCS`: use :c:func:`PyUnicode_AsMBCSString` or
2320 :c:func:`PyUnicode_EncodeCodePage` (with ``CP_ACP`` code_page)
2321* :c:func:`PyUnicode_EncodeDecimal`,
2322 :c:func:`PyUnicode_TransformDecimalToASCII`
Victor Stinner46606ce2011-11-20 18:27:55 +01002323
2324
Stefan Krah029780b2012-08-24 20:14:12 +02002325Deprecated features
2326-------------------
2327
2328The :mod:`array` module's ``'u'`` format code is now deprecated and will be
2329removed in Python 4 together with the rest of the (:c:type:`Py_UNICODE`) API.
2330
2331
Giampaolo Rodolà3108f982011-02-24 20:59:48 +00002332Porting to Python 3.3
2333=====================
2334
2335This section lists previously described changes and other bugfixes
Antoine Pitrou037ffbf2011-10-24 00:25:41 +02002336that may require changes to your code.
2337
Barry Warsawc1e721b2012-07-30 16:24:12 -04002338.. _portingpythoncode:
2339
Antoine Pitrou037ffbf2011-10-24 00:25:41 +02002340Porting Python code
2341-------------------
Giampaolo Rodolà3108f982011-02-24 20:59:48 +00002342
Victor Stinnerfa0d6282012-08-05 15:56:51 +02002343* Hash randomization is enabled by default. Set the :envvar:`PYTHONHASHSEED`
2344 environment variable to ``0`` to disable hash randomization. See also the
2345 :meth:`object.__hash__` method.
Georg Brandld6c43402012-03-07 08:55:52 +01002346
Victor Stinner19bd0692011-11-16 00:18:57 +01002347* :issue:`12326`: On Linux, sys.platform doesn't contain the major version
Victor Stinnerff3d9392011-08-20 23:39:26 +02002348 anymore. It is now always 'linux', instead of 'linux2' or 'linux3' depending
2349 on the Linux version used to build Python. Replace sys.platform == 'linux2'
2350 with sys.platform.startswith('linux'), or directly sys.platform == 'linux' if
2351 you don't need to support older Python versions.
Éric Araujoc09fca62011-03-23 02:06:24 +01002352
Victor Stinnerecc6e662012-03-14 00:39:29 +01002353* :issue:`13847`, :issue:`14180`: :mod:`time` and :mod:`datetime`:
2354 :exc:`OverflowError` is now raised instead of :exc:`ValueError` if a
2355 timestamp is out of range. :exc:`OSError` is now raised if C functions
2356 :c:func:`gmtime` or :c:func:`localtime` failed.
2357
Brett Cannonc2043482012-04-29 20:59:41 -04002358* The default finders used by import now utilize a cache of what is contained
2359 within a specific directory. If you create a Python source file or sourceless
2360 bytecode file, make sure to call :func:`importlib.invalidate_caches` to clear
2361 out the cache for the finders to notice the new file.
2362
Senthil Kumaranb4760ef2015-06-14 17:35:37 -07002363* :exc:`ImportError` now uses the full name of the module that was attempted to
Brett Cannonc2043482012-04-29 20:59:41 -04002364 be imported. Doctests that check ImportErrors' message will need to be
2365 updated to use the full name of the module instead of just the tail of the
2366 name.
2367
Ezio Melotti7598e182012-09-20 08:33:53 +03002368* The *index* argument to :func:`__import__` now defaults to 0 instead of -1
Brett Cannonc2043482012-04-29 20:59:41 -04002369 and no longer support negative values. It was an oversight when :pep:`328` was
2370 implemented that the default value remained -1. If you need to continue to
2371 perform a relative import followed by an absolute import, then perform the
2372 relative import using an index of 1, followed by another import using an
2373 index of 0. It is preferred, though, that you use
2374 :func:`importlib.import_module` rather than call :func:`__import__` directly.
2375
2376* :func:`__import__` no longer allows one to use an index value other than 0
2377 for top-level modules. E.g. ``__import__('sys', level=1)`` is now an error.
2378
2379* Because :attr:`sys.meta_path` and :attr:`sys.path_hooks` now have finders on
2380 them by default, you will most likely want to use :meth:`list.insert` instead
2381 of :meth:`list.append` to add to those lists.
2382
2383* Because ``None`` is now inserted into :attr:`sys.path_importer_cache`, if you
2384 are clearing out entries in the dictionary of paths that do not have a
2385 finder, you will need to remove keys paired with values of ``None`` **and**
Brett Cannon903c27c2012-07-09 14:15:32 -04002386 :class:`imp.NullImporter` to be backwards-compatible. This will lead to extra
Brett Cannonc2043482012-04-29 20:59:41 -04002387 overhead on older versions of Python that re-insert ``None`` into
2388 :attr:`sys.path_importer_cache` where it repesents the use of implicit
2389 finders, but semantically it should not change anything.
2390
Brett Cannon077ef452012-08-02 17:50:06 -04002391* :class:`importlib.abc.Finder` no longer specifies a `find_module()` abstract
2392 method that must be implemented. If you were relying on subclasses to
2393 implement that method, make sure to check for the method's existence first.
2394 You will probably want to check for `find_loader()` first, though, in the
2395 case of working with :term:`path entry finders <path entry finder>`.
2396
Nick Coghlan60610002012-07-15 22:39:39 +10002397* :mod:`pkgutil` has been converted to use :mod:`importlib` internally. This
2398 eliminates many edge cases where the old behaviour of the PEP 302 import
2399 emulation failed to match the behaviour of the real import system. The
2400 import emulation itself is still present, but is now deprecated. The
2401 :func:`pkgutil.iter_importers` and :func:`pkgutil.walk_packages` functions
2402 special case the standard import hooks so they are still supported even
2403 though they do not provide the non-standard ``iter_modules()`` method.
Brett Cannon903c27c2012-07-09 14:15:32 -04002404
R David Murrayea226852012-09-30 01:27:24 -04002405* A longstanding RFC-compliance bug (:issue:`1079`) in the parsing done by
2406 :func:`email.header.decode_header` has been fixed. Code that uses the
2407 standard idiom to convert encoded headers into unicode
2408 (``str(make_header(decode_header(h))``) will see no change, but code that
2409 looks at the individual tuples returned by decode_header will see that
2410 whitespace that precedes or follows ``ASCII`` sections is now included in the
2411 ``ASCII`` section. Code that builds headers using ``make_header`` should
2412 also continue to work without change, since ``make_header`` continues to add
2413 whitespace between ``ASCII`` and non-``ASCII`` sections if it is not already
2414 present in the input strings.
2415
2416* :func:`email.utils.formataddr` now does the correct content transfer
2417 encoding when passed non-``ASCII`` display names. Any code that depended on
2418 the previous buggy behavior that preserved the non-``ASCII`` unicode in the
R David Murrayd2489cf2012-09-30 17:28:54 -04002419 formatted output string will need to be changed (:issue:`1690608`).
2420
2421* :meth:`poplib.POP3.quit` may now raise protocol errors like all other
2422 ``poplib`` methods. Code that assumes ``quit`` does not raise
2423 :exc:`poplib.error_proto` errors may need to be changed if errors on ``quit``
2424 are encountered by a particular application (:issue:`11291`).
R David Murrayea226852012-09-30 01:27:24 -04002425
R David Murray445d69c2012-09-30 21:59:56 -04002426* The ``strict`` argument to :class:`email.parser.Parser`, deprecated since
2427 Python 2.4, has finally been removed.
2428
2429* The deprecated method ``unittest.TestCase.assertSameElements`` has been
2430 removed.
2431
2432* The deprecated variable ``time.accept2dyear`` has been removed.
2433
R David Murray1e218c92012-10-06 18:18:55 -04002434* The deprecated ``Context._clamp`` attribute has been removed from the
2435 :mod:`decimal` module. It was previously replaced by the public attribute
2436 :attr:`~decimal.Context.clamp`. (See :issue:`8540`.)
2437
R David Murray3430fb82012-10-02 18:24:56 -04002438* The undocumented internal helper class ``SSLFakeFile`` has been removed
2439 from :mod:`smtplib`, since its functionality has long been provided directly
2440 by :meth:`socket.socket.makefile`.
2441
2442* Passing a negative value to :func:`time.sleep` on Windows now raises an
2443 error instead of sleeping forever. It has always raised an error on posix.
2444
2445* The ``ast.__version__`` constant has been removed. If you need to
2446 make decisions affected by the AST version, use :attr:`sys.version_info`
2447 to make the decision.
R David Murray994ce1a2012-10-02 10:19:08 -04002448
R David Murrayef4d2862012-10-06 14:35:35 -04002449* Code that used to work around the fact that the :mod:`threading` module used
2450 factory functions by subclassing the private classes will need to change to
2451 subclass the now-public classes.
2452
R David Murraye54c7182012-10-16 21:52:24 -04002453* The undocumented debugging machinery in the threading module has been
2454 removed, simplifying the code. This should have no effect on production
2455 code, but is mentioned here in case any application debug frameworks were
2456 interacting with it (:issue:`13550`).
2457
Brett Cannonc2043482012-04-29 20:59:41 -04002458
Antoine Pitrou037ffbf2011-10-24 00:25:41 +02002459Porting C code
2460--------------
2461
Stefan Krah54c32032012-02-29 17:47:21 +01002462* In the course of changes to the buffer API the undocumented
2463 :c:member:`~Py_buffer.smalltable` member of the
2464 :c:type:`Py_buffer` structure has been removed and the
2465 layout of the :c:type:`PyMemoryViewObject` has changed.
2466
2467 All extensions relying on the relevant parts in ``memoryobject.h``
2468 or ``object.h`` must be rebuilt.
2469
Antoine Pitrou037ffbf2011-10-24 00:25:41 +02002470* Due to :ref:`PEP 393 <pep-393>`, the :c:type:`Py_UNICODE` type and all
2471 functions using this type are deprecated (but will stay available for
2472 at least five years). If you were using low-level Unicode APIs to
2473 construct and access unicode objects and you want to benefit of the
Éric Araujo4f61a2d2012-04-04 23:01:01 -04002474 memory footprint reduction provided by PEP 393, you have to convert
Antoine Pitrou037ffbf2011-10-24 00:25:41 +02002475 your code to the new :doc:`Unicode API <../c-api/unicode>`.
2476
2477 However, if you only have been using high-level functions such as
2478 :c:func:`PyUnicode_Concat()`, :c:func:`PyUnicode_Join` or
2479 :c:func:`PyUnicode_FromFormat()`, your code will automatically take
2480 advantage of the new unicode representations.
2481
Brett Cannon77b2abd2012-07-09 16:09:00 -04002482* :c:func:`PyImport_GetMagicNumber` now returns -1 upon failure.
2483
Ezio Melotti7598e182012-09-20 08:33:53 +03002484* As a negative value for the *level* argument to :func:`__import__` is no
Brett Cannon522267e2012-08-10 18:55:08 -04002485 longer valid, the same now holds for :c:func:`PyImport_ImportModuleLevel`.
Ezio Melotti7598e182012-09-20 08:33:53 +03002486 This also means that the value of *level* used by
Brett Cannon522267e2012-08-10 18:55:08 -04002487 :c:func:`PyImport_ImportModuleEx` is now 0 instead of -1.
2488
Brett Cannon77b2abd2012-07-09 16:09:00 -04002489
Antoine Pitrouc229e6e2012-02-20 19:41:11 +01002490Building C extensions
2491---------------------
2492
2493* The range of possible file names for C extensions has been narrowed.
2494 Very rarely used spellings have been suppressed: under POSIX, files
2495 named ``xxxmodule.so``, ``xxxmodule.abi3.so`` and
2496 ``xxxmodule.cpython-*.so`` are no longer recognized as implementing
2497 the ``xxx`` module. If you had been generating such files, you have
2498 to switch to the other spellings (i.e., remove the ``module`` string
2499 from the file names).
2500
2501 (implemented in :issue:`14040`.)
2502
2503
R David Murray1764c802012-09-29 11:42:36 -04002504Command Line Switch Changes
2505---------------------------
Antoine Pitrou037ffbf2011-10-24 00:25:41 +02002506
R David Murray1764c802012-09-29 11:42:36 -04002507* The -Q command-line flag and related artifacts have been removed. Code
2508 checking sys.flags.division_warning will need updating.
Éric Araujobe3bd572011-03-26 01:55:15 +01002509
R David Murray1764c802012-09-29 11:42:36 -04002510 (:issue:`10998`, contributed by Éric Araujo.)
2511
2512* When :program:`python` is started with :option:`-S`, ``import site``
2513 will no longer add site-specific paths to the module search paths. In
2514 previous versions, it did.
2515
2516 (:issue:`11591`, contributed by Carl Meyer with editions by Éric Araujo.)