blob: 3b98cc292112fca221f9954cea754df086491ffa [file] [log] [blame]
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +00001****************************
2 What's New in Python 2.7
3****************************
4
5:Author: A.M. Kuchling (amk at amk.ca)
6:Release: |release|
7:Date: |today|
8
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +00009.. Fix accents on Kristjan Valur Jonsson, Fuerstenau, Tarek Ziade.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +000010
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000011.. $Id$
12 Rules for maintenance:
13
14 * Anyone can add text to this document. Do not spend very much time
15 on the wording of your changes, because your text will probably
16 get rewritten to some degree.
17
18 * The maintainer will go through Misc/NEWS periodically and add
19 changes; it's therefore more important to add your changes to
20 Misc/NEWS than to this file.
21
22 * This is not a complete list of every single change; completeness
23 is the purpose of Misc/NEWS. Some changes I consider too small
24 or esoteric to include. If such a change is added to the text,
25 I'll just remove it. (This is another reason you shouldn't spend
26 too much time on writing your addition.)
27
28 * If you want to draw your new text to the attention of the
29 maintainer, add 'XXX' to the beginning of the paragraph or
30 section.
31
32 * It's OK to just add a fragmentary note about a change. For
33 example: "XXX Describe the transmogrify() function added to the
34 socket module." The maintainer will research the change and
35 write the necessary text.
36
37 * You can comment out your additions if you like, but it's not
38 necessary (especially when a final release is some months away).
39
40 * Credit the author of a patch or bugfix. Just the name is
41 sufficient; the e-mail address isn't necessary.
42
43 * It's helpful to add the bug/patch number in a parenthetical comment.
44
45 XXX Describe the transmogrify() function added to the socket
46 module.
47 (Contributed by P.Y. Developer; :issue:`12345`.)
48
49 This saves the maintainer some effort going through the SVN logs
50 when researching a change.
51
52This article explains the new features in Python 2.7.
53No release schedule has been decided yet for 2.7.
54
55.. Compare with previous release in 2 - 3 sentences here.
56 add hyperlink when the documentation becomes available online.
57
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000058Python 3.1
59================
60
61Much as Python 2.6 incorporated features from Python 3.0,
62version 2.7 is influenced by features from 3.1.
63
64XXX mention importlib; anything else?
65
66One porting change: the :option:`-3` switch now automatically
67enables the :option:`-Qwarn` switch that causes warnings
68about using classic division with integers and long integers.
69
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000070.. ========================================================================
71.. Large, PEP-level features and changes should be described here.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000072.. ========================================================================
73
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +000074PEP 372: Adding an ordered dictionary to collections
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000075====================================================
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +000076
77XXX write this
78
79Several modules will now use :class:`OrderedDict` by default. The
80:mod:`ConfigParser` module uses :class:`OrderedDict` for the list
81of sections and the options within a section.
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +000082The :meth:`namedtuple._asdict` method returns an :class:`OrderedDict`
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +000083as well.
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +000084
85
86Other Language Changes
87======================
88
89Some smaller changes made to the core Python language are:
90
Benjamin Petersonaa0a0b92009-04-11 20:27:15 +000091* :meth:`str.format` method now supports automatic numbering of the replacement
92 fields. This makes using :meth:`str.format` more closely resemble using
93 ``%s`` formatting::
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +000094
95 >>> '{}:{}:{}'.format(2009, 04, 'Sunday')
96 '2009:4:Sunday'
97 >>> '{}:{}:{day}'.format(2009, 4, day='Sunday')
98 '2009:4:Sunday'
99
Benjamin Petersonaa0a0b92009-04-11 20:27:15 +0000100 The auto-numbering takes the fields from left to right, so the first ``{...}``
101 specifier will use the first argument to :meth:`str.format`, the next
102 specifier will use the next argument, and so on. You can't mix auto-numbering
103 and explicit numbering -- either number all of your specifier fields or none
104 of them -- but you can mix auto-numbering and named fields, as in the second
105 example above. (Contributed by XXX; :issue`5237`.)
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000106
Mark Dickinson1a707982008-12-17 16:14:37 +0000107* The :func:`int` and :func:`long` types gained a ``bit_length``
Georg Brandl64e1c752009-04-11 18:19:27 +0000108 method that returns the number of bits necessary to represent
Mark Dickinson1a707982008-12-17 16:14:37 +0000109 its argument in binary::
110
111 >>> n = 37
112 >>> bin(37)
113 '0b100101'
114 >>> n.bit_length()
115 6
116 >>> n = 2**123-1
117 >>> n.bit_length()
118 123
119 >>> (n+1).bit_length()
120 124
121
122 (Contributed by Fredrik Johansson and Victor Stinner; :issue:`3439`.)
123
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000124* The :class:`bytearray` type's :meth:`translate` method will
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000125 now accept ``None`` as its first argument. (Fixed by Georg Brandl;
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000126 :issue:`4759`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000127
128.. ======================================================================
129
130
131Optimizations
132-------------
133
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000134Several performance enhancements have been added:
135
136.. * A new :program:`configure` option, :option:`--with-computed-gotos`,
137 compiles the main bytecode interpreter loop using a new dispatch
138 mechanism that gives speedups of up to 20%, depending on the system
139 and benchmark. The new mechanism is only supported on certain
140 compilers, such as gcc, SunPro, and icc.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000141
142* The garbage collector now performs better when many objects are
143 being allocated without deallocating any. A full garbage collection
144 pass is only performed when the middle generation has been collected
145 10 times and when the number of survivor objects from the middle
146 generation exceeds 10% of the number of objects in the oldest
147 generation. The second condition was added to reduce the number
148 of full garbage collections as the number of objects on the heap grows,
149 avoiding quadratic performance when allocating very many objects.
150 (Suggested by Martin von Loewis and implemented by Antoine Pitrou;
151 :issue:`4074`.)
152
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000153* The garbage collector tries to avoid tracking simple containers
154 which can't be part of a cycle. In Python 2.7, this is now true for
155 tuples and dicts containing atomic types (such as ints, strings,
156 etc.). Transitively, a dict containing tuples of atomic types won't
157 be tracked either. This helps reduce the cost of each
158 garbage collection by decreasing the number of objects to be
159 considered and traversed by the collector.
Antoine Pitrouc18f6b02009-03-28 19:10:13 +0000160 (Contributed by Antoine Pitrou; :issue:`4688`.)
161
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000162* Integers are now stored internally either in base 2**15 or in base
163 2**30, the base being determined at build time. Previously, they
164 were always stored in base 2**15. Using base 2**30 gives
165 significant performance improvements on 64-bit machines, but
166 benchmark results on 32-bit machines have been mixed. Therefore,
167 the default is to use base 2**30 on 64-bit machines and base 2**15
168 on 32-bit machines; on Unix, there's a new configure option
169 :option:`--enable-big-digits` that can be used to override this default.
170
171 Apart from the performance improvements this change should be
172 invisible to end users, with one exception: for testing and
173 debugging purposes there's a new structseq ``sys.long_info`` that
174 provides information about the internal format, giving the number of
175 bits per digit and the size in bytes of the C type used to store
176 each digit::
177
178 >>> import sys
179 >>> sys.long_info
180 sys.long_info(bits_per_digit=30, sizeof_digit=4)
181
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000182 (Contributed by Mark Dickinson; :issue:`4258`.)
183
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000184 Another set of changes made long objects a few bytes smaller: 2 bytes
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000185 smaller on 32-bit systems and 6 bytes on 64-bit.
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000186 (Contributed by Mark Dickinson; :issue:`5260`.)
187
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000188* The division algorithm for long integers has been made faster
189 by tightening the inner loop, doing shifts instead of multiplications,
190 and fixing an unnecessary extra iteration.
191 Various benchmarks show speedups of between 50% and 150% for long
192 integer divisions and modulo operations.
193 (Contributed by Mark Dickinson; :issue:`5512`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000194
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000195* The implementation of ``%`` checks for the left-side operand being
196 a Python string and special-cases it; this results in a 1-3%
197 performance increase for applications that frequently use ``%``
198 with strings, such as templating libraries.
199 (Implemented by Collin Winter; :issue:`5176`.)
200
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000201* List comprehensions with an ``if`` condition are compiled into
202 faster bytecode. (Patch by Antoine Pitrou, back-ported to 2.7
203 by Jeffrey Yasskin; :issue:`4715`.)
204
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000205.. ======================================================================
206
207New, Improved, and Deprecated Modules
208=====================================
209
210As in every release, Python's standard library received a number of
211enhancements and bug fixes. Here's a partial list of the most notable
212changes, sorted alphabetically by module name. Consult the
213:file:`Misc/NEWS` file in the source tree for a more complete list of
214changes, or look through the Subversion logs for all the details.
215
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000216* The :mod:`bz2` module's :class:`BZ2File` now supports the context
217 management protocol, so you can write ``with bz2.BZ2File(...) as f: ...``.
218 (Contributed by Hagen Fuerstenau; :issue:`3860`.)
219
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000220* New class: the :class:`Counter` class in the :mod:`collections` module is
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000221 useful for tallying data. :class:`Counter` instances behave mostly
222 like dictionaries but return zero for missing keys instead of
223 raising a :exc:`KeyError`::
224
225 >>> from collections import Counter
226 >>> c=Counter()
227 >>> for letter in 'here is a sample of english text':
228 ... c[letter] += 1
229 ...
230 >>> c
231 Counter({' ': 6, 'e': 5, 's': 3, 'a': 2, 'i': 2, 'h': 2,
232 'l': 2, 't': 2, 'g': 1, 'f': 1, 'm': 1, 'o': 1, 'n': 1,
233 'p': 1, 'r': 1, 'x': 1})
234 >>> c['e']
235 5
236 >>> c['z']
237 0
238
239 There are two additional :class:`Counter` methods: :meth:`most_common`
240 returns the N most common elements and their counts, and :meth:`elements`
241 returns an iterator over the contained element, repeating each element
242 as many times as its count::
243
244 >>> c.most_common(5)
245 [(' ', 6), ('e', 5), ('s', 3), ('a', 2), ('i', 2)]
246 >>> c.elements() ->
247 'a', 'a', ' ', ' ', ' ', ' ', ' ', ' ',
248 'e', 'e', 'e', 'e', 'e', 'g', 'f', 'i', 'i',
249 'h', 'h', 'm', 'l', 'l', 'o', 'n', 'p', 's',
250 's', 's', 'r', 't', 't', 'x']
251
252 Contributed by Raymond Hettinger; :issue:`1696199`.
253
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000254 The :class:`namedtuple` class now has an optional *rename* parameter.
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000255 If *rename* is true, field names that are invalid because they've
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000256 been repeated or that aren't legal Python identifiers will be
257 renamed to legal names that are derived from the field's
258 position within the list of fields:
259
260 >>> T=namedtuple('T', ['field1', '$illegal', 'for', 'field2'], rename=True)
261 >>> T._fields
262 ('field1', '_1', '_2', 'field2')
263
264 (Added by Raymond Hettinger; :issue:`1818`.)
265
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000266 The :class:`deque` data type now exposes its maximum length as the
267 read-only :attr:`maxlen` attribute. (Added by Raymond Hettinger.)
268
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000269* In Distutils, :func:`distutils.sdist.add_defaults` now uses
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000270 *package_dir* and *data_files* to create the MANIFEST file.
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000271 :mod:`distutils.sysconfig` will now read the :envvar:`AR`
272 environment variable.
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000273
274 It is no longer mandatory to store clear-text passwords in the
275 :file:`.pypirc` file when registering and uploading packages to PyPI. As long
276 as the username is present in that file, the :mod:`distutils` package will
277 prompt for the password if not present. (Added by Tarek Ziade,
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000278 based on an initial contribution by Nathan Van Gheem; :issue:`4394`.)
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000279
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000280 A Distutils setup can now specify that a C extension is optional by
281 setting the *optional* option setting to true. If this optional is
282 supplied, failure to build the extension will not abort the build
283 process, but instead simply not install the failing extension.
Georg Brandl64e1c752009-04-11 18:19:27 +0000284 (Contributed by Georg Brandl; :issue:`5583`.)
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000285
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000286* New method: the :class:`Decimal` class gained a
287 :meth:`from_float` class method that performs an exact conversion
288 of a floating-point number to a :class:`Decimal`.
289 Note that this is an **exact** conversion that strives for the
290 closest decimal approximation to the floating-point representation's value;
291 the resulting decimal value will therefore still include the inaccuracy,
292 if any.
293 For example, ``Decimal.from_float(0.1)`` returns
294 ``Decimal('0.1000000000000000055511151231257827021181583404541015625')``.
295 (Implemented by Raymond Hettinger; :issue:`4796`.)
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000296
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000297* New function: the :mod:`gc` module's :func:`is_tracked` returns
298 true if a given instance is tracked by the garbage collector, false
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000299 otherwise. (Contributed by Antoine Pitrou; :issue:`4688`.)
300
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000301* The :mod:`gzip` module's :class:`GzipFile` now supports the context
302 management protocol, so you can write ``with gzip.GzipFile(...) as f: ...``.
303 (Contributed by Hagen Fuerstenau; :issue:`3860`.)
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000304 It's now possible to override the modification time
305 recorded in a gzipped file by providing an optional timestamp to
306 the constructor. (Contributed by Jacques Frechet; :issue:`4272`.)
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000307
308* The :class:`io.FileIO` class now raises an :exc:`OSError` when passed
309 an invalid file descriptor. (Implemented by Benjamin Peterson;
310 :issue:`4991`.)
311
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000312* New function: ``itertools.compress(*data*, *selectors*)`` takes two
313 iterators. Elements of *data* are returned if the corresponding
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000314 value in *selectors* is true::
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000315
316 itertools.compress('ABCDEF', [1,0,1,0,1,1]) =>
317 A, C, E, F
318
319 New function: ``itertools.combinations_with_replacement(*iter*, *r*)``
320 returns all the possible *r*-length combinations of elements from the
321 iterable *iter*. Unlike :func:`combinations`, individual elements
322 can be repeated in the generated combinations::
323
324 itertools.combinations_with_replacement('abc', 2) =>
325 ('a', 'a'), ('a', 'b'), ('a', 'c'),
326 ('b', 'b'), ('b', 'c'), ('c', 'c')
327
328 Note that elements are treated as unique depending on their position
329 in the input, not their actual values.
330
331 The :class:`itertools.count` function now has a *step* argument that
332 allows incrementing by values other than 1. :func:`count` also
333 now allows keyword arguments, and using non-integer values such as
334 floats or :class:`Decimal` instances. (Implemented by Raymond
335 Hettinger; :issue:`5032`.)
336
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000337 :func:`itertools.combinations` and :func:`itertools.product` were
338 previously raising :exc:`ValueError` for values of *r* larger than
339 the input iterable. This was deemed a specification error, so they
340 now return an empty iterator. (Fixed by Raymond Hettinger; :issue:`4816`.)
341
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000342* The :mod:`json` module was upgraded to version 2.0.9 of the
343 simplejson package, which includes a C extension that makes
344 encoding and decoding faster.
345 (Contributed by Bob Ippolito; :issue:`4136`.)
346
347 To support the new :class:`OrderedDict` type, :func:`json.load`
348 now has an optional *object_pairs_hook* parameter that will be called
349 with any object literal that decodes to a list of pairs.
350 (Contributed by Raymond Hettinger; :issue:`5381`.)
351
Andrew M. Kuchling24520b42009-04-09 11:22:47 +0000352* The :mod:`multiprocessing` module's :class:`Manager*` classes
353 can now be passed a callable that will be called whenever
354 a subprocess is started, along with a set of arguments that will be
355 passed to the callable.
356 (Contributed by lekma; :issue:`5585`.)
357
Andrew M. Kuchling9cb42772009-01-21 02:15:43 +0000358* The :mod:`pydoc` module now has help for the various symbols that Python
359 uses. You can now do ``help('<<')`` or ``help('@')``, for example.
360 (Contributed by David Laban; :issue:`4739`.)
361
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000362* The :mod:`re` module's :func:`split`, :func:`sub`, and :func:`subn`
363 now accept an optional *flags* argument, for consistency with the
364 other functions in the module. (Added by Gregory P. Smith.)
365
366* New function: the :mod:`subprocess` module's
367 :func:`check_output` runs a command with a specified set of arguments
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000368 and returns the command's output as a string when the command runs without
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +0000369 error, or raises a :exc:`CalledProcessError` exception otherwise.
370
371 ::
372
373 >>> subprocess.check_output(['df', '-h', '.'])
374 'Filesystem Size Used Avail Capacity Mounted on\n
375 /dev/disk0s2 52G 49G 3.0G 94% /\n'
376
377 >>> subprocess.check_output(['df', '-h', '/bogus'])
378 ...
379 subprocess.CalledProcessError: Command '['df', '-h', '/bogus']' returned non-zero exit status 1
380
381 (Contributed by Gregory P. Smith.)
382
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000383* New function: :func:`is_declared_global` in the :mod:`symtable` module
384 returns true for variables that are explicitly declared to be global,
385 false for ones that are implicitly global.
386 (Contributed by Jeremy Hylton.)
387
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000388* The ``sys.version_info`` value is now a named tuple, with attributes
389 named ``major``, ``minor``, ``micro``, ``releaselevel``, and ``serial``.
390 (Contributed by Ross Light; :issue:`4285`.)
391
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000392* The :mod:`threading` module's :meth:`Event.wait` method now returns
393 the internal flag on exit. This means the method will usually
394 return true because :meth:`wait` is supposed to block until the
395 internal flag becomes true. The return value will only be false if
396 a timeout was provided and the operation timed out.
397 (Contributed by XXX; :issue:`1674032`.)
398
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000399* The :mod:`unittest` module was enhanced in several ways.
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000400 The progress messages will now show 'x' for expected failures
401 and 'u' for unexpected successes when run in verbose mode.
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000402 (Contributed by Benjamin Peterson.)
Andrew M. Kuchling24520b42009-04-09 11:22:47 +0000403 Test cases can raise the :exc:`SkipTest` exception to skip a test.
404 (:issue:`1034053`.)
405
406 The error messages for :meth:`assertEqual`,
407 :meth:`assertTrue`, and :meth:`assertFalse`
408 failures now provide more information. If you set the
409 :attr:`longMessage` attribute of your :class:`TestCase` classes to
410 true, both the standard error message and any additional message you
411 provide will be printed for failures. (Added by Michael Foord; :issue:`5663`.)
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000412
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000413 The :meth:`assertRaises` and :meth:`failUnlessRaises` methods now
414 return a context handler when called without providing a callable
415 object to run. For example, you can write this::
416
Andrew M. Kuchling24520b42009-04-09 11:22:47 +0000417 with self.assertRaises(KeyError):
418 raise ValueError
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000419
420 (Implemented by Antoine Pitrou; :issue:`4444`.)
421
Andrew M. Kuchling24520b42009-04-09 11:22:47 +0000422 A number of new methods were added that provide more specialized
423 tests. Many of these methods were written by Google engineers
424 for use in their test suites; Gregory P. Smith, Michael Foord, and
425 GvR worked on merging them into Python's version of :mod:`unittest`.
426
427 * :meth:`assertIsNone` and :meth:`assertIsNotNone` take one
428 expression and verify that the result is or is not ``None``.
429
430 * :meth:`assertIs` and :meth:`assertIsNot` take two values and check
431 whether the two values evaluate to the same object or not.
432 (Added by Michael Foord; :issue:`2578`.)
433
434 * :meth:`assertGreater`, :meth:`assertGreaterEqual`,
435 :meth:`assertLess`, and :meth:`assertLessEqual` compare
436 two quantities.
437
438 * :meth:`assertMultiLineEqual` compares two strings, and if they're
439 not equal, displays a helpful comparison that highlights the
440 differences in the two strings.
441
442 * :meth:`assertRegexpMatches` checks whether its first argument is a
443 string matching a regular expression provided as its second argument.
444
445 * :meth:`assertRaisesRegexp` checks whether a particular exception
446 is raised, and then also checks that the string representation of
447 the exception matches the provided regular expression.
448
449 * :meth:`assertIn` and :meth:`assertNotIn` tests whether
450 *first* is or is not in *second*.
451
452 * :meth:`assertSameElements` tests whether two provided sequences
453 contain the same elements.
454
455 * :meth:`assertSetEqual` compares whether two sets are equal, and
456 only reports the differences between the sets in case of error.
457
458 * Similarly, :meth:`assertListEqual` and :meth:`assertTupleEqual`
459 compare the specified types and explain the differences.
460 More generally, :meth:`assertSequenceEqual` compares two sequences
461 and can optionally check whether both sequences are of a
462 particular type.
463
464 * :meth:`assertDictEqual` compares two dictionaries and reports the
465 differences. :meth:`assertDictContainsSubset` checks whether
466 all of the key/value pairs in *first* are found in *second*.
467
468 * A new hook, :meth:`addTypeEqualityFunc` takes a type object and a
469 function. The :meth:`assertEqual` method will use the function
470 when both of the objects being compared are of the specified type.
471 This function should compare the two objects and raise an
472 exception if they don't match; it's a good idea for the function
473 to provide additional information about why the two objects are
474 matching, much as the new sequence comparison methods do.
475
Andrew M. Kuchling9cb42772009-01-21 02:15:43 +0000476* The :func:`is_zipfile` function in the :mod:`zipfile` module will now
477 accept a file object, in addition to the path names accepted in earlier
478 versions. (Contributed by Gabriel Genellina; :issue:`4756`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000479
Andrew M. Kuchling6c2633e2009-03-30 23:09:46 +0000480 :mod:`zipfile` now supports archiving empty directories and
481 extracts them correctly. (Fixed by Kuba Wieczorek; :issue:`4710`.)
482
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000483.. ======================================================================
484.. whole new modules get described in subsections here
485
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000486importlib: Importing Modules
487------------------------------
488
Andrew M. Kuchling2c130b62009-04-11 16:12:23 +0000489Python 3.1 includes the :mod:`importlib` package, a re-implementation
490of the logic underlying Python's :keyword:`import` statement.
491:mod:`importlib` is useful for implementors of Python interpreters and
492to user who wish to write new importers that can participate in the
493import process. Python 2.7 doesn't contain the complete
494:mod:`importlib` package, but instead has a tiny subset that contains
495a single function, :func:`import_module`.
496
497``import_module(*name*, *package*=None)`` imports a module. *name* is
498a string containing the module or package's name. It's possible to do
499relative imports by providing a string that begins with a ``.``
500character, such as ``..utils.errors``. For relative imports, the
501*package* argument must be provided and is the name of the package that
502will be used as the anchor for
503the relative import. :func:`import_module` both inserts the imported
504module into ``sys.modules`` and returns the module object.
505
506Here are some examples::
507
508 >>> from importlib import import_module
509 >>> anydbm = import_module('anydbm') # Standard absolute import
510 >>> anydbm
511 <module 'anydbm' from '/p/python/Lib/anydbm.py'>
512 >>> # Relative import
513 >>> sysconfig = import_module('..sysconfig', 'distutils.command')
514 >>> sysconfig
515 <module 'distutils.sysconfig' from '/p/python/Lib/distutils/sysconfig.pyc'>
516
517:mod:`importlib` was implemented by Brett Cannon and introduced in
518Python 3.1.
519
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000520
Andrew M. Kuchlinga17cd4a2009-01-31 02:50:09 +0000521ttk: Themed Widgets for Tk
522--------------------------
523
524Tcl/Tk 8.5 includes a set of themed widgets that re-implement basic Tk
525widgets but have a more customizable appearance and can therefore more
526closely resemble the native platform's widgets. This widget
527set was originally called Tile, but was renamed to Ttk (for "themed Tk")
528on being added to Tcl/Tck release 8.5.
529
530XXX write a brief discussion and an example here.
531
532The :mod:`ttk` module was written by Guilherme Polo and added in
533:issue:`2983`. An alternate version called ``Tile.py``, written by
534Martin Franklin and maintained by Kevin Walzer, was proposed for
535inclusion in :issue:`2618`, but the authors argued that Guilherme
536Polo's work was more comprehensive.
537
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000538.. ======================================================================
539
540
541Build and C API Changes
542=======================
543
544Changes to Python's build process and to the C API include:
545
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +0000546* If you use the :file:`.gdbinit` file provided with Python,
547 the "pyo" macro in the 2.7 version will now work when the thread being
548 debugged doesn't hold the GIL; the macro will now acquire it before printing.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000549 (Contributed by Victor Stinner; :issue:`3632`.)
550
Andrew M. Kuchling9a4b94c2009-04-03 21:43:00 +0000551* :cfunc:`Py_AddPendingCall` is now thread-safe, letting any
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000552 worker thread submit notifications to the main Python thread. This
553 is particularly useful for asynchronous IO operations.
554 (Contributed by Kristjan Valur Jonsson; :issue:`4293`.)
555
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000556* The :program:`configure` script now checks for floating-point rounding bugs
557 on certain 32-bit Intel chips and defines a :cmacro:`X87_DOUBLE_ROUNDING`
558 preprocessor definition. No code currently uses this definition,
559 but it's available if anyone wishes to use it.
560 (Added by Mark Dickinson; :issue:`2937`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000561
562.. ======================================================================
563
564Port-Specific Changes: Windows
565-----------------------------------
566
Andrew M. Kuchling10b1ec92009-01-02 21:00:35 +0000567* The :mod:`msvcrt` module now contains some constants from
568 the :file:`crtassem.h` header file:
569 :data:`CRT_ASSEMBLY_VERSION`,
570 :data:`VC_ASSEMBLY_PUBLICKEYTOKEN`,
571 and :data:`LIBRARIES_ASSEMBLY_NAME_PREFIX`.
Andrew M. Kuchling466bd9d2009-01-24 03:28:18 +0000572 (Contributed by David Cournapeau; :issue:`4365`.)
573
574* The new :cfunc:`_beginthreadex` API is used to start threads, and
575 the native thread-local storage functions are now used.
576 (Contributed by Kristjan Valur Jonsson; :issue:`3582`.)
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000577
578.. ======================================================================
579
580Port-Specific Changes: Mac OS X
581-----------------------------------
582
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000583* The ``/Library/Python/2.7/site-packages`` is now appended to
584 ``sys.path``, in order to share added packages between the system
585 installation and a user-installed copy of the same version.
586 (Changed by Ronald Oussoren; :issue:`4865`.)
587
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000588
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000589Other Changes and Fixes
590=======================
591
Andrew M. Kuchling77069572009-03-31 01:21:01 +0000592* When importing a module from a :file:`.pyc` or :file:`.pyo` file
593 with an existing :file:`.py` counterpart, the :attr:`co_filename`
594 attributes of all code objects if the original filename is obsolete,
595 which can happen if the file has been renamed, moved, or is accessed
596 through different paths. (Patch by Ziga Seilnacht and Jean-Paul
597 Calderone; :issue:`1180193`.)
598
Andrew M. Kuchling71d5c282009-03-30 22:30:20 +0000599* The :file:`regrtest.py` script now takes a :option:`--randseed=`
600 switch that takes an integer that will be used as the random seed
601 for the :option:`-r` option that executes tests in random order.
602 The :option:`-r` option also now reports the seed that was used
603 (Added by Collin Winter.)
604
605
Andrew M. Kuchlingce1882b2008-10-04 16:52:31 +0000606.. ======================================================================
607
608Porting to Python 2.7
609=====================
610
611This section lists previously described changes and other bugfixes
612that may require changes to your code:
613
614To be written.
615
616.. ======================================================================
617
618
619.. _acks27:
620
621Acknowledgements
622================
623
624The author would like to thank the following people for offering
625suggestions, corrections and assistance with various drafts of this
626article: no one yet.
627