blob: 847794b7d022f0a9c774fb4a8c9cc0a1b42928ae [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. Kuchling71d5c282009-03-30 22:30:20 +00009.. Fix accents on Kristjan Valur Jonsson, Fuerstenau, Tarek Ziade.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +000010
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000011.. $Id$
12 Rules for maintenance:
13
14 * Anyone can add text to this document. Do not spend very much time
15 on the wording of your changes, because your text will probably
16 get rewritten to some degree.
17
18 * The maintainer will go through Misc/NEWS periodically and add
19 changes; it's therefore more important to add your changes to
20 Misc/NEWS than to this file.
21
22 * This is not a complete list of every single change; completeness
23 is the purpose of Misc/NEWS. Some changes I consider too small
24 or esoteric to include. If such a change is added to the text,
25 I'll just remove it. (This is another reason you shouldn't spend
26 too much time on writing your addition.)
27
28 * If you want to draw your new text to the attention of the
29 maintainer, add 'XXX' to the beginning of the paragraph or
30 section.
31
32 * It's OK to just add a fragmentary note about a change. For
33 example: "XXX Describe the transmogrify() function added to the
34 socket module." The maintainer will research the change and
35 write the necessary text.
36
37 * You can comment out your additions if you like, but it's not
38 necessary (especially when a final release is some months away).
39
40 * Credit the author of a patch or bugfix. Just the name is
41 sufficient; the e-mail address isn't necessary.
42
43 * It's helpful to add the bug/patch number in a parenthetical comment.
44
45 XXX Describe the transmogrify() function added to the socket
46 module.
47 (Contributed by P.Y. Developer; :issue:`12345`.)
48
49 This saves the maintainer some effort going through the SVN logs
50 when researching a change.
51
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000052This article explains the new features in Python 2.7. No release
53schedule has been decided yet for 2.7; the schedule will eventually be
54described in :pep:`373`.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000055
56.. Compare with previous release in 2 - 3 sentences here.
57 add hyperlink when the documentation becomes available online.
58
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000059.. _whatsnew27-python31:
60
61Python 3.1 Features
62=======================
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000063
64Much as Python 2.6 incorporated features from Python 3.0,
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000065version 2.7 incorporates some of the new features
66in Python 3.1. The 2.x series continues to provide tools
67for migrating to the 3.x series.
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000068
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000069A partial list of 3.1 features that were backported to 2.7:
70
71* A version of the :mod:`io` library, rewritten in C for performance.
72* The ordered-dictionary type described in :ref:`pep-0372`.
73* The new format specified described in :ref:`pep-0378`.
74* The :class:`memoryview` object.
75* A small subset of the :mod:`importlib` module `described below <#importlib-section>`__.
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000076
77One porting change: the :option:`-3` switch now automatically
78enables the :option:`-Qwarn` switch that causes warnings
79about using classic division with integers and long integers.
80
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000081Other new Python3-mode warnings include:
82
83* :func:`operator.isCallable` and :func:`operator.sequenceIncludes`,
84 which are not supported in 3.x.
85
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000086.. ========================================================================
87.. Large, PEP-level features and changes should be described here.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000088.. ========================================================================
89
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000090.. _pep-0372:
91
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +000092PEP 372: Adding an ordered dictionary to collections
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000093====================================================
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +000094
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000095Regular Python dictionaries iterate over key/value pairs in arbitrary order.
96Over the years, a number of authors have written alternative implementations
97that remember the order that the keys were originally inserted. Based on
98the experiences from those implementations, a new
99:class:`collections.OrderedDict` class has been introduced.
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000100
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000101The :class:`OrderedDict` API is substantially the same as regular dictionaries
102but will iterate over keys and values in a guaranteed order depending on
103when a key was first inserted::
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000104
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000105 >>> from collections import OrderedDict
106 >>> d = OrderedDict([('first', 1), ('second', 2),
107 ... ('third', 3)])
108 >>> d.items()
109 [('first', 1), ('second', 2), ('third', 3)]
110
111If a new entry overwrites an existing entry, the original insertion
112position is left unchanged::
113
114 >>> d['second'] = 4
115 >>> d.items()
116 [('first', 1), ('second', 4), ('third', 3)]
117
118Deleting an entry and reinserting it will move it to the end::
119
120 >>> del d['second']
121 >>> d['second'] = 5
122 >>> d.items()
123 [('first', 1), ('third', 3), ('second', 5)]
124
125The :meth:`popitem` method has an optional *last* argument
126that defaults to True. If *last* is True, the most recently
127added key is returned and removed; if it's False, the
128oldest key is selected::
129
130 >>> od = OrderedDict([(x,0) for x in range(20)])
131 >>> od.popitem()
132 (19, 0)
133 >>> od.popitem()
134 (18, 0)
135 >>> od.popitem(False)
136 (0, 0)
137 >>> od.popitem(False)
138 (1, 0)
139
140Comparing two ordered dictionaries checks both the keys and values,
141and requires that the insertion order was the same::
142
143 >>> od1 = OrderedDict([('first', 1), ('second', 2),
144 ... ('third', 3)])
145 >>> od2 = OrderedDict([('third', 3), ('first', 1),
146 ... ('second', 2)])
147 >>> od1==od2
148 False
149 >>> # Move 'third' key to the end
150 >>> del od2['third'] ; od2['third'] = 3
151 >>> od1==od2
152 True
153
154Comparing an :class:`OrderedDict` with a regular dictionary
155ignores the insertion order and just compares the keys and values.
156
157How does the :class:`OrderedDict` work? It maintains a doubly-linked
158list of keys, appending new keys to the list as they're inserted. A
159secondary dictionary maps keys to their corresponding list node, so
160deletion doesn't have to traverse the entire linked list and therefore
161remains O(1).
162
163.. XXX check O(1)-ness with Raymond
164
165The standard library now supports use of ordered dictionaries in several
166modules. The :mod:`configparser` module uses them by default. This lets
167configuration files be read, modified, and then written back in their original
168order. The *_asdict()* method for :func:`collections.namedtuple` now
169returns an ordered dictionary with the values appearing in the same order as
170the underlying tuple indicies. The :mod:`json` module is being built-out with
171an *object_pairs_hook* to allow OrderedDicts to be built by the decoder.
172Support was also added for third-party tools like `PyYAML <http://pyyaml.org/>`_.
173
174
175.. _pep-0378:
176
177PEP 378: Format Specifier for Thousands Separator
178====================================================
179
180To make program output more readable, it can be useful to add
181separators to large numbers and render them as
18218,446,744,073,709,551,616 instead of 18446744073709551616.
183
184The fully general solution for doing this is the :mod:`locale` module,
185which can use different separators ("," in North America, "." in
186Europe) and different grouping sizes, but :mod:`locale` is complicated
187to use and unsuitable for multi-threaded applications where different
188threads are producing output for different locales.
189
190Therefore, a simple comma-grouping mechanism has been added to the
191mini-language used by the string :meth:`format` method. When
192formatting a floating-point number, simply include a comma between the
193width and the precision::
194
195 >>> '{:20,.2}'.format(f)
196 '18,446,744,073,709,551,616.00'
197
198This mechanism is not adaptable at all; commas are always used as the
199separator and the grouping is always into three-digit groups. The
200comma-formatting mechanism isn't as general as the :mod:`locale`
201module, but it's easier to use.
202
203.. XXX "Format String Syntax" in string.rst doesn't describe ',';
204 could use many more examples.
205
206.. seealso::
207
208 :pep:`378` - Format Specifier for Thousands Separator
209 PEP written by Raymond Hettinger; implemented by Eric Smith.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000210
211Other Language Changes
212======================
213
214Some smaller changes made to the core Python language are:
215
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000216* The :keyword:`with` statement can now use multiple context managers
217 in one statement. Context managers are processed from left to right
218 and each one is treated as beginning a new :keyword:`with` statement.
219 This means that::
220
221 with A() as a, B() as b:
222 ... suite of statements ...
223
224 is equivalent to::
225
226 with A() as a:
227 with B() as b:
228 ... suite of statements ...
229
230 The :func:`contextlib.nested` function provides a very similar
231 function, so it's no longer necessary and has been deprecated.
232
233 (Proposed in http://codereview.appspot.com/53094; implemented by
234 Georg Brandl.)
235
236* The :meth:`str.format` method now supports automatic numbering of the replacement
Benjamin Petersonaa0a0b92009-04-11 20:27:15 +0000237 fields. This makes using :meth:`str.format` more closely resemble using
238 ``%s`` formatting::
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000239
240 >>> '{}:{}:{}'.format(2009, 04, 'Sunday')
241 '2009:4:Sunday'
242 >>> '{}:{}:{day}'.format(2009, 4, day='Sunday')
243 '2009:4:Sunday'
244
Benjamin Petersonaa0a0b92009-04-11 20:27:15 +0000245 The auto-numbering takes the fields from left to right, so the first ``{...}``
246 specifier will use the first argument to :meth:`str.format`, the next
247 specifier will use the next argument, and so on. You can't mix auto-numbering
248 and explicit numbering -- either number all of your specifier fields or none
249 of them -- but you can mix auto-numbering and named fields, as in the second
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000250 example above. (Contributed by Eric Smith; :issue:`5237`.)
251
252 Complex numbers now correctly support usage with :func:`format`.
253 Specifying a precision or comma-separation applies to both the real
254 and imaginary parts of the number, but a specified field width and
255 alignment is applied to the whole of the resulting ``1.5+3j``
256 output. (Contributed by Eric Smith; :issue:`1588`.)
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000257
Mark Dickinson1a707982008-12-17 16:14:37 +0000258* The :func:`int` and :func:`long` types gained a ``bit_length``
Georg Brandl64e1c752009-04-11 18:19:27 +0000259 method that returns the number of bits necessary to represent
Mark Dickinson1a707982008-12-17 16:14:37 +0000260 its argument in binary::
261
262 >>> n = 37
263 >>> bin(37)
264 '0b100101'
265 >>> n.bit_length()
266 6
267 >>> n = 2**123-1
268 >>> n.bit_length()
269 123
270 >>> (n+1).bit_length()
271 124
272
273 (Contributed by Fredrik Johansson and Victor Stinner; :issue:`3439`.)
274
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000275* Conversions from long integers and regular integers to floating
276 point now round differently, returning the floating-point number
277 closest to the number. This doesn't matter for small integers that
278 can be converted exactly, but for large numbers that will
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000279 unavoidably lose precision, Python 2.7 now approximates more
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000280 closely. For example, Python 2.6 computed the following::
281
282 >>> n = 295147905179352891391
283 >>> float(n)
284 2.9514790517935283e+20
285 >>> n - long(float(n))
286 65535L
287
288 Python 2.7's floating-point result is larger, but much closer to the
289 true value::
290
291 >>> n = 295147905179352891391
292 >>> float(n)
293 2.9514790517935289e+20
294 >>> n-long(float(n)
295 ... )
296 -1L
297
298 (Implemented by Mark Dickinson; :issue:`3166`.)
299
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000300* The :class:`bytearray` type's :meth:`translate` method now accepts
301 ``None`` as its first argument. (Fixed by Georg Brandl;
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000302 :issue:`4759`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000303
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000304* When using ``@classmethod`` and ``@staticmethod`` to wrap
305 methods as class or static methods, the wrapper object now
306 exposes the wrapped function as their :attr:`__func__` attribute.
307 (Contributed by Amaury Forgeot d'Arc, after a suggestion by
308 George Sakkis; :issue:`5982`.)
309
310* A new encoding named "cp720", used primarily for Arabic text, is now
311 supported. (Contributed by Alexander Belchenko and Amaury Forgeot
312 d'Arc; :issue:`1616979`.)
313
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000314.. ======================================================================
315
316
317Optimizations
318-------------
319
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000320Several performance enhancements have been added:
321
322.. * A new :program:`configure` option, :option:`--with-computed-gotos`,
323 compiles the main bytecode interpreter loop using a new dispatch
324 mechanism that gives speedups of up to 20%, depending on the system
325 and benchmark. The new mechanism is only supported on certain
326 compilers, such as gcc, SunPro, and icc.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000327
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000328* A new opcode was added to perform the initial setup for
329 :keyword:`with` statements, looking up the :meth:`__enter__` and
330 :meth:`__exit__` methods. (Contributed by Benjamin Peterson.)
331
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000332* The garbage collector now performs better when many objects are
333 being allocated without deallocating any. A full garbage collection
334 pass is only performed when the middle generation has been collected
335 10 times and when the number of survivor objects from the middle
336 generation exceeds 10% of the number of objects in the oldest
337 generation. The second condition was added to reduce the number
338 of full garbage collections as the number of objects on the heap grows,
339 avoiding quadratic performance when allocating very many objects.
340 (Suggested by Martin von Loewis and implemented by Antoine Pitrou;
341 :issue:`4074`.)
342
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000343* The garbage collector tries to avoid tracking simple containers
344 which can't be part of a cycle. In Python 2.7, this is now true for
345 tuples and dicts containing atomic types (such as ints, strings,
346 etc.). Transitively, a dict containing tuples of atomic types won't
347 be tracked either. This helps reduce the cost of each
348 garbage collection by decreasing the number of objects to be
349 considered and traversed by the collector.
Antoine Pitrouc18f6b02009-03-28 19:10:13 +0000350 (Contributed by Antoine Pitrou; :issue:`4688`.)
351
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000352* Long integers are now stored internally either in base 2**15 or in base
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000353 2**30, the base being determined at build time. Previously, they
354 were always stored in base 2**15. Using base 2**30 gives
355 significant performance improvements on 64-bit machines, but
356 benchmark results on 32-bit machines have been mixed. Therefore,
357 the default is to use base 2**30 on 64-bit machines and base 2**15
358 on 32-bit machines; on Unix, there's a new configure option
359 :option:`--enable-big-digits` that can be used to override this default.
360
361 Apart from the performance improvements this change should be
362 invisible to end users, with one exception: for testing and
363 debugging purposes there's a new structseq ``sys.long_info`` that
364 provides information about the internal format, giving the number of
365 bits per digit and the size in bytes of the C type used to store
366 each digit::
367
368 >>> import sys
369 >>> sys.long_info
370 sys.long_info(bits_per_digit=30, sizeof_digit=4)
371
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000372 (Contributed by Mark Dickinson; :issue:`4258`.)
373
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000374 Another set of changes made long objects a few bytes smaller: 2 bytes
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000375 smaller on 32-bit systems and 6 bytes on 64-bit.
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000376 (Contributed by Mark Dickinson; :issue:`5260`.)
377
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000378* The division algorithm for long integers has been made faster
379 by tightening the inner loop, doing shifts instead of multiplications,
380 and fixing an unnecessary extra iteration.
381 Various benchmarks show speedups of between 50% and 150% for long
382 integer divisions and modulo operations.
383 (Contributed by Mark Dickinson; :issue:`5512`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000384
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000385* The implementation of ``%`` checks for the left-side operand being
386 a Python string and special-cases it; this results in a 1-3%
387 performance increase for applications that frequently use ``%``
388 with strings, such as templating libraries.
389 (Implemented by Collin Winter; :issue:`5176`.)
390
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000391* List comprehensions with an ``if`` condition are compiled into
392 faster bytecode. (Patch by Antoine Pitrou, back-ported to 2.7
393 by Jeffrey Yasskin; :issue:`4715`.)
394
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000395* The :mod:`pickle` and :mod:`cPickle` modules now automatically
396 intern the strings used for attribute names, reducing memory usage
397 of the objects resulting from unpickling. (Contributed by Jake
398 McGuire; :issue:`5084`.)
399
400* The :mod:`cPickle` module now special-cases dictionaries,
401 nearly halving the time required to pickle them.
402 (Contributed by Collin Winter; :issue:`5670`.)
403
404* Converting an integer or long integer to a decimal string was made
405 faster by special-casing base 10 instead of using a generalized
406 conversion function that supports arbitrary bases.
407 (Patch by Gawain Bolton; :issue:`6713`.)
408
409
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000410.. ======================================================================
411
412New, Improved, and Deprecated Modules
413=====================================
414
415As in every release, Python's standard library received a number of
416enhancements and bug fixes. Here's a partial list of the most notable
417changes, sorted alphabetically by module name. Consult the
418:file:`Misc/NEWS` file in the source tree for a more complete list of
419changes, or look through the Subversion logs for all the details.
420
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000421* The :mod:`bdb` module's base debugging class :class:`Bdb`
422 gained a feature for skipping modules. The constructor
423 now takes an iterable containing glob-style patterns such as
424 ``django.*``; the debugger will not step into stack frames
425 from a module that matches one of these patterns.
426 (Contributed by Maru Newby after a suggestion by
427 Senthil Kumaran; :issue:`5142`.)
428
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000429* The :mod:`bz2` module's :class:`BZ2File` now supports the context
430 management protocol, so you can write ``with bz2.BZ2File(...) as f: ...``.
431 (Contributed by Hagen Fuerstenau; :issue:`3860`.)
432
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000433* New class: the :class:`Counter` class in the :mod:`collections` module is
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000434 useful for tallying data. :class:`Counter` instances behave mostly
435 like dictionaries but return zero for missing keys instead of
Georg Brandlf6dab952009-04-28 21:48:35 +0000436 raising a :exc:`KeyError`:
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000437
Georg Brandlf6dab952009-04-28 21:48:35 +0000438 .. doctest::
439 :options: +NORMALIZE_WHITESPACE
440
441 >>> from collections import Counter
442 >>> c = Counter()
443 >>> for letter in 'here is a sample of english text':
444 ... c[letter] += 1
445 ...
446 >>> c
447 Counter({' ': 6, 'e': 5, 's': 3, 'a': 2, 'i': 2, 'h': 2,
448 'l': 2, 't': 2, 'g': 1, 'f': 1, 'm': 1, 'o': 1, 'n': 1,
449 'p': 1, 'r': 1, 'x': 1})
450 >>> c['e']
451 5
452 >>> c['z']
453 0
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000454
455 There are two additional :class:`Counter` methods: :meth:`most_common`
456 returns the N most common elements and their counts, and :meth:`elements`
457 returns an iterator over the contained element, repeating each element
458 as many times as its count::
459
460 >>> c.most_common(5)
461 [(' ', 6), ('e', 5), ('s', 3), ('a', 2), ('i', 2)]
462 >>> c.elements() ->
463 'a', 'a', ' ', ' ', ' ', ' ', ' ', ' ',
464 'e', 'e', 'e', 'e', 'e', 'g', 'f', 'i', 'i',
465 'h', 'h', 'm', 'l', 'l', 'o', 'n', 'p', 's',
Georg Brandlf6dab952009-04-28 21:48:35 +0000466 's', 's', 'r', 't', 't', 'x'
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000467
468 Contributed by Raymond Hettinger; :issue:`1696199`.
469
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000470 The new `OrderedDict` class is described in the earlier section
471 :ref:`pep-0372`.
472
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000473 The :class:`namedtuple` class now has an optional *rename* parameter.
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000474 If *rename* is true, field names that are invalid because they've
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000475 been repeated or that aren't legal Python identifiers will be
476 renamed to legal names that are derived from the field's
477 position within the list of fields:
478
Georg Brandlf6dab952009-04-28 21:48:35 +0000479 >>> from collections import namedtuple
480 >>> T = namedtuple('T', ['field1', '$illegal', 'for', 'field2'], rename=True)
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000481 >>> T._fields
482 ('field1', '_1', '_2', 'field2')
483
484 (Added by Raymond Hettinger; :issue:`1818`.)
485
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000486 The :class:`deque` data type now exposes its maximum length as the
487 read-only :attr:`maxlen` attribute. (Added by Raymond Hettinger.)
488
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000489* The :mod:`ctypes` module now always converts ``None`` to a C NULL
490 pointer for arguments declared as pointers. (Changed by Thomas
491 Heller; :issue:`4606`.)
492
493* New method: the :class:`Decimal` class gained a
494 :meth:`from_float` class method that performs an exact conversion
495 of a floating-point number to a :class:`Decimal`.
496 Note that this is an **exact** conversion that strives for the
497 closest decimal approximation to the floating-point representation's value;
498 the resulting decimal value will therefore still include the inaccuracy,
499 if any.
500 For example, ``Decimal.from_float(0.1)`` returns
501 ``Decimal('0.1000000000000000055511151231257827021181583404541015625')``.
502 (Implemented by Raymond Hettinger; :issue:`4796`.)
503
504 The constructor for :class:`Decimal` now accepts non-European
505 Unicode characters, such as Arabic-Indic digits. (Contributed by
506 Mark Dickinson; :issue:`6595`.)
507
508 When using :class:`Decimal` instances with a string's
509 :meth:`format` method, the default alignment was previously
510 left-alignment. This has been changed to right-alignment, which seems
511 more sensible for numeric types. (Changed by Mark Dickinson; :issue:`6857`.)
512
513* Distutils is being more actively developed, thanks to Tarek Ziade
514 has taken over maintenance of the package. A new
515 :file:`setup.py` subcommand, ``check``, will
516 check that the arguments being passed to the :func:`setup` function
517 are complete and correct (:issue:`5732`).
518
519 :func:`distutils.sdist.add_defaults` now uses
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000520 *package_dir* and *data_files* to create the MANIFEST file.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000521 :mod:`distutils.sysconfig` now reads the :envvar:`AR` and
522 :envvar:`ARFLAGS` environment variables.
523
524 .. ARFLAGS done in #5941
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000525
526 It is no longer mandatory to store clear-text passwords in the
527 :file:`.pypirc` file when registering and uploading packages to PyPI. As long
528 as the username is present in that file, the :mod:`distutils` package will
529 prompt for the password if not present. (Added by Tarek Ziade,
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000530 based on an initial contribution by Nathan Van Gheem; :issue:`4394`.)
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000531
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000532 A Distutils setup can now specify that a C extension is optional by
533 setting the *optional* option setting to true. If this optional is
534 supplied, failure to build the extension will not abort the build
535 process, but instead simply not install the failing extension.
Georg Brandl64e1c752009-04-11 18:19:27 +0000536 (Contributed by Georg Brandl; :issue:`5583`.)
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000537
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000538* The :class:`Fraction` class now accepts two rational numbers
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000539 as arguments to its constructor.
540 (Implemented by Mark Dickinson; :issue:`5812`.)
541
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000542* New function: the :mod:`gc` module's :func:`is_tracked` returns
543 true if a given instance is tracked by the garbage collector, false
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000544 otherwise. (Contributed by Antoine Pitrou; :issue:`4688`.)
545
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000546* The :mod:`gzip` module's :class:`GzipFile` now supports the context
547 management protocol, so you can write ``with gzip.GzipFile(...) as f: ...``.
548 (Contributed by Hagen Fuerstenau; :issue:`3860`.)
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000549 It's now possible to override the modification time
550 recorded in a gzipped file by providing an optional timestamp to
551 the constructor. (Contributed by Jacques Frechet; :issue:`4272`.)
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000552
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000553* The :mod:`hashlib` module was inconsistent about accepting
554 input as a Unicode object or an object that doesn't support
555 the buffer protocol. The behavior was different depending on
556 whether :mod:`hashlib` was using an external OpenSSL library
557 or its built-in implementations. Python 2.7 makes the
558 behavior consistent, always rejecting such objects by raising a
559 :exc:`TypeError`. (Fixed by Gregory P. Smith; :issue:`3745`.)
560
561* The default :class:`HTTPResponse` class used by the :mod:`httplib` module now
562 supports buffering, resulting in much faster reading of HTTP responses.
563 (Contributed by Kristjan Valur Jonsson; :issue:`4879`.)
564
565* The :mod:`imaplib` module now supports IPv6 addresses.
566 (Contributed by Derek Morr; :issue:`1655`.)
567
568* The :mod:`io` library has been upgraded to the version shipped with
569 Python 3.1. For 3.1, the I/O library was entirely rewritten in C
570 and is 2 to 20 times faster depending on the task at hand. The
571 original Python version was renamed to the :mod:`_pyio` module.
572
573 One minor resulting change: the :class:`io.TextIOBase` class now
574 has an :attr:`errors` attribute giving the error setting
575 used for encoding and decoding errors (one of ``'strict'``, ``'replace'``,
576 ``'ignore'``).
577
578 The :class:`io.FileIO` class now raises an :exc:`OSError` when passed
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000579 an invalid file descriptor. (Implemented by Benjamin Peterson;
580 :issue:`4991`.)
581
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000582* New function: ``itertools.compress(*data*, *selectors*)`` takes two
583 iterators. Elements of *data* are returned if the corresponding
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000584 value in *selectors* is true::
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000585
586 itertools.compress('ABCDEF', [1,0,1,0,1,1]) =>
587 A, C, E, F
588
589 New function: ``itertools.combinations_with_replacement(*iter*, *r*)``
590 returns all the possible *r*-length combinations of elements from the
591 iterable *iter*. Unlike :func:`combinations`, individual elements
592 can be repeated in the generated combinations::
593
594 itertools.combinations_with_replacement('abc', 2) =>
595 ('a', 'a'), ('a', 'b'), ('a', 'c'),
596 ('b', 'b'), ('b', 'c'), ('c', 'c')
597
598 Note that elements are treated as unique depending on their position
599 in the input, not their actual values.
600
601 The :class:`itertools.count` function now has a *step* argument that
602 allows incrementing by values other than 1. :func:`count` also
603 now allows keyword arguments, and using non-integer values such as
604 floats or :class:`Decimal` instances. (Implemented by Raymond
605 Hettinger; :issue:`5032`.)
606
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000607 :func:`itertools.combinations` and :func:`itertools.product` were
608 previously raising :exc:`ValueError` for values of *r* larger than
609 the input iterable. This was deemed a specification error, so they
610 now return an empty iterator. (Fixed by Raymond Hettinger; :issue:`4816`.)
611
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000612* The :mod:`json` module was upgraded to version 2.0.9 of the
613 simplejson package, which includes a C extension that makes
614 encoding and decoding faster.
615 (Contributed by Bob Ippolito; :issue:`4136`.)
616
617 To support the new :class:`OrderedDict` type, :func:`json.load`
618 now has an optional *object_pairs_hook* parameter that will be called
619 with any object literal that decodes to a list of pairs.
620 (Contributed by Raymond Hettinger; :issue:`5381`.)
621
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000622* New functions: the :mod:`math` module now has
623 a :func:`gamma` function.
624 (Contributed by Mark Dickinson and nirinA raseliarison; :issue:`3366`.)
625
Andrew M. Kuchling24520b42009-04-09 11:22:47 +0000626* The :mod:`multiprocessing` module's :class:`Manager*` classes
627 can now be passed a callable that will be called whenever
628 a subprocess is started, along with a set of arguments that will be
629 passed to the callable.
630 (Contributed by lekma; :issue:`5585`.)
631
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000632* The :mod:`nntplib` module now supports IPv6 addresses.
633 (Contributed by Derek Morr; :issue:`1664`.)
634
Andrew M. Kuchling9cb42772009-01-21 02:15:43 +0000635* The :mod:`pydoc` module now has help for the various symbols that Python
636 uses. You can now do ``help('<<')`` or ``help('@')``, for example.
637 (Contributed by David Laban; :issue:`4739`.)
638
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000639* The :mod:`re` module's :func:`split`, :func:`sub`, and :func:`subn`
640 now accept an optional *flags* argument, for consistency with the
641 other functions in the module. (Added by Gregory P. Smith.)
642
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000643* The :mod:`shutil` module's :func:`copyfile` and :func:`copytree`
644 functions now raises a :exc:`SpecialFileError` exception when
645 asked to copy a named pipe. Previously the code would treat
646 named pipes like a regular file by opening them for reading, and
647 this would block indefinitely. (Fixed by Antoine Pitrou; :issue:`3002`.)
648
649* New functions: in the :mod:`site` module, three new functions
650 return various site- and user-specific paths.
651 :func:`getsitepackages` returns a list containing all
652 global site-packages directories, and
653 :func:`getusersitepackages` returns the path of the user's
654 site-packages directory.
655 :func:`getuserbase` returns the value of the :envvar:``USER_BASE``
656 environment variable, giving the path to a directory that can be used
657 to store data.
658 (Contributed by Tarek Ziade; :issue:`6693`.)
659
660* The :mod:`SocketServer` module's :class:`TCPServer` class now
661 has a :attr:`disable_nagle_algorithm` class attribute.
662 The default value is False; if overridden to be True,
663 new request connections will have the TCP_NODELAY option set to
664 prevent buffering many small sends into a single TCP packet.
665 (Contributed by Kristjan Valur Jonsson; :issue:`6192`.)
666
667 .. XXX the documentation for this attr was silently dropped from
668 .. Doc/library/socketserver.rst.
669
670* The :mod:`struct` module will no longer silently ignore overflow
671 errors when a value is too large for a particular integer format
672 code (one of ``bBhHiIlLqQ``); it now always raises a
673 :exc:`struct.error` exception. (Changed by Mark Dickinson;
674 :issue:`1523`.)
675
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000676* New function: the :mod:`subprocess` module's
677 :func:`check_output` runs a command with a specified set of arguments
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000678 and returns the command's output as a string when the command runs without
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +0000679 error, or raises a :exc:`CalledProcessError` exception otherwise.
680
681 ::
682
683 >>> subprocess.check_output(['df', '-h', '.'])
684 'Filesystem Size Used Avail Capacity Mounted on\n
685 /dev/disk0s2 52G 49G 3.0G 94% /\n'
686
687 >>> subprocess.check_output(['df', '-h', '/bogus'])
688 ...
689 subprocess.CalledProcessError: Command '['df', '-h', '/bogus']' returned non-zero exit status 1
690
691 (Contributed by Gregory P. Smith.)
692
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000693* New function: :func:`is_declared_global` in the :mod:`symtable` module
694 returns true for variables that are explicitly declared to be global,
695 false for ones that are implicitly global.
696 (Contributed by Jeremy Hylton.)
697
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000698* The ``sys.version_info`` value is now a named tuple, with attributes
699 named ``major``, ``minor``, ``micro``, ``releaselevel``, and ``serial``.
700 (Contributed by Ross Light; :issue:`4285`.)
701
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000702* The :mod:`tarfile` module now supports filtering the :class:`TarInfo`
703 objects being added to a tar file. When you call :meth:`TarFile.add`,
704 instance, you may supply an optional *filter* argument
705 that's a callable. The *filter* callable will be passed the
706 :class:`TarInfo` for every file being added, and can modify and return it.
707 If the callable returns ``None``, the file will be excluded from the
708 resulting archive. This is more powerful than the existing
709 *exclude* argument, which has therefore been deprecated.
710 (Added by Lars Gustaebel; :issue:`6856`.)
711
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000712* The :mod:`threading` module's :meth:`Event.wait` method now returns
713 the internal flag on exit. This means the method will usually
714 return true because :meth:`wait` is supposed to block until the
715 internal flag becomes true. The return value will only be false if
716 a timeout was provided and the operation timed out.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000717 (Contributed by Tim Lesher; :issue:`1674032`.)
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000718
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000719* The :func:`is_zipfile` function in the :mod:`zipfile` module now
720 accepts a file object, in addition to the path names accepted in earlier
Andrew M. Kuchling9cb42772009-01-21 02:15:43 +0000721 versions. (Contributed by Gabriel Genellina; :issue:`4756`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000722
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000723 :mod:`zipfile` now supports archiving empty directories and
724 extracts them correctly. (Fixed by Kuba Wieczorek; :issue:`4710`.)
725
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000726.. ======================================================================
727.. whole new modules get described in subsections here
728
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000729Unit Testing Enhancements
730---------------------------------
731
732The :mod:`unittest` module was enhanced in several ways.
733The progress messages now shows 'x' for expected failures
734and 'u' for unexpected successes when run in verbose mode.
735(Contributed by Benjamin Peterson.)
736Test cases can raise the :exc:`SkipTest` exception to skip a test.
737(:issue:`1034053`.)
738
739.. XXX describe test discovery (Contributed by Michael Foord; :issue:`6001`.)
740
741The error messages for :meth:`assertEqual`,
742:meth:`assertTrue`, and :meth:`assertFalse`
743failures now provide more information. If you set the
744:attr:`longMessage` attribute of your :class:`TestCase` classes to
745true, both the standard error message and any additional message you
746provide will be printed for failures. (Added by Michael Foord; :issue:`5663`.)
747
748The :meth:`assertRaises` and :meth:`failUnlessRaises` methods now
749return a context handler when called without providing a callable
750object to run. For example, you can write this::
751
752 with self.assertRaises(KeyError):
753 raise ValueError
754
755(Implemented by Antoine Pitrou; :issue:`4444`.)
756
757The methods :meth:`addCleanup` and :meth:`doCleanups` were added.
758:meth:`addCleanup` allows you to add cleanup functions that
759will be called unconditionally (after :meth:`setUp` if
760:meth:`setUp` fails, otherwise after :meth:`tearDown`). This allows
761for much simpler resource allocation and deallocation during tests.
762:issue:`5679`
763
764A number of new methods were added that provide more specialized
765tests. Many of these methods were written by Google engineers
766for use in their test suites; Gregory P. Smith, Michael Foord, and
767GvR worked on merging them into Python's version of :mod:`unittest`.
768
769* :meth:`assertIsNone` and :meth:`assertIsNotNone` take one
770 expression and verify that the result is or is not ``None``.
771
772* :meth:`assertIs` and :meth:`assertIsNot` take two values and check
773 whether the two values evaluate to the same object or not.
774 (Added by Michael Foord; :issue:`2578`.)
775
776* :meth:`assertGreater`, :meth:`assertGreaterEqual`,
777 :meth:`assertLess`, and :meth:`assertLessEqual` compare
778 two quantities.
779
780* :meth:`assertMultiLineEqual` compares two strings, and if they're
781 not equal, displays a helpful comparison that highlights the
782 differences in the two strings.
783
784* :meth:`assertRegexpMatches` checks whether its first argument is a
785 string matching a regular expression provided as its second argument.
786
787* :meth:`assertRaisesRegexp` checks whether a particular exception
788 is raised, and then also checks that the string representation of
789 the exception matches the provided regular expression.
790
791* :meth:`assertIn` and :meth:`assertNotIn` tests whether
792 *first* is or is not in *second*.
793
794* :meth:`assertSameElements` tests whether two provided sequences
795 contain the same elements.
796
797* :meth:`assertSetEqual` compares whether two sets are equal, and
798 only reports the differences between the sets in case of error.
799
800* Similarly, :meth:`assertListEqual` and :meth:`assertTupleEqual`
801 compare the specified types and explain the differences.
802 More generally, :meth:`assertSequenceEqual` compares two sequences
803 and can optionally check whether both sequences are of a
804 particular type.
805
806* :meth:`assertDictEqual` compares two dictionaries and reports the
807 differences. :meth:`assertDictContainsSubset` checks whether
808 all of the key/value pairs in *first* are found in *second*.
809
810* :meth:`assertAlmostEqual` and :meth:`assertNotAlmostEqual` short-circuit
811 (automatically pass or fail without checking decimal places) if the objects
812 are equal.
813
814* :meth:`loadTestsFromName` properly honors the ``suiteClass`` attribute of
815 the :class:`TestLoader`. (Fixed by Mark Roddy; :issue:`6866`.)
816
817* A new hook, :meth:`addTypeEqualityFunc` takes a type object and a
818 function. The :meth:`assertEqual` method will use the function
819 when both of the objects being compared are of the specified type.
820 This function should compare the two objects and raise an
821 exception if they don't match; it's a good idea for the function
822 to provide additional information about why the two objects are
823 matching, much as the new sequence comparison methods do.
824
825:func:`unittest.main` now takes an optional ``exit`` argument.
826If False ``main`` doesn't call :func:`sys.exit` allowing it to
827be used from the interactive interpreter. :issue:`3379`.
828
829:class:`TestResult` has new :meth:`startTestRun` and
830:meth:`stopTestRun` methods; called immediately before
831and after a test run. :issue:`5728` by Robert Collins.
832
833With all these changes, the :file:`unittest.py` was becoming awkwardly
834large, so the module was turned into a package and the code split into
835several files (by Benjamin Peterson). This doesn't affect how the
836module is imported.
837
838
839.. _importlib-section:
840
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000841importlib: Importing Modules
842------------------------------
843
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000844Python 3.1 includes the :mod:`importlib` package, a re-implementation
845of the logic underlying Python's :keyword:`import` statement.
846:mod:`importlib` is useful for implementors of Python interpreters and
847to user who wish to write new importers that can participate in the
848import process. Python 2.7 doesn't contain the complete
849:mod:`importlib` package, but instead has a tiny subset that contains
850a single function, :func:`import_module`.
851
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000852``import_module(name, package=None)`` imports a module. *name* is
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000853a string containing the module or package's name. It's possible to do
854relative imports by providing a string that begins with a ``.``
855character, such as ``..utils.errors``. For relative imports, the
856*package* argument must be provided and is the name of the package that
857will be used as the anchor for
858the relative import. :func:`import_module` both inserts the imported
859module into ``sys.modules`` and returns the module object.
860
861Here are some examples::
862
863 >>> from importlib import import_module
864 >>> anydbm = import_module('anydbm') # Standard absolute import
865 >>> anydbm
866 <module 'anydbm' from '/p/python/Lib/anydbm.py'>
867 >>> # Relative import
868 >>> sysconfig = import_module('..sysconfig', 'distutils.command')
869 >>> sysconfig
870 <module 'distutils.sysconfig' from '/p/python/Lib/distutils/sysconfig.pyc'>
871
872:mod:`importlib` was implemented by Brett Cannon and introduced in
873Python 3.1.
874
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000875
Andrew M. Kuchlinga17cd4a2009-01-31 02:50:09 +0000876ttk: Themed Widgets for Tk
877--------------------------
878
879Tcl/Tk 8.5 includes a set of themed widgets that re-implement basic Tk
880widgets but have a more customizable appearance and can therefore more
881closely resemble the native platform's widgets. This widget
882set was originally called Tile, but was renamed to Ttk (for "themed Tk")
883on being added to Tcl/Tck release 8.5.
884
885XXX write a brief discussion and an example here.
886
887The :mod:`ttk` module was written by Guilherme Polo and added in
888:issue:`2983`. An alternate version called ``Tile.py``, written by
889Martin Franklin and maintained by Kevin Walzer, was proposed for
890inclusion in :issue:`2618`, but the authors argued that Guilherme
891Polo's work was more comprehensive.
892
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000893.. ======================================================================
894
895
896Build and C API Changes
897=======================
898
899Changes to Python's build process and to the C API include:
900
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +0000901* If you use the :file:`.gdbinit` file provided with Python,
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000902 the "pyo" macro in the 2.7 version now works correctly when the thread being
903 debugged doesn't hold the GIL; the macro now acquires it before printing.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000904 (Contributed by Victor Stinner; :issue:`3632`.)
905
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000906* :cfunc:`Py_AddPendingCall` is now thread-safe, letting any
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000907 worker thread submit notifications to the main Python thread. This
908 is particularly useful for asynchronous IO operations.
909 (Contributed by Kristjan Valur Jonsson; :issue:`4293`.)
910
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000911* New function: :cfunc:`PyCode_NewEmpty` creates an empty code object;
912 only the filename, function name, and first line number are required.
913 This is useful to extension modules that are attempting to
914 construct a more useful traceback stack. Previously such
915 extensions needed to call :cfunc:`PyCode_New`, which had many
916 more arguments. (Added by Jeffrey Yasskin.)
917
918* New function: :cfunc:`PyFrame_GetLineNumber` takes a frame object
919 and returns the line number that the frame is currently executing.
920 Previously code would need to get the index of the bytecode
921 instruction currently executing, and then look up the line number
922 corresponding to that address. (Added by Jeffrey Yasskin.)
923
924* New macros: the Python header files now define the following macros:
925 :cmacro:`Py_ISALNUM`,
926 :cmacro:`Py_ISALPHA`,
927 :cmacro:`Py_ISDIGIT`,
928 :cmacro:`Py_ISLOWER`,
929 :cmacro:`Py_ISSPACE`,
930 :cmacro:`Py_ISUPPER`,
931 :cmacro:`Py_ISXDIGIT`,
932 and :cmacro:`Py_TOLOWER`, :cmacro:`Py_TOUPPER`.
933 All of these functions are analogous to the C
934 standard macros for classifying characters, but ignore the current
935 locale setting, because in
936 several places Python needs to analyze characters in a
937 locale-independent way. (Added by Eric Smith;
938 :issue:`5793`.)
939
940 .. XXX these macros don't seem to be described in the c-api docs.
941
942* The complicated interaction between threads and process forking has
943 been changed. Previously, the child process created by
944 :func:`os.fork` might fail because the child is created with only a
945 single thread running, the thread performing the :func:`os.fork`.
946 If other threads were holding a lock, such as Python's import lock,
947 when the fork was performed, the lock would still be marked as
948 "held" in the new process. But in the child process nothing would
949 ever release the lock, since the other threads weren't replicated,
950 and the child process would no longer be able to perform imports.
951
952 Python 2.7 now acquires the import lock before performing an
953 :func:`os.fork`, and will also clean up any locks created using the
954 :mod:`threading` module. C extension modules that have internal
955 locks, or that call :cfunc:`fork()` themselves, will not benefit
956 from this clean-up.
957
958 (Fixed by Thomas Wouters; :issue:`1590864`.)
959
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000960* Global symbols defined by the :mod:`ctypes` module are now prefixed
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000961 with ``Py``, or with ``_ctypes``. (Implemented by Thomas
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000962 Heller; :issue:`3102`.)
963
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000964* The :program:`configure` script now checks for floating-point rounding bugs
965 on certain 32-bit Intel chips and defines a :cmacro:`X87_DOUBLE_ROUNDING`
966 preprocessor definition. No code currently uses this definition,
967 but it's available if anyone wishes to use it.
968 (Added by Mark Dickinson; :issue:`2937`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000969
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000970* The build process now creates the necessary files for pkg-config
971 support. (Contributed by Clinton Roy; :issue:`3585`.)
972
973* The build process now supports Subversion 1.7. (Contributed by
974 Arfrever Frehtes Taifersar Arahesis; :issue:`6094`.)
975
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000976.. ======================================================================
977
978Port-Specific Changes: Windows
979-----------------------------------
980
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +0000981* The :mod:`msvcrt` module now contains some constants from
982 the :file:`crtassem.h` header file:
983 :data:`CRT_ASSEMBLY_VERSION`,
984 :data:`VC_ASSEMBLY_PUBLICKEYTOKEN`,
985 and :data:`LIBRARIES_ASSEMBLY_NAME_PREFIX`.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000986 (Contributed by David Cournapeau; :issue:`4365`.)
987
988* The new :cfunc:`_beginthreadex` API is used to start threads, and
989 the native thread-local storage functions are now used.
990 (Contributed by Kristjan Valur Jonsson; :issue:`3582`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000991
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000992* The :func:`os.listdir` function now correctly fails
993 for an empty path. (Fixed by Hirokazu Yamamoto; :issue:`5913`.)
994
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000995.. ======================================================================
996
997Port-Specific Changes: Mac OS X
998-----------------------------------
999
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001000* The path ``/Library/Python/2.7/site-packages`` is now appended to
Andrew M. Kuchling77069572009-03-31 01:21:01 +00001001 ``sys.path``, in order to share added packages between the system
1002 installation and a user-installed copy of the same version.
1003 (Changed by Ronald Oussoren; :issue:`4865`.)
1004
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001005
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001006Other Changes and Fixes
1007=======================
1008
Andrew M. Kuchling77069572009-03-31 01:21:01 +00001009* When importing a module from a :file:`.pyc` or :file:`.pyo` file
1010 with an existing :file:`.py` counterpart, the :attr:`co_filename`
Andrew M. Kuchling92b97002009-05-02 17:12:15 +00001011 attributes of the resulting code objects are overwritten when the
1012 original filename is obsolete. This can happen if the file has been
1013 renamed, moved, or is accessed through different paths. (Patch by
1014 Ziga Seilnacht and Jean-Paul Calderone; :issue:`1180193`.)
Andrew M. Kuchling77069572009-03-31 01:21:01 +00001015
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001016* The :file:`regrtest.py` script now takes a :option:`--randseed=`
1017 switch that takes an integer that will be used as the random seed
1018 for the :option:`-r` option that executes tests in random order.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001019 The :option:`-r` option also reports the seed that was used
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001020 (Added by Collin Winter.)
1021
Antoine Pitrou4698d992009-05-31 14:20:14 +00001022* The :file:`regrtest.py` script now takes a :option:`-j` switch
1023 that takes an integer specifying how many tests run in parallel. This
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001024 allows reducing the total runtime on multi-core machines.
Antoine Pitrou4698d992009-05-31 14:20:14 +00001025 This option is compatible with several other options, including the
1026 :option:`-R` switch which is known to produce long runtimes.
1027 (Added by Antoine Pitrou, :issue:`6152`.)
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001028
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001029.. ======================================================================
1030
1031Porting to Python 2.7
1032=====================
1033
1034This section lists previously described changes and other bugfixes
1035that may require changes to your code:
1036
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001037* When using :class:`Decimal` instances with a string's
1038 :meth:`format` method, the default alignment was previously
1039 left-alignment. This has been changed to right-alignment, which might
1040 change the output of your programs.
1041 (Changed by Mark Dickinson; :issue:`6857`.)
1042
1043 Another :meth:`format`-related change: the default precision used
1044 for floating-point and complex numbers was changed from 6 decimal
1045 places to 12, which matches the precision used by :func:`str`.
1046 (Changed by Eric Smith; :issue:`5920`.)
1047
Amaury Forgeot d'Arc901f2002009-06-09 23:08:13 +00001048* Because of an optimization for the :keyword:`with` statement, the special
1049 methods :meth:`__enter__` and :meth:`__exit__` must belong to the object's
1050 type, and cannot be directly attached to the object's instance. This
Amaury Forgeot d'Arcd81333c2009-06-10 20:30:19 +00001051 affects new-style classes (derived from :class:`object`) and C extension
Amaury Forgeot d'Arc901f2002009-06-09 23:08:13 +00001052 types. (:issue:`6101`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001053
1054.. ======================================================================
1055
1056
1057.. _acks27:
1058
1059Acknowledgements
1060================
1061
1062The author would like to thank the following people for offering
1063suggestions, corrections and assistance with various drafts of this
1064article: no one yet.
1065