blob: e18db48ef692dc98462ae305cfbce04909699196 [file] [log] [blame]
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001****************************
2 What's New in Python 2.7
3****************************
4
5:Author: A.M. Kuchling (amk at amk.ca)
6:Release: |release|
7:Date: |today|
8
Andrew M. Kuchling039c8992010-02-01 02:04:26 +00009.. Fix accents on Kristjan Valur Jonsson, Fuerstenau
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +000010
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +000011.. Big jobs: argparse, ElementTree 1.3, pep 391, 3106, sysconfig
12.. unittest test discovery
13
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000014.. $Id$
15 Rules for maintenance:
16
17 * Anyone can add text to this document. Do not spend very much time
18 on the wording of your changes, because your text will probably
19 get rewritten to some degree.
20
21 * The maintainer will go through Misc/NEWS periodically and add
22 changes; it's therefore more important to add your changes to
23 Misc/NEWS than to this file.
24
25 * This is not a complete list of every single change; completeness
26 is the purpose of Misc/NEWS. Some changes I consider too small
27 or esoteric to include. If such a change is added to the text,
28 I'll just remove it. (This is another reason you shouldn't spend
29 too much time on writing your addition.)
30
31 * If you want to draw your new text to the attention of the
32 maintainer, add 'XXX' to the beginning of the paragraph or
33 section.
34
35 * It's OK to just add a fragmentary note about a change. For
36 example: "XXX Describe the transmogrify() function added to the
37 socket module." The maintainer will research the change and
38 write the necessary text.
39
40 * You can comment out your additions if you like, but it's not
41 necessary (especially when a final release is some months away).
42
Ezio Melotti021f3342010-04-06 03:26:49 +000043 * Credit the author of a patch or bugfix. Just the name is
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000044 sufficient; the e-mail address isn't necessary.
45
46 * It's helpful to add the bug/patch number in a parenthetical comment.
47
48 XXX Describe the transmogrify() function added to the socket
49 module.
50 (Contributed by P.Y. Developer; :issue:`12345`.)
51
52 This saves the maintainer some effort going through the SVN logs
53 when researching a change.
54
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +000055This article explains the new features in Python 2.7. The final
56release of 2.7 is currently scheduled for June 2010; the detailed
57schedule is described in :pep:`373`.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000058
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +000059Python 2.7 is planned to be the last major release in the 2.x series.
60Though more major releases have not been absolutely ruled out, it's
61likely that the 2.7 release will have an extended period of
62maintenance compared to earlier 2.x versions.
63
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000064.. Compare with previous release in 2 - 3 sentences here.
65 add hyperlink when the documentation becomes available online.
66
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000067.. _whatsnew27-python31:
68
69Python 3.1 Features
70=======================
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000071
72Much as Python 2.6 incorporated features from Python 3.0,
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000073version 2.7 incorporates some of the new features
74in Python 3.1. The 2.x series continues to provide tools
75for migrating to the 3.x series.
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000076
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000077A partial list of 3.1 features that were backported to 2.7:
78
79* A version of the :mod:`io` library, rewritten in C for performance.
80* The ordered-dictionary type described in :ref:`pep-0372`.
Andrew M. Kuchling8f254e72009-12-08 02:37:05 +000081* The new format specifier described in :ref:`pep-0378`.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000082* The :class:`memoryview` object.
83* A small subset of the :mod:`importlib` module `described below <#importlib-section>`__.
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +000084* Float-to-string and string-to-float conversions now round their
85 results more correctly. And :func:`repr` of a floating-point
86 number *x* returns a result that's guaranteed to round back to the
87 same number when converted back to a string.
88* The :cfunc:`PyLong_AsLongAndOverflow` C API function.
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000089
90One porting change: the :option:`-3` switch now automatically
91enables the :option:`-Qwarn` switch that causes warnings
92about using classic division with integers and long integers.
93
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000094Other new Python3-mode warnings include:
95
96* :func:`operator.isCallable` and :func:`operator.sequenceIncludes`,
97 which are not supported in 3.x.
98
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000099.. ========================================================================
100.. Large, PEP-level features and changes should be described here.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000101.. ========================================================================
102
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000103.. _pep-0372:
104
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000105PEP 372: Adding an ordered dictionary to collections
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000106====================================================
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000107
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000108Regular Python dictionaries iterate over key/value pairs in arbitrary order.
109Over the years, a number of authors have written alternative implementations
110that remember the order that the keys were originally inserted. Based on
111the experiences from those implementations, a new
Ezio Melotti021f3342010-04-06 03:26:49 +0000112:class:`~collections.OrderedDict` class has been introduced in the
113:mod:`collections` module.
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000114
Ezio Melotti021f3342010-04-06 03:26:49 +0000115The :class:`~collections.OrderedDict` API is substantially the same as regular
116dictionaries but will iterate over keys and values in a guaranteed order
117depending on when a key was first inserted::
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000118
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000119 >>> from collections import OrderedDict
120 >>> d = OrderedDict([('first', 1), ('second', 2),
121 ... ('third', 3)])
122 >>> d.items()
123 [('first', 1), ('second', 2), ('third', 3)]
124
125If a new entry overwrites an existing entry, the original insertion
126position is left unchanged::
127
128 >>> d['second'] = 4
129 >>> d.items()
130 [('first', 1), ('second', 4), ('third', 3)]
131
132Deleting an entry and reinserting it will move it to the end::
133
134 >>> del d['second']
135 >>> d['second'] = 5
136 >>> d.items()
137 [('first', 1), ('third', 3), ('second', 5)]
138
Ezio Melotti021f3342010-04-06 03:26:49 +0000139The :meth:`~collections.OrderedDict.popitem` method has an optional *last*
140argument that defaults to True. If *last* is True, the most recently
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000141added key is returned and removed; if it's False, the
142oldest key is selected::
143
144 >>> od = OrderedDict([(x,0) for x in range(20)])
145 >>> od.popitem()
146 (19, 0)
147 >>> od.popitem()
148 (18, 0)
Ezio Melotti021f3342010-04-06 03:26:49 +0000149 >>> od.popitem(last=False)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000150 (0, 0)
Ezio Melotti021f3342010-04-06 03:26:49 +0000151 >>> od.popitem(last=False)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000152 (1, 0)
153
154Comparing two ordered dictionaries checks both the keys and values,
155and requires that the insertion order was the same::
156
157 >>> od1 = OrderedDict([('first', 1), ('second', 2),
158 ... ('third', 3)])
159 >>> od2 = OrderedDict([('third', 3), ('first', 1),
160 ... ('second', 2)])
Ezio Melotti021f3342010-04-06 03:26:49 +0000161 >>> od1 == od2
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000162 False
163 >>> # Move 'third' key to the end
Ezio Melotti021f3342010-04-06 03:26:49 +0000164 >>> del od2['third']; od2['third'] = 3
165 >>> od1 == od2
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000166 True
167
Ezio Melotti021f3342010-04-06 03:26:49 +0000168Comparing an :class:`~collections.OrderedDict` with a regular dictionary
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000169ignores the insertion order and just compares the keys and values.
170
Ezio Melotti021f3342010-04-06 03:26:49 +0000171How does the :class:`~collections.OrderedDict` work? It maintains a
172doubly-linked list of keys, appending new keys to the list as they're inserted.
173A secondary dictionary maps keys to their corresponding list node, so
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000174deletion doesn't have to traverse the entire linked list and therefore
175remains O(1).
176
177.. XXX check O(1)-ness with Raymond
Ezio Melotti021f3342010-04-06 03:26:49 +0000178.. Also check if the 'somenamedtuple' in the collection module should
179.. be replaced/removed in order to use
180.. :meth:`~collections.namedtuple._asdict()` (see below)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000181
182The standard library now supports use of ordered dictionaries in several
Ezio Melotti021f3342010-04-06 03:26:49 +0000183modules. The :mod:`ConfigParser` module uses them by default. This lets
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000184configuration files be read, modified, and then written back in their original
Ezio Melotti021f3342010-04-06 03:26:49 +0000185order. The :meth:`~collections.somenamedtuple._asdict()` method for
186:func:`collections.namedtuple` now returns an ordered dictionary with the
187values appearing in the same order as the underlying tuple indices.
188The :mod:`json` module is being built-out with an *object_pairs_hook* to allow
189OrderedDicts to be built by the decoder.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000190Support was also added for third-party tools like `PyYAML <http://pyyaml.org/>`_.
191
Andrew M. Kuchling7fe65a02009-10-13 15:49:33 +0000192.. seealso::
193
194 :pep:`372` - Adding an ordered dictionary to collections
195 PEP written by Armin Ronacher and Raymond Hettinger;
196 implemented by Raymond Hettinger.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000197
198.. _pep-0378:
199
200PEP 378: Format Specifier for Thousands Separator
Ezio Melotti021f3342010-04-06 03:26:49 +0000201=================================================
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000202
203To make program output more readable, it can be useful to add
204separators to large numbers and render them as
20518,446,744,073,709,551,616 instead of 18446744073709551616.
206
207The fully general solution for doing this is the :mod:`locale` module,
208which can use different separators ("," in North America, "." in
209Europe) and different grouping sizes, but :mod:`locale` is complicated
210to use and unsuitable for multi-threaded applications where different
211threads are producing output for different locales.
212
213Therefore, a simple comma-grouping mechanism has been added to the
Ezio Melotti021f3342010-04-06 03:26:49 +0000214mini-language used by the :meth:`str.format` method. When
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000215formatting a floating-point number, simply include a comma between the
216width and the precision::
217
Eric Smithc4663852010-04-06 14:30:15 +0000218 >>> '{:20,.2f}'.format(18446744073709551616.0)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000219 '18,446,744,073,709,551,616.00'
220
221This mechanism is not adaptable at all; commas are always used as the
222separator and the grouping is always into three-digit groups. The
223comma-formatting mechanism isn't as general as the :mod:`locale`
224module, but it's easier to use.
225
Andrew M. Kuchling85ea4bf2009-10-05 22:45:39 +0000226.. XXX "Format String Syntax" in string.rst could use many more examples.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000227
228.. seealso::
229
230 :pep:`378` - Format Specifier for Thousands Separator
231 PEP written by Raymond Hettinger; implemented by Eric Smith.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000232
Andrew M. Kuchlingab21f752010-03-02 13:55:33 +0000233PEP 389: The argparse Module for Parsing Command Lines
234======================================================
235
236XXX write this section.
237
238.. seealso::
239
240 :pep:`389` - argparse - New Command Line Parsing Module
241 PEP written and implemented by Steven Bethard.
242
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000243PEP 391: Dictionary-Based Configuration For Logging
244====================================================
245
246XXX write this section.
247
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000248Two smaller enhancements to the logging module are:
249
250.. rev79293
251
252* :class:`Logger` instances gained a :meth:`getChild` that retrieves a
253 descendant logger using a relative path. For example,
254 once you retrieve a logger by doing ``log = getLogger('app')``,
255 calling ``log.getChild('network.listen')`` is equivalent to
256 ``getLogger('app.network.listen')``.
257
258* The :class:`LoggerAdapter` class gained a :meth:`isEnabledFor` method
259 that takes a *level* and returns whether the underlying logger would
260 process a message of that level of importance.
261
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000262.. seealso::
263
264 :pep:`391` - Dictionary-Based Configuration For Logging
265 PEP written and implemented by Vinay Sajip.
266
267PEP 3106: Dictionary Views
268====================================================
269
270XXX write this section.
271
272.. seealso::
273
274 :pep:`3106` - Revamping dict.keys(), .values() and .items()
275 PEP written by Guido van Rossum.
276 Backported to 2.7 by Alexandre Vassalotti; :issue:`1967`.
277
278
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000279Other Language Changes
280======================
281
282Some smaller changes made to the core Python language are:
283
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000284* The syntax for set literals has been backported from Python 3.x.
285 Curly brackets are used to surround the contents of the resulting
286 mutable set; set literals are
287 distinguished from dictionaries by not containing colons and values.
288 ``{}`` continues to represent an empty dictionary; use
289 ``set()`` for an empty set.
290
291 >>> {1,2,3,4,5}
292 set([1, 2, 3, 4, 5])
Ezio Melotti021f3342010-04-06 03:26:49 +0000293 >>> set() # empty set
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000294 set([])
Ezio Melotti021f3342010-04-06 03:26:49 +0000295 >>> {} # empty dict
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000296 {}
297
298 Backported by Alexandre Vassalotti; :issue:`2335`.
299
300* Dictionary and set comprehensions are another feature backported from
301 3.x, generalizing list/generator comprehensions to use
302 the literal syntax for sets and dictionaries.
303
304 >>> {x:x*x for x in range(6)}
305 {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
306 >>> {'a'*x for x in range(6)}
307 set(['', 'a', 'aa', 'aaa', 'aaaa', 'aaaaa'])
308
309 Backported by Alexandre Vassalotti; :issue:`2333`.
310
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000311* The :keyword:`with` statement can now use multiple context managers
312 in one statement. Context managers are processed from left to right
313 and each one is treated as beginning a new :keyword:`with` statement.
314 This means that::
315
316 with A() as a, B() as b:
317 ... suite of statements ...
318
319 is equivalent to::
320
321 with A() as a:
322 with B() as b:
323 ... suite of statements ...
324
325 The :func:`contextlib.nested` function provides a very similar
326 function, so it's no longer necessary and has been deprecated.
327
328 (Proposed in http://codereview.appspot.com/53094; implemented by
329 Georg Brandl.)
330
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000331* Conversions between floating-point numbers and strings are
332 now correctly rounded on most platforms. These conversions occur
333 in many different places: :func:`str` on
334 floats and complex numbers; the :class:`float` and :class:`complex`
335 constructors;
336 numeric formatting; serialization and
337 deserialization of floats and complex numbers using the
338 :mod:`marshal`, :mod:`pickle`
339 and :mod:`json` modules;
340 parsing of float and imaginary literals in Python code;
Ezio Melotti021f3342010-04-06 03:26:49 +0000341 and :class:`~decimal.Decimal`-to-float conversion.
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000342
343 Related to this, the :func:`repr` of a floating-point number *x*
344 now returns a result based on the shortest decimal string that's
345 guaranteed to round back to *x* under correct rounding (with
346 round-half-to-even rounding mode). Previously it gave a string
347 based on rounding x to 17 decimal digits.
348
Ezio Melotti021f3342010-04-06 03:26:49 +0000349 .. maybe add an example?
350
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000351 The rounding library responsible for this improvement works on
352 Windows, and on Unix platforms using the gcc, icc, or suncc
353 compilers. There may be a small number of platforms where correct
354 operation of this code cannot be guaranteed, so the code is not
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +0000355 used on such systems. You can find out which code is being used
356 by checking :data:`sys.float_repr_style`, which will be ``short``
357 if the new code is in use and ``legacy`` if it isn't.
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000358
Mark Dickinsonbdd863d2010-01-07 09:28:29 +0000359 Implemented by Eric Smith and Mark Dickinson, using David Gay's
360 :file:`dtoa.c` library; :issue:`7117`.
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000361
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000362* The :meth:`str.format` method now supports automatic numbering of the replacement
Benjamin Petersonaa0a0b92009-04-11 20:27:15 +0000363 fields. This makes using :meth:`str.format` more closely resemble using
364 ``%s`` formatting::
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000365
366 >>> '{}:{}:{}'.format(2009, 04, 'Sunday')
367 '2009:4:Sunday'
368 >>> '{}:{}:{day}'.format(2009, 4, day='Sunday')
369 '2009:4:Sunday'
370
Benjamin Petersonaa0a0b92009-04-11 20:27:15 +0000371 The auto-numbering takes the fields from left to right, so the first ``{...}``
372 specifier will use the first argument to :meth:`str.format`, the next
373 specifier will use the next argument, and so on. You can't mix auto-numbering
374 and explicit numbering -- either number all of your specifier fields or none
375 of them -- but you can mix auto-numbering and named fields, as in the second
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000376 example above. (Contributed by Eric Smith; :issue:`5237`.)
377
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000378 Complex numbers now correctly support usage with :func:`format`,
379 and default to being right-aligned.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000380 Specifying a precision or comma-separation applies to both the real
381 and imaginary parts of the number, but a specified field width and
382 alignment is applied to the whole of the resulting ``1.5+3j``
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000383 output. (Contributed by Eric Smith; :issue:`1588` and :issue:`7988`.)
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000384
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000385 The 'F' format code now always formats its output using uppercase characters,
386 so it will now produce 'INF' and 'NAN'.
387 (Contributed by Eric Smith; :issue:`3382`.)
388
Mark Dickinson1a707982008-12-17 16:14:37 +0000389* The :func:`int` and :func:`long` types gained a ``bit_length``
Georg Brandl64e1c752009-04-11 18:19:27 +0000390 method that returns the number of bits necessary to represent
Mark Dickinson1a707982008-12-17 16:14:37 +0000391 its argument in binary::
392
393 >>> n = 37
Ezio Melotti021f3342010-04-06 03:26:49 +0000394 >>> bin(n)
Mark Dickinson1a707982008-12-17 16:14:37 +0000395 '0b100101'
396 >>> n.bit_length()
397 6
398 >>> n = 2**123-1
399 >>> n.bit_length()
400 123
401 >>> (n+1).bit_length()
402 124
403
404 (Contributed by Fredrik Johansson and Victor Stinner; :issue:`3439`.)
405
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000406* Conversions from long integers and regular integers to floating
407 point now round differently, returning the floating-point number
408 closest to the number. This doesn't matter for small integers that
409 can be converted exactly, but for large numbers that will
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000410 unavoidably lose precision, Python 2.7 now approximates more
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000411 closely. For example, Python 2.6 computed the following::
412
413 >>> n = 295147905179352891391
414 >>> float(n)
415 2.9514790517935283e+20
416 >>> n - long(float(n))
417 65535L
418
419 Python 2.7's floating-point result is larger, but much closer to the
420 true value::
421
422 >>> n = 295147905179352891391
423 >>> float(n)
424 2.9514790517935289e+20
Ezio Melotti021f3342010-04-06 03:26:49 +0000425 >>> n - long(float(n))
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000426 -1L
427
428 (Implemented by Mark Dickinson; :issue:`3166`.)
429
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000430 Integer division is also more accurate in its rounding behaviours. (Also
431 implemented by Mark Dickinson; :issue:`1811`.)
432
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000433* It's now possible for a subclass of the built-in :class:`unicode` type
434 to override the :meth:`__unicode__` method. (Implemented by
435 Victor Stinner; :issue:`1583863`.)
436
Ezio Melotti021f3342010-04-06 03:26:49 +0000437* The :class:`bytearray` type's :meth:`~bytearray.translate` method now accepts
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000438 ``None`` as its first argument. (Fixed by Georg Brandl;
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000439 :issue:`4759`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000440
Ezio Melotti021f3342010-04-06 03:26:49 +0000441 .. bytearray doesn't seem to be documented
442
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000443* When using ``@classmethod`` and ``@staticmethod`` to wrap
444 methods as class or static methods, the wrapper object now
445 exposes the wrapped function as their :attr:`__func__` attribute.
446 (Contributed by Amaury Forgeot d'Arc, after a suggestion by
447 George Sakkis; :issue:`5982`.)
448
449* A new encoding named "cp720", used primarily for Arabic text, is now
450 supported. (Contributed by Alexander Belchenko and Amaury Forgeot
451 d'Arc; :issue:`1616979`.)
452
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000453* The :class:`file` object will now set the :attr:`filename` attribute
454 on the :exc:`IOError` exception when trying to open a directory
Andrew M. Kuchling0e7123f2010-02-08 13:22:24 +0000455 on POSIX platforms (noted by Jan Kaliszewski; :issue:`4764`), and
456 now explicitly checks for and forbids writing to read-only file objects
457 instead of trusting the C library to catch and report the error
458 (fixed by Stefan Krah; :issue:`5677`).
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000459
Benjamin Petersonae9a0a02009-12-31 16:49:37 +0000460* The Python tokenizer now translates line endings itself, so the
461 :func:`compile` built-in function can now accept code using any
462 line-ending convention. Additionally, it no longer requires that the
463 code end in a newline.
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +0000464
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000465* Extra parentheses in function definitions are illegal in Python 3.x,
466 meaning that you get a syntax error from ``def f((x)): pass``. In
467 Python3-warning mode, Python 2.7 will now warn about this odd usage.
468 (Noted by James Lingard; :issue:`7362`.)
469
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000470* When a module object is garbage-collected, the module's dictionary is
471 now only cleared if no one else is holding a reference to the
472 dictionary (:issue:`7140`).
473
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000474.. ======================================================================
475
476
477Optimizations
478-------------
479
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000480Several performance enhancements have been added:
481
482.. * A new :program:`configure` option, :option:`--with-computed-gotos`,
483 compiles the main bytecode interpreter loop using a new dispatch
484 mechanism that gives speedups of up to 20%, depending on the system
485 and benchmark. The new mechanism is only supported on certain
486 compilers, such as gcc, SunPro, and icc.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000487
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000488* A new opcode was added to perform the initial setup for
489 :keyword:`with` statements, looking up the :meth:`__enter__` and
490 :meth:`__exit__` methods. (Contributed by Benjamin Peterson.)
491
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000492* The garbage collector now performs better for one common usage
493 pattern: when many objects are being allocated without deallocating
494 any of them. This would previously take quadratic
495 time for garbage collection, but now the number of full garbage collections
496 is reduced as the number of objects on the heap grows.
497 The new logic is to only perform a full garbage collection pass when
498 the middle generation has been collected 10 times and when the
499 number of survivor objects from the middle generation exceeds 10% of
500 the number of objects in the oldest generation. (Suggested by Martin
Ezio Melotti021f3342010-04-06 03:26:49 +0000501 von Löwis and implemented by Antoine Pitrou; :issue:`4074`.)
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000502
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000503* The garbage collector tries to avoid tracking simple containers
504 which can't be part of a cycle. In Python 2.7, this is now true for
505 tuples and dicts containing atomic types (such as ints, strings,
506 etc.). Transitively, a dict containing tuples of atomic types won't
507 be tracked either. This helps reduce the cost of each
508 garbage collection by decreasing the number of objects to be
509 considered and traversed by the collector.
Antoine Pitrouc18f6b02009-03-28 19:10:13 +0000510 (Contributed by Antoine Pitrou; :issue:`4688`.)
511
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000512* Long integers are now stored internally either in base 2**15 or in base
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000513 2**30, the base being determined at build time. Previously, they
514 were always stored in base 2**15. Using base 2**30 gives
515 significant performance improvements on 64-bit machines, but
516 benchmark results on 32-bit machines have been mixed. Therefore,
517 the default is to use base 2**30 on 64-bit machines and base 2**15
518 on 32-bit machines; on Unix, there's a new configure option
519 :option:`--enable-big-digits` that can be used to override this default.
520
521 Apart from the performance improvements this change should be
522 invisible to end users, with one exception: for testing and
Ezio Melotti021f3342010-04-06 03:26:49 +0000523 debugging purposes there's a new structseq :data:`sys.long_info` that
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000524 provides information about the internal format, giving the number of
525 bits per digit and the size in bytes of the C type used to store
526 each digit::
527
528 >>> import sys
529 >>> sys.long_info
530 sys.long_info(bits_per_digit=30, sizeof_digit=4)
531
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000532 (Contributed by Mark Dickinson; :issue:`4258`.)
533
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000534 Another set of changes made long objects a few bytes smaller: 2 bytes
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000535 smaller on 32-bit systems and 6 bytes on 64-bit.
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000536 (Contributed by Mark Dickinson; :issue:`5260`.)
537
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000538* The division algorithm for long integers has been made faster
539 by tightening the inner loop, doing shifts instead of multiplications,
540 and fixing an unnecessary extra iteration.
541 Various benchmarks show speedups of between 50% and 150% for long
542 integer divisions and modulo operations.
543 (Contributed by Mark Dickinson; :issue:`5512`.)
Andrew M. Kuchlinga7f59472009-12-31 16:38:53 +0000544 Bitwise operations are also significantly faster (initial patch by
545 Gregory Smith; :issue:`1087418`).
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000546
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000547* The implementation of ``%`` checks for the left-side operand being
548 a Python string and special-cases it; this results in a 1-3%
549 performance increase for applications that frequently use ``%``
550 with strings, such as templating libraries.
551 (Implemented by Collin Winter; :issue:`5176`.)
552
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000553* List comprehensions with an ``if`` condition are compiled into
554 faster bytecode. (Patch by Antoine Pitrou, back-ported to 2.7
555 by Jeffrey Yasskin; :issue:`4715`.)
556
Andrew M. Kuchling7f8ebdb2010-01-03 01:15:21 +0000557* Converting an integer or long integer to a decimal string was made
558 faster by special-casing base 10 instead of using a generalized
559 conversion function that supports arbitrary bases.
560 (Patch by Gawain Bolton; :issue:`6713`.)
561
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +0000562* The :meth:`split`, :meth:`replace`, :meth:`rindex`,
563 :meth:`rpartition`, and :meth:`rsplit` methods of string-like types
564 (strings, Unicode strings, and :class:`bytearray` objects) now use a
565 fast reverse-search algorithm instead of a character-by-character
566 scan. This is sometimes faster by a factor of 10. (Added by
567 Florent Xicluna; :issue:`7462` and :issue:`7622`.)
Andrew M. Kuchling7f8ebdb2010-01-03 01:15:21 +0000568
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000569* The :mod:`pickle` and :mod:`cPickle` modules now automatically
570 intern the strings used for attribute names, reducing memory usage
571 of the objects resulting from unpickling. (Contributed by Jake
572 McGuire; :issue:`5084`.)
573
574* The :mod:`cPickle` module now special-cases dictionaries,
575 nearly halving the time required to pickle them.
576 (Contributed by Collin Winter; :issue:`5670`.)
577
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000578.. ======================================================================
579
Georg Brandl0516f812009-11-18 18:52:35 +0000580New and Improved Modules
581========================
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000582
583As in every release, Python's standard library received a number of
584enhancements and bug fixes. Here's a partial list of the most notable
585changes, sorted alphabetically by module name. Consult the
586:file:`Misc/NEWS` file in the source tree for a more complete list of
587changes, or look through the Subversion logs for all the details.
588
Ezio Melotti021f3342010-04-06 03:26:49 +0000589* The :mod:`bdb` module's base debugging class :class:`~bdb.Bdb`
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000590 gained a feature for skipping modules. The constructor
591 now takes an iterable containing glob-style patterns such as
592 ``django.*``; the debugger will not step into stack frames
593 from a module that matches one of these patterns.
594 (Contributed by Maru Newby after a suggestion by
595 Senthil Kumaran; :issue:`5142`.)
596
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +0000597* The :mod:`binascii` module now supports the buffer API, so it can be
598 used with :class:`memoryview` instances and other similar buffer objects.
599 (Backported from 3.x by Florent Xicluna; :issue:`7703`.)
600
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000601* Updated module: the :mod:`bsddb` module has been updated from 4.7.2devel9
602 to version 4.8.4 of
603 `the pybsddb package <http://www.jcea.es/programacion/pybsddb.htm>`__.
604 The new version features better Python 3.x compatibility, various bug fixes,
605 and adds several new BerkeleyDB flags and methods.
Ezio Melotti021f3342010-04-06 03:26:49 +0000606 (Updated by Jesús Cea Avión; :issue:`8156`. The pybsddb
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000607 changelog can be browsed at http://hg.jcea.es/pybsddb/file/tip/ChangeLog.)
608
Ezio Melotti021f3342010-04-06 03:26:49 +0000609* The :mod:`bz2` module's :class:`~bz2.BZ2File` now supports the context
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000610 management protocol, so you can write ``with bz2.BZ2File(...) as f: ...``.
611 (Contributed by Hagen Fuerstenau; :issue:`3860`.)
612
Ezio Melotti021f3342010-04-06 03:26:49 +0000613* New class: the :class:`~collections.Counter` class in the :mod:`collections`
614 module is useful for tallying data. :class:`~collections.Counter` instances
615 behave mostly like dictionaries but return zero for missing keys instead of
Georg Brandlf6dab952009-04-28 21:48:35 +0000616 raising a :exc:`KeyError`:
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000617
Georg Brandlf6dab952009-04-28 21:48:35 +0000618 .. doctest::
619 :options: +NORMALIZE_WHITESPACE
620
621 >>> from collections import Counter
622 >>> c = Counter()
623 >>> for letter in 'here is a sample of english text':
624 ... c[letter] += 1
625 ...
626 >>> c
627 Counter({' ': 6, 'e': 5, 's': 3, 'a': 2, 'i': 2, 'h': 2,
628 'l': 2, 't': 2, 'g': 1, 'f': 1, 'm': 1, 'o': 1, 'n': 1,
629 'p': 1, 'r': 1, 'x': 1})
630 >>> c['e']
631 5
632 >>> c['z']
633 0
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000634
Ezio Melotti021f3342010-04-06 03:26:49 +0000635 There are two additional :class:`~collections.Counter` methods:
636 :meth:`~collections.Counter.most_common` returns the N most common elements
637 and their counts, and :meth:`~collections.Counter.elements`
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000638 returns an iterator over the contained element, repeating each element
639 as many times as its count::
640
641 >>> c.most_common(5)
642 [(' ', 6), ('e', 5), ('s', 3), ('a', 2), ('i', 2)]
643 >>> c.elements() ->
644 'a', 'a', ' ', ' ', ' ', ' ', ' ', ' ',
645 'e', 'e', 'e', 'e', 'e', 'g', 'f', 'i', 'i',
646 'h', 'h', 'm', 'l', 'l', 'o', 'n', 'p', 's',
Georg Brandlf6dab952009-04-28 21:48:35 +0000647 's', 's', 'r', 't', 't', 'x'
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000648
Ezio Melotti021f3342010-04-06 03:26:49 +0000649 .. maybe it's better to use list(c.elements()) here
650
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000651 Contributed by Raymond Hettinger; :issue:`1696199`.
652
Ezio Melotti021f3342010-04-06 03:26:49 +0000653 The new :class:`~collections.OrderedDict` class is described in the earlier
654 section :ref:`pep-0372`.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000655
Ezio Melotti021f3342010-04-06 03:26:49 +0000656 The :class:`~collections.namedtuple` class now has an optional *rename* parameter.
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000657 If *rename* is true, field names that are invalid because they've
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000658 been repeated or that aren't legal Python identifiers will be
659 renamed to legal names that are derived from the field's
660 position within the list of fields:
661
Georg Brandlf6dab952009-04-28 21:48:35 +0000662 >>> from collections import namedtuple
663 >>> T = namedtuple('T', ['field1', '$illegal', 'for', 'field2'], rename=True)
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000664 >>> T._fields
665 ('field1', '_1', '_2', 'field2')
666
667 (Added by Raymond Hettinger; :issue:`1818`.)
668
Ezio Melotti021f3342010-04-06 03:26:49 +0000669 The :class:`~collections.deque` data type now exposes its maximum length as the
670 read-only :attr:`~collections.deque.maxlen` attribute, and has a
671 :meth:`~collections.deque.reverse` method that reverses the elements of the deque in-place.
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000672 (Added by Raymond Hettinger.)
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000673
Ezio Melotti021f3342010-04-06 03:26:49 +0000674* The :mod:`copy` module's :func:`~copy.deepcopy` function will now
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000675 correctly copy bound instance methods. (Implemented by
676 Robert Collins; :issue:`1515`.)
677
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000678* The :mod:`ctypes` module now always converts ``None`` to a C NULL
679 pointer for arguments declared as pointers. (Changed by Thomas
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +0000680 Heller; :issue:`4606`.) The underlying `libffi library
681 <http://sourceware.org/libffi/>`__ has been updated to version
682 3.0.9, containing various fixes for different platforms. (Updated
683 by Matthias Klose; :issue:`8142`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000684
Ezio Melotti021f3342010-04-06 03:26:49 +0000685* New method: the :mod:`datetime` module's :class:`~datetime.timedelta` class
686 gained a :meth:`~datetime.timedelta.total_seconds` method that returns the
687 number of seconds in the duration. (Contributed by Brian Quinlan; :issue:`5788`.)
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000688
Ezio Melotti021f3342010-04-06 03:26:49 +0000689* New method: the :class:`~decimal.Decimal` class gained a
690 :meth:`~decimal.Decimal.from_float` class method that performs an exact
691 conversion of a floating-point number to a :class:`~decimal.Decimal`.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000692 Note that this is an **exact** conversion that strives for the
693 closest decimal approximation to the floating-point representation's value;
694 the resulting decimal value will therefore still include the inaccuracy,
695 if any.
696 For example, ``Decimal.from_float(0.1)`` returns
697 ``Decimal('0.1000000000000000055511151231257827021181583404541015625')``.
698 (Implemented by Raymond Hettinger; :issue:`4796`.)
699
Ezio Melotti021f3342010-04-06 03:26:49 +0000700 Most of the methods of the :class:`~decimal.Context` class now accept integers
701 as well as :class:`~decimal.Decimal` instances; the only exceptions are the
702 :meth:`~decimal.Context.canonical` and :meth:`~decimal.Context.is_canonical`
703 methods. (Patch by Juan José Conti; :issue:`7633`.)
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000704
Ezio Melotti021f3342010-04-06 03:26:49 +0000705 The constructor for :class:`~decimal.Decimal` now accepts non-European
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000706 Unicode characters, such as Arabic-Indic digits. (Contributed by
707 Mark Dickinson; :issue:`6595`.)
708
Ezio Melotti021f3342010-04-06 03:26:49 +0000709 When using :class:`~decimal.Decimal` instances with a string's
710 :meth:`~str.format` method, the default alignment was previously
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000711 left-alignment. This has been changed to right-alignment, which seems
712 more sensible for numeric types. (Changed by Mark Dickinson; :issue:`6857`.)
713
Ezio Melotti021f3342010-04-06 03:26:49 +0000714* The :class:`~fractions.Fraction` class now accepts two rational numbers
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000715 as arguments to its constructor.
716 (Implemented by Mark Dickinson; :issue:`5812`.)
717
Ezio Melotti021f3342010-04-06 03:26:49 +0000718* New class: a new :class:`~ftplib.FTP_TLS` class in
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +0000719 the :mod:`ftplib` module provides secure FTP
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000720 connections using TLS encapsulation of authentication as well as
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +0000721 subsequent control and data transfers.
722 (Contributed by Giampaolo Rodola', :issue:`2054`.)
723
Ezio Melotti021f3342010-04-06 03:26:49 +0000724 The :meth:`~ftplib.FTP.storbinary` method for binary uploads can now restart
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +0000725 uploads thanks to an added *rest* parameter (patch by Pablo Mouzo;
726 :issue:`6845`.)
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000727
Ezio Melotti021f3342010-04-06 03:26:49 +0000728* New function: the :mod:`gc` module's :func:`~gc.is_tracked` returns
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000729 true if a given instance is tracked by the garbage collector, false
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000730 otherwise. (Contributed by Antoine Pitrou; :issue:`4688`.)
731
Ezio Melotti021f3342010-04-06 03:26:49 +0000732* The :mod:`gzip` module's :class:`~gzip.GzipFile` now supports the context
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000733 management protocol, so you can write ``with gzip.GzipFile(...) as f: ...``
734 (contributed by Hagen Fuerstenau; :issue:`3860`), and it now implements
735 the :class:`io.BufferedIOBase` ABC, so you can wrap it with
736 :class:`io.BufferedReader` for faster processing
737 (contributed by Nir Aides; :issue:`7471`).
738 It's also now possible to override the modification time
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000739 recorded in a gzipped file by providing an optional timestamp to
740 the constructor. (Contributed by Jacques Frechet; :issue:`4272`.)
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000741
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +0000742 Files in gzip format can be padded with trailing zero bytes; the
743 :mod:`gzip` module will now consume these trailing bytes. (Fixed by
744 Tadek Pietraszek and Brian Curtin; :issue:`2846`.)
745
Ezio Melotti021f3342010-04-06 03:26:49 +0000746* New attribute: the :mod:`hashlib` module now has an :attr:`~hashlib.hashlib.algorithms`
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000747 attribute containing a tuple naming the supported algorithms.
748 In Python 2.7, ``hashlib.algorithms`` contains
749 ``('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')``
750 (Contributed by Carl Chenet; :issue:`7418`.)
751
Ezio Melotti021f3342010-04-06 03:26:49 +0000752* The default :class:`~httplib.HTTPResponse` class used by the :mod:`httplib` module now
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000753 supports buffering, resulting in much faster reading of HTTP responses.
754 (Contributed by Kristjan Valur Jonsson; :issue:`4879`.)
755
Ezio Melotti021f3342010-04-06 03:26:49 +0000756 The :class:`~httplib.HTTPConnection` and :class:`~httplib.HTTPSConnection` classes
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +0000757 now support a *source_address* parameter, a ``(host, port)`` 2-tuple
758 giving the source address that will be used for the connection.
759 (Contributed by Eldon Ziegler; :issue:`3972`.)
760
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000761* The :mod:`imaplib` module now supports IPv6 addresses.
762 (Contributed by Derek Morr; :issue:`1655`.)
763
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +0000764* Updated module: The :mod:`io` library has been upgraded to the version shipped with
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000765 Python 3.1. For 3.1, the I/O library was entirely rewritten in C
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +0000766 and is 2 to 20 times faster depending on the task being performed. The
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000767 original Python version was renamed to the :mod:`_pyio` module.
768
769 One minor resulting change: the :class:`io.TextIOBase` class now
770 has an :attr:`errors` attribute giving the error setting
771 used for encoding and decoding errors (one of ``'strict'``, ``'replace'``,
772 ``'ignore'``).
773
774 The :class:`io.FileIO` class now raises an :exc:`OSError` when passed
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000775 an invalid file descriptor. (Implemented by Benjamin Peterson;
Ezio Melotti021f3342010-04-06 03:26:49 +0000776 :issue:`4991`.) The :meth:`~io.IOBase.truncate` method now preserves the
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +0000777 file position; previously it would change the file position to the
778 end of the new file. (Fixed by Pascal Chambon; :issue:`6939`.)
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000779
Andrew M. Kuchling5a73ff82009-12-02 14:27:11 +0000780* New function: ``itertools.compress(data, selectors)`` takes two
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000781 iterators. Elements of *data* are returned if the corresponding
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000782 value in *selectors* is true::
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000783
784 itertools.compress('ABCDEF', [1,0,1,0,1,1]) =>
785 A, C, E, F
786
Ezio Melotti021f3342010-04-06 03:26:49 +0000787 .. maybe here is better to use >>> list(itertools.compress(...)) instead
788
Andrew M. Kuchling5a73ff82009-12-02 14:27:11 +0000789 New function: ``itertools.combinations_with_replacement(iter, r)``
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000790 returns all the possible *r*-length combinations of elements from the
Ezio Melotti021f3342010-04-06 03:26:49 +0000791 iterable *iter*. Unlike :func:`~itertools.combinations`, individual elements
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000792 can be repeated in the generated combinations::
793
794 itertools.combinations_with_replacement('abc', 2) =>
795 ('a', 'a'), ('a', 'b'), ('a', 'c'),
796 ('b', 'b'), ('b', 'c'), ('c', 'c')
797
798 Note that elements are treated as unique depending on their position
799 in the input, not their actual values.
800
Ezio Melotti021f3342010-04-06 03:26:49 +0000801 The :func:`itertools.count` function now has a *step* argument that
802 allows incrementing by values other than 1. :func:`~itertools.count` also
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000803 now allows keyword arguments, and using non-integer values such as
Ezio Melotti021f3342010-04-06 03:26:49 +0000804 floats or :class:`~decimal.Decimal` instances. (Implemented by Raymond
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000805 Hettinger; :issue:`5032`.)
806
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000807 :func:`itertools.combinations` and :func:`itertools.product` were
808 previously raising :exc:`ValueError` for values of *r* larger than
809 the input iterable. This was deemed a specification error, so they
810 now return an empty iterator. (Fixed by Raymond Hettinger; :issue:`4816`.)
811
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +0000812* Updated module: The :mod:`json` module was upgraded to version 2.0.9 of the
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000813 simplejson package, which includes a C extension that makes
814 encoding and decoding faster.
815 (Contributed by Bob Ippolito; :issue:`4136`.)
816
Ezio Melotti021f3342010-04-06 03:26:49 +0000817 To support the new :class:`collections.OrderedDict` type, :func:`json.load`
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000818 now has an optional *object_pairs_hook* parameter that will be called
819 with any object literal that decodes to a list of pairs.
820 (Contributed by Raymond Hettinger; :issue:`5381`.)
821
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000822* New functions: the :mod:`math` module gained
Ezio Melotti021f3342010-04-06 03:26:49 +0000823 :func:`~math.erf` and :func:`~math.erfc` for the error function and the complementary error function,
824 :func:`~math.expm1` which computes ``e**x - 1`` with more precision than
825 using :func:`~math.exp` and subtracting 1,
826 :func:`~math.gamma` for the Gamma function, and
827 :func:`~math.lgamma` for the natural log of the Gamma function.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000828 (Contributed by Mark Dickinson and nirinA raseliarison; :issue:`3366`.)
829
Andrew M. Kuchling24520b42009-04-09 11:22:47 +0000830* The :mod:`multiprocessing` module's :class:`Manager*` classes
831 can now be passed a callable that will be called whenever
832 a subprocess is started, along with a set of arguments that will be
833 passed to the callable.
834 (Contributed by lekma; :issue:`5585`.)
835
Ezio Melotti021f3342010-04-06 03:26:49 +0000836 The :class:`~multiprocessing.Pool` class, which controls a pool of worker processes,
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +0000837 now has an optional *maxtasksperchild* parameter. Worker processes
838 will perform the specified number of tasks and then exit, causing the
Ezio Melotti021f3342010-04-06 03:26:49 +0000839 :class:`~multiprocessing.Pool` to start a new worker. This is useful if tasks may leak
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +0000840 memory or other resources, or if some tasks will cause the worker to
841 become very large.
842 (Contributed by Charles Cazabon; :issue:`6963`.)
843
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000844* The :mod:`nntplib` module now supports IPv6 addresses.
845 (Contributed by Derek Morr; :issue:`1664`.)
846
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000847* New functions: the :mod:`os` module wraps the following POSIX system
Ezio Melotti021f3342010-04-06 03:26:49 +0000848 calls: :func:`~os.getresgid` and :func:`~os.getresuid`, which return the
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000849 real, effective, and saved GIDs and UIDs;
Ezio Melotti021f3342010-04-06 03:26:49 +0000850 :func:`~os.setresgid` and :func:`~os.setresuid`, which set
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000851 real, effective, and saved GIDs and UIDs to new values;
Ezio Melotti021f3342010-04-06 03:26:49 +0000852 :func:`~os.initgroups`. (GID/UID functions
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000853 contributed by Travis H.; :issue:`6508`. Support for initgroups added
854 by Jean-Paul Calderone; :issue:`7333`.)
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000855
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +0000856 The :func:`os.fork` function now re-initializes the import lock in
Ezio Melotti021f3342010-04-06 03:26:49 +0000857 the child process; this fixes problems on Solaris when :func:`~os.fork`
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +0000858 is called from a thread. (Fixed by Zsolt Cserna; :issue:`7242`.)
859
Ezio Melotti021f3342010-04-06 03:26:49 +0000860* In the :mod:`os.path` module, the :func:`~os.path.normpath` and
861 :func:`~os.path.abspath` functions now preserve Unicode; if their input path
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +0000862 is a Unicode string, the return value is also a Unicode string.
Ezio Melotti021f3342010-04-06 03:26:49 +0000863 (:meth:`~os.path.normpath` fixed by Matt Giuca in :issue:`5827`;
864 :meth:`~os.path.abspath` fixed by Ezio Melotti in :issue:`3426`.)
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +0000865
Andrew M. Kuchling9cb42772009-01-21 02:15:43 +0000866* The :mod:`pydoc` module now has help for the various symbols that Python
867 uses. You can now do ``help('<<')`` or ``help('@')``, for example.
868 (Contributed by David Laban; :issue:`4739`.)
869
Ezio Melotti021f3342010-04-06 03:26:49 +0000870* The :mod:`re` module's :func:`~re.split`, :func:`~re.sub`, and :func:`~re.subn`
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000871 now accept an optional *flags* argument, for consistency with the
872 other functions in the module. (Added by Gregory P. Smith.)
873
Ezio Melotti021f3342010-04-06 03:26:49 +0000874* New function: in the :mod:`shutil` module, :func:`~shutil.make_archive`
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +0000875 takes a filename, archive type (zip or tar-format), and a directory
876 path, and creates an archive containing the directory's contents.
877 (Added by Tarek Ziadé.)
878
Ezio Melotti021f3342010-04-06 03:26:49 +0000879 :mod:`shutil`'s :func:`~shutil.copyfile` and :func:`~shutil.copytree`
880 functions now raise a :exc:`~shutil.SpecialFileError` exception when
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000881 asked to copy a named pipe. Previously the code would treat
882 named pipes like a regular file by opening them for reading, and
883 this would block indefinitely. (Fixed by Antoine Pitrou; :issue:`3002`.)
884
885* New functions: in the :mod:`site` module, three new functions
886 return various site- and user-specific paths.
Ezio Melotti021f3342010-04-06 03:26:49 +0000887 :func:`~site.getsitepackages` returns a list containing all
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000888 global site-packages directories, and
Ezio Melotti021f3342010-04-06 03:26:49 +0000889 :func:`~site.getusersitepackages` returns the path of the user's
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000890 site-packages directory.
Ezio Melotti021f3342010-04-06 03:26:49 +0000891 :func:`~site.getuserbase` returns the value of the :envvar:`USER_BASE`
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000892 environment variable, giving the path to a directory that can be used
893 to store data.
Andrew M. Kuchling039c8992010-02-01 02:04:26 +0000894 (Contributed by Tarek Ziadé; :issue:`6693`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000895
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +0000896 The :mod:`site` module now reports exceptions occurring
897 when the :mod:`sitecustomize` module is imported, and will no longer
Florent Xiclunaad598332010-03-31 21:40:32 +0000898 catch and swallow the :exc:`KeyboardInterrupt` exception. (Fixed by
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +0000899 Victor Stinner; :issue:`3137`.)
900
Ezio Melotti021f3342010-04-06 03:26:49 +0000901* The :mod:`socket` module's :class:`~ssl.SSL` objects now support the
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000902 buffer API, which fixed a test suite failure. (Fixed by Antoine
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +0000903 Pitrou; :issue:`7133`.)
904
Ezio Melotti021f3342010-04-06 03:26:49 +0000905 The :func:`~socket.create_connection` function
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000906 gained a *source_address* parameter, a ``(host, port)`` 2-tuple
907 giving the source address that will be used for the connection.
908 (Contributed by Eldon Ziegler; :issue:`3972`.)
Andrew M. Kuchlinga7f59472009-12-31 16:38:53 +0000909
Ezio Melotti021f3342010-04-06 03:26:49 +0000910 The :meth:`~socket.socket.recv_into` and :meth:`~socket.socket.recvfrom_into`
911 methods will now write into objects that support the buffer API, most usefully
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +0000912 the :class:`bytearray` and :class:`memoryview` objects. (Implemented by
913 Antoine Pitrou; :issue:`8104`.)
914
Ezio Melotti021f3342010-04-06 03:26:49 +0000915* The :mod:`SocketServer` module's :class:`~SocketServer.TCPServer` class now
916 has a :attr:`~SocketServer.TCPServer.disable_nagle_algorithm` class attribute.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000917 The default value is False; if overridden to be True,
918 new request connections will have the TCP_NODELAY option set to
919 prevent buffering many small sends into a single TCP packet.
920 (Contributed by Kristjan Valur Jonsson; :issue:`6192`.)
921
Ezio Melotti021f3342010-04-06 03:26:49 +0000922* Updated module: the :mod:`sqlite3` module has been updated to
Andrew M. Kuchlingfed15762010-03-08 12:00:39 +0000923 version 2.6.0 of the `pysqlite package <http://code.google.com/p/pysqlite/>`__. Version 2.6.0 includes a number of bugfixes, and adds
924 the ability to load SQLite extensions from shared libraries.
925 Call the ``enable_load_extension(True)`` method to enable extensions,
Ezio Melotti021f3342010-04-06 03:26:49 +0000926 and then call :meth:`~sqlite3.Connection.load_extension` to load a particular shared library.
Andrew M. Kuchlingfed15762010-03-08 12:00:39 +0000927 (Updated by Gerhard Häring.)
928
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000929* The :mod:`struct` module will no longer silently ignore overflow
930 errors when a value is too large for a particular integer format
931 code (one of ``bBhHiIlLqQ``); it now always raises a
932 :exc:`struct.error` exception. (Changed by Mark Dickinson;
933 :issue:`1523`.)
934
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000935* New function: the :mod:`subprocess` module's
Ezio Melotti021f3342010-04-06 03:26:49 +0000936 :func:`~subprocess.check_output` runs a command with a specified set of arguments
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000937 and returns the command's output as a string when the command runs without
Ezio Melotti021f3342010-04-06 03:26:49 +0000938 error, or raises a :exc:`~subprocess.CalledProcessError` exception otherwise.
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +0000939
940 ::
941
942 >>> subprocess.check_output(['df', '-h', '.'])
943 'Filesystem Size Used Avail Capacity Mounted on\n
944 /dev/disk0s2 52G 49G 3.0G 94% /\n'
945
946 >>> subprocess.check_output(['df', '-h', '/bogus'])
947 ...
948 subprocess.CalledProcessError: Command '['df', '-h', '/bogus']' returned non-zero exit status 1
949
950 (Contributed by Gregory P. Smith.)
951
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +0000952 The :mod:`subprocess` module will now retry its internal system calls
953 on receiving an :const:`EINTR` signal. (Reported by several people; final
954 patch by Gregory P. Smith in :issue:`1068268`.)
955
Ezio Melotti021f3342010-04-06 03:26:49 +0000956* New function: :func:`~symtable.is_declared_global` in the :mod:`symtable` module
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000957 returns true for variables that are explicitly declared to be global,
958 false for ones that are implicitly global.
959 (Contributed by Jeremy Hylton.)
960
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000961* The ``sys.version_info`` value is now a named tuple, with attributes
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +0000962 named :attr:`major`, :attr:`minor`, :attr:`micro`,
963 :attr:`releaselevel`, and :attr:`serial`. (Contributed by Ross
964 Light; :issue:`4285`.)
965
966 :func:`sys.getwindowsversion` also returns a named tuple,
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000967 with attributes named :attr:`major`, :attr:`minor`, :attr:`build`,
Ezio Melotti12477752010-02-08 22:22:41 +0000968 :attr:`platform`, :attr:`service_pack`, :attr:`service_pack_major`,
Eric Smithb3c54882010-02-03 14:17:50 +0000969 :attr:`service_pack_minor`, :attr:`suite_mask`, and
970 :attr:`product_type`. (Contributed by Brian Curtin; :issue:`7766`.)
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000971
Andrew M. Kuchling039c8992010-02-01 02:04:26 +0000972* The :mod:`tarfile` module's default error handling has changed, to
973 no longer suppress fatal errors. The default error level was previously 0,
974 which meant that errors would only result in a message being written to the
975 debug log, but because the debug log is not activated by default,
976 these errors go unnoticed. The default error level is now 1,
977 which raises an exception if there's an error.
978 (Changed by Lars Gustäbel; :issue:`7357`.)
979
Ezio Melotti021f3342010-04-06 03:26:49 +0000980 :mod:`tarfile` now supports filtering the :class:`~tarfile.TarInfo`
981 objects being added to a tar file. When you call :meth:`~tarfile.TarFile.add`,
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000982 instance, you may supply an optional *filter* argument
983 that's a callable. The *filter* callable will be passed the
Ezio Melotti021f3342010-04-06 03:26:49 +0000984 :class:`~tarfile.TarInfo` for every file being added, and can modify and return it.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000985 If the callable returns ``None``, the file will be excluded from the
986 resulting archive. This is more powerful than the existing
987 *exclude* argument, which has therefore been deprecated.
Andrew M. Kuchling039c8992010-02-01 02:04:26 +0000988 (Added by Lars Gustäbel; :issue:`6856`.)
Ezio Melotti021f3342010-04-06 03:26:49 +0000989 The :class:`~tarfile.TarFile` class also now supports the context manager protocol.
Andrew M. Kuchlingfed15762010-03-08 12:00:39 +0000990 (Added by Lars Gustäbel; :issue:`7232`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000991
Ezio Melotti021f3342010-04-06 03:26:49 +0000992* The :meth:`~threading.Event.wait` method of the :class:`threading.Event` class
993 now returns the internal flag on exit. This means the method will usually
994 return true because :meth:`~threading.Event.wait` is supposed to block until the
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000995 internal flag becomes true. The return value will only be false if
996 a timeout was provided and the operation timed out.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000997 (Contributed by Tim Lesher; :issue:`1674032`.)
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000998
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000999* The Unicode database provided by the :mod:`unicodedata` module is
1000 now used internally to determine which characters are numeric,
1001 whitespace, or represent line breaks. The database also
1002 includes information from the :file:`Unihan.txt` data file (patch
1003 by Anders Chrigström and Amaury Forgeot d'Arc; :issue:`1571184`)
1004 and has been updated to version 5.2.0 (updated by
1005 Florent Xicluna; :issue:`8024`).
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001006
Ezio Melotti021f3342010-04-06 03:26:49 +00001007* The :class:`~UserDict.UserDict` class is now a new-style class. (Changed by
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001008 Benjamin Peterson.)
1009
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001010* The ElementTree library, :mod:`xml.etree`, no longer escapes
1011 ampersands and angle brackets when outputting an XML processing
Ezio Melotti021f3342010-04-06 03:26:49 +00001012 instruction (which looks like ``<?xml-stylesheet href="#style1"?>``)
1013 or comment (which looks like ``<!-- comment -->``).
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001014 (Patch by Neil Muller; :issue:`2746`.)
1015
Ezio Melotti021f3342010-04-06 03:26:49 +00001016* The :mod:`zipfile` module's :class:`~zipfile.ZipFile` now supports the context
Andrew M. Kuchling039c8992010-02-01 02:04:26 +00001017 management protocol, so you can write ``with zipfile.ZipFile(...) as f: ...``.
1018 (Contributed by Brian Curtin; :issue:`5511`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001019
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +00001020 :mod:`zipfile` now supports archiving empty directories and
1021 extracts them correctly. (Fixed by Kuba Wieczorek; :issue:`4710`.)
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001022 Reading files out of an archive is now faster, and interleaving
Ezio Melotti021f3342010-04-06 03:26:49 +00001023 :meth:`~zipfile.ZipFile.read` and :meth:`~zipfile.ZipFile.readline` now works correctly.
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001024 (Contributed by Nir Aides; :issue:`7610`.)
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +00001025
Ezio Melotti021f3342010-04-06 03:26:49 +00001026 The :func:`~zipfile.is_zipfile` function now
Andrew M. Kuchling039c8992010-02-01 02:04:26 +00001027 accepts a file object, in addition to the path names accepted in earlier
1028 versions. (Contributed by Gabriel Genellina; :issue:`4756`.)
1029
Ezio Melotti021f3342010-04-06 03:26:49 +00001030 The :meth:`~zipfile.ZipFile.writestr` method now has an optional *compress_type* parameter
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001031 that lets you override the default compression method specified in the
Ezio Melotti021f3342010-04-06 03:26:49 +00001032 :class:`~zipfile.ZipFile` constructor. (Contributed by Ronald Oussoren;
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001033 :issue:`6003`.)
1034
1035
Andrew M. Kuchling0e7123f2010-02-08 13:22:24 +00001036New module: sysconfig
1037---------------------------------
1038
1039XXX A new :mod:`sysconfig` module has been extracted from
1040:mod:`distutils` and put in the standard library.
1041
1042The :mod:`sysconfig` module provides access to Python's configuration
1043information like the list of installation paths and the configuration
Tarek Ziadé1e069ee2010-02-23 05:20:22 +00001044variables relevant for the current platform. (contributed by Tarek)
Andrew M. Kuchling0e7123f2010-02-08 13:22:24 +00001045
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +00001046Updated module: ElementTree 1.3
1047---------------------------------
1048
1049XXX write this.
1050
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001051.. ======================================================================
1052.. whole new modules get described in subsections here
1053
Tarek Ziadé2b210692010-02-02 23:39:40 +00001054
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +00001055Distutils Enhancements
1056---------------------------------
1057
Tarek Ziadé0b93a6b2010-04-05 14:58:14 +00001058XXX all of this work has been moved to Distutils2
1059XXX Not sure what we should say here
1060
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +00001061Distutils is being more actively developed, thanks to Tarek Ziadé
1062who has taken over maintenance of the package, so there are a number
1063of fixes and improvements.
1064
1065A new :file:`setup.py` subcommand, ``check``, will check that the
1066arguments being passed to the :func:`setup` function are complete
1067and correct (:issue:`5732`).
1068
1069Byte-compilation by the ``install_lib`` subcommand is now only done
1070if the ``sys.dont_write_bytecode`` setting allows it (:issue:`7071`).
1071
1072:func:`distutils.sdist.add_defaults` now uses
1073*package_dir* and *data_files* to create the MANIFEST file.
1074:mod:`distutils.sysconfig` now reads the :envvar:`AR` and
1075:envvar:`ARFLAGS` environment variables.
1076
1077.. ARFLAGS done in #5941
1078
1079It is no longer mandatory to store clear-text passwords in the
1080:file:`.pypirc` file when registering and uploading packages to PyPI. As long
1081as the username is present in that file, the :mod:`distutils` package will
1082prompt for the password if not present. (Added by Tarek Ziadé,
1083based on an initial contribution by Nathan Van Gheem; :issue:`4394`.)
1084
1085A Distutils setup can now specify that a C extension is optional by
1086setting the *optional* option setting to true. If this optional is
1087supplied, failure to build the extension will not abort the build
1088process, but instead simply not install the failing extension.
1089(Contributed by Georg Brandl; :issue:`5583`.)
1090
1091The :class:`distutils.dist.DistributionMetadata` class'
1092:meth:`read_pkg_file` method will read the contents of a package's
1093:file:`PKG-INFO` metadata file. For an example of its use, see
1094:ref:`reading-metadata`.
1095(Contributed by Tarek Ziadé; :issue:`7457`.)
1096
1097:file:`setup.py` files will now accept a :option:`--no-user-cfg` switch
1098to skip reading the :file:`~/.pydistutils.cfg` file. (Suggested by
1099by Michael Hoffman, and implemented by Paul Winkler; :issue:`1180`.)
1100
1101When creating a tar-format archive, the ``sdist`` subcommand now
1102allows specifying the user id and group that will own the files in the
1103archives using the :option:`--owner` and :option:`--group` switches
1104(:issue:`6516`).
1105
Andrew M. Kuchling0e7123f2010-02-08 13:22:24 +00001106
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001107Unit Testing Enhancements
1108---------------------------------
1109
1110The :mod:`unittest` module was enhanced in several ways.
1111The progress messages now shows 'x' for expected failures
1112and 'u' for unexpected successes when run in verbose mode.
1113(Contributed by Benjamin Peterson.)
Ezio Melotti021f3342010-04-06 03:26:49 +00001114Test cases can raise the :exc:`~unittest.SkipTest` exception to skip a test.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001115(:issue:`1034053`.)
1116
1117.. XXX describe test discovery (Contributed by Michael Foord; :issue:`6001`.)
1118
Ezio Melotti021f3342010-04-06 03:26:49 +00001119The error messages for :meth:`~unittest.TestCase.assertEqual`,
1120:meth:`~unittest.TestCase.assertTrue`, and :meth:`~unittest.TestCase.assertFalse`
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001121failures now provide more information. If you set the
Ezio Melotti021f3342010-04-06 03:26:49 +00001122:attr:`~unittest.TestCase.longMessage` attribute of your :class:`~unittest.TestCase` classes to
1123True, both the standard error message and any additional message you
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001124provide will be printed for failures. (Added by Michael Foord; :issue:`5663`.)
1125
Ezio Melotti021f3342010-04-06 03:26:49 +00001126The :meth:`~unittest.TestCase.assertRaises` method now
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001127return a context handler when called without providing a callable
1128object to run. For example, you can write this::
1129
1130 with self.assertRaises(KeyError):
Ezio Melotti021f3342010-04-06 03:26:49 +00001131 {}['foo']
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001132
1133(Implemented by Antoine Pitrou; :issue:`4444`.)
1134
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +00001135.. rev 78774
1136
1137Module- and class-level setup and teardown fixtures are now supported.
Ezio Melotti021f3342010-04-06 03:26:49 +00001138Modules can contain :func:`~unittest.setUpModule` and :func:`~unittest.tearDownModule`
1139functions. Classes can have :meth:`~unittest.TestCase.setUpClass` and
1140:meth:`~unittest.TestCase.tearDownClass` methods that must be defined as class methods
1141(using ``@classmethod`` or equivalent). These functions and
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +00001142methods are invoked when the test runner switches to a test case in a
1143different module or class.
1144
Ezio Melotti021f3342010-04-06 03:26:49 +00001145The methods :meth:`~unittest.TestCase.addCleanup` and
1146:meth:`~unittest.TestCase.doCleanups` were added.
1147:meth:`~unittest.TestCase.addCleanup` allows you to add cleanup functions that
1148will be called unconditionally (after :meth:`~unittest.TestCase.setUp` if
1149:meth:`~unittest.TestCase.setUp` fails, otherwise after :meth:`~unittest.TestCase.tearDown`). This allows
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +00001150for much simpler resource allocation and deallocation during tests
1151(:issue:`5679`).
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001152
1153A number of new methods were added that provide more specialized
1154tests. Many of these methods were written by Google engineers
1155for use in their test suites; Gregory P. Smith, Michael Foord, and
1156GvR worked on merging them into Python's version of :mod:`unittest`.
1157
Ezio Melotti021f3342010-04-06 03:26:49 +00001158* :meth:`~unittest.TestCase.assertIsNone` and :meth:`~unittest.TestCase.assertIsNotNone` take one
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001159 expression and verify that the result is or is not ``None``.
1160
Ezio Melotti021f3342010-04-06 03:26:49 +00001161* :meth:`~unittest.TestCase.assertIs` and :meth:`~unittest.TestCase.assertIsNot`
1162 take two values and check whether the two values evaluate to the same object or not.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001163 (Added by Michael Foord; :issue:`2578`.)
1164
Ezio Melotti021f3342010-04-06 03:26:49 +00001165* :meth:`~unittest.TestCase.assertIsInstance` and
1166 :meth:`~unittest.TestCase.assertNotIsInstance` check whether
Andrew M. Kuchlinga7f59472009-12-31 16:38:53 +00001167 the resulting object is an instance of a particular class, or of
1168 one of a tuple of classes. (Added by Georg Brandl; :issue:`7031`.)
1169
Ezio Melotti021f3342010-04-06 03:26:49 +00001170* :meth:`~unittest.TestCase.assertGreater`, :meth:`~unittest.TestCase.assertGreaterEqual`,
1171 :meth:`~unittest.TestCase.assertLess`, and :meth:`~unittest.TestCase.assertLessEqual` compare
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001172 two quantities.
1173
Ezio Melotti021f3342010-04-06 03:26:49 +00001174* :meth:`~unittest.TestCase.assertMultiLineEqual` compares two strings, and if they're
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001175 not equal, displays a helpful comparison that highlights the
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001176 differences in the two strings. This comparison is now used by
Ezio Melotti021f3342010-04-06 03:26:49 +00001177 default when Unicode strings are compared with :meth:`~unittest.TestCase.assertEqual`.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001178
Ezio Melotti021f3342010-04-06 03:26:49 +00001179* :meth:`~unittest.TestCase.assertRegexpMatches` checks whether its first argument is a
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001180 string matching a regular expression provided as its second argument.
1181
Ezio Melotti021f3342010-04-06 03:26:49 +00001182 .. XXX add assertNotRegexpMatches see issue 8038
1183
1184* :meth:`~unittest.TestCase.assertRaisesRegexp` checks whether a particular exception
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001185 is raised, and then also checks that the string representation of
1186 the exception matches the provided regular expression.
1187
Ezio Melotti021f3342010-04-06 03:26:49 +00001188* :meth:`~unittest.TestCase.assertIn` and :meth:`~unittest.TestCase.assertNotIn`
1189 tests whether *first* is or is not in *second*.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001190
Ezio Melotti021f3342010-04-06 03:26:49 +00001191* :meth:`~unittest.TestCase.assertItemsEqual` tests whether two provided sequences
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001192 contain the same elements.
1193
Ezio Melotti021f3342010-04-06 03:26:49 +00001194* :meth:`~unittest.TestCase.assertSetEqual` compares whether two sets are equal, and
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001195 only reports the differences between the sets in case of error.
1196
Ezio Melotti021f3342010-04-06 03:26:49 +00001197* Similarly, :meth:`~unittest.TestCase.assertListEqual` and :meth:`~unittest.TestCase.assertTupleEqual`
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001198 compare the specified types and explain any differences without necessarily
1199 printing their full values; these methods are now used by default
Ezio Melotti021f3342010-04-06 03:26:49 +00001200 when comparing lists and tuples using :meth:`~unittest.TestCase.assertEqual`.
1201 More generally, :meth:`~unittest.TestCase.assertSequenceEqual` compares two sequences
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001202 and can optionally check whether both sequences are of a
1203 particular type.
1204
Ezio Melotti021f3342010-04-06 03:26:49 +00001205* :meth:`~unittest.TestCase.assertDictEqual` compares two dictionaries and reports the
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001206 differences; it's now used by default when you compare two dictionaries
Ezio Melotti021f3342010-04-06 03:26:49 +00001207 using :meth:`~unittest.TestCase.assertEqual`. :meth:`~unittest.TestCase.assertDictContainsSubset` checks whether
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001208 all of the key/value pairs in *first* are found in *second*.
1209
Ezio Melotti021f3342010-04-06 03:26:49 +00001210* :meth:`~unittest.TestCase.assertAlmostEqual` and :meth:`~unittest.TestCase.assertNotAlmostEqual` test
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001211 whether *first* and *second* are approximately equal by computing
1212 their difference, rounding the result to an optionally-specified number
1213 of *places* (the default is 7), and comparing to zero.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001214
Ezio Melotti021f3342010-04-06 03:26:49 +00001215* :meth:`~unittest.TestLoader.loadTestsFromName` properly honors the
1216 :attr:`~unittest.TestLoader.suiteClass` attribute of
1217 the :class:`~unittest.TestLoader`. (Fixed by Mark Roddy; :issue:`6866`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001218
Ezio Melotti021f3342010-04-06 03:26:49 +00001219* A new hook lets you extend the :meth:`~unittest.TestCase.assertEqual` method to handle
1220 new data types. The :meth:`~unittest.TestCase.addTypeEqualityFunc` method takes a type
Andrew M. Kuchling9858f632010-03-23 18:39:24 +00001221 object and a function. The function will be used when both of the
1222 objects being compared are of the specified type. This function
1223 should compare the two objects and raise an exception if they don't
1224 match; it's a good idea for the function to provide additional
1225 information about why the two objects are matching, much as the new
1226 sequence comparison methods do.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001227
Andrew M. Kuchling9858f632010-03-23 18:39:24 +00001228:func:`unittest.main` now takes an optional ``exit`` argument. If
Ezio Melotti021f3342010-04-06 03:26:49 +00001229False, :func:`~unittest.main` doesn't call :func:`sys.exit`, allowing it to be
Andrew M. Kuchling9858f632010-03-23 18:39:24 +00001230used from the interactive interpreter. (Contributed by J. Pablo
1231Fernández; :issue:`3379`.)
1232
1233A new command-line switch, :option:`-f` or :option:`--failfast`, makes
1234test execution stop immediately when a test fails instead of
1235continuing to execute further tests. (Suggested by Cliff Dyer and
1236implemented by Michael Foord; :issue:`8074`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001237
Ezio Melotti021f3342010-04-06 03:26:49 +00001238.. XXX document the other new switches
1239
1240:class:`~unittest.TestResult` has new :meth:`~unittest.TestResult.startTestRun` and
1241:meth:`~unittest.TestResult.stopTestRun` methods that are called immediately before
Andrew M. Kuchling9858f632010-03-23 18:39:24 +00001242and after a test run. (Contributed by Robert Collins; :issue:`5728`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001243
1244With all these changes, the :file:`unittest.py` was becoming awkwardly
1245large, so the module was turned into a package and the code split into
1246several files (by Benjamin Peterson). This doesn't affect how the
1247module is imported.
1248
1249
1250.. _importlib-section:
1251
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001252importlib: Importing Modules
1253------------------------------
1254
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001255Python 3.1 includes the :mod:`importlib` package, a re-implementation
1256of the logic underlying Python's :keyword:`import` statement.
1257:mod:`importlib` is useful for implementors of Python interpreters and
Brett Cannonca2dc472009-12-22 02:37:37 +00001258to users who wish to write new importers that can participate in the
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001259import process. Python 2.7 doesn't contain the complete
1260:mod:`importlib` package, but instead has a tiny subset that contains
Ezio Melotti021f3342010-04-06 03:26:49 +00001261a single function, :func:`~importlib.import_module`.
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001262
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001263``import_module(name, package=None)`` imports a module. *name* is
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001264a string containing the module or package's name. It's possible to do
1265relative imports by providing a string that begins with a ``.``
1266character, such as ``..utils.errors``. For relative imports, the
1267*package* argument must be provided and is the name of the package that
1268will be used as the anchor for
Ezio Melotti021f3342010-04-06 03:26:49 +00001269the relative import. :func:`~importlib.import_module` both inserts the imported
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001270module into ``sys.modules`` and returns the module object.
1271
1272Here are some examples::
1273
1274 >>> from importlib import import_module
1275 >>> anydbm = import_module('anydbm') # Standard absolute import
1276 >>> anydbm
1277 <module 'anydbm' from '/p/python/Lib/anydbm.py'>
1278 >>> # Relative import
1279 >>> sysconfig = import_module('..sysconfig', 'distutils.command')
1280 >>> sysconfig
1281 <module 'distutils.sysconfig' from '/p/python/Lib/distutils/sysconfig.pyc'>
1282
1283:mod:`importlib` was implemented by Brett Cannon and introduced in
1284Python 3.1.
1285
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001286
Andrew M. Kuchlinga17cd4a2009-01-31 02:50:09 +00001287ttk: Themed Widgets for Tk
1288--------------------------
1289
1290Tcl/Tk 8.5 includes a set of themed widgets that re-implement basic Tk
1291widgets but have a more customizable appearance and can therefore more
1292closely resemble the native platform's widgets. This widget
1293set was originally called Tile, but was renamed to Ttk (for "themed Tk")
1294on being added to Tcl/Tck release 8.5.
1295
1296XXX write a brief discussion and an example here.
1297
1298The :mod:`ttk` module was written by Guilherme Polo and added in
1299:issue:`2983`. An alternate version called ``Tile.py``, written by
1300Martin Franklin and maintained by Kevin Walzer, was proposed for
1301inclusion in :issue:`2618`, but the authors argued that Guilherme
1302Polo's work was more comprehensive.
1303
Georg Brandl0516f812009-11-18 18:52:35 +00001304
1305Deprecations and Removals
1306=========================
1307
1308* :func:`contextlib.nested`, which allows handling more than one context manager
1309 with one :keyword:`with` statement, has been deprecated; :keyword:`with`
1310 supports multiple context managers syntactically now.
1311
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001312.. ======================================================================
1313
1314
1315Build and C API Changes
1316=======================
1317
1318Changes to Python's build process and to the C API include:
1319
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +00001320* If you use the :file:`.gdbinit` file provided with Python,
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001321 the "pyo" macro in the 2.7 version now works correctly when the thread being
1322 debugged doesn't hold the GIL; the macro now acquires it before printing.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +00001323 (Contributed by Victor Stinner; :issue:`3632`.)
1324
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +00001325* :cfunc:`Py_AddPendingCall` is now thread-safe, letting any
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +00001326 worker thread submit notifications to the main Python thread. This
1327 is particularly useful for asynchronous IO operations.
1328 (Contributed by Kristjan Valur Jonsson; :issue:`4293`.)
1329
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001330* New function: :cfunc:`PyCode_NewEmpty` creates an empty code object;
1331 only the filename, function name, and first line number are required.
1332 This is useful to extension modules that are attempting to
1333 construct a more useful traceback stack. Previously such
1334 extensions needed to call :cfunc:`PyCode_New`, which had many
1335 more arguments. (Added by Jeffrey Yasskin.)
1336
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +00001337* New function: :cfunc:`PyErr_NewExceptionWithDoc` creates a new
1338 exception class, just as the existing :cfunc:`PyErr_NewException` does,
1339 but takes an extra ``char *`` argument containing the docstring for the
1340 new exception class. (Added by the 'lekma' user on the Python bug tracker;
1341 :issue:`7033`.)
1342
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001343* New function: :cfunc:`PyFrame_GetLineNumber` takes a frame object
1344 and returns the line number that the frame is currently executing.
1345 Previously code would need to get the index of the bytecode
1346 instruction currently executing, and then look up the line number
1347 corresponding to that address. (Added by Jeffrey Yasskin.)
1348
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001349* New functions: :cfunc:`PyLong_AsLongAndOverflow` and
1350 :cfunc:`PyLong_AsLongLongAndOverflow` approximates a Python long
1351 integer as a C :ctype:`long` or :ctype:`long long`.
1352 If the number is too large to fit into
1353 the output type, an *overflow* flag is set and returned to the caller.
1354 (Contributed by Case Van Horsen; :issue:`7528` and :issue:`7767`.)
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +00001355
Andrew M. Kuchlinga7f59472009-12-31 16:38:53 +00001356* New function: stemming from the rewrite of string-to-float conversion,
1357 a new :cfunc:`PyOS_string_to_double` function was added. The old
1358 :cfunc:`PyOS_ascii_strtod` and :cfunc:`PyOS_ascii_atof` functions
1359 are now deprecated.
1360
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001361* New macros: the Python header files now define the following macros:
1362 :cmacro:`Py_ISALNUM`,
1363 :cmacro:`Py_ISALPHA`,
1364 :cmacro:`Py_ISDIGIT`,
1365 :cmacro:`Py_ISLOWER`,
1366 :cmacro:`Py_ISSPACE`,
1367 :cmacro:`Py_ISUPPER`,
1368 :cmacro:`Py_ISXDIGIT`,
1369 and :cmacro:`Py_TOLOWER`, :cmacro:`Py_TOUPPER`.
1370 All of these functions are analogous to the C
1371 standard macros for classifying characters, but ignore the current
1372 locale setting, because in
1373 several places Python needs to analyze characters in a
1374 locale-independent way. (Added by Eric Smith;
1375 :issue:`5793`.)
1376
1377 .. XXX these macros don't seem to be described in the c-api docs.
1378
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +00001379* New format codes: the :cfunc:`PyFormat_FromString`,
1380 :cfunc:`PyFormat_FromStringV`, and :cfunc:`PyErr_Format` now
1381 accepts ``%lld`` and ``%llu`` format codes for displaying values of
1382 C's :ctype:`long long` types.
1383 (Contributed by Mark Dickinson; :issue:`7228`.)
1384
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001385* The complicated interaction between threads and process forking has
1386 been changed. Previously, the child process created by
1387 :func:`os.fork` might fail because the child is created with only a
1388 single thread running, the thread performing the :func:`os.fork`.
1389 If other threads were holding a lock, such as Python's import lock,
1390 when the fork was performed, the lock would still be marked as
1391 "held" in the new process. But in the child process nothing would
1392 ever release the lock, since the other threads weren't replicated,
1393 and the child process would no longer be able to perform imports.
1394
1395 Python 2.7 now acquires the import lock before performing an
1396 :func:`os.fork`, and will also clean up any locks created using the
1397 :mod:`threading` module. C extension modules that have internal
1398 locks, or that call :cfunc:`fork()` themselves, will not benefit
1399 from this clean-up.
1400
1401 (Fixed by Thomas Wouters; :issue:`1590864`.)
1402
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +00001403* The :cfunc:`Py_Finalize` function now calls the internal
1404 :func:`threading._shutdown` function; this prevents some exceptions from
1405 being raised when an interpreter shuts down.
1406 (Patch by Adam Olsen; :issue:`1722344`.)
1407
Andrew M. Kuchling92b97002009-05-02 17:12:15 +00001408* Global symbols defined by the :mod:`ctypes` module are now prefixed
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001409 with ``Py``, or with ``_ctypes``. (Implemented by Thomas
Andrew M. Kuchling92b97002009-05-02 17:12:15 +00001410 Heller; :issue:`3102`.)
1411
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +00001412* New configure option: the :option:`--with-system-expat` switch allows
1413 building the :mod:`pyexpat` module to use the system Expat library.
1414 (Contributed by Arfrever Frehtes Taifersar Arahesis; :issue:`7609`.)
1415
1416* New configure option: Compiling Python with the
1417 :option:`--with-valgrind` option will now disable the pymalloc
1418 allocator, which is difficult for the Valgrind to analyze correctly.
1419 Valgrind will therefore be better at detecting memory leaks and
1420 overruns. (Contributed by James Henstridge; :issue:`2422`.)
1421
Andrew M. Kuchling7f8ebdb2010-01-03 01:15:21 +00001422* New configure option: you can now supply no arguments to
1423 :option:`--with-dbmliborder=` in order to build none of the various
1424 DBM modules. (Added by Arfrever Frehtes Taifersar Arahesis;
1425 :issue:`6491`.)
1426
Andrew M. Kuchling77069572009-03-31 01:21:01 +00001427* The :program:`configure` script now checks for floating-point rounding bugs
1428 on certain 32-bit Intel chips and defines a :cmacro:`X87_DOUBLE_ROUNDING`
1429 preprocessor definition. No code currently uses this definition,
1430 but it's available if anyone wishes to use it.
1431 (Added by Mark Dickinson; :issue:`2937`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001432
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001433* The build process now creates the necessary files for pkg-config
1434 support. (Contributed by Clinton Roy; :issue:`3585`.)
1435
1436* The build process now supports Subversion 1.7. (Contributed by
1437 Arfrever Frehtes Taifersar Arahesis; :issue:`6094`.)
1438
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +00001439
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001440.. ======================================================================
1441
1442Port-Specific Changes: Windows
1443-----------------------------------
1444
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +00001445* The :mod:`msvcrt` module now contains some constants from
1446 the :file:`crtassem.h` header file:
1447 :data:`CRT_ASSEMBLY_VERSION`,
1448 :data:`VC_ASSEMBLY_PUBLICKEYTOKEN`,
1449 and :data:`LIBRARIES_ASSEMBLY_NAME_PREFIX`.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +00001450 (Contributed by David Cournapeau; :issue:`4365`.)
1451
1452* The new :cfunc:`_beginthreadex` API is used to start threads, and
1453 the native thread-local storage functions are now used.
1454 (Contributed by Kristjan Valur Jonsson; :issue:`3582`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001455
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001456* The :func:`os.listdir` function now correctly fails
1457 for an empty path. (Fixed by Hirokazu Yamamoto; :issue:`5913`.)
1458
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +00001459* The :mod:`mimelib` module will now read the MIME database from
1460 the Windows registry when initializing.
1461 (Patch by Gabriel Genellina; :issue:`4969`.)
1462
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001463.. ======================================================================
1464
1465Port-Specific Changes: Mac OS X
1466-----------------------------------
1467
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001468* The path ``/Library/Python/2.7/site-packages`` is now appended to
Andrew M. Kuchling77069572009-03-31 01:21:01 +00001469 ``sys.path``, in order to share added packages between the system
1470 installation and a user-installed copy of the same version.
1471 (Changed by Ronald Oussoren; :issue:`4865`.)
1472
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001473
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001474Other Changes and Fixes
1475=======================
1476
Andrew M. Kuchling0e7123f2010-02-08 13:22:24 +00001477* Two benchmark scripts, :file:`iobench` and :file:`ccbench`, were
1478 added to the :file:`Tools` directory. :file:`iobench` measures the
Antoine Pitroudde96e62010-02-08 20:25:47 +00001479 speed of built-in file I/O objects (as returned by :func:`open`)
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +00001480 while performing various operations, and :file:`ccbench` is a
1481 concurrency benchmark that tries to measure computing throughput,
1482 thread switching latency, and IO processing bandwidth when
1483 performing several tasks using a varying number of threads.
Andrew M. Kuchling0e7123f2010-02-08 13:22:24 +00001484
Andrew M. Kuchling77069572009-03-31 01:21:01 +00001485* When importing a module from a :file:`.pyc` or :file:`.pyo` file
1486 with an existing :file:`.py` counterpart, the :attr:`co_filename`
Andrew M. Kuchling92b97002009-05-02 17:12:15 +00001487 attributes of the resulting code objects are overwritten when the
1488 original filename is obsolete. This can happen if the file has been
1489 renamed, moved, or is accessed through different paths. (Patch by
1490 Ziga Seilnacht and Jean-Paul Calderone; :issue:`1180193`.)
Andrew M. Kuchling77069572009-03-31 01:21:01 +00001491
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001492* The :file:`regrtest.py` script now takes a :option:`--randseed=`
1493 switch that takes an integer that will be used as the random seed
1494 for the :option:`-r` option that executes tests in random order.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001495 The :option:`-r` option also reports the seed that was used
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001496 (Added by Collin Winter.)
1497
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +00001498* Another :file:`regrtest.py` switch is :option:`-j`, which
1499 takes an integer specifying how many tests run in parallel. This
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001500 allows reducing the total runtime on multi-core machines.
Antoine Pitrou4698d992009-05-31 14:20:14 +00001501 This option is compatible with several other options, including the
1502 :option:`-R` switch which is known to produce long runtimes.
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +00001503 (Added by Antoine Pitrou, :issue:`6152`.) This can also be used
1504 with a new :option:`-F` switch that runs selected tests in a loop
1505 until they fail. (Added by Antoine Pitrou; :issue:`7312`.)
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001506
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001507.. ======================================================================
1508
1509Porting to Python 2.7
1510=====================
1511
1512This section lists previously described changes and other bugfixes
1513that may require changes to your code:
1514
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001515* When using :class:`Decimal` instances with a string's
1516 :meth:`format` method, the default alignment was previously
1517 left-alignment. This has been changed to right-alignment, which might
1518 change the output of your programs.
1519 (Changed by Mark Dickinson; :issue:`6857`.)
1520
1521 Another :meth:`format`-related change: the default precision used
1522 for floating-point and complex numbers was changed from 6 decimal
1523 places to 12, which matches the precision used by :func:`str`.
1524 (Changed by Eric Smith; :issue:`5920`.)
1525
Amaury Forgeot d'Arc901f2002009-06-09 23:08:13 +00001526* Because of an optimization for the :keyword:`with` statement, the special
1527 methods :meth:`__enter__` and :meth:`__exit__` must belong to the object's
1528 type, and cannot be directly attached to the object's instance. This
Amaury Forgeot d'Arcd81333c2009-06-10 20:30:19 +00001529 affects new-style classes (derived from :class:`object`) and C extension
Amaury Forgeot d'Arc901f2002009-06-09 23:08:13 +00001530 types. (:issue:`6101`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001531
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +00001532* The :meth:`readline` method of :class:`StringIO` objects now does
1533 nothing when a negative length is requested, as other file-like
1534 objects do. (:issue:`7348`).
1535
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001536In the standard library:
1537
1538* The ElementTree library, :mod:`xml.etree`, no longer escapes
1539 ampersands and angle brackets when outputting an XML processing
1540 instruction (which looks like `<?xml-stylesheet href="#style1"?>`)
1541 or comment (which looks like `<!-- comment -->`).
1542 (Patch by Neil Muller; :issue:`2746`.)
1543
Andrew M. Kuchlinga7f59472009-12-31 16:38:53 +00001544For C extensions:
1545
Andrew M. Kuchling7f8ebdb2010-01-03 01:15:21 +00001546* C extensions that use integer format codes with the ``PyArg_Parse*``
1547 family of functions will now raise a :exc:`TypeError` exception
1548 instead of triggering a :exc:`DeprecationWarning` (:issue:`5080`).
1549
Andrew M. Kuchlinga7f59472009-12-31 16:38:53 +00001550* Use the new :cfunc:`PyOS_string_to_double` function instead of the old
1551 :cfunc:`PyOS_ascii_strtod` and :cfunc:`PyOS_ascii_atof` functions,
1552 which are now deprecated.
1553
Andrew M. Kuchling7f8ebdb2010-01-03 01:15:21 +00001554
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001555.. ======================================================================
1556
1557
1558.. _acks27:
1559
1560Acknowledgements
1561================
1562
1563The author would like to thank the following people for offering
1564suggestions, corrections and assistance with various drafts of this
Andrew M. Kuchling8f254e72009-12-08 02:37:05 +00001565article: Ryan Lovett, Hugh Secker-Walker.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001566