blob: f9d35b76a855772f58b792f00e66ab9b14b55dbf [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. Kuchling85f928a2010-04-15 01:42:27 +000011.. Big jobs: ElementTree 1.3, pep 391, sysconfig
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +000012.. unittest test discovery
Andrew M. Kuchling6d7dfa22010-04-11 12:49:37 +000013.. hyperlink all the methods & functions.
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +000014
Andrew M. Kuchling15c82d22010-04-29 00:22:16 +000015.. T_STRING_INPLACE not described in main docs
16
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000017.. $Id$
18 Rules for maintenance:
19
20 * Anyone can add text to this document. Do not spend very much time
21 on the wording of your changes, because your text will probably
22 get rewritten to some degree.
23
24 * The maintainer will go through Misc/NEWS periodically and add
25 changes; it's therefore more important to add your changes to
26 Misc/NEWS than to this file.
27
28 * This is not a complete list of every single change; completeness
29 is the purpose of Misc/NEWS. Some changes I consider too small
30 or esoteric to include. If such a change is added to the text,
31 I'll just remove it. (This is another reason you shouldn't spend
32 too much time on writing your addition.)
33
34 * If you want to draw your new text to the attention of the
35 maintainer, add 'XXX' to the beginning of the paragraph or
36 section.
37
38 * It's OK to just add a fragmentary note about a change. For
39 example: "XXX Describe the transmogrify() function added to the
40 socket module." The maintainer will research the change and
41 write the necessary text.
42
43 * You can comment out your additions if you like, but it's not
44 necessary (especially when a final release is some months away).
45
Ezio Melotti021f3342010-04-06 03:26:49 +000046 * Credit the author of a patch or bugfix. Just the name is
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000047 sufficient; the e-mail address isn't necessary.
48
49 * It's helpful to add the bug/patch number in a parenthetical comment.
50
51 XXX Describe the transmogrify() function added to the socket
52 module.
53 (Contributed by P.Y. Developer; :issue:`12345`.)
54
55 This saves the maintainer some effort going through the SVN logs
56 when researching a change.
57
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +000058This article explains the new features in Python 2.7. The final
59release of 2.7 is currently scheduled for June 2010; the detailed
60schedule is described in :pep:`373`.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000061
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +000062Python 2.7 is planned to be the last major release in the 2.x series.
Andrew M. Kuchling4515f0d2010-04-11 20:40:09 +000063Though more major releases have not been absolutely ruled out, the
64Python maintainers are planning to focus more on Python 3.x. Despite
65that, it's likely that the 2.7 release will have a longer period of
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +000066maintenance compared to earlier 2.x versions.
67
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000068.. Compare with previous release in 2 - 3 sentences here.
69 add hyperlink when the documentation becomes available online.
70
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000071.. _whatsnew27-python31:
72
73Python 3.1 Features
74=======================
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000075
76Much as Python 2.6 incorporated features from Python 3.0,
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000077version 2.7 incorporates some of the new features
78in Python 3.1. The 2.x series continues to provide tools
79for migrating to the 3.x series.
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000080
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000081A partial list of 3.1 features that were backported to 2.7:
82
83* A version of the :mod:`io` library, rewritten in C for performance.
84* The ordered-dictionary type described in :ref:`pep-0372`.
Andrew M. Kuchling8f254e72009-12-08 02:37:05 +000085* The new format specifier described in :ref:`pep-0378`.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000086* The :class:`memoryview` object.
87* A small subset of the :mod:`importlib` module `described below <#importlib-section>`__.
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +000088* Float-to-string and string-to-float conversions now round their
89 results more correctly. And :func:`repr` of a floating-point
90 number *x* returns a result that's guaranteed to round back to the
91 same number when converted back to a string.
92* The :cfunc:`PyLong_AsLongAndOverflow` C API function.
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000093
94One porting change: the :option:`-3` switch now automatically
95enables the :option:`-Qwarn` switch that causes warnings
96about using classic division with integers and long integers.
97
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +000098Other new Python3-mode warnings include:
99
100* :func:`operator.isCallable` and :func:`operator.sequenceIncludes`,
101 which are not supported in 3.x.
102
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000103.. ========================================================================
104.. Large, PEP-level features and changes should be described here.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000105.. ========================================================================
106
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000107.. _pep-0372:
108
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000109PEP 372: Adding an ordered dictionary to collections
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000110====================================================
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000111
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000112Regular Python dictionaries iterate over key/value pairs in arbitrary order.
113Over the years, a number of authors have written alternative implementations
114that remember the order that the keys were originally inserted. Based on
115the experiences from those implementations, a new
Ezio Melotti021f3342010-04-06 03:26:49 +0000116:class:`~collections.OrderedDict` class has been introduced in the
117:mod:`collections` module.
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000118
Ezio Melotti021f3342010-04-06 03:26:49 +0000119The :class:`~collections.OrderedDict` API is substantially the same as regular
120dictionaries but will iterate over keys and values in a guaranteed order
121depending on when a key was first inserted::
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000122
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000123 >>> from collections import OrderedDict
124 >>> d = OrderedDict([('first', 1), ('second', 2),
125 ... ('third', 3)])
126 >>> d.items()
127 [('first', 1), ('second', 2), ('third', 3)]
128
129If a new entry overwrites an existing entry, the original insertion
130position is left unchanged::
131
132 >>> d['second'] = 4
133 >>> d.items()
134 [('first', 1), ('second', 4), ('third', 3)]
135
136Deleting an entry and reinserting it will move it to the end::
137
138 >>> del d['second']
139 >>> d['second'] = 5
140 >>> d.items()
141 [('first', 1), ('third', 3), ('second', 5)]
142
Ezio Melotti021f3342010-04-06 03:26:49 +0000143The :meth:`~collections.OrderedDict.popitem` method has an optional *last*
144argument that defaults to True. If *last* is True, the most recently
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000145added key is returned and removed; if it's False, the
146oldest key is selected::
147
148 >>> od = OrderedDict([(x,0) for x in range(20)])
149 >>> od.popitem()
150 (19, 0)
151 >>> od.popitem()
152 (18, 0)
Ezio Melotti021f3342010-04-06 03:26:49 +0000153 >>> od.popitem(last=False)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000154 (0, 0)
Ezio Melotti021f3342010-04-06 03:26:49 +0000155 >>> od.popitem(last=False)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000156 (1, 0)
157
158Comparing two ordered dictionaries checks both the keys and values,
159and requires that the insertion order was the same::
160
161 >>> od1 = OrderedDict([('first', 1), ('second', 2),
162 ... ('third', 3)])
163 >>> od2 = OrderedDict([('third', 3), ('first', 1),
164 ... ('second', 2)])
Ezio Melotti021f3342010-04-06 03:26:49 +0000165 >>> od1 == od2
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000166 False
167 >>> # Move 'third' key to the end
Ezio Melotti021f3342010-04-06 03:26:49 +0000168 >>> del od2['third']; od2['third'] = 3
169 >>> od1 == od2
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000170 True
171
Ezio Melotti021f3342010-04-06 03:26:49 +0000172Comparing an :class:`~collections.OrderedDict` with a regular dictionary
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000173ignores the insertion order and just compares the keys and values.
174
Ezio Melotti021f3342010-04-06 03:26:49 +0000175How does the :class:`~collections.OrderedDict` work? It maintains a
176doubly-linked list of keys, appending new keys to the list as they're inserted.
177A secondary dictionary maps keys to their corresponding list node, so
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000178deletion doesn't have to traverse the entire linked list and therefore
179remains O(1).
180
181.. XXX check O(1)-ness with Raymond
Ezio Melotti021f3342010-04-06 03:26:49 +0000182.. Also check if the 'somenamedtuple' in the collection module should
183.. be replaced/removed in order to use
184.. :meth:`~collections.namedtuple._asdict()` (see below)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000185
186The standard library now supports use of ordered dictionaries in several
Andrew M. Kuchling363dbcc2010-04-14 23:55:17 +0000187modules.
188
189* The :mod:`ConfigParser` module uses them by default, letting
190 configuration files be read, modified, and then written back in their original
191 order.
192
193* The :meth:`~collections.somenamedtuple._asdict()` method for
194 :func:`collections.namedtuple` now returns an ordered dictionary with the
195 values appearing in the same order as the underlying tuple indices.
196
197* The :mod:`json` module's :class:`~json.JSONDecoder` class
198 constructor was extended with an *object_pairs_hook* parameter to
199 allow :class:`OrderedDict` instances to be built by the decoder.
200 Support was also added for third-party tools like
201 `PyYAML <http://pyyaml.org/>`_.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000202
Andrew M. Kuchling7fe65a02009-10-13 15:49:33 +0000203.. seealso::
204
205 :pep:`372` - Adding an ordered dictionary to collections
206 PEP written by Armin Ronacher and Raymond Hettinger;
207 implemented by Raymond Hettinger.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000208
209.. _pep-0378:
210
211PEP 378: Format Specifier for Thousands Separator
Ezio Melotti021f3342010-04-06 03:26:49 +0000212=================================================
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000213
214To make program output more readable, it can be useful to add
215separators to large numbers and render them as
21618,446,744,073,709,551,616 instead of 18446744073709551616.
217
218The fully general solution for doing this is the :mod:`locale` module,
219which can use different separators ("," in North America, "." in
220Europe) and different grouping sizes, but :mod:`locale` is complicated
221to use and unsuitable for multi-threaded applications where different
222threads are producing output for different locales.
223
224Therefore, a simple comma-grouping mechanism has been added to the
Ezio Melotti021f3342010-04-06 03:26:49 +0000225mini-language used by the :meth:`str.format` method. When
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000226formatting a floating-point number, simply include a comma between the
227width and the precision::
228
Eric Smithc4663852010-04-06 14:30:15 +0000229 >>> '{:20,.2f}'.format(18446744073709551616.0)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000230 '18,446,744,073,709,551,616.00'
231
Eric Smith6a928602010-04-06 15:17:33 +0000232When formatting an integer, include the comma after the width:
233
234 >>> '{:20,d}'.format(18446744073709551616)
235 '18,446,744,073,709,551,616'
236
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000237This mechanism is not adaptable at all; commas are always used as the
238separator and the grouping is always into three-digit groups. The
239comma-formatting mechanism isn't as general as the :mod:`locale`
240module, but it's easier to use.
241
Andrew M. Kuchling85ea4bf2009-10-05 22:45:39 +0000242.. XXX "Format String Syntax" in string.rst could use many more examples.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000243
244.. seealso::
245
246 :pep:`378` - Format Specifier for Thousands Separator
247 PEP written by Raymond Hettinger; implemented by Eric Smith.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000248
Andrew M. Kuchlingab21f752010-03-02 13:55:33 +0000249PEP 389: The argparse Module for Parsing Command Lines
250======================================================
251
Andrew M. Kuchlingec6393f2010-04-11 01:40:30 +0000252The :mod:`argparse` module for parsing command-line arguments was
253added, intended as a more powerful replacement for the
254:mod:`optparse` module.
255
256This means Python now supports three different modules for parsing
257command-line arguments: :mod:`getopt`, :mod:`optparse`, and
258:mod:`argparse`. The :mod:`getopt` module closely resembles the C
259:cfunc:`getopt` function, so it remains useful if you're writing a
260Python prototype that will eventually be rewritten in C.
261:mod:`optparse` becomes redundant, but there are no plans to remove it
262because there are many scripts still using it, and there's no
263automated way to update these scripts. (Making the :mod:`argparse`
264API consistent with :mod:`optparse`'s interface was discussed but
265rejected as too messy and difficult.)
266
Andrew M. Kuchlingf03641a2010-04-14 01:14:59 +0000267In short, if you're writing a new script and don't need to worry
Andrew M. Kuchlingec6393f2010-04-11 01:40:30 +0000268about compatibility with earlier versions of Python, use
269:mod:`argparse` instead of :mod:`optparse`.
270
Andrew M. Kuchlingf03641a2010-04-14 01:14:59 +0000271Here's an example::
272
273 import argparse
274
275 parser = argparse.ArgumentParser(description='Command-line example.')
276
277 # Add optional switches
278 parser.add_argument('-v', action='store_true', dest='is_verbose',
279 help='produce verbose output')
280 parser.add_argument('-o', action='store', dest='output',
281 metavar='FILE',
282 help='direct output to FILE instead of stdout')
283 parser.add_argument('-C', action='store', type=int, dest='context',
284 metavar='NUM', default=0,
285 help='display NUM lines of added context')
286
287 # Allow any number of additional arguments.
288 parser.add_argument(nargs='*', action='store', dest='inputs',
289 help='input filenames (default is stdin)')
290
291 args = parser.parse_args()
292 print args.__dict__
293
294Unless you override it, :option:`-h` and :option:`--help` switches
295are automatically added, and produce neatly formatted output::
296
297 -> ./python.exe argparse-example.py --help
Andrew M. Kuchling363dbcc2010-04-14 23:55:17 +0000298 usage: argparse-example.py [-h] [-v] [-o FILE] [-C NUM] [inputs [inputs ...]]
Andrew M. Kuchlingf03641a2010-04-14 01:14:59 +0000299
300 Command-line example.
301
302 positional arguments:
303 inputs input filenames (default is stdin)
304
305 optional arguments:
306 -h, --help show this help message and exit
307 -v produce verbose output
308 -o FILE direct output to FILE instead of stdout
309 -C NUM display NUM lines of added context
310
311Similarly to :mod:`optparse`, the command-line switches and arguments
312are returned as an object with attributes named by the *dest* parameters::
313
314 -> ./python.exe argparse-example.py -v
315 {'output': None, 'is_verbose': True, 'context': 0, 'inputs': []}
316
317 -> ./python.exe argparse-example.py -v -o /tmp/output -C 4 file1 file2
318 {'output': '/tmp/output', 'is_verbose': True, 'context': 4,
319 'inputs': ['file1', 'file2']}
320
321:mod:`argparse` has much fancier validation than :mod:`optparse`; you
322can specify an exact number of arguments as an integer, 0 or more
323arguments by passing ``'*'``, 1 or more by passing ``'+'``, or an
324optional argument with ``'?'``. A top-level parser can contain
325sub-parsers, so you can define subcommands that have different sets of
326switches, as in ``svn commit``, ``svn checkout``, etc. You can
327specify an argument type as :class:`~argparse.FileType`, which will
328automatically open files for you and understands that ``'-'`` means
329standard input or output.
Andrew M. Kuchlingab21f752010-03-02 13:55:33 +0000330
331.. seealso::
332
Andrew M. Kuchlingec6393f2010-04-11 01:40:30 +0000333 `argparse module documentation <http://docs.python.org/dev/library/argparse.html>`__
334
335 `Upgrading optparse code to use argparse <http://docs.python.org/dev/library/argparse.html#upgrading-optparse-code>`__
336
Andrew M. Kuchlingab21f752010-03-02 13:55:33 +0000337 :pep:`389` - argparse - New Command Line Parsing Module
338 PEP written and implemented by Steven Bethard.
339
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000340PEP 391: Dictionary-Based Configuration For Logging
341====================================================
342
Andrew M. Kuchlingb6c1aeb2010-04-14 14:28:31 +0000343.. not documented in library reference yet.
344
345The :mod:`logging` module is very flexible; an application can define
346a tree of logging subsystems, and each logger in this tree can filter
347out certain messages, format them differently, and direct messages to
348a varying number of handlers.
349
350All this flexibility can require a lot of configuration. You can
351write Python statements to create objects and set their properties,
352but a complex set-up would require verbose but boring code.
353:mod:`logging` also supports a :func:`~logging.config.fileConfig`
354function that parses a file, but the file format doesn't support
355configuring filters, and it's messier to generate programmatically.
356
357Python 2.7 adds a :func:`~logging.config.dictConfig` function that
358uses a dictionary, and there are many ways to produce a dictionary
359from different sources. You can construct one with code, of course.
360Python's standard library now includes a JSON parser, so you could
361parse a file containing JSON, or you could use a YAML parsing library
362if one is installed.
363
364XXX describe an example.
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000365
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000366Two smaller enhancements to the logging module are:
367
368.. rev79293
369
370* :class:`Logger` instances gained a :meth:`getChild` that retrieves a
371 descendant logger using a relative path. For example,
372 once you retrieve a logger by doing ``log = getLogger('app')``,
373 calling ``log.getChild('network.listen')`` is equivalent to
374 ``getLogger('app.network.listen')``.
375
376* The :class:`LoggerAdapter` class gained a :meth:`isEnabledFor` method
377 that takes a *level* and returns whether the underlying logger would
378 process a message of that level of importance.
379
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000380.. seealso::
381
382 :pep:`391` - Dictionary-Based Configuration For Logging
383 PEP written and implemented by Vinay Sajip.
384
385PEP 3106: Dictionary Views
386====================================================
387
Andrew M. Kuchling85f928a2010-04-15 01:42:27 +0000388The dictionary methods :meth:`keys`, :meth:`values`, and :meth:`items`
389are different in Python 3.x. They return an object called a :dfn:`view`
390instead of a fully materialized list.
391
392.. Views can be iterated over, but they also behave like sets. XXX not working.
393
394It's not possible to change the return values of :meth:`keys`,
395:meth:`values`, and :meth:`items` in Python 2.7 because too much code
396would break. Instead the 3.x versions were added under the new names
397of :meth:`viewkeys`, :meth:`viewvalues`, and :meth:`viewitems`.
398
399::
400
401 >>> d = dict((i*10, chr(65+i)) for i in range(26))
402 >>> d
403 {0: 'A', 130: 'N', 10: 'B', 140: 'O', 20: ..., 250: 'Z'}
404 >>> d.viewkeys()
405 dict_keys([0, 130, 10, 140, 20, 150, 30, ..., 250])
406
407The view keeps track of the dictionary and its contents change as the
408dictionary is modified::
409
410 >>> vk = d.viewkeys()
411 >>> vk
412 dict_keys([0, 130, 10, ..., 250])
413 >>> d[260] = '&'
414 >>> vk
415 dict_keys([0, 130, 260, 10, ..., 250])
416
417However, note that you can't add or remove keys while you're iterating
418over the view::
419
420 >>> for k in vk:
421 ... d[k*2] = k
422 ...
423 Traceback (most recent call last):
424 File "<stdin>", line 1, in <module>
425 RuntimeError: dictionary changed size during iteration
426
427You can use the view methods in Python 2.x code, and the 2to3
428converter will change them to the standard :meth:`keys`,
429:meth:`values`, and :meth:`items` methods.
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000430
431.. seealso::
432
433 :pep:`3106` - Revamping dict.keys(), .values() and .items()
434 PEP written by Guido van Rossum.
435 Backported to 2.7 by Alexandre Vassalotti; :issue:`1967`.
436
437
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000438Other Language Changes
439======================
440
441Some smaller changes made to the core Python language are:
442
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000443* The syntax for set literals has been backported from Python 3.x.
444 Curly brackets are used to surround the contents of the resulting
445 mutable set; set literals are
446 distinguished from dictionaries by not containing colons and values.
447 ``{}`` continues to represent an empty dictionary; use
448 ``set()`` for an empty set.
449
450 >>> {1,2,3,4,5}
451 set([1, 2, 3, 4, 5])
Ezio Melotti021f3342010-04-06 03:26:49 +0000452 >>> set() # empty set
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000453 set([])
Ezio Melotti021f3342010-04-06 03:26:49 +0000454 >>> {} # empty dict
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000455 {}
456
457 Backported by Alexandre Vassalotti; :issue:`2335`.
458
459* Dictionary and set comprehensions are another feature backported from
460 3.x, generalizing list/generator comprehensions to use
461 the literal syntax for sets and dictionaries.
462
463 >>> {x:x*x for x in range(6)}
464 {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
465 >>> {'a'*x for x in range(6)}
466 set(['', 'a', 'aa', 'aaa', 'aaaa', 'aaaaa'])
467
468 Backported by Alexandre Vassalotti; :issue:`2333`.
469
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000470* The :keyword:`with` statement can now use multiple context managers
471 in one statement. Context managers are processed from left to right
472 and each one is treated as beginning a new :keyword:`with` statement.
473 This means that::
474
475 with A() as a, B() as b:
476 ... suite of statements ...
477
478 is equivalent to::
479
480 with A() as a:
481 with B() as b:
482 ... suite of statements ...
483
484 The :func:`contextlib.nested` function provides a very similar
485 function, so it's no longer necessary and has been deprecated.
486
487 (Proposed in http://codereview.appspot.com/53094; implemented by
488 Georg Brandl.)
489
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000490* Conversions between floating-point numbers and strings are
491 now correctly rounded on most platforms. These conversions occur
492 in many different places: :func:`str` on
493 floats and complex numbers; the :class:`float` and :class:`complex`
494 constructors;
495 numeric formatting; serialization and
496 deserialization of floats and complex numbers using the
497 :mod:`marshal`, :mod:`pickle`
498 and :mod:`json` modules;
499 parsing of float and imaginary literals in Python code;
Ezio Melotti021f3342010-04-06 03:26:49 +0000500 and :class:`~decimal.Decimal`-to-float conversion.
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000501
502 Related to this, the :func:`repr` of a floating-point number *x*
503 now returns a result based on the shortest decimal string that's
504 guaranteed to round back to *x* under correct rounding (with
505 round-half-to-even rounding mode). Previously it gave a string
506 based on rounding x to 17 decimal digits.
507
Ezio Melotti021f3342010-04-06 03:26:49 +0000508 .. maybe add an example?
509
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000510 The rounding library responsible for this improvement works on
511 Windows, and on Unix platforms using the gcc, icc, or suncc
512 compilers. There may be a small number of platforms where correct
513 operation of this code cannot be guaranteed, so the code is not
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +0000514 used on such systems. You can find out which code is being used
515 by checking :data:`sys.float_repr_style`, which will be ``short``
516 if the new code is in use and ``legacy`` if it isn't.
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000517
Mark Dickinsonbdd863d2010-01-07 09:28:29 +0000518 Implemented by Eric Smith and Mark Dickinson, using David Gay's
519 :file:`dtoa.c` library; :issue:`7117`.
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000520
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000521* The :meth:`str.format` method now supports automatic numbering of the replacement
Benjamin Petersonaa0a0b92009-04-11 20:27:15 +0000522 fields. This makes using :meth:`str.format` more closely resemble using
523 ``%s`` formatting::
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000524
525 >>> '{}:{}:{}'.format(2009, 04, 'Sunday')
526 '2009:4:Sunday'
527 >>> '{}:{}:{day}'.format(2009, 4, day='Sunday')
528 '2009:4:Sunday'
529
Benjamin Petersonaa0a0b92009-04-11 20:27:15 +0000530 The auto-numbering takes the fields from left to right, so the first ``{...}``
531 specifier will use the first argument to :meth:`str.format`, the next
532 specifier will use the next argument, and so on. You can't mix auto-numbering
533 and explicit numbering -- either number all of your specifier fields or none
534 of them -- but you can mix auto-numbering and named fields, as in the second
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000535 example above. (Contributed by Eric Smith; :issue:`5237`.)
536
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000537 Complex numbers now correctly support usage with :func:`format`,
538 and default to being right-aligned.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000539 Specifying a precision or comma-separation applies to both the real
540 and imaginary parts of the number, but a specified field width and
541 alignment is applied to the whole of the resulting ``1.5+3j``
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000542 output. (Contributed by Eric Smith; :issue:`1588` and :issue:`7988`.)
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000543
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000544 The 'F' format code now always formats its output using uppercase characters,
545 so it will now produce 'INF' and 'NAN'.
546 (Contributed by Eric Smith; :issue:`3382`.)
547
Mark Dickinson1a707982008-12-17 16:14:37 +0000548* The :func:`int` and :func:`long` types gained a ``bit_length``
Georg Brandl64e1c752009-04-11 18:19:27 +0000549 method that returns the number of bits necessary to represent
Mark Dickinson1a707982008-12-17 16:14:37 +0000550 its argument in binary::
551
552 >>> n = 37
Ezio Melotti021f3342010-04-06 03:26:49 +0000553 >>> bin(n)
Mark Dickinson1a707982008-12-17 16:14:37 +0000554 '0b100101'
555 >>> n.bit_length()
556 6
557 >>> n = 2**123-1
558 >>> n.bit_length()
559 123
560 >>> (n+1).bit_length()
561 124
562
563 (Contributed by Fredrik Johansson and Victor Stinner; :issue:`3439`.)
564
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000565* Conversions from long integers and regular integers to floating
566 point now round differently, returning the floating-point number
567 closest to the number. This doesn't matter for small integers that
568 can be converted exactly, but for large numbers that will
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000569 unavoidably lose precision, Python 2.7 now approximates more
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000570 closely. For example, Python 2.6 computed the following::
571
572 >>> n = 295147905179352891391
573 >>> float(n)
574 2.9514790517935283e+20
575 >>> n - long(float(n))
576 65535L
577
578 Python 2.7's floating-point result is larger, but much closer to the
579 true value::
580
581 >>> n = 295147905179352891391
582 >>> float(n)
583 2.9514790517935289e+20
Ezio Melotti021f3342010-04-06 03:26:49 +0000584 >>> n - long(float(n))
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000585 -1L
586
587 (Implemented by Mark Dickinson; :issue:`3166`.)
588
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000589 Integer division is also more accurate in its rounding behaviours. (Also
590 implemented by Mark Dickinson; :issue:`1811`.)
591
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000592* It's now possible for a subclass of the built-in :class:`unicode` type
593 to override the :meth:`__unicode__` method. (Implemented by
594 Victor Stinner; :issue:`1583863`.)
595
Ezio Melotti021f3342010-04-06 03:26:49 +0000596* The :class:`bytearray` type's :meth:`~bytearray.translate` method now accepts
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000597 ``None`` as its first argument. (Fixed by Georg Brandl;
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000598 :issue:`4759`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000599
Ezio Melotti021f3342010-04-06 03:26:49 +0000600 .. bytearray doesn't seem to be documented
601
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000602* When using ``@classmethod`` and ``@staticmethod`` to wrap
603 methods as class or static methods, the wrapper object now
604 exposes the wrapped function as their :attr:`__func__` attribute.
605 (Contributed by Amaury Forgeot d'Arc, after a suggestion by
606 George Sakkis; :issue:`5982`.)
607
608* A new encoding named "cp720", used primarily for Arabic text, is now
609 supported. (Contributed by Alexander Belchenko and Amaury Forgeot
610 d'Arc; :issue:`1616979`.)
611
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000612* The :class:`file` object will now set the :attr:`filename` attribute
613 on the :exc:`IOError` exception when trying to open a directory
Andrew M. Kuchling0e7123f2010-02-08 13:22:24 +0000614 on POSIX platforms (noted by Jan Kaliszewski; :issue:`4764`), and
615 now explicitly checks for and forbids writing to read-only file objects
616 instead of trusting the C library to catch and report the error
617 (fixed by Stefan Krah; :issue:`5677`).
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000618
Benjamin Petersonae9a0a02009-12-31 16:49:37 +0000619* The Python tokenizer now translates line endings itself, so the
620 :func:`compile` built-in function can now accept code using any
621 line-ending convention. Additionally, it no longer requires that the
622 code end in a newline.
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +0000623
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000624* Extra parentheses in function definitions are illegal in Python 3.x,
625 meaning that you get a syntax error from ``def f((x)): pass``. In
626 Python3-warning mode, Python 2.7 will now warn about this odd usage.
627 (Noted by James Lingard; :issue:`7362`.)
628
Andrew M. Kuchling4515f0d2010-04-11 20:40:09 +0000629* It's now possible to create weak references to old-style class
630 objects. New-style classes were always weak-referenceable. (Fixed
631 by Antoine Pitrou; :issue:`8268`.)
632
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000633* When a module object is garbage-collected, the module's dictionary is
634 now only cleared if no one else is holding a reference to the
635 dictionary (:issue:`7140`).
636
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000637.. ======================================================================
638
Andrew M. Kuchlingec6393f2010-04-11 01:40:30 +0000639.. _new-27-interpreter:
640
641Interpreter Changes
642-------------------------------
643
644A new environment variable, :envvar:`PYTHONWARNINGS`,
645allows controlling warnings. It should be set to a string
646containing warning settings, equivalent to those
647used with the :option:`-W` switch, separated by commas.
648(Contributed by Brian Curtin; :issue:`7301`.)
649
650For example, the following setting will print warnings every time
651they occur, but turn warnings from the :mod:`Cookie` module into an
652error. (The exact syntax for setting an environment variable varies
653across operating systems and shells, so it may be different for you.)
654
655::
656
657 export PYTHONWARNINGS=all,error:::Cookie:0
658
Andrew M. Kuchling15c82d22010-04-29 00:22:16 +0000659When running a module using the interpreter's :option:`-m` switch,
660``sys.argv[0]`` will now be set to the string ``'-m'`` while the
Andrew M. Kuchlingc121f132010-04-30 01:33:40 +0000661module is being located, while executing the :file:`__init__.py` files
662for any parent packages of the module to be executed.
663(Suggested by Michael Foord; implemented by Nick Coghlan;
664:issue:`8202`.)
Andrew M. Kuchlingec6393f2010-04-11 01:40:30 +0000665
666.. ======================================================================
667
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000668
669Optimizations
670-------------
671
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000672Several performance enhancements have been added:
673
674.. * A new :program:`configure` option, :option:`--with-computed-gotos`,
675 compiles the main bytecode interpreter loop using a new dispatch
676 mechanism that gives speedups of up to 20%, depending on the system
677 and benchmark. The new mechanism is only supported on certain
678 compilers, such as gcc, SunPro, and icc.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000679
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000680* A new opcode was added to perform the initial setup for
681 :keyword:`with` statements, looking up the :meth:`__enter__` and
682 :meth:`__exit__` methods. (Contributed by Benjamin Peterson.)
683
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000684* The garbage collector now performs better for one common usage
685 pattern: when many objects are being allocated without deallocating
686 any of them. This would previously take quadratic
687 time for garbage collection, but now the number of full garbage collections
688 is reduced as the number of objects on the heap grows.
689 The new logic is to only perform a full garbage collection pass when
690 the middle generation has been collected 10 times and when the
691 number of survivor objects from the middle generation exceeds 10% of
692 the number of objects in the oldest generation. (Suggested by Martin
Ezio Melotti021f3342010-04-06 03:26:49 +0000693 von Löwis and implemented by Antoine Pitrou; :issue:`4074`.)
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000694
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000695* The garbage collector tries to avoid tracking simple containers
696 which can't be part of a cycle. In Python 2.7, this is now true for
697 tuples and dicts containing atomic types (such as ints, strings,
698 etc.). Transitively, a dict containing tuples of atomic types won't
699 be tracked either. This helps reduce the cost of each
700 garbage collection by decreasing the number of objects to be
701 considered and traversed by the collector.
Antoine Pitrouc18f6b02009-03-28 19:10:13 +0000702 (Contributed by Antoine Pitrou; :issue:`4688`.)
703
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000704* Long integers are now stored internally either in base 2**15 or in base
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000705 2**30, the base being determined at build time. Previously, they
706 were always stored in base 2**15. Using base 2**30 gives
707 significant performance improvements on 64-bit machines, but
708 benchmark results on 32-bit machines have been mixed. Therefore,
709 the default is to use base 2**30 on 64-bit machines and base 2**15
710 on 32-bit machines; on Unix, there's a new configure option
711 :option:`--enable-big-digits` that can be used to override this default.
712
713 Apart from the performance improvements this change should be
714 invisible to end users, with one exception: for testing and
Ezio Melotti021f3342010-04-06 03:26:49 +0000715 debugging purposes there's a new structseq :data:`sys.long_info` that
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000716 provides information about the internal format, giving the number of
717 bits per digit and the size in bytes of the C type used to store
718 each digit::
719
720 >>> import sys
721 >>> sys.long_info
722 sys.long_info(bits_per_digit=30, sizeof_digit=4)
723
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000724 (Contributed by Mark Dickinson; :issue:`4258`.)
725
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000726 Another set of changes made long objects a few bytes smaller: 2 bytes
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000727 smaller on 32-bit systems and 6 bytes on 64-bit.
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000728 (Contributed by Mark Dickinson; :issue:`5260`.)
729
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000730* The division algorithm for long integers has been made faster
731 by tightening the inner loop, doing shifts instead of multiplications,
732 and fixing an unnecessary extra iteration.
733 Various benchmarks show speedups of between 50% and 150% for long
734 integer divisions and modulo operations.
735 (Contributed by Mark Dickinson; :issue:`5512`.)
Andrew M. Kuchlinga7f59472009-12-31 16:38:53 +0000736 Bitwise operations are also significantly faster (initial patch by
737 Gregory Smith; :issue:`1087418`).
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000738
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000739* The implementation of ``%`` checks for the left-side operand being
740 a Python string and special-cases it; this results in a 1-3%
741 performance increase for applications that frequently use ``%``
742 with strings, such as templating libraries.
743 (Implemented by Collin Winter; :issue:`5176`.)
744
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000745* List comprehensions with an ``if`` condition are compiled into
746 faster bytecode. (Patch by Antoine Pitrou, back-ported to 2.7
747 by Jeffrey Yasskin; :issue:`4715`.)
748
Andrew M. Kuchling7f8ebdb2010-01-03 01:15:21 +0000749* Converting an integer or long integer to a decimal string was made
750 faster by special-casing base 10 instead of using a generalized
751 conversion function that supports arbitrary bases.
752 (Patch by Gawain Bolton; :issue:`6713`.)
753
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +0000754* The :meth:`split`, :meth:`replace`, :meth:`rindex`,
755 :meth:`rpartition`, and :meth:`rsplit` methods of string-like types
756 (strings, Unicode strings, and :class:`bytearray` objects) now use a
757 fast reverse-search algorithm instead of a character-by-character
758 scan. This is sometimes faster by a factor of 10. (Added by
759 Florent Xicluna; :issue:`7462` and :issue:`7622`.)
Andrew M. Kuchling7f8ebdb2010-01-03 01:15:21 +0000760
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000761* The :mod:`pickle` and :mod:`cPickle` modules now automatically
762 intern the strings used for attribute names, reducing memory usage
763 of the objects resulting from unpickling. (Contributed by Jake
764 McGuire; :issue:`5084`.)
765
766* The :mod:`cPickle` module now special-cases dictionaries,
767 nearly halving the time required to pickle them.
768 (Contributed by Collin Winter; :issue:`5670`.)
769
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000770.. ======================================================================
771
Georg Brandl0516f812009-11-18 18:52:35 +0000772New and Improved Modules
773========================
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000774
775As in every release, Python's standard library received a number of
776enhancements and bug fixes. Here's a partial list of the most notable
777changes, sorted alphabetically by module name. Consult the
778:file:`Misc/NEWS` file in the source tree for a more complete list of
779changes, or look through the Subversion logs for all the details.
780
Ezio Melotti021f3342010-04-06 03:26:49 +0000781* The :mod:`bdb` module's base debugging class :class:`~bdb.Bdb`
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000782 gained a feature for skipping modules. The constructor
783 now takes an iterable containing glob-style patterns such as
784 ``django.*``; the debugger will not step into stack frames
785 from a module that matches one of these patterns.
786 (Contributed by Maru Newby after a suggestion by
787 Senthil Kumaran; :issue:`5142`.)
788
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +0000789* The :mod:`binascii` module now supports the buffer API, so it can be
790 used with :class:`memoryview` instances and other similar buffer objects.
791 (Backported from 3.x by Florent Xicluna; :issue:`7703`.)
792
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000793* Updated module: the :mod:`bsddb` module has been updated from 4.7.2devel9
794 to version 4.8.4 of
795 `the pybsddb package <http://www.jcea.es/programacion/pybsddb.htm>`__.
796 The new version features better Python 3.x compatibility, various bug fixes,
797 and adds several new BerkeleyDB flags and methods.
Ezio Melotti021f3342010-04-06 03:26:49 +0000798 (Updated by Jesús Cea Avión; :issue:`8156`. The pybsddb
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000799 changelog can be browsed at http://hg.jcea.es/pybsddb/file/tip/ChangeLog.)
800
Ezio Melotti021f3342010-04-06 03:26:49 +0000801* The :mod:`bz2` module's :class:`~bz2.BZ2File` now supports the context
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000802 management protocol, so you can write ``with bz2.BZ2File(...) as f: ...``.
803 (Contributed by Hagen Fuerstenau; :issue:`3860`.)
804
Ezio Melotti021f3342010-04-06 03:26:49 +0000805* New class: the :class:`~collections.Counter` class in the :mod:`collections`
806 module is useful for tallying data. :class:`~collections.Counter` instances
807 behave mostly like dictionaries but return zero for missing keys instead of
Georg Brandlf6dab952009-04-28 21:48:35 +0000808 raising a :exc:`KeyError`:
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000809
Georg Brandlf6dab952009-04-28 21:48:35 +0000810 .. doctest::
811 :options: +NORMALIZE_WHITESPACE
812
813 >>> from collections import Counter
814 >>> c = Counter()
815 >>> for letter in 'here is a sample of english text':
816 ... c[letter] += 1
817 ...
818 >>> c
819 Counter({' ': 6, 'e': 5, 's': 3, 'a': 2, 'i': 2, 'h': 2,
820 'l': 2, 't': 2, 'g': 1, 'f': 1, 'm': 1, 'o': 1, 'n': 1,
821 'p': 1, 'r': 1, 'x': 1})
822 >>> c['e']
823 5
824 >>> c['z']
825 0
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000826
Andrew M. Kuchling4515f0d2010-04-11 20:40:09 +0000827 There are three additional :class:`~collections.Counter` methods:
828 :meth:`~collections.Counter.most_common` returns the N most common
829 elements and their counts. :meth:`~collections.Counter.elements`
830 returns an iterator over the contained elements, repeating each
831 element as many times as its count.
832 :meth:`~collections.Counter.subtract` takes an iterable and
833 subtracts one for each element instead of adding; if the argument is
834 a dictionary or another :class:`Counter`, the counts are
835 subtracted. ::
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000836
837 >>> c.most_common(5)
838 [(' ', 6), ('e', 5), ('s', 3), ('a', 2), ('i', 2)]
839 >>> c.elements() ->
840 'a', 'a', ' ', ' ', ' ', ' ', ' ', ' ',
841 'e', 'e', 'e', 'e', 'e', 'g', 'f', 'i', 'i',
842 'h', 'h', 'm', 'l', 'l', 'o', 'n', 'p', 's',
Georg Brandlf6dab952009-04-28 21:48:35 +0000843 's', 's', 'r', 't', 't', 'x'
Andrew M. Kuchling4515f0d2010-04-11 20:40:09 +0000844 >>> c['e']
845 5
846 >>> c.subtract('very heavy on the letter e')
847 >>> c['e'] # Count is now lower
848 -1
Ezio Melotti021f3342010-04-06 03:26:49 +0000849
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000850 Contributed by Raymond Hettinger; :issue:`1696199`.
851
Andrew M. Kuchling4515f0d2010-04-11 20:40:09 +0000852 .. revision 79660
853
Ezio Melotti021f3342010-04-06 03:26:49 +0000854 The new :class:`~collections.OrderedDict` class is described in the earlier
855 section :ref:`pep-0372`.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000856
Ezio Melotti021f3342010-04-06 03:26:49 +0000857 The :class:`~collections.namedtuple` class now has an optional *rename* parameter.
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000858 If *rename* is true, field names that are invalid because they've
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000859 been repeated or that aren't legal Python identifiers will be
860 renamed to legal names that are derived from the field's
861 position within the list of fields:
862
Georg Brandlf6dab952009-04-28 21:48:35 +0000863 >>> from collections import namedtuple
864 >>> T = namedtuple('T', ['field1', '$illegal', 'for', 'field2'], rename=True)
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000865 >>> T._fields
866 ('field1', '_1', '_2', 'field2')
867
868 (Added by Raymond Hettinger; :issue:`1818`.)
869
Andrew M. Kuchling6d7dfa22010-04-11 12:49:37 +0000870 The :class:`~collections.deque` data type now has a
871 :meth:`~collections.deque.count` method that returns the number of
872 contained elements equal to the supplied argument *x*, and a
873 :meth:`~collections.deque.reverse` method that reverses the elements
874 of the deque in-place. :class:`deque` also exposes its maximum
875 length as the read-only :attr:`~collections.deque.maxlen` attribute.
876 (Both features added by Raymond Hettinger.)
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000877
Ezio Melotti021f3342010-04-06 03:26:49 +0000878* The :mod:`copy` module's :func:`~copy.deepcopy` function will now
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000879 correctly copy bound instance methods. (Implemented by
880 Robert Collins; :issue:`1515`.)
881
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000882* The :mod:`ctypes` module now always converts ``None`` to a C NULL
883 pointer for arguments declared as pointers. (Changed by Thomas
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +0000884 Heller; :issue:`4606`.) The underlying `libffi library
885 <http://sourceware.org/libffi/>`__ has been updated to version
886 3.0.9, containing various fixes for different platforms. (Updated
887 by Matthias Klose; :issue:`8142`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000888
Ezio Melotti021f3342010-04-06 03:26:49 +0000889* New method: the :mod:`datetime` module's :class:`~datetime.timedelta` class
890 gained a :meth:`~datetime.timedelta.total_seconds` method that returns the
891 number of seconds in the duration. (Contributed by Brian Quinlan; :issue:`5788`.)
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +0000892
Ezio Melotti021f3342010-04-06 03:26:49 +0000893* New method: the :class:`~decimal.Decimal` class gained a
894 :meth:`~decimal.Decimal.from_float` class method that performs an exact
895 conversion of a floating-point number to a :class:`~decimal.Decimal`.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000896 Note that this is an **exact** conversion that strives for the
897 closest decimal approximation to the floating-point representation's value;
898 the resulting decimal value will therefore still include the inaccuracy,
899 if any.
900 For example, ``Decimal.from_float(0.1)`` returns
901 ``Decimal('0.1000000000000000055511151231257827021181583404541015625')``.
902 (Implemented by Raymond Hettinger; :issue:`4796`.)
903
Ezio Melotti021f3342010-04-06 03:26:49 +0000904 Most of the methods of the :class:`~decimal.Context` class now accept integers
905 as well as :class:`~decimal.Decimal` instances; the only exceptions are the
906 :meth:`~decimal.Context.canonical` and :meth:`~decimal.Context.is_canonical`
907 methods. (Patch by Juan José Conti; :issue:`7633`.)
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000908
Andrew M. Kuchling4515f0d2010-04-11 20:40:09 +0000909 The constructor for :class:`~decimal.Decimal` now accepts
910 floating-point numbers (added by Raymond Hettinger; :issue:`8257`)
911 and non-European Unicode characters such as Arabic-Indic digits
912 (contributed by Mark Dickinson; :issue:`6595`).
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000913
Ezio Melotti021f3342010-04-06 03:26:49 +0000914 When using :class:`~decimal.Decimal` instances with a string's
915 :meth:`~str.format` method, the default alignment was previously
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000916 left-alignment. This has been changed to right-alignment, which seems
917 more sensible for numeric types. (Changed by Mark Dickinson; :issue:`6857`.)
918
Andrew M. Kuchlingc121f132010-04-30 01:33:40 +0000919 Comparisons involving a signaling NaN value (or ``sNAN``) now signal
920 :const:`InvalidOperation` instead of silently returning a true or
921 false value depending on the comparison operator. Quiet NaN values
922 (or ``NaN``) are now hashable. (Fixed by Mark Dickinson;
923 :issue:`7279`.)
924
Andrew M. Kuchling363dbcc2010-04-14 23:55:17 +0000925* The :mod:`difflib` module now produces output that is more
Andrew M. Kuchling15c82d22010-04-29 00:22:16 +0000926 compatible with modern :command:`diff`/:command:`patch` tools
927 through one small change, using a tab character instead of spaces as
928 a separator in the header giving the filename. (Fixed by Anatoly
929 Techtonik; :issue:`7585`.)
930
931* The :mod:`doctest` module's :const:`IGNORE_EXCEPTION_DETAIL` flag
932 will now ignore the name of the module containing the exception
933 being tested. (Patch by Lennart Regebro; :issue:`7490`.)
Andrew M. Kuchling363dbcc2010-04-14 23:55:17 +0000934
Andrew M. Kuchling4515f0d2010-04-11 20:40:09 +0000935* The :class:`~fractions.Fraction` class now accepts a single float or
936 :class:`~decimal.Decimal` instance, or two rational numbers, as
937 arguments to its constructor. (Implemented by Mark Dickinson;
938 rationals added in :issue:`5812`, and float/decimal in
939 :issue:`8294`.)
Andrew M. Kuchling92b97002009-05-02 17:12:15 +0000940
Andrew M. Kuchlingec6393f2010-04-11 01:40:30 +0000941 An oversight was fixed, making the :class:`Fraction` match the other
942 numeric types; ordering comparisons (``<``, ``<=``, ``>``, ``>=``) between
943 fractions and complex numbers now raise a :exc:`TypeError`.
944
945 .. revision 79455
946
Ezio Melotti021f3342010-04-06 03:26:49 +0000947* New class: a new :class:`~ftplib.FTP_TLS` class in
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +0000948 the :mod:`ftplib` module provides secure FTP
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000949 connections using TLS encapsulation of authentication as well as
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +0000950 subsequent control and data transfers.
951 (Contributed by Giampaolo Rodola', :issue:`2054`.)
952
Ezio Melotti021f3342010-04-06 03:26:49 +0000953 The :meth:`~ftplib.FTP.storbinary` method for binary uploads can now restart
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +0000954 uploads thanks to an added *rest* parameter (patch by Pablo Mouzo;
955 :issue:`6845`.)
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +0000956
Andrew M. Kuchling6d7dfa22010-04-11 12:49:37 +0000957* New class decorator: :func:`total_ordering` in the :mod:`functools`
958 module takes a class that defines an :meth:`__eq__` method and one of
959 :meth:`__lt__`, :meth:`__le__`, :meth:`__gt__`, or :meth:`__ge__`,
960 and generates the missing comparison methods. Since the
961 :meth:`__cmp__` method is being deprecated in Python 3.x,
962 this decorator makes it easier to define ordered classes.
963 (Added by Raymond Hettinger; :issue:`5479`.)
964
965 New function: :func:`cmp_to_key` will take an old-style comparison
966 function that expects two arguments and return a new callable that
967 can be used as the *key* parameter to functions such as
968 :func:`sorted`, :func:`min` and :func:`max`, etc. The primary
969 intended use is to help with making code compatible with Python 3.x.
970 (Added by Raymond Hettinger.)
971
Ezio Melotti021f3342010-04-06 03:26:49 +0000972* New function: the :mod:`gc` module's :func:`~gc.is_tracked` returns
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000973 true if a given instance is tracked by the garbage collector, false
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000974 otherwise. (Contributed by Antoine Pitrou; :issue:`4688`.)
975
Ezio Melotti021f3342010-04-06 03:26:49 +0000976* The :mod:`gzip` module's :class:`~gzip.GzipFile` now supports the context
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +0000977 management protocol, so you can write ``with gzip.GzipFile(...) as f: ...``
978 (contributed by Hagen Fuerstenau; :issue:`3860`), and it now implements
979 the :class:`io.BufferedIOBase` ABC, so you can wrap it with
980 :class:`io.BufferedReader` for faster processing
981 (contributed by Nir Aides; :issue:`7471`).
982 It's also now possible to override the modification time
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000983 recorded in a gzipped file by providing an optional timestamp to
984 the constructor. (Contributed by Jacques Frechet; :issue:`4272`.)
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000985
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +0000986 Files in gzip format can be padded with trailing zero bytes; the
987 :mod:`gzip` module will now consume these trailing bytes. (Fixed by
988 Tadek Pietraszek and Brian Curtin; :issue:`2846`.)
989
Ezio Melotti021f3342010-04-06 03:26:49 +0000990* New attribute: the :mod:`hashlib` module now has an :attr:`~hashlib.hashlib.algorithms`
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +0000991 attribute containing a tuple naming the supported algorithms.
992 In Python 2.7, ``hashlib.algorithms`` contains
993 ``('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')``
994 (Contributed by Carl Chenet; :issue:`7418`.)
995
Ezio Melotti021f3342010-04-06 03:26:49 +0000996* The default :class:`~httplib.HTTPResponse` class used by the :mod:`httplib` module now
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +0000997 supports buffering, resulting in much faster reading of HTTP responses.
998 (Contributed by Kristjan Valur Jonsson; :issue:`4879`.)
999
Ezio Melotti021f3342010-04-06 03:26:49 +00001000 The :class:`~httplib.HTTPConnection` and :class:`~httplib.HTTPSConnection` classes
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001001 now support a *source_address* parameter, a ``(host, port)`` 2-tuple
1002 giving the source address that will be used for the connection.
1003 (Contributed by Eldon Ziegler; :issue:`3972`.)
1004
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001005* The :mod:`imaplib` module now supports IPv6 addresses.
1006 (Contributed by Derek Morr; :issue:`1655`.)
1007
Andrew M. Kuchlingce690522010-04-13 01:32:51 +00001008* New function: the :mod:`inspect` module's :func:`~inspect.getcallargs`
1009 takes a callable and its positional and keyword arguments,
1010 and figures out which of the callable's parameters will receive each argument,
1011 returning a dictionary mapping argument names to their values. For example::
1012
1013 >>> from inspect import getcallargs
1014 >>> def f(a, b=1, *pos, **named):
1015 ... pass
1016 >>> getcallargs(f, 1, 2, 3)
1017 {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)}
1018 >>> getcallargs(f, a=2, x=4)
1019 {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()}
1020 >>> getcallargs(f)
1021 Traceback (most recent call last):
1022 ...
1023 TypeError: f() takes at least 1 argument (0 given)
1024
1025 Contributed by George Sakkis; :issue:`3135`.
1026
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +00001027* Updated module: The :mod:`io` library has been upgraded to the version shipped with
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001028 Python 3.1. For 3.1, the I/O library was entirely rewritten in C
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +00001029 and is 2 to 20 times faster depending on the task being performed. The
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001030 original Python version was renamed to the :mod:`_pyio` module.
1031
1032 One minor resulting change: the :class:`io.TextIOBase` class now
1033 has an :attr:`errors` attribute giving the error setting
1034 used for encoding and decoding errors (one of ``'strict'``, ``'replace'``,
1035 ``'ignore'``).
1036
1037 The :class:`io.FileIO` class now raises an :exc:`OSError` when passed
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +00001038 an invalid file descriptor. (Implemented by Benjamin Peterson;
Ezio Melotti021f3342010-04-06 03:26:49 +00001039 :issue:`4991`.) The :meth:`~io.IOBase.truncate` method now preserves the
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001040 file position; previously it would change the file position to the
1041 end of the new file. (Fixed by Pascal Chambon; :issue:`6939`.)
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +00001042
Andrew M. Kuchling5a73ff82009-12-02 14:27:11 +00001043* New function: ``itertools.compress(data, selectors)`` takes two
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +00001044 iterators. Elements of *data* are returned if the corresponding
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001045 value in *selectors* is true::
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +00001046
1047 itertools.compress('ABCDEF', [1,0,1,0,1,1]) =>
1048 A, C, E, F
1049
Ezio Melotti021f3342010-04-06 03:26:49 +00001050 .. maybe here is better to use >>> list(itertools.compress(...)) instead
1051
Andrew M. Kuchling5a73ff82009-12-02 14:27:11 +00001052 New function: ``itertools.combinations_with_replacement(iter, r)``
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +00001053 returns all the possible *r*-length combinations of elements from the
Ezio Melotti021f3342010-04-06 03:26:49 +00001054 iterable *iter*. Unlike :func:`~itertools.combinations`, individual elements
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +00001055 can be repeated in the generated combinations::
1056
1057 itertools.combinations_with_replacement('abc', 2) =>
1058 ('a', 'a'), ('a', 'b'), ('a', 'c'),
1059 ('b', 'b'), ('b', 'c'), ('c', 'c')
1060
1061 Note that elements are treated as unique depending on their position
1062 in the input, not their actual values.
1063
Ezio Melotti021f3342010-04-06 03:26:49 +00001064 The :func:`itertools.count` function now has a *step* argument that
1065 allows incrementing by values other than 1. :func:`~itertools.count` also
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +00001066 now allows keyword arguments, and using non-integer values such as
Ezio Melotti021f3342010-04-06 03:26:49 +00001067 floats or :class:`~decimal.Decimal` instances. (Implemented by Raymond
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +00001068 Hettinger; :issue:`5032`.)
1069
Andrew M. Kuchling77069572009-03-31 01:21:01 +00001070 :func:`itertools.combinations` and :func:`itertools.product` were
1071 previously raising :exc:`ValueError` for values of *r* larger than
1072 the input iterable. This was deemed a specification error, so they
1073 now return an empty iterator. (Fixed by Raymond Hettinger; :issue:`4816`.)
1074
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +00001075* Updated module: The :mod:`json` module was upgraded to version 2.0.9 of the
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001076 simplejson package, which includes a C extension that makes
1077 encoding and decoding faster.
1078 (Contributed by Bob Ippolito; :issue:`4136`.)
1079
Ezio Melotti021f3342010-04-06 03:26:49 +00001080 To support the new :class:`collections.OrderedDict` type, :func:`json.load`
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001081 now has an optional *object_pairs_hook* parameter that will be called
1082 with any object literal that decodes to a list of pairs.
1083 (Contributed by Raymond Hettinger; :issue:`5381`.)
1084
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +00001085* New functions: the :mod:`math` module gained
Ezio Melotti021f3342010-04-06 03:26:49 +00001086 :func:`~math.erf` and :func:`~math.erfc` for the error function and the complementary error function,
1087 :func:`~math.expm1` which computes ``e**x - 1`` with more precision than
1088 using :func:`~math.exp` and subtracting 1,
1089 :func:`~math.gamma` for the Gamma function, and
1090 :func:`~math.lgamma` for the natural log of the Gamma function.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001091 (Contributed by Mark Dickinson and nirinA raseliarison; :issue:`3366`.)
1092
Andrew M. Kuchling24520b42009-04-09 11:22:47 +00001093* The :mod:`multiprocessing` module's :class:`Manager*` classes
1094 can now be passed a callable that will be called whenever
1095 a subprocess is started, along with a set of arguments that will be
1096 passed to the callable.
1097 (Contributed by lekma; :issue:`5585`.)
1098
Ezio Melotti021f3342010-04-06 03:26:49 +00001099 The :class:`~multiprocessing.Pool` class, which controls a pool of worker processes,
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001100 now has an optional *maxtasksperchild* parameter. Worker processes
1101 will perform the specified number of tasks and then exit, causing the
Ezio Melotti021f3342010-04-06 03:26:49 +00001102 :class:`~multiprocessing.Pool` to start a new worker. This is useful if tasks may leak
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001103 memory or other resources, or if some tasks will cause the worker to
1104 become very large.
1105 (Contributed by Charles Cazabon; :issue:`6963`.)
1106
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001107* The :mod:`nntplib` module now supports IPv6 addresses.
1108 (Contributed by Derek Morr; :issue:`1664`.)
1109
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +00001110* New functions: the :mod:`os` module wraps the following POSIX system
Ezio Melotti021f3342010-04-06 03:26:49 +00001111 calls: :func:`~os.getresgid` and :func:`~os.getresuid`, which return the
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +00001112 real, effective, and saved GIDs and UIDs;
Ezio Melotti021f3342010-04-06 03:26:49 +00001113 :func:`~os.setresgid` and :func:`~os.setresuid`, which set
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +00001114 real, effective, and saved GIDs and UIDs to new values;
Ezio Melotti021f3342010-04-06 03:26:49 +00001115 :func:`~os.initgroups`. (GID/UID functions
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +00001116 contributed by Travis H.; :issue:`6508`. Support for initgroups added
1117 by Jean-Paul Calderone; :issue:`7333`.)
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +00001118
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +00001119 The :func:`os.fork` function now re-initializes the import lock in
Ezio Melotti021f3342010-04-06 03:26:49 +00001120 the child process; this fixes problems on Solaris when :func:`~os.fork`
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +00001121 is called from a thread. (Fixed by Zsolt Cserna; :issue:`7242`.)
1122
Ezio Melotti021f3342010-04-06 03:26:49 +00001123* In the :mod:`os.path` module, the :func:`~os.path.normpath` and
1124 :func:`~os.path.abspath` functions now preserve Unicode; if their input path
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001125 is a Unicode string, the return value is also a Unicode string.
Ezio Melotti021f3342010-04-06 03:26:49 +00001126 (:meth:`~os.path.normpath` fixed by Matt Giuca in :issue:`5827`;
1127 :meth:`~os.path.abspath` fixed by Ezio Melotti in :issue:`3426`.)
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001128
Andrew M. Kuchling9cb42772009-01-21 02:15:43 +00001129* The :mod:`pydoc` module now has help for the various symbols that Python
1130 uses. You can now do ``help('<<')`` or ``help('@')``, for example.
1131 (Contributed by David Laban; :issue:`4739`.)
1132
Ezio Melotti021f3342010-04-06 03:26:49 +00001133* The :mod:`re` module's :func:`~re.split`, :func:`~re.sub`, and :func:`~re.subn`
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001134 now accept an optional *flags* argument, for consistency with the
1135 other functions in the module. (Added by Gregory P. Smith.)
1136
Ezio Melotti021f3342010-04-06 03:26:49 +00001137* New function: in the :mod:`shutil` module, :func:`~shutil.make_archive`
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +00001138 takes a filename, archive type (zip or tar-format), and a directory
1139 path, and creates an archive containing the directory's contents.
1140 (Added by Tarek Ziadé.)
1141
Ezio Melotti021f3342010-04-06 03:26:49 +00001142 :mod:`shutil`'s :func:`~shutil.copyfile` and :func:`~shutil.copytree`
1143 functions now raise a :exc:`~shutil.SpecialFileError` exception when
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001144 asked to copy a named pipe. Previously the code would treat
1145 named pipes like a regular file by opening them for reading, and
1146 this would block indefinitely. (Fixed by Antoine Pitrou; :issue:`3002`.)
1147
1148* New functions: in the :mod:`site` module, three new functions
1149 return various site- and user-specific paths.
Ezio Melotti021f3342010-04-06 03:26:49 +00001150 :func:`~site.getsitepackages` returns a list containing all
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001151 global site-packages directories, and
Ezio Melotti021f3342010-04-06 03:26:49 +00001152 :func:`~site.getusersitepackages` returns the path of the user's
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001153 site-packages directory.
Ezio Melotti021f3342010-04-06 03:26:49 +00001154 :func:`~site.getuserbase` returns the value of the :envvar:`USER_BASE`
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001155 environment variable, giving the path to a directory that can be used
1156 to store data.
Andrew M. Kuchling039c8992010-02-01 02:04:26 +00001157 (Contributed by Tarek Ziadé; :issue:`6693`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001158
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +00001159 The :mod:`site` module now reports exceptions occurring
1160 when the :mod:`sitecustomize` module is imported, and will no longer
Florent Xiclunaad598332010-03-31 21:40:32 +00001161 catch and swallow the :exc:`KeyboardInterrupt` exception. (Fixed by
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +00001162 Victor Stinner; :issue:`3137`.)
1163
Andrew M. Kuchlingc121f132010-04-30 01:33:40 +00001164* The :func:`~socket.create_connection` function
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +00001165 gained a *source_address* parameter, a ``(host, port)`` 2-tuple
1166 giving the source address that will be used for the connection.
1167 (Contributed by Eldon Ziegler; :issue:`3972`.)
Andrew M. Kuchlinga7f59472009-12-31 16:38:53 +00001168
Ezio Melotti021f3342010-04-06 03:26:49 +00001169 The :meth:`~socket.socket.recv_into` and :meth:`~socket.socket.recvfrom_into`
1170 methods will now write into objects that support the buffer API, most usefully
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +00001171 the :class:`bytearray` and :class:`memoryview` objects. (Implemented by
1172 Antoine Pitrou; :issue:`8104`.)
1173
Ezio Melotti021f3342010-04-06 03:26:49 +00001174* The :mod:`SocketServer` module's :class:`~SocketServer.TCPServer` class now
1175 has a :attr:`~SocketServer.TCPServer.disable_nagle_algorithm` class attribute.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001176 The default value is False; if overridden to be True,
1177 new request connections will have the TCP_NODELAY option set to
1178 prevent buffering many small sends into a single TCP packet.
1179 (Contributed by Kristjan Valur Jonsson; :issue:`6192`.)
1180
Ezio Melotti021f3342010-04-06 03:26:49 +00001181* Updated module: the :mod:`sqlite3` module has been updated to
Andrew M. Kuchlingfed15762010-03-08 12:00:39 +00001182 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
1183 the ability to load SQLite extensions from shared libraries.
1184 Call the ``enable_load_extension(True)`` method to enable extensions,
Ezio Melotti021f3342010-04-06 03:26:49 +00001185 and then call :meth:`~sqlite3.Connection.load_extension` to load a particular shared library.
Andrew M. Kuchlingfed15762010-03-08 12:00:39 +00001186 (Updated by Gerhard Häring.)
1187
Andrew M. Kuchlingc121f132010-04-30 01:33:40 +00001188* The :mod:`ssl` module's :class:`~ssl.SSL` objects now support the
1189 buffer API, which fixed a test suite failure (fix by Antoine Pitrou;
1190 :issue:`7133`) and automatically set
1191 OpenSSL's :cmacro:`SSL_MODE_AUTO_RETRY`, which will prevent an error
1192 code being returned from :meth:`recv` operations that trigger an SSL
1193 renegotiation (fix by Antoine Pitrou; :issue:`8222`).
1194
1195 The :func:`wrap_socket` constructor function now takes a
1196 *ciphers* argument that's a string listing the encryption algorithms
1197 to be allowed; the format of the string is described
1198 `in the OpenSSL documentation <http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT>`__. (Added by Antoine Pitrou; :issue:`8322`.)
1199
1200 Another change makes the extension load all of OpenSSL's ciphers and
1201 digest algorithms so that they're all available. Some SSL
1202 certificates couldn't be verified, reporting an 'unknown algorithm'
1203 error. (Reported by Beda Kosata, and fixed by Antoine Pitrou;
1204 :issue:`8484`.)
1205
1206 The version of OpenSSL being used is now available as the module
1207 attributes :attr:`OPENSSL_VERSION` (a string),
1208 :attr:`OPENSSL_VERSION_INFO` (a 5-tuple), and
1209 :attr:`OPENSSL_VERSION_NUMBER` (an integer). (Added by Antoine
1210 Pitrou; :issue:`8321`.)
1211
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001212* The :mod:`struct` module will no longer silently ignore overflow
1213 errors when a value is too large for a particular integer format
1214 code (one of ``bBhHiIlLqQ``); it now always raises a
1215 :exc:`struct.error` exception. (Changed by Mark Dickinson;
Andrew M. Kuchling4515f0d2010-04-11 20:40:09 +00001216 :issue:`1523`.) The :func:`~struct.pack` function will also
1217 attempt to use :meth:`__index__` to convert and pack non-integers
1218 before trying the :meth:`__int__` method or reporting an error.
1219 (Changed by Mark Dickinson; :issue:`8300`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001220
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001221* New function: the :mod:`subprocess` module's
Ezio Melotti021f3342010-04-06 03:26:49 +00001222 :func:`~subprocess.check_output` runs a command with a specified set of arguments
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +00001223 and returns the command's output as a string when the command runs without
Ezio Melotti021f3342010-04-06 03:26:49 +00001224 error, or raises a :exc:`~subprocess.CalledProcessError` exception otherwise.
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +00001225
1226 ::
1227
1228 >>> subprocess.check_output(['df', '-h', '.'])
1229 'Filesystem Size Used Avail Capacity Mounted on\n
1230 /dev/disk0s2 52G 49G 3.0G 94% /\n'
1231
1232 >>> subprocess.check_output(['df', '-h', '/bogus'])
1233 ...
1234 subprocess.CalledProcessError: Command '['df', '-h', '/bogus']' returned non-zero exit status 1
1235
1236 (Contributed by Gregory P. Smith.)
1237
Andrew M. Kuchlingf91a6792010-03-24 18:07:43 +00001238 The :mod:`subprocess` module will now retry its internal system calls
1239 on receiving an :const:`EINTR` signal. (Reported by several people; final
1240 patch by Gregory P. Smith in :issue:`1068268`.)
1241
Ezio Melotti021f3342010-04-06 03:26:49 +00001242* New function: :func:`~symtable.is_declared_global` in the :mod:`symtable` module
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001243 returns true for variables that are explicitly declared to be global,
1244 false for ones that are implicitly global.
1245 (Contributed by Jeremy Hylton.)
1246
Andrew M. Kuchling15c82d22010-04-29 00:22:16 +00001247* The :mod:`syslog` module will now use the value of ``sys.argv[0]`` as the
1248 identifier instead of the previous default value of ``'python'``.
1249 (Changed by Sean Reifschneider; :issue:`8451`.)
1250
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +00001251* The ``sys.version_info`` value is now a named tuple, with attributes
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001252 named :attr:`major`, :attr:`minor`, :attr:`micro`,
1253 :attr:`releaselevel`, and :attr:`serial`. (Contributed by Ross
1254 Light; :issue:`4285`.)
1255
1256 :func:`sys.getwindowsversion` also returns a named tuple,
Andrew M. Kuchling9e483ef2010-02-08 01:35:35 +00001257 with attributes named :attr:`major`, :attr:`minor`, :attr:`build`,
Ezio Melotti12477752010-02-08 22:22:41 +00001258 :attr:`platform`, :attr:`service_pack`, :attr:`service_pack_major`,
Eric Smithb3c54882010-02-03 14:17:50 +00001259 :attr:`service_pack_minor`, :attr:`suite_mask`, and
1260 :attr:`product_type`. (Contributed by Brian Curtin; :issue:`7766`.)
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +00001261
Andrew M. Kuchling039c8992010-02-01 02:04:26 +00001262* The :mod:`tarfile` module's default error handling has changed, to
1263 no longer suppress fatal errors. The default error level was previously 0,
1264 which meant that errors would only result in a message being written to the
1265 debug log, but because the debug log is not activated by default,
1266 these errors go unnoticed. The default error level is now 1,
1267 which raises an exception if there's an error.
1268 (Changed by Lars Gustäbel; :issue:`7357`.)
1269
Ezio Melotti021f3342010-04-06 03:26:49 +00001270 :mod:`tarfile` now supports filtering the :class:`~tarfile.TarInfo`
1271 objects being added to a tar file. When you call :meth:`~tarfile.TarFile.add`,
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001272 instance, you may supply an optional *filter* argument
1273 that's a callable. The *filter* callable will be passed the
Ezio Melotti021f3342010-04-06 03:26:49 +00001274 :class:`~tarfile.TarInfo` for every file being added, and can modify and return it.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001275 If the callable returns ``None``, the file will be excluded from the
1276 resulting archive. This is more powerful than the existing
1277 *exclude* argument, which has therefore been deprecated.
Andrew M. Kuchling039c8992010-02-01 02:04:26 +00001278 (Added by Lars Gustäbel; :issue:`6856`.)
Ezio Melotti021f3342010-04-06 03:26:49 +00001279 The :class:`~tarfile.TarFile` class also now supports the context manager protocol.
Andrew M. Kuchlingfed15762010-03-08 12:00:39 +00001280 (Added by Lars Gustäbel; :issue:`7232`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001281
Ezio Melotti021f3342010-04-06 03:26:49 +00001282* The :meth:`~threading.Event.wait` method of the :class:`threading.Event` class
1283 now returns the internal flag on exit. This means the method will usually
1284 return true because :meth:`~threading.Event.wait` is supposed to block until the
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001285 internal flag becomes true. The return value will only be false if
1286 a timeout was provided and the operation timed out.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001287 (Contributed by Tim Lesher; :issue:`1674032`.)
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001288
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +00001289* The Unicode database provided by the :mod:`unicodedata` module is
1290 now used internally to determine which characters are numeric,
1291 whitespace, or represent line breaks. The database also
1292 includes information from the :file:`Unihan.txt` data file (patch
1293 by Anders Chrigström and Amaury Forgeot d'Arc; :issue:`1571184`)
1294 and has been updated to version 5.2.0 (updated by
1295 Florent Xicluna; :issue:`8024`).
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001296
Andrew M. Kuchlingc121f132010-04-30 01:33:40 +00001297* The :mod:`urlparse` module now supports IPv6 literal addresses as defined by
1298 :rfc:`2732` (contributed by Senthil Kumaran; :issue:`2987`). ::
1299
1300 >>> urlparse.urlparse('http://[1080::8:800:200C:417A]/foo')
1301 ParseResult(scheme='http', netloc='[1080::8:800:200C:417A]',
1302 path='/foo', params='', query='', fragment='')
1303
Ezio Melotti021f3342010-04-06 03:26:49 +00001304* The :class:`~UserDict.UserDict` class is now a new-style class. (Changed by
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001305 Benjamin Peterson.)
1306
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001307* The ElementTree library, :mod:`xml.etree`, no longer escapes
1308 ampersands and angle brackets when outputting an XML processing
Ezio Melotti021f3342010-04-06 03:26:49 +00001309 instruction (which looks like ``<?xml-stylesheet href="#style1"?>``)
1310 or comment (which looks like ``<!-- comment -->``).
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001311 (Patch by Neil Muller; :issue:`2746`.)
1312
Ezio Melotti021f3342010-04-06 03:26:49 +00001313* The :mod:`zipfile` module's :class:`~zipfile.ZipFile` now supports the context
Andrew M. Kuchling039c8992010-02-01 02:04:26 +00001314 management protocol, so you can write ``with zipfile.ZipFile(...) as f: ...``.
1315 (Contributed by Brian Curtin; :issue:`5511`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001316
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +00001317 :mod:`zipfile` now supports archiving empty directories and
1318 extracts them correctly. (Fixed by Kuba Wieczorek; :issue:`4710`.)
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001319 Reading files out of an archive is now faster, and interleaving
Ezio Melotti021f3342010-04-06 03:26:49 +00001320 :meth:`~zipfile.ZipFile.read` and :meth:`~zipfile.ZipFile.readline` now works correctly.
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001321 (Contributed by Nir Aides; :issue:`7610`.)
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +00001322
Ezio Melotti021f3342010-04-06 03:26:49 +00001323 The :func:`~zipfile.is_zipfile` function now
Andrew M. Kuchling039c8992010-02-01 02:04:26 +00001324 accepts a file object, in addition to the path names accepted in earlier
1325 versions. (Contributed by Gabriel Genellina; :issue:`4756`.)
1326
Ezio Melotti021f3342010-04-06 03:26:49 +00001327 The :meth:`~zipfile.ZipFile.writestr` method now has an optional *compress_type* parameter
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001328 that lets you override the default compression method specified in the
Ezio Melotti021f3342010-04-06 03:26:49 +00001329 :class:`~zipfile.ZipFile` constructor. (Contributed by Ronald Oussoren;
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001330 :issue:`6003`.)
1331
1332
Andrew M. Kuchling0e7123f2010-02-08 13:22:24 +00001333New module: sysconfig
1334---------------------------------
1335
1336XXX A new :mod:`sysconfig` module has been extracted from
1337:mod:`distutils` and put in the standard library.
1338
1339The :mod:`sysconfig` module provides access to Python's configuration
1340information like the list of installation paths and the configuration
Tarek Ziadé1e069ee2010-02-23 05:20:22 +00001341variables relevant for the current platform. (contributed by Tarek)
Andrew M. Kuchling0e7123f2010-02-08 13:22:24 +00001342
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +00001343Updated module: ElementTree 1.3
1344---------------------------------
1345
1346XXX write this.
1347
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001348.. ======================================================================
1349.. whole new modules get described in subsections here
1350
Tarek Ziadé2b210692010-02-02 23:39:40 +00001351
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001352Unit Testing Enhancements
1353---------------------------------
1354
Andrew M. Kuchlingb2454b22010-04-29 01:45:41 +00001355The :mod:`unittest` module was greatly enhanced; many
1356new features were added. Most of these features were implemented
1357by Michael Foord, unless otherwise noted.
1358
Andrew M. Kuchlingc121f132010-04-30 01:33:40 +00001359When used from the command line, the module can automatically discover
1360tests. It's not as fancy as `py.test <http://pytest.org>`__ or
1361`nose <http://code.google.com/p/python-nose/>`__, but provides a simple way
1362to run tests kept within a set of package directories. For example,
1363the following command will search the :file:`test/` subdirectory for
1364any importable test files named ``test*.py``::
1365
1366 python -m unittest discover -s test
1367
1368Consult the :mod:`unittest` module documentation for more details.
1369(Developed in :issue:`6001`.)
1370
1371The :func:`main` function supports some other new options:
1372
1373* :option:`-b` or :option:`--buffer` will buffer the standard output
1374 and standard error streams during each test. If the test passes,
1375 any resulting output will be discard; on failure, the buffered
1376 output will be displayed.
1377
1378* :option:`-c` or :option:`--catch` will cause the control-C interrupt
1379 to be handled more gracefully. Instead of interrupting the test
1380 process immediately, the currently running test will be completed
1381 and then the resulting partial results will be reported. If you're
1382 impatient, a second press of control-C will cause an immediate
1383 interruption.
1384
1385 This control-C handler tries to avoid interfering when the code
1386 being tested or the tests being run have defined a signal handler of
1387 their own, by noticing that a signal handler was already set and
1388 calling it. If this doesn't work for you, there's a
1389 :func:`removeHandler` decorator that can be used to mark tests that
1390 should have the control-C handling disabled.
1391
1392* :option:`-f` or :option:`--failfast` makes
1393 test execution stop immediately when a test fails instead of
1394 continuing to execute further tests. (Suggested by Cliff Dyer and
1395 implemented by Michael Foord; :issue:`8074`.)
1396
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001397The progress messages now shows 'x' for expected failures
1398and 'u' for unexpected successes when run in verbose mode.
1399(Contributed by Benjamin Peterson.)
Andrew M. Kuchlingb2454b22010-04-29 01:45:41 +00001400
1401Test cases can raise the :exc:`~unittest.SkipTest` exception to skip a
1402test. (:issue:`1034053`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001403
Ezio Melotti021f3342010-04-06 03:26:49 +00001404The error messages for :meth:`~unittest.TestCase.assertEqual`,
1405:meth:`~unittest.TestCase.assertTrue`, and :meth:`~unittest.TestCase.assertFalse`
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001406failures now provide more information. If you set the
Ezio Melotti021f3342010-04-06 03:26:49 +00001407:attr:`~unittest.TestCase.longMessage` attribute of your :class:`~unittest.TestCase` classes to
1408True, both the standard error message and any additional message you
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001409provide will be printed for failures. (Added by Michael Foord; :issue:`5663`.)
1410
Ezio Melotti021f3342010-04-06 03:26:49 +00001411The :meth:`~unittest.TestCase.assertRaises` method now
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001412return a context handler when called without providing a callable
1413object to run. For example, you can write this::
1414
1415 with self.assertRaises(KeyError):
Ezio Melotti021f3342010-04-06 03:26:49 +00001416 {}['foo']
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001417
1418(Implemented by Antoine Pitrou; :issue:`4444`.)
1419
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +00001420.. rev 78774
1421
1422Module- and class-level setup and teardown fixtures are now supported.
Ezio Melotti021f3342010-04-06 03:26:49 +00001423Modules can contain :func:`~unittest.setUpModule` and :func:`~unittest.tearDownModule`
1424functions. Classes can have :meth:`~unittest.TestCase.setUpClass` and
1425:meth:`~unittest.TestCase.tearDownClass` methods that must be defined as class methods
1426(using ``@classmethod`` or equivalent). These functions and
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +00001427methods are invoked when the test runner switches to a test case in a
1428different module or class.
1429
Ezio Melotti021f3342010-04-06 03:26:49 +00001430The methods :meth:`~unittest.TestCase.addCleanup` and
1431:meth:`~unittest.TestCase.doCleanups` were added.
1432:meth:`~unittest.TestCase.addCleanup` allows you to add cleanup functions that
1433will be called unconditionally (after :meth:`~unittest.TestCase.setUp` if
1434:meth:`~unittest.TestCase.setUp` fails, otherwise after :meth:`~unittest.TestCase.tearDown`). This allows
Andrew M. Kuchling4a0661b2010-03-25 01:35:51 +00001435for much simpler resource allocation and deallocation during tests
1436(:issue:`5679`).
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001437
1438A number of new methods were added that provide more specialized
1439tests. Many of these methods were written by Google engineers
1440for use in their test suites; Gregory P. Smith, Michael Foord, and
1441GvR worked on merging them into Python's version of :mod:`unittest`.
1442
Ezio Melotti021f3342010-04-06 03:26:49 +00001443* :meth:`~unittest.TestCase.assertIsNone` and :meth:`~unittest.TestCase.assertIsNotNone` take one
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001444 expression and verify that the result is or is not ``None``.
1445
Ezio Melotti021f3342010-04-06 03:26:49 +00001446* :meth:`~unittest.TestCase.assertIs` and :meth:`~unittest.TestCase.assertIsNot`
1447 take two values and check whether the two values evaluate to the same object or not.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001448 (Added by Michael Foord; :issue:`2578`.)
1449
Ezio Melotti021f3342010-04-06 03:26:49 +00001450* :meth:`~unittest.TestCase.assertIsInstance` and
1451 :meth:`~unittest.TestCase.assertNotIsInstance` check whether
Andrew M. Kuchlinga7f59472009-12-31 16:38:53 +00001452 the resulting object is an instance of a particular class, or of
1453 one of a tuple of classes. (Added by Georg Brandl; :issue:`7031`.)
1454
Ezio Melotti021f3342010-04-06 03:26:49 +00001455* :meth:`~unittest.TestCase.assertGreater`, :meth:`~unittest.TestCase.assertGreaterEqual`,
1456 :meth:`~unittest.TestCase.assertLess`, and :meth:`~unittest.TestCase.assertLessEqual` compare
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001457 two quantities.
1458
Ezio Melotti021f3342010-04-06 03:26:49 +00001459* :meth:`~unittest.TestCase.assertMultiLineEqual` compares two strings, and if they're
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001460 not equal, displays a helpful comparison that highlights the
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001461 differences in the two strings. This comparison is now used by
Ezio Melotti021f3342010-04-06 03:26:49 +00001462 default when Unicode strings are compared with :meth:`~unittest.TestCase.assertEqual`.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001463
Andrew M. Kuchlingb2454b22010-04-29 01:45:41 +00001464* :meth:`~unittest.TestCase.assertRegexpMatches` and
1465 :meth:`~unittest.TestCase.assertNotRegexpMatches` checks whether the
1466 first argument is a string matching or not matching the regular
1467 expression provided as the second argument (:issue:`8038`).
Ezio Melotti021f3342010-04-06 03:26:49 +00001468
1469* :meth:`~unittest.TestCase.assertRaisesRegexp` checks whether a particular exception
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001470 is raised, and then also checks that the string representation of
1471 the exception matches the provided regular expression.
1472
Ezio Melotti021f3342010-04-06 03:26:49 +00001473* :meth:`~unittest.TestCase.assertIn` and :meth:`~unittest.TestCase.assertNotIn`
1474 tests whether *first* is or is not in *second*.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001475
Ezio Melotti021f3342010-04-06 03:26:49 +00001476* :meth:`~unittest.TestCase.assertItemsEqual` tests whether two provided sequences
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001477 contain the same elements.
1478
Ezio Melotti021f3342010-04-06 03:26:49 +00001479* :meth:`~unittest.TestCase.assertSetEqual` compares whether two sets are equal, and
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001480 only reports the differences between the sets in case of error.
1481
Ezio Melotti021f3342010-04-06 03:26:49 +00001482* Similarly, :meth:`~unittest.TestCase.assertListEqual` and :meth:`~unittest.TestCase.assertTupleEqual`
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001483 compare the specified types and explain any differences without necessarily
1484 printing their full values; these methods are now used by default
Ezio Melotti021f3342010-04-06 03:26:49 +00001485 when comparing lists and tuples using :meth:`~unittest.TestCase.assertEqual`.
1486 More generally, :meth:`~unittest.TestCase.assertSequenceEqual` compares two sequences
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001487 and can optionally check whether both sequences are of a
1488 particular type.
1489
Ezio Melotti021f3342010-04-06 03:26:49 +00001490* :meth:`~unittest.TestCase.assertDictEqual` compares two dictionaries and reports the
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001491 differences; it's now used by default when you compare two dictionaries
Ezio Melotti021f3342010-04-06 03:26:49 +00001492 using :meth:`~unittest.TestCase.assertEqual`. :meth:`~unittest.TestCase.assertDictContainsSubset` checks whether
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001493 all of the key/value pairs in *first* are found in *second*.
1494
Ezio Melotti021f3342010-04-06 03:26:49 +00001495* :meth:`~unittest.TestCase.assertAlmostEqual` and :meth:`~unittest.TestCase.assertNotAlmostEqual` test
Andrew M. Kuchlingb2454b22010-04-29 01:45:41 +00001496 whether *first* and *second* are approximately equal. This method
1497 can either round their difference to an optionally-specified number
1498 of *places* (the default is 7) and compare it to zero, or require
1499 the difference to be smaller than a supplied *delta* value.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001500
Ezio Melotti021f3342010-04-06 03:26:49 +00001501* :meth:`~unittest.TestLoader.loadTestsFromName` properly honors the
1502 :attr:`~unittest.TestLoader.suiteClass` attribute of
1503 the :class:`~unittest.TestLoader`. (Fixed by Mark Roddy; :issue:`6866`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001504
Ezio Melotti021f3342010-04-06 03:26:49 +00001505* A new hook lets you extend the :meth:`~unittest.TestCase.assertEqual` method to handle
1506 new data types. The :meth:`~unittest.TestCase.addTypeEqualityFunc` method takes a type
Andrew M. Kuchling9858f632010-03-23 18:39:24 +00001507 object and a function. The function will be used when both of the
1508 objects being compared are of the specified type. This function
1509 should compare the two objects and raise an exception if they don't
1510 match; it's a good idea for the function to provide additional
1511 information about why the two objects are matching, much as the new
1512 sequence comparison methods do.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001513
Andrew M. Kuchling9858f632010-03-23 18:39:24 +00001514:func:`unittest.main` now takes an optional ``exit`` argument. If
Ezio Melotti021f3342010-04-06 03:26:49 +00001515False, :func:`~unittest.main` doesn't call :func:`sys.exit`, allowing it to be
Andrew M. Kuchling9858f632010-03-23 18:39:24 +00001516used from the interactive interpreter. (Contributed by J. Pablo
1517Fernández; :issue:`3379`.)
1518
Ezio Melotti021f3342010-04-06 03:26:49 +00001519:class:`~unittest.TestResult` has new :meth:`~unittest.TestResult.startTestRun` and
1520:meth:`~unittest.TestResult.stopTestRun` methods that are called immediately before
Andrew M. Kuchling9858f632010-03-23 18:39:24 +00001521and after a test run. (Contributed by Robert Collins; :issue:`5728`.)
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001522
1523With all these changes, the :file:`unittest.py` was becoming awkwardly
1524large, so the module was turned into a package and the code split into
1525several files (by Benjamin Peterson). This doesn't affect how the
Andrew M. Kuchlingb2454b22010-04-29 01:45:41 +00001526module is imported or used.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001527
1528
1529.. _importlib-section:
1530
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001531importlib: Importing Modules
1532------------------------------
1533
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001534Python 3.1 includes the :mod:`importlib` package, a re-implementation
1535of the logic underlying Python's :keyword:`import` statement.
1536:mod:`importlib` is useful for implementors of Python interpreters and
Brett Cannonca2dc472009-12-22 02:37:37 +00001537to users who wish to write new importers that can participate in the
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001538import process. Python 2.7 doesn't contain the complete
1539:mod:`importlib` package, but instead has a tiny subset that contains
Ezio Melotti021f3342010-04-06 03:26:49 +00001540a single function, :func:`~importlib.import_module`.
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001541
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001542``import_module(name, package=None)`` imports a module. *name* is
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001543a string containing the module or package's name. It's possible to do
1544relative imports by providing a string that begins with a ``.``
1545character, such as ``..utils.errors``. For relative imports, the
1546*package* argument must be provided and is the name of the package that
1547will be used as the anchor for
Ezio Melotti021f3342010-04-06 03:26:49 +00001548the relative import. :func:`~importlib.import_module` both inserts the imported
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +00001549module into ``sys.modules`` and returns the module object.
1550
1551Here are some examples::
1552
1553 >>> from importlib import import_module
1554 >>> anydbm = import_module('anydbm') # Standard absolute import
1555 >>> anydbm
1556 <module 'anydbm' from '/p/python/Lib/anydbm.py'>
1557 >>> # Relative import
1558 >>> sysconfig = import_module('..sysconfig', 'distutils.command')
1559 >>> sysconfig
1560 <module 'distutils.sysconfig' from '/p/python/Lib/distutils/sysconfig.pyc'>
1561
1562:mod:`importlib` was implemented by Brett Cannon and introduced in
1563Python 3.1.
1564
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001565
Andrew M. Kuchlinga17cd4a2009-01-31 02:50:09 +00001566ttk: Themed Widgets for Tk
1567--------------------------
1568
1569Tcl/Tk 8.5 includes a set of themed widgets that re-implement basic Tk
1570widgets but have a more customizable appearance and can therefore more
1571closely resemble the native platform's widgets. This widget
1572set was originally called Tile, but was renamed to Ttk (for "themed Tk")
1573on being added to Tcl/Tck release 8.5.
1574
1575XXX write a brief discussion and an example here.
1576
1577The :mod:`ttk` module was written by Guilherme Polo and added in
1578:issue:`2983`. An alternate version called ``Tile.py``, written by
1579Martin Franklin and maintained by Kevin Walzer, was proposed for
1580inclusion in :issue:`2618`, but the authors argued that Guilherme
1581Polo's work was more comprehensive.
1582
Georg Brandl0516f812009-11-18 18:52:35 +00001583
1584Deprecations and Removals
1585=========================
1586
1587* :func:`contextlib.nested`, which allows handling more than one context manager
1588 with one :keyword:`with` statement, has been deprecated; :keyword:`with`
1589 supports multiple context managers syntactically now.
1590
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001591.. ======================================================================
1592
1593
1594Build and C API Changes
1595=======================
1596
1597Changes to Python's build process and to the C API include:
1598
Andrew M. Kuchling4515f0d2010-04-11 20:40:09 +00001599* The latest release of the GNU Debugger, GDB 7, can be `scripted
1600 using Python
1601 <http://sourceware.org/gdb/current/onlinedocs/gdb/Python.html>`__.
1602 When you begin debugging an executable program P, GDB will look for
1603 a file named ``P-gdb.py`` and automatically read it. Dave Malcolm
1604 contributed a :file:`python-gdb.py` that adds a number of useful
1605 commands when debugging Python itself. For example, there are
1606 ``py-up`` and ``py-down`` that go up or down one Python stack frame,
1607 which usually corresponds to several C stack frames. ``py-print``
1608 prints the value of a Python variable, and ``py-bt`` prints the
1609 Python stack trace. (Added as a result of :issue:`8032`.)
1610
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +00001611* If you use the :file:`.gdbinit` file provided with Python,
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001612 the "pyo" macro in the 2.7 version now works correctly when the thread being
1613 debugged doesn't hold the GIL; the macro now acquires it before printing.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +00001614 (Contributed by Victor Stinner; :issue:`3632`.)
1615
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +00001616* :cfunc:`Py_AddPendingCall` is now thread-safe, letting any
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +00001617 worker thread submit notifications to the main Python thread. This
1618 is particularly useful for asynchronous IO operations.
1619 (Contributed by Kristjan Valur Jonsson; :issue:`4293`.)
1620
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001621* New function: :cfunc:`PyCode_NewEmpty` creates an empty code object;
1622 only the filename, function name, and first line number are required.
1623 This is useful to extension modules that are attempting to
1624 construct a more useful traceback stack. Previously such
1625 extensions needed to call :cfunc:`PyCode_New`, which had many
1626 more arguments. (Added by Jeffrey Yasskin.)
1627
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +00001628* New function: :cfunc:`PyErr_NewExceptionWithDoc` creates a new
1629 exception class, just as the existing :cfunc:`PyErr_NewException` does,
1630 but takes an extra ``char *`` argument containing the docstring for the
1631 new exception class. (Added by the 'lekma' user on the Python bug tracker;
1632 :issue:`7033`.)
1633
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001634* New function: :cfunc:`PyFrame_GetLineNumber` takes a frame object
1635 and returns the line number that the frame is currently executing.
1636 Previously code would need to get the index of the bytecode
1637 instruction currently executing, and then look up the line number
1638 corresponding to that address. (Added by Jeffrey Yasskin.)
1639
Andrew M. Kuchling17ae2ba2010-02-03 02:19:14 +00001640* New functions: :cfunc:`PyLong_AsLongAndOverflow` and
1641 :cfunc:`PyLong_AsLongLongAndOverflow` approximates a Python long
1642 integer as a C :ctype:`long` or :ctype:`long long`.
1643 If the number is too large to fit into
1644 the output type, an *overflow* flag is set and returned to the caller.
1645 (Contributed by Case Van Horsen; :issue:`7528` and :issue:`7767`.)
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +00001646
Andrew M. Kuchlinga7f59472009-12-31 16:38:53 +00001647* New function: stemming from the rewrite of string-to-float conversion,
1648 a new :cfunc:`PyOS_string_to_double` function was added. The old
1649 :cfunc:`PyOS_ascii_strtod` and :cfunc:`PyOS_ascii_atof` functions
1650 are now deprecated.
1651
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001652* New macros: the Python header files now define the following macros:
1653 :cmacro:`Py_ISALNUM`,
1654 :cmacro:`Py_ISALPHA`,
1655 :cmacro:`Py_ISDIGIT`,
1656 :cmacro:`Py_ISLOWER`,
1657 :cmacro:`Py_ISSPACE`,
1658 :cmacro:`Py_ISUPPER`,
1659 :cmacro:`Py_ISXDIGIT`,
1660 and :cmacro:`Py_TOLOWER`, :cmacro:`Py_TOUPPER`.
1661 All of these functions are analogous to the C
1662 standard macros for classifying characters, but ignore the current
1663 locale setting, because in
1664 several places Python needs to analyze characters in a
1665 locale-independent way. (Added by Eric Smith;
1666 :issue:`5793`.)
1667
1668 .. XXX these macros don't seem to be described in the c-api docs.
1669
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +00001670* New format codes: the :cfunc:`PyFormat_FromString`,
1671 :cfunc:`PyFormat_FromStringV`, and :cfunc:`PyErr_Format` now
1672 accepts ``%lld`` and ``%llu`` format codes for displaying values of
1673 C's :ctype:`long long` types.
1674 (Contributed by Mark Dickinson; :issue:`7228`.)
1675
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001676* The complicated interaction between threads and process forking has
1677 been changed. Previously, the child process created by
1678 :func:`os.fork` might fail because the child is created with only a
1679 single thread running, the thread performing the :func:`os.fork`.
1680 If other threads were holding a lock, such as Python's import lock,
1681 when the fork was performed, the lock would still be marked as
1682 "held" in the new process. But in the child process nothing would
1683 ever release the lock, since the other threads weren't replicated,
1684 and the child process would no longer be able to perform imports.
1685
1686 Python 2.7 now acquires the import lock before performing an
1687 :func:`os.fork`, and will also clean up any locks created using the
1688 :mod:`threading` module. C extension modules that have internal
1689 locks, or that call :cfunc:`fork()` themselves, will not benefit
1690 from this clean-up.
1691
1692 (Fixed by Thomas Wouters; :issue:`1590864`.)
1693
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +00001694* The :cfunc:`Py_Finalize` function now calls the internal
1695 :func:`threading._shutdown` function; this prevents some exceptions from
1696 being raised when an interpreter shuts down.
1697 (Patch by Adam Olsen; :issue:`1722344`.)
1698
Andrew M. Kuchling15c82d22010-04-29 00:22:16 +00001699* When using the :ctype:`PyMemberDef` structure to define attributes
1700 of a type, Python will no longer let you try to delete or set a
1701 :const:`T_STRING_INPLACE` attribute.
1702
1703 .. rev 79644
1704
Andrew M. Kuchling92b97002009-05-02 17:12:15 +00001705* Global symbols defined by the :mod:`ctypes` module are now prefixed
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001706 with ``Py``, or with ``_ctypes``. (Implemented by Thomas
Andrew M. Kuchling92b97002009-05-02 17:12:15 +00001707 Heller; :issue:`3102`.)
1708
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +00001709* New configure option: the :option:`--with-system-expat` switch allows
1710 building the :mod:`pyexpat` module to use the system Expat library.
1711 (Contributed by Arfrever Frehtes Taifersar Arahesis; :issue:`7609`.)
1712
Andrew M. Kuchlingce690522010-04-13 01:32:51 +00001713* New configure option: compiling Python with the
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +00001714 :option:`--with-valgrind` option will now disable the pymalloc
Andrew M. Kuchlingce690522010-04-13 01:32:51 +00001715 allocator, which is difficult for the Valgrind memory-error detector
1716 to analyze correctly.
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +00001717 Valgrind will therefore be better at detecting memory leaks and
1718 overruns. (Contributed by James Henstridge; :issue:`2422`.)
1719
Andrew M. Kuchling7f8ebdb2010-01-03 01:15:21 +00001720* New configure option: you can now supply no arguments to
1721 :option:`--with-dbmliborder=` in order to build none of the various
1722 DBM modules. (Added by Arfrever Frehtes Taifersar Arahesis;
1723 :issue:`6491`.)
1724
Andrew M. Kuchling77069572009-03-31 01:21:01 +00001725* The :program:`configure` script now checks for floating-point rounding bugs
1726 on certain 32-bit Intel chips and defines a :cmacro:`X87_DOUBLE_ROUNDING`
1727 preprocessor definition. No code currently uses this definition,
1728 but it's available if anyone wishes to use it.
1729 (Added by Mark Dickinson; :issue:`2937`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001730
Andrew M. Kuchling4515f0d2010-04-11 20:40:09 +00001731 :program:`configure` also now sets a :envvar:`LDCXXSHARED` Makefile
1732 variable for supporting C++ linking. (Contributed by Arfrever
1733 Frehtes Taifersar Arahesis; :issue:`1222585`.)
1734
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001735* The build process now creates the necessary files for pkg-config
1736 support. (Contributed by Clinton Roy; :issue:`3585`.)
1737
1738* The build process now supports Subversion 1.7. (Contributed by
1739 Arfrever Frehtes Taifersar Arahesis; :issue:`6094`.)
1740
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +00001741
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001742.. ======================================================================
1743
1744Port-Specific Changes: Windows
1745-----------------------------------
1746
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +00001747* The :mod:`msvcrt` module now contains some constants from
1748 the :file:`crtassem.h` header file:
1749 :data:`CRT_ASSEMBLY_VERSION`,
1750 :data:`VC_ASSEMBLY_PUBLICKEYTOKEN`,
1751 and :data:`LIBRARIES_ASSEMBLY_NAME_PREFIX`.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +00001752 (Contributed by David Cournapeau; :issue:`4365`.)
1753
Andrew M. Kuchling15c82d22010-04-29 00:22:16 +00001754* The :mod:`_winreg` module for accessing the registry now implements
1755 the :func:`CreateKeyEx` and :func:`DeleteKeyEx` functions, extended
1756 versions of previously-supported functions that take several extra
1757 arguments. The :func:`DisableReflectionKey`,
1758 :func:`EnableReflectionKey`, and :func:`QueryReflectionKey` were also
1759 tested and documented.
1760 (Implemented by Brian Curtin: :issue:`7347`.)
1761
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +00001762* The new :cfunc:`_beginthreadex` API is used to start threads, and
1763 the native thread-local storage functions are now used.
1764 (Contributed by Kristjan Valur Jonsson; :issue:`3582`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001765
Andrew M. Kuchling363dbcc2010-04-14 23:55:17 +00001766* The :func:`os.kill` function now works on Windows. The signal value
1767 can be the constants :const:`CTRL_C_EVENT`,
1768 :const:`CTRL_BREAK_EVENT`, or any integer. The Control-C and
1769 Control-Break keystroke events can be sent to subprocesses; any
1770 other value will use the :cfunc:`TerminateProcess` API.
1771 (Contributed by Miki Tebeka; :issue:`1220212`.)
1772
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001773* The :func:`os.listdir` function now correctly fails
1774 for an empty path. (Fixed by Hirokazu Yamamoto; :issue:`5913`.)
1775
Andrew M. Kuchling3c8a24e2009-12-29 23:41:04 +00001776* The :mod:`mimelib` module will now read the MIME database from
1777 the Windows registry when initializing.
1778 (Patch by Gabriel Genellina; :issue:`4969`.)
1779
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001780.. ======================================================================
1781
1782Port-Specific Changes: Mac OS X
1783-----------------------------------
1784
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001785* The path ``/Library/Python/2.7/site-packages`` is now appended to
Andrew M. Kuchling77069572009-03-31 01:21:01 +00001786 ``sys.path``, in order to share added packages between the system
1787 installation and a user-installed copy of the same version.
1788 (Changed by Ronald Oussoren; :issue:`4865`.)
1789
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001790
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001791Other Changes and Fixes
1792=======================
1793
Andrew M. Kuchling0e7123f2010-02-08 13:22:24 +00001794* Two benchmark scripts, :file:`iobench` and :file:`ccbench`, were
1795 added to the :file:`Tools` directory. :file:`iobench` measures the
Antoine Pitroudde96e62010-02-08 20:25:47 +00001796 speed of built-in file I/O objects (as returned by :func:`open`)
Andrew M. Kuchling46c2db52010-03-21 18:47:12 +00001797 while performing various operations, and :file:`ccbench` is a
1798 concurrency benchmark that tries to measure computing throughput,
1799 thread switching latency, and IO processing bandwidth when
1800 performing several tasks using a varying number of threads.
Andrew M. Kuchling0e7123f2010-02-08 13:22:24 +00001801
Andrew M. Kuchling77069572009-03-31 01:21:01 +00001802* When importing a module from a :file:`.pyc` or :file:`.pyo` file
1803 with an existing :file:`.py` counterpart, the :attr:`co_filename`
Andrew M. Kuchling92b97002009-05-02 17:12:15 +00001804 attributes of the resulting code objects are overwritten when the
1805 original filename is obsolete. This can happen if the file has been
1806 renamed, moved, or is accessed through different paths. (Patch by
1807 Ziga Seilnacht and Jean-Paul Calderone; :issue:`1180193`.)
Andrew M. Kuchling77069572009-03-31 01:21:01 +00001808
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001809* The :file:`regrtest.py` script now takes a :option:`--randseed=`
1810 switch that takes an integer that will be used as the random seed
1811 for the :option:`-r` option that executes tests in random order.
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001812 The :option:`-r` option also reports the seed that was used
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001813 (Added by Collin Winter.)
1814
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +00001815* Another :file:`regrtest.py` switch is :option:`-j`, which
1816 takes an integer specifying how many tests run in parallel. This
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001817 allows reducing the total runtime on multi-core machines.
Antoine Pitrou4698d992009-05-31 14:20:14 +00001818 This option is compatible with several other options, including the
1819 :option:`-R` switch which is known to produce long runtimes.
Andrew M. Kuchling91e0db82009-12-31 16:17:05 +00001820 (Added by Antoine Pitrou, :issue:`6152`.) This can also be used
1821 with a new :option:`-F` switch that runs selected tests in a loop
1822 until they fail. (Added by Antoine Pitrou; :issue:`7312`.)
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00001823
Andrew M. Kuchling85f928a2010-04-15 01:42:27 +00001824* When executed as a script, the :file:`py_compile.py` module now
1825 accepts ``'-'`` as an argument, which will read standard input for
1826 the list of filenames to be compiled. (Contributed by Piotr
1827 Ożarowski; :issue:`8233`.)
1828
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001829.. ======================================================================
1830
1831Porting to Python 2.7
1832=====================
1833
1834This section lists previously described changes and other bugfixes
1835that may require changes to your code:
1836
Andrew M. Kuchling15c82d22010-04-29 00:22:16 +00001837* The string :meth:`format` method changed the default precision used
1838 for floating-point and complex numbers from 6 decimal
Andrew M. Kuchling5a9c40b2009-10-05 22:30:22 +00001839 places to 12, which matches the precision used by :func:`str`.
1840 (Changed by Eric Smith; :issue:`5920`.)
1841
Amaury Forgeot d'Arc901f2002009-06-09 23:08:13 +00001842* Because of an optimization for the :keyword:`with` statement, the special
1843 methods :meth:`__enter__` and :meth:`__exit__` must belong to the object's
1844 type, and cannot be directly attached to the object's instance. This
Amaury Forgeot d'Arcd81333c2009-06-10 20:30:19 +00001845 affects new-style classes (derived from :class:`object`) and C extension
Amaury Forgeot d'Arc901f2002009-06-09 23:08:13 +00001846 types. (:issue:`6101`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001847
Andrew M. Kuchlingb4a4f512009-12-29 20:10:16 +00001848* The :meth:`readline` method of :class:`StringIO` objects now does
1849 nothing when a negative length is requested, as other file-like
1850 objects do. (:issue:`7348`).
1851
Andrew M. Kuchling15c82d22010-04-29 00:22:16 +00001852
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001853In the standard library:
1854
Andrew M. Kuchling15c82d22010-04-29 00:22:16 +00001855* When using :class:`Decimal` instances with a string's
1856 :meth:`format` method, the default alignment was previously
1857 left-alignment. This has been changed to right-alignment, which might
1858 change the output of your programs.
1859 (Changed by Mark Dickinson; :issue:`6857`.)
1860
Andrew M. Kuchlingc121f132010-04-30 01:33:40 +00001861 Comparisons involving a signaling NaN value (or ``sNAN``) now signal
1862 :const:`InvalidOperation` instead of silently returning a true or
1863 false value depending on the comparison operator. Quiet NaN values
1864 (or ``NaN``) are now hashable. (Fixed by Mark Dickinson;
1865 :issue:`7279`.)
1866
Andrew M. Kuchlinge41e4db2010-02-18 14:16:48 +00001867* The ElementTree library, :mod:`xml.etree`, no longer escapes
1868 ampersands and angle brackets when outputting an XML processing
1869 instruction (which looks like `<?xml-stylesheet href="#style1"?>`)
1870 or comment (which looks like `<!-- comment -->`).
1871 (Patch by Neil Muller; :issue:`2746`.)
1872
Andrew M. Kuchling15c82d22010-04-29 00:22:16 +00001873* The :mod:`syslog` module will now use the value of ``sys.argv[0]`` as the
1874 identifier instead of the previous default value of ``'python'``.
1875 (Changed by Sean Reifschneider; :issue:`8451`.)
1876
Andrew M. Kuchlinga7f59472009-12-31 16:38:53 +00001877For C extensions:
1878
Andrew M. Kuchling7f8ebdb2010-01-03 01:15:21 +00001879* C extensions that use integer format codes with the ``PyArg_Parse*``
1880 family of functions will now raise a :exc:`TypeError` exception
1881 instead of triggering a :exc:`DeprecationWarning` (:issue:`5080`).
1882
Andrew M. Kuchlinga7f59472009-12-31 16:38:53 +00001883* Use the new :cfunc:`PyOS_string_to_double` function instead of the old
1884 :cfunc:`PyOS_ascii_strtod` and :cfunc:`PyOS_ascii_atof` functions,
1885 which are now deprecated.
1886
Andrew M. Kuchling7f8ebdb2010-01-03 01:15:21 +00001887
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001888.. ======================================================================
1889
1890
1891.. _acks27:
1892
1893Acknowledgements
1894================
1895
1896The author would like to thank the following people for offering
1897suggestions, corrections and assistance with various drafts of this
Andrew M. Kuchlingc121f132010-04-30 01:33:40 +00001898article: Nick Coghlan, Ryan Lovett, R. David Murray, Hugh Secker-Walker.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001899