Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1 | **************************** |
| 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 | |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 9 | .. Fix accents on Kristjan Valur Jonsson, Fuerstenau |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 10 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 11 | .. Big jobs: argparse, ElementTree 1.3, pep 391, 3106, sysconfig |
| 12 | .. unittest test discovery |
| 13 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 14 | .. $Id$ |
| 15 | Rules for maintenance: |
| 16 | |
| 17 | * Anyone can add text to this document. Do not spend very much time |
| 18 | on the wording of your changes, because your text will probably |
| 19 | get rewritten to some degree. |
| 20 | |
| 21 | * The maintainer will go through Misc/NEWS periodically and add |
| 22 | changes; it's therefore more important to add your changes to |
| 23 | Misc/NEWS than to this file. |
| 24 | |
| 25 | * This is not a complete list of every single change; completeness |
| 26 | is the purpose of Misc/NEWS. Some changes I consider too small |
| 27 | or esoteric to include. If such a change is added to the text, |
| 28 | I'll just remove it. (This is another reason you shouldn't spend |
| 29 | too much time on writing your addition.) |
| 30 | |
| 31 | * If you want to draw your new text to the attention of the |
| 32 | maintainer, add 'XXX' to the beginning of the paragraph or |
| 33 | section. |
| 34 | |
| 35 | * It's OK to just add a fragmentary note about a change. For |
| 36 | example: "XXX Describe the transmogrify() function added to the |
| 37 | socket module." The maintainer will research the change and |
| 38 | write the necessary text. |
| 39 | |
| 40 | * You can comment out your additions if you like, but it's not |
| 41 | necessary (especially when a final release is some months away). |
| 42 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 43 | * Credit the author of a patch or bugfix. Just the name is |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 44 | sufficient; the e-mail address isn't necessary. |
| 45 | |
| 46 | * It's helpful to add the bug/patch number in a parenthetical comment. |
| 47 | |
| 48 | XXX Describe the transmogrify() function added to the socket |
| 49 | module. |
| 50 | (Contributed by P.Y. Developer; :issue:`12345`.) |
| 51 | |
| 52 | This saves the maintainer some effort going through the SVN logs |
| 53 | when researching a change. |
| 54 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 55 | This article explains the new features in Python 2.7. The final |
| 56 | release of 2.7 is currently scheduled for June 2010; the detailed |
| 57 | schedule is described in :pep:`373`. |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 58 | |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 59 | Python 2.7 is planned to be the last major release in the 2.x series. |
| 60 | Though more major releases have not been absolutely ruled out, it's |
| 61 | likely that the 2.7 release will have an extended period of |
| 62 | maintenance compared to earlier 2.x versions. |
| 63 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 64 | .. Compare with previous release in 2 - 3 sentences here. |
| 65 | add hyperlink when the documentation becomes available online. |
| 66 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 67 | .. _whatsnew27-python31: |
| 68 | |
| 69 | Python 3.1 Features |
| 70 | ======================= |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 71 | |
| 72 | Much as Python 2.6 incorporated features from Python 3.0, |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 73 | version 2.7 incorporates some of the new features |
| 74 | in Python 3.1. The 2.x series continues to provide tools |
| 75 | for migrating to the 3.x series. |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 76 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 77 | A partial list of 3.1 features that were backported to 2.7: |
| 78 | |
| 79 | * A version of the :mod:`io` library, rewritten in C for performance. |
| 80 | * The ordered-dictionary type described in :ref:`pep-0372`. |
Benjamin Peterson | 97dd987 | 2009-12-13 01:23:39 +0000 | [diff] [blame] | 81 | * The new format specifier described in :ref:`pep-0378`. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 82 | * The :class:`memoryview` object. |
| 83 | * A small subset of the :mod:`importlib` module `described below <#importlib-section>`__. |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 84 | * Float-to-string and string-to-float conversions now round their |
| 85 | results more correctly. And :func:`repr` of a floating-point |
| 86 | number *x* returns a result that's guaranteed to round back to the |
| 87 | same number when converted back to a string. |
| 88 | * The :cfunc:`PyLong_AsLongAndOverflow` C API function. |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 89 | |
| 90 | One porting change: the :option:`-3` switch now automatically |
| 91 | enables the :option:`-Qwarn` switch that causes warnings |
| 92 | about using classic division with integers and long integers. |
| 93 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 94 | Other new Python3-mode warnings include: |
| 95 | |
| 96 | * :func:`operator.isCallable` and :func:`operator.sequenceIncludes`, |
| 97 | which are not supported in 3.x. |
| 98 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 99 | .. ======================================================================== |
| 100 | .. Large, PEP-level features and changes should be described here. |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 101 | .. ======================================================================== |
| 102 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 103 | .. _pep-0372: |
| 104 | |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 105 | PEP 372: Adding an ordered dictionary to collections |
| 106 | ==================================================== |
| 107 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 108 | Regular Python dictionaries iterate over key/value pairs in arbitrary order. |
| 109 | Over the years, a number of authors have written alternative implementations |
| 110 | that remember the order that the keys were originally inserted. Based on |
| 111 | the experiences from those implementations, a new |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 112 | :class:`~collections.OrderedDict` class has been introduced in the |
| 113 | :mod:`collections` module. |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 114 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 115 | The :class:`~collections.OrderedDict` API is substantially the same as regular |
| 116 | dictionaries but will iterate over keys and values in a guaranteed order |
| 117 | depending on when a key was first inserted:: |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 118 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 119 | >>> from collections import OrderedDict |
| 120 | >>> d = OrderedDict([('first', 1), ('second', 2), |
| 121 | ... ('third', 3)]) |
| 122 | >>> d.items() |
| 123 | [('first', 1), ('second', 2), ('third', 3)] |
| 124 | |
| 125 | If a new entry overwrites an existing entry, the original insertion |
| 126 | position is left unchanged:: |
| 127 | |
| 128 | >>> d['second'] = 4 |
| 129 | >>> d.items() |
| 130 | [('first', 1), ('second', 4), ('third', 3)] |
| 131 | |
| 132 | Deleting an entry and reinserting it will move it to the end:: |
| 133 | |
| 134 | >>> del d['second'] |
| 135 | >>> d['second'] = 5 |
| 136 | >>> d.items() |
| 137 | [('first', 1), ('third', 3), ('second', 5)] |
| 138 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 139 | The :meth:`~collections.OrderedDict.popitem` method has an optional *last* |
| 140 | argument that defaults to True. If *last* is True, the most recently |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 141 | added key is returned and removed; if it's False, the |
| 142 | oldest key is selected:: |
| 143 | |
| 144 | >>> od = OrderedDict([(x,0) for x in range(20)]) |
| 145 | >>> od.popitem() |
| 146 | (19, 0) |
| 147 | >>> od.popitem() |
| 148 | (18, 0) |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 149 | >>> od.popitem(last=False) |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 150 | (0, 0) |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 151 | >>> od.popitem(last=False) |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 152 | (1, 0) |
| 153 | |
| 154 | Comparing two ordered dictionaries checks both the keys and values, |
| 155 | and requires that the insertion order was the same:: |
| 156 | |
| 157 | >>> od1 = OrderedDict([('first', 1), ('second', 2), |
| 158 | ... ('third', 3)]) |
| 159 | >>> od2 = OrderedDict([('third', 3), ('first', 1), |
| 160 | ... ('second', 2)]) |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 161 | >>> od1 == od2 |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 162 | False |
| 163 | >>> # Move 'third' key to the end |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 164 | >>> del od2['third']; od2['third'] = 3 |
| 165 | >>> od1 == od2 |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 166 | True |
| 167 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 168 | Comparing an :class:`~collections.OrderedDict` with a regular dictionary |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 169 | ignores the insertion order and just compares the keys and values. |
| 170 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 171 | How does the :class:`~collections.OrderedDict` work? It maintains a |
| 172 | doubly-linked list of keys, appending new keys to the list as they're inserted. |
| 173 | A secondary dictionary maps keys to their corresponding list node, so |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 174 | deletion doesn't have to traverse the entire linked list and therefore |
| 175 | remains O(1). |
| 176 | |
| 177 | .. XXX check O(1)-ness with Raymond |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 178 | .. Also check if the 'somenamedtuple' in the collection module should |
| 179 | .. be replaced/removed in order to use |
| 180 | .. :meth:`~collections.namedtuple._asdict()` (see below) |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 181 | |
| 182 | The standard library now supports use of ordered dictionaries in several |
| 183 | modules. The :mod:`configparser` module uses them by default. This lets |
| 184 | configuration files be read, modified, and then written back in their original |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 185 | order. The :meth:`~collections.somenamedtuple._asdict()` method for |
| 186 | :func:`collections.namedtuple` now returns an ordered dictionary with the |
| 187 | values appearing in the same order as the underlying tuple indices. |
| 188 | The :mod:`json` module is being built-out with an *object_pairs_hook* to allow |
| 189 | OrderedDicts to be built by the decoder. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 190 | Support was also added for third-party tools like `PyYAML <http://pyyaml.org/>`_. |
| 191 | |
| 192 | .. seealso:: |
| 193 | |
| 194 | :pep:`372` - Adding an ordered dictionary to collections |
| 195 | PEP written by Armin Ronacher and Raymond Hettinger; |
| 196 | implemented by Raymond Hettinger. |
| 197 | |
| 198 | .. _pep-0378: |
| 199 | |
| 200 | PEP 378: Format Specifier for Thousands Separator |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 201 | ================================================= |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 202 | |
| 203 | To make program output more readable, it can be useful to add |
| 204 | separators to large numbers and render them as |
| 205 | 18,446,744,073,709,551,616 instead of 18446744073709551616. |
| 206 | |
| 207 | The fully general solution for doing this is the :mod:`locale` module, |
| 208 | which can use different separators ("," in North America, "." in |
| 209 | Europe) and different grouping sizes, but :mod:`locale` is complicated |
| 210 | to use and unsuitable for multi-threaded applications where different |
| 211 | threads are producing output for different locales. |
| 212 | |
| 213 | Therefore, a simple comma-grouping mechanism has been added to the |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 214 | mini-language used by the :meth:`str.format` method. When |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 215 | formatting a floating-point number, simply include a comma between the |
| 216 | width and the precision:: |
| 217 | |
Eric Smith | 2b1a116 | 2010-04-06 14:57:57 +0000 | [diff] [blame] | 218 | >>> '{:20,.2f}'.format(18446744073709551616.0) |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 219 | '18,446,744,073,709,551,616.00' |
| 220 | |
Eric Smith | 21e85c7 | 2010-04-06 15:21:59 +0000 | [diff] [blame] | 221 | When formatting an integer, include the comma after the width: |
| 222 | |
| 223 | >>> '{:20,d}'.format(18446744073709551616) |
| 224 | '18,446,744,073,709,551,616' |
| 225 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 226 | This mechanism is not adaptable at all; commas are always used as the |
| 227 | separator and the grouping is always into three-digit groups. The |
| 228 | comma-formatting mechanism isn't as general as the :mod:`locale` |
| 229 | module, but it's easier to use. |
| 230 | |
| 231 | .. XXX "Format String Syntax" in string.rst could use many more examples. |
| 232 | |
| 233 | .. seealso:: |
| 234 | |
| 235 | :pep:`378` - Format Specifier for Thousands Separator |
| 236 | PEP written by Raymond Hettinger; implemented by Eric Smith. |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 237 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 238 | PEP 389: The argparse Module for Parsing Command Lines |
| 239 | ====================================================== |
| 240 | |
| 241 | XXX write this section. |
| 242 | |
| 243 | .. seealso:: |
| 244 | |
| 245 | :pep:`389` - argparse - New Command Line Parsing Module |
| 246 | PEP written and implemented by Steven Bethard. |
| 247 | |
| 248 | PEP 391: Dictionary-Based Configuration For Logging |
| 249 | ==================================================== |
| 250 | |
| 251 | XXX write this section. |
| 252 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 253 | Two smaller enhancements to the logging module are: |
| 254 | |
| 255 | .. rev79293 |
| 256 | |
| 257 | * :class:`Logger` instances gained a :meth:`getChild` that retrieves a |
| 258 | descendant logger using a relative path. For example, |
| 259 | once you retrieve a logger by doing ``log = getLogger('app')``, |
| 260 | calling ``log.getChild('network.listen')`` is equivalent to |
| 261 | ``getLogger('app.network.listen')``. |
| 262 | |
| 263 | * The :class:`LoggerAdapter` class gained a :meth:`isEnabledFor` method |
| 264 | that takes a *level* and returns whether the underlying logger would |
| 265 | process a message of that level of importance. |
| 266 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 267 | .. seealso:: |
| 268 | |
| 269 | :pep:`391` - Dictionary-Based Configuration For Logging |
| 270 | PEP written and implemented by Vinay Sajip. |
| 271 | |
| 272 | PEP 3106: Dictionary Views |
| 273 | ==================================================== |
| 274 | |
| 275 | XXX write this section. |
| 276 | |
| 277 | .. seealso:: |
| 278 | |
| 279 | :pep:`3106` - Revamping dict.keys(), .values() and .items() |
| 280 | PEP written by Guido van Rossum. |
| 281 | Backported to 2.7 by Alexandre Vassalotti; :issue:`1967`. |
| 282 | |
| 283 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 284 | Other Language Changes |
| 285 | ====================== |
| 286 | |
| 287 | Some smaller changes made to the core Python language are: |
| 288 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 289 | * The syntax for set literals has been backported from Python 3.x. |
| 290 | Curly brackets are used to surround the contents of the resulting |
| 291 | mutable set; set literals are |
| 292 | distinguished from dictionaries by not containing colons and values. |
| 293 | ``{}`` continues to represent an empty dictionary; use |
| 294 | ``set()`` for an empty set. |
| 295 | |
| 296 | >>> {1,2,3,4,5} |
| 297 | set([1, 2, 3, 4, 5]) |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 298 | >>> set() # empty set |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 299 | set([]) |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 300 | >>> {} # empty dict |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 301 | {} |
| 302 | |
| 303 | Backported by Alexandre Vassalotti; :issue:`2335`. |
| 304 | |
| 305 | * Dictionary and set comprehensions are another feature backported from |
| 306 | 3.x, generalizing list/generator comprehensions to use |
| 307 | the literal syntax for sets and dictionaries. |
| 308 | |
| 309 | >>> {x:x*x for x in range(6)} |
| 310 | {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25} |
| 311 | >>> {'a'*x for x in range(6)} |
| 312 | set(['', 'a', 'aa', 'aaa', 'aaaa', 'aaaaa']) |
| 313 | |
| 314 | Backported by Alexandre Vassalotti; :issue:`2333`. |
| 315 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 316 | * The :keyword:`with` statement can now use multiple context managers |
| 317 | in one statement. Context managers are processed from left to right |
| 318 | and each one is treated as beginning a new :keyword:`with` statement. |
| 319 | This means that:: |
| 320 | |
| 321 | with A() as a, B() as b: |
| 322 | ... suite of statements ... |
| 323 | |
| 324 | is equivalent to:: |
| 325 | |
| 326 | with A() as a: |
| 327 | with B() as b: |
| 328 | ... suite of statements ... |
| 329 | |
| 330 | The :func:`contextlib.nested` function provides a very similar |
| 331 | function, so it's no longer necessary and has been deprecated. |
| 332 | |
| 333 | (Proposed in http://codereview.appspot.com/53094; implemented by |
| 334 | Georg Brandl.) |
| 335 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 336 | * Conversions between floating-point numbers and strings are |
| 337 | now correctly rounded on most platforms. These conversions occur |
| 338 | in many different places: :func:`str` on |
| 339 | floats and complex numbers; the :class:`float` and :class:`complex` |
| 340 | constructors; |
| 341 | numeric formatting; serialization and |
| 342 | deserialization of floats and complex numbers using the |
| 343 | :mod:`marshal`, :mod:`pickle` |
| 344 | and :mod:`json` modules; |
| 345 | parsing of float and imaginary literals in Python code; |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 346 | and :class:`~decimal.Decimal`-to-float conversion. |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 347 | |
| 348 | Related to this, the :func:`repr` of a floating-point number *x* |
| 349 | now returns a result based on the shortest decimal string that's |
| 350 | guaranteed to round back to *x* under correct rounding (with |
| 351 | round-half-to-even rounding mode). Previously it gave a string |
| 352 | based on rounding x to 17 decimal digits. |
| 353 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 354 | .. maybe add an example? |
| 355 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 356 | The rounding library responsible for this improvement works on |
| 357 | Windows, and on Unix platforms using the gcc, icc, or suncc |
| 358 | compilers. There may be a small number of platforms where correct |
| 359 | operation of this code cannot be guaranteed, so the code is not |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 360 | used on such systems. You can find out which code is being used |
| 361 | by checking :data:`sys.float_repr_style`, which will be ``short`` |
| 362 | if the new code is in use and ``legacy`` if it isn't. |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 363 | |
Mark Dickinson | 0bc8f90 | 2010-01-07 09:31:48 +0000 | [diff] [blame] | 364 | Implemented by Eric Smith and Mark Dickinson, using David Gay's |
| 365 | :file:`dtoa.c` library; :issue:`7117`. |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 366 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 367 | * The :meth:`str.format` method now supports automatic numbering of the replacement |
Benjamin Peterson | 3f96a87 | 2009-04-11 20:58:12 +0000 | [diff] [blame] | 368 | fields. This makes using :meth:`str.format` more closely resemble using |
| 369 | ``%s`` formatting:: |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 370 | |
| 371 | >>> '{}:{}:{}'.format(2009, 04, 'Sunday') |
| 372 | '2009:4:Sunday' |
| 373 | >>> '{}:{}:{day}'.format(2009, 4, day='Sunday') |
| 374 | '2009:4:Sunday' |
| 375 | |
Benjamin Peterson | 3f96a87 | 2009-04-11 20:58:12 +0000 | [diff] [blame] | 376 | The auto-numbering takes the fields from left to right, so the first ``{...}`` |
| 377 | specifier will use the first argument to :meth:`str.format`, the next |
| 378 | specifier will use the next argument, and so on. You can't mix auto-numbering |
| 379 | and explicit numbering -- either number all of your specifier fields or none |
| 380 | of them -- but you can mix auto-numbering and named fields, as in the second |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 381 | example above. (Contributed by Eric Smith; :issue:`5237`.) |
| 382 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 383 | Complex numbers now correctly support usage with :func:`format`, |
| 384 | and default to being right-aligned. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 385 | Specifying a precision or comma-separation applies to both the real |
| 386 | and imaginary parts of the number, but a specified field width and |
| 387 | alignment is applied to the whole of the resulting ``1.5+3j`` |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 388 | output. (Contributed by Eric Smith; :issue:`1588` and :issue:`7988`.) |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 389 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 390 | The 'F' format code now always formats its output using uppercase characters, |
| 391 | so it will now produce 'INF' and 'NAN'. |
| 392 | (Contributed by Eric Smith; :issue:`3382`.) |
| 393 | |
Mark Dickinson | 54bc1ec | 2008-12-17 16:19:07 +0000 | [diff] [blame] | 394 | * The :func:`int` and :func:`long` types gained a ``bit_length`` |
| 395 | method that returns the number of bits necessary to represent |
| 396 | its argument in binary:: |
| 397 | |
| 398 | >>> n = 37 |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 399 | >>> bin(n) |
Mark Dickinson | 54bc1ec | 2008-12-17 16:19:07 +0000 | [diff] [blame] | 400 | '0b100101' |
| 401 | >>> n.bit_length() |
| 402 | 6 |
| 403 | >>> n = 2**123-1 |
| 404 | >>> n.bit_length() |
| 405 | 123 |
| 406 | >>> (n+1).bit_length() |
| 407 | 124 |
| 408 | |
| 409 | (Contributed by Fredrik Johansson and Victor Stinner; :issue:`3439`.) |
| 410 | |
Benjamin Peterson | 25c95f1 | 2009-05-08 20:42:26 +0000 | [diff] [blame] | 411 | * Conversions from long integers and regular integers to floating |
| 412 | point now round differently, returning the floating-point number |
| 413 | closest to the number. This doesn't matter for small integers that |
| 414 | can be converted exactly, but for large numbers that will |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 415 | unavoidably lose precision, Python 2.7 now approximates more |
Benjamin Peterson | 25c95f1 | 2009-05-08 20:42:26 +0000 | [diff] [blame] | 416 | closely. For example, Python 2.6 computed the following:: |
| 417 | |
| 418 | >>> n = 295147905179352891391 |
| 419 | >>> float(n) |
| 420 | 2.9514790517935283e+20 |
| 421 | >>> n - long(float(n)) |
| 422 | 65535L |
| 423 | |
| 424 | Python 2.7's floating-point result is larger, but much closer to the |
| 425 | true value:: |
| 426 | |
| 427 | >>> n = 295147905179352891391 |
| 428 | >>> float(n) |
| 429 | 2.9514790517935289e+20 |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 430 | >>> n - long(float(n)) |
Benjamin Peterson | 25c95f1 | 2009-05-08 20:42:26 +0000 | [diff] [blame] | 431 | -1L |
| 432 | |
| 433 | (Implemented by Mark Dickinson; :issue:`3166`.) |
| 434 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 435 | Integer division is also more accurate in its rounding behaviours. (Also |
| 436 | implemented by Mark Dickinson; :issue:`1811`.) |
| 437 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 438 | * It's now possible for a subclass of the built-in :class:`unicode` type |
| 439 | to override the :meth:`__unicode__` method. (Implemented by |
| 440 | Victor Stinner; :issue:`1583863`.) |
| 441 | |
| 442 | * The :class:`bytearray` type's :meth:`~bytearray.translate` method now accepts |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 443 | ``None`` as its first argument. (Fixed by Georg Brandl; |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 444 | :issue:`4759`.) |
Mark Dickinson | d72c7b6 | 2009-03-20 16:00:49 +0000 | [diff] [blame] | 445 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 446 | .. bytearray doesn't seem to be documented |
| 447 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 448 | * When using ``@classmethod`` and ``@staticmethod`` to wrap |
| 449 | methods as class or static methods, the wrapper object now |
| 450 | exposes the wrapped function as their :attr:`__func__` attribute. |
| 451 | (Contributed by Amaury Forgeot d'Arc, after a suggestion by |
| 452 | George Sakkis; :issue:`5982`.) |
| 453 | |
| 454 | * A new encoding named "cp720", used primarily for Arabic text, is now |
| 455 | supported. (Contributed by Alexander Belchenko and Amaury Forgeot |
| 456 | d'Arc; :issue:`1616979`.) |
| 457 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 458 | * The :class:`file` object will now set the :attr:`filename` attribute |
| 459 | on the :exc:`IOError` exception when trying to open a directory |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 460 | on POSIX platforms (noted by Jan Kaliszewski; :issue:`4764`), and |
| 461 | now explicitly checks for and forbids writing to read-only file objects |
| 462 | instead of trusting the C library to catch and report the error |
| 463 | (fixed by Stefan Krah; :issue:`5677`). |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 464 | |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 465 | * The Python tokenizer now translates line endings itself, so the |
| 466 | :func:`compile` built-in function can now accept code using any |
| 467 | line-ending convention. Additionally, it no longer requires that the |
| 468 | code end in a newline. |
| 469 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 470 | * Extra parentheses in function definitions are illegal in Python 3.x, |
| 471 | meaning that you get a syntax error from ``def f((x)): pass``. In |
| 472 | Python3-warning mode, Python 2.7 will now warn about this odd usage. |
| 473 | (Noted by James Lingard; :issue:`7362`.) |
| 474 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 475 | * When a module object is garbage-collected, the module's dictionary is |
| 476 | now only cleared if no one else is holding a reference to the |
| 477 | dictionary (:issue:`7140`). |
| 478 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 479 | .. ====================================================================== |
| 480 | |
| 481 | |
| 482 | Optimizations |
| 483 | ------------- |
| 484 | |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 485 | Several performance enhancements have been added: |
| 486 | |
| 487 | .. * A new :program:`configure` option, :option:`--with-computed-gotos`, |
| 488 | compiles the main bytecode interpreter loop using a new dispatch |
| 489 | mechanism that gives speedups of up to 20%, depending on the system |
| 490 | and benchmark. The new mechanism is only supported on certain |
| 491 | compilers, such as gcc, SunPro, and icc. |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 492 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 493 | * A new opcode was added to perform the initial setup for |
| 494 | :keyword:`with` statements, looking up the :meth:`__enter__` and |
| 495 | :meth:`__exit__` methods. (Contributed by Benjamin Peterson.) |
| 496 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 497 | * The garbage collector now performs better for one common usage |
| 498 | pattern: when many objects are being allocated without deallocating |
| 499 | any of them. This would previously take quadratic |
| 500 | time for garbage collection, but now the number of full garbage collections |
| 501 | is reduced as the number of objects on the heap grows. |
| 502 | The new logic is to only perform a full garbage collection pass when |
| 503 | the middle generation has been collected 10 times and when the |
| 504 | number of survivor objects from the middle generation exceeds 10% of |
| 505 | the number of objects in the oldest generation. (Suggested by Martin |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 506 | von Löwis and implemented by Antoine Pitrou; :issue:`4074`.) |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 507 | |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 508 | * The garbage collector tries to avoid tracking simple containers |
| 509 | which can't be part of a cycle. In Python 2.7, this is now true for |
| 510 | tuples and dicts containing atomic types (such as ints, strings, |
| 511 | etc.). Transitively, a dict containing tuples of atomic types won't |
| 512 | be tracked either. This helps reduce the cost of each |
| 513 | garbage collection by decreasing the number of objects to be |
| 514 | considered and traversed by the collector. |
Antoine Pitrou | 9d81def | 2009-03-28 19:20:09 +0000 | [diff] [blame] | 515 | (Contributed by Antoine Pitrou; :issue:`4688`.) |
| 516 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 517 | * Long integers are now stored internally either in base 2**15 or in base |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 518 | 2**30, the base being determined at build time. Previously, they |
| 519 | were always stored in base 2**15. Using base 2**30 gives |
| 520 | significant performance improvements on 64-bit machines, but |
| 521 | benchmark results on 32-bit machines have been mixed. Therefore, |
| 522 | the default is to use base 2**30 on 64-bit machines and base 2**15 |
| 523 | on 32-bit machines; on Unix, there's a new configure option |
| 524 | :option:`--enable-big-digits` that can be used to override this default. |
| 525 | |
| 526 | Apart from the performance improvements this change should be |
| 527 | invisible to end users, with one exception: for testing and |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 528 | debugging purposes there's a new structseq :data:`sys.long_info` that |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 529 | provides information about the internal format, giving the number of |
| 530 | bits per digit and the size in bytes of the C type used to store |
| 531 | each digit:: |
| 532 | |
| 533 | >>> import sys |
| 534 | >>> sys.long_info |
| 535 | sys.long_info(bits_per_digit=30, sizeof_digit=4) |
| 536 | |
| 537 | (Contributed by Mark Dickinson; :issue:`4258`.) |
| 538 | |
| 539 | Another set of changes made long objects a few bytes smaller: 2 bytes |
| 540 | smaller on 32-bit systems and 6 bytes on 64-bit. |
| 541 | (Contributed by Mark Dickinson; :issue:`5260`.) |
| 542 | |
| 543 | * The division algorithm for long integers has been made faster |
| 544 | by tightening the inner loop, doing shifts instead of multiplications, |
| 545 | and fixing an unnecessary extra iteration. |
| 546 | Various benchmarks show speedups of between 50% and 150% for long |
| 547 | integer divisions and modulo operations. |
| 548 | (Contributed by Mark Dickinson; :issue:`5512`.) |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 549 | Bitwise operations are also significantly faster (initial patch by |
| 550 | Gregory Smith; :issue:`1087418`). |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 551 | |
| 552 | * The implementation of ``%`` checks for the left-side operand being |
| 553 | a Python string and special-cases it; this results in a 1-3% |
| 554 | performance increase for applications that frequently use ``%`` |
| 555 | with strings, such as templating libraries. |
| 556 | (Implemented by Collin Winter; :issue:`5176`.) |
| 557 | |
| 558 | * List comprehensions with an ``if`` condition are compiled into |
| 559 | faster bytecode. (Patch by Antoine Pitrou, back-ported to 2.7 |
| 560 | by Jeffrey Yasskin; :issue:`4715`.) |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 561 | |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 562 | * Converting an integer or long integer to a decimal string was made |
| 563 | faster by special-casing base 10 instead of using a generalized |
| 564 | conversion function that supports arbitrary bases. |
| 565 | (Patch by Gawain Bolton; :issue:`6713`.) |
| 566 | |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 567 | * The :meth:`split`, :meth:`replace`, :meth:`rindex`, |
| 568 | :meth:`rpartition`, and :meth:`rsplit` methods of string-like types |
| 569 | (strings, Unicode strings, and :class:`bytearray` objects) now use a |
| 570 | fast reverse-search algorithm instead of a character-by-character |
| 571 | scan. This is sometimes faster by a factor of 10. (Added by |
| 572 | Florent Xicluna; :issue:`7462` and :issue:`7622`.) |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 573 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 574 | * The :mod:`pickle` and :mod:`cPickle` modules now automatically |
| 575 | intern the strings used for attribute names, reducing memory usage |
| 576 | of the objects resulting from unpickling. (Contributed by Jake |
| 577 | McGuire; :issue:`5084`.) |
| 578 | |
| 579 | * The :mod:`cPickle` module now special-cases dictionaries, |
| 580 | nearly halving the time required to pickle them. |
| 581 | (Contributed by Collin Winter; :issue:`5670`.) |
| 582 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 583 | .. ====================================================================== |
| 584 | |
Georg Brandl | 4d131ee | 2009-11-18 18:53:14 +0000 | [diff] [blame] | 585 | New and Improved Modules |
| 586 | ======================== |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 587 | |
| 588 | As in every release, Python's standard library received a number of |
| 589 | enhancements and bug fixes. Here's a partial list of the most notable |
| 590 | changes, sorted alphabetically by module name. Consult the |
| 591 | :file:`Misc/NEWS` file in the source tree for a more complete list of |
| 592 | changes, or look through the Subversion logs for all the details. |
| 593 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 594 | * The :mod:`bdb` module's base debugging class :class:`~bdb.Bdb` |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 595 | gained a feature for skipping modules. The constructor |
| 596 | now takes an iterable containing glob-style patterns such as |
| 597 | ``django.*``; the debugger will not step into stack frames |
| 598 | from a module that matches one of these patterns. |
| 599 | (Contributed by Maru Newby after a suggestion by |
| 600 | Senthil Kumaran; :issue:`5142`.) |
| 601 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 602 | * The :mod:`binascii` module now supports the buffer API, so it can be |
| 603 | used with :class:`memoryview` instances and other similar buffer objects. |
| 604 | (Backported from 3.x by Florent Xicluna; :issue:`7703`.) |
| 605 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 606 | * Updated module: the :mod:`bsddb` module has been updated from 4.7.2devel9 |
| 607 | to version 4.8.4 of |
| 608 | `the pybsddb package <http://www.jcea.es/programacion/pybsddb.htm>`__. |
| 609 | The new version features better Python 3.x compatibility, various bug fixes, |
| 610 | and adds several new BerkeleyDB flags and methods. |
| 611 | (Updated by Jesús Cea Avión; :issue:`8156`. The pybsddb |
| 612 | changelog can be browsed at http://hg.jcea.es/pybsddb/file/tip/ChangeLog.) |
| 613 | |
| 614 | * The :mod:`bz2` module's :class:`~bz2.BZ2File` now supports the context |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 615 | management protocol, so you can write ``with bz2.BZ2File(...) as f: ...``. |
| 616 | (Contributed by Hagen Fuerstenau; :issue:`3860`.) |
| 617 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 618 | * New class: the :class:`~collections.Counter` class in the :mod:`collections` |
| 619 | module is useful for tallying data. :class:`~collections.Counter` instances |
| 620 | behave mostly like dictionaries but return zero for missing keys instead of |
Benjamin Peterson | 25c95f1 | 2009-05-08 20:42:26 +0000 | [diff] [blame] | 621 | raising a :exc:`KeyError`: |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 622 | |
Benjamin Peterson | 25c95f1 | 2009-05-08 20:42:26 +0000 | [diff] [blame] | 623 | .. doctest:: |
| 624 | :options: +NORMALIZE_WHITESPACE |
| 625 | |
| 626 | >>> from collections import Counter |
| 627 | >>> c = Counter() |
| 628 | >>> for letter in 'here is a sample of english text': |
| 629 | ... c[letter] += 1 |
| 630 | ... |
| 631 | >>> c |
| 632 | Counter({' ': 6, 'e': 5, 's': 3, 'a': 2, 'i': 2, 'h': 2, |
| 633 | 'l': 2, 't': 2, 'g': 1, 'f': 1, 'm': 1, 'o': 1, 'n': 1, |
| 634 | 'p': 1, 'r': 1, 'x': 1}) |
| 635 | >>> c['e'] |
| 636 | 5 |
| 637 | >>> c['z'] |
| 638 | 0 |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 639 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 640 | There are two additional :class:`~collections.Counter` methods: |
| 641 | :meth:`~collections.Counter.most_common` returns the N most common elements |
| 642 | and their counts, and :meth:`~collections.Counter.elements` |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 643 | returns an iterator over the contained element, repeating each element |
| 644 | as many times as its count:: |
| 645 | |
| 646 | >>> c.most_common(5) |
| 647 | [(' ', 6), ('e', 5), ('s', 3), ('a', 2), ('i', 2)] |
| 648 | >>> c.elements() -> |
| 649 | 'a', 'a', ' ', ' ', ' ', ' ', ' ', ' ', |
| 650 | 'e', 'e', 'e', 'e', 'e', 'g', 'f', 'i', 'i', |
| 651 | 'h', 'h', 'm', 'l', 'l', 'o', 'n', 'p', 's', |
Benjamin Peterson | 25c95f1 | 2009-05-08 20:42:26 +0000 | [diff] [blame] | 652 | 's', 's', 'r', 't', 't', 'x' |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 653 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 654 | .. maybe it's better to use list(c.elements()) here |
| 655 | |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 656 | Contributed by Raymond Hettinger; :issue:`1696199`. |
| 657 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 658 | The new :class:`~collections.OrderedDict` class is described in the earlier |
| 659 | section :ref:`pep-0372`. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 660 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 661 | The :class:`~collections.namedtuple` class now has an optional *rename* parameter. |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 662 | If *rename* is true, field names that are invalid because they've |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 663 | been repeated or that aren't legal Python identifiers will be |
| 664 | renamed to legal names that are derived from the field's |
| 665 | position within the list of fields: |
| 666 | |
Benjamin Peterson | 25c95f1 | 2009-05-08 20:42:26 +0000 | [diff] [blame] | 667 | >>> from collections import namedtuple |
| 668 | >>> T = namedtuple('T', ['field1', '$illegal', 'for', 'field2'], rename=True) |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 669 | >>> T._fields |
| 670 | ('field1', '_1', '_2', 'field2') |
| 671 | |
| 672 | (Added by Raymond Hettinger; :issue:`1818`.) |
| 673 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 674 | The :class:`~collections.deque` data type now exposes its maximum length as the |
| 675 | read-only :attr:`~collections.deque.maxlen` attribute, and has a |
| 676 | :meth:`~collections.deque.reverse` method that reverses the elements of the deque in-place. |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 677 | (Added by Raymond Hettinger.) |
| 678 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 679 | * The :mod:`copy` module's :func:`~copy.deepcopy` function will now |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 680 | correctly copy bound instance methods. (Implemented by |
| 681 | Robert Collins; :issue:`1515`.) |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 682 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 683 | * The :mod:`ctypes` module now always converts ``None`` to a C NULL |
| 684 | pointer for arguments declared as pointers. (Changed by Thomas |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 685 | Heller; :issue:`4606`.) The underlying `libffi library |
| 686 | <http://sourceware.org/libffi/>`__ has been updated to version |
| 687 | 3.0.9, containing various fixes for different platforms. (Updated |
| 688 | by Matthias Klose; :issue:`8142`.) |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 689 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 690 | * New method: the :mod:`datetime` module's :class:`~datetime.timedelta` class |
| 691 | gained a :meth:`~datetime.timedelta.total_seconds` method that returns the |
| 692 | number of seconds in the duration. (Contributed by Brian Quinlan; :issue:`5788`.) |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 693 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 694 | * New method: the :class:`~decimal.Decimal` class gained a |
| 695 | :meth:`~decimal.Decimal.from_float` class method that performs an exact |
| 696 | conversion of a floating-point number to a :class:`~decimal.Decimal`. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 697 | Note that this is an **exact** conversion that strives for the |
| 698 | closest decimal approximation to the floating-point representation's value; |
| 699 | the resulting decimal value will therefore still include the inaccuracy, |
| 700 | if any. |
| 701 | For example, ``Decimal.from_float(0.1)`` returns |
| 702 | ``Decimal('0.1000000000000000055511151231257827021181583404541015625')``. |
| 703 | (Implemented by Raymond Hettinger; :issue:`4796`.) |
| 704 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 705 | Most of the methods of the :class:`~decimal.Context` class now accept integers |
| 706 | as well as :class:`~decimal.Decimal` instances; the only exceptions are the |
| 707 | :meth:`~decimal.Context.canonical` and :meth:`~decimal.Context.is_canonical` |
| 708 | methods. (Patch by Juan José Conti; :issue:`7633`.) |
| 709 | |
| 710 | The constructor for :class:`~decimal.Decimal` now accepts non-European |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 711 | Unicode characters, such as Arabic-Indic digits. (Contributed by |
| 712 | Mark Dickinson; :issue:`6595`.) |
| 713 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 714 | When using :class:`~decimal.Decimal` instances with a string's |
| 715 | :meth:`~str.format` method, the default alignment was previously |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 716 | left-alignment. This has been changed to right-alignment, which seems |
| 717 | more sensible for numeric types. (Changed by Mark Dickinson; :issue:`6857`.) |
| 718 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 719 | * The :class:`~fractions.Fraction` class now accepts two rational numbers |
Benjamin Peterson | 25c95f1 | 2009-05-08 20:42:26 +0000 | [diff] [blame] | 720 | as arguments to its constructor. |
| 721 | (Implemented by Mark Dickinson; :issue:`5812`.) |
| 722 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 723 | * New class: a new :class:`~ftplib.FTP_TLS` class in |
| 724 | the :mod:`ftplib` module provides secure FTP |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 725 | connections using TLS encapsulation of authentication as well as |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 726 | subsequent control and data transfers. |
| 727 | (Contributed by Giampaolo Rodola', :issue:`2054`.) |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 728 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 729 | The :meth:`~ftplib.FTP.storbinary` method for binary uploads can now restart |
| 730 | uploads thanks to an added *rest* parameter (patch by Pablo Mouzo; |
| 731 | :issue:`6845`.) |
| 732 | |
| 733 | * New function: the :mod:`gc` module's :func:`~gc.is_tracked` returns |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 734 | true if a given instance is tracked by the garbage collector, false |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 735 | otherwise. (Contributed by Antoine Pitrou; :issue:`4688`.) |
| 736 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 737 | * The :mod:`gzip` module's :class:`~gzip.GzipFile` now supports the context |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 738 | management protocol, so you can write ``with gzip.GzipFile(...) as f: ...`` |
| 739 | (contributed by Hagen Fuerstenau; :issue:`3860`), and it now implements |
| 740 | the :class:`io.BufferedIOBase` ABC, so you can wrap it with |
| 741 | :class:`io.BufferedReader` for faster processing |
| 742 | (contributed by Nir Aides; :issue:`7471`). |
| 743 | It's also now possible to override the modification time |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 744 | recorded in a gzipped file by providing an optional timestamp to |
| 745 | the constructor. (Contributed by Jacques Frechet; :issue:`4272`.) |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 746 | |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 747 | Files in gzip format can be padded with trailing zero bytes; the |
| 748 | :mod:`gzip` module will now consume these trailing bytes. (Fixed by |
| 749 | Tadek Pietraszek and Brian Curtin; :issue:`2846`.) |
| 750 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 751 | * New attribute: the :mod:`hashlib` module now has an :attr:`~hashlib.hashlib.algorithms` |
| 752 | attribute containing a tuple naming the supported algorithms. |
| 753 | In Python 2.7, ``hashlib.algorithms`` contains |
| 754 | ``('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')`` |
| 755 | (Contributed by Carl Chenet; :issue:`7418`.) |
| 756 | |
| 757 | * The default :class:`~httplib.HTTPResponse` class used by the :mod:`httplib` module now |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 758 | supports buffering, resulting in much faster reading of HTTP responses. |
| 759 | (Contributed by Kristjan Valur Jonsson; :issue:`4879`.) |
| 760 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 761 | The :class:`~httplib.HTTPConnection` and :class:`~httplib.HTTPSConnection` classes |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 762 | now support a *source_address* parameter, a ``(host, port)`` 2-tuple |
| 763 | giving the source address that will be used for the connection. |
| 764 | (Contributed by Eldon Ziegler; :issue:`3972`.) |
| 765 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 766 | * The :mod:`imaplib` module now supports IPv6 addresses. |
| 767 | (Contributed by Derek Morr; :issue:`1655`.) |
| 768 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 769 | * Updated module: The :mod:`io` library has been upgraded to the version shipped with |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 770 | Python 3.1. For 3.1, the I/O library was entirely rewritten in C |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 771 | and is 2 to 20 times faster depending on the task being performed. The |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 772 | original Python version was renamed to the :mod:`_pyio` module. |
| 773 | |
| 774 | One minor resulting change: the :class:`io.TextIOBase` class now |
| 775 | has an :attr:`errors` attribute giving the error setting |
| 776 | used for encoding and decoding errors (one of ``'strict'``, ``'replace'``, |
| 777 | ``'ignore'``). |
| 778 | |
| 779 | The :class:`io.FileIO` class now raises an :exc:`OSError` when passed |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 780 | an invalid file descriptor. (Implemented by Benjamin Peterson; |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 781 | :issue:`4991`.) The :meth:`~io.IOBase.truncate` method now preserves the |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 782 | file position; previously it would change the file position to the |
| 783 | end of the new file. (Fixed by Pascal Chambon; :issue:`6939`.) |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 784 | |
Benjamin Peterson | 97dd987 | 2009-12-13 01:23:39 +0000 | [diff] [blame] | 785 | * New function: ``itertools.compress(data, selectors)`` takes two |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 786 | iterators. Elements of *data* are returned if the corresponding |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 787 | value in *selectors* is true:: |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 788 | |
| 789 | itertools.compress('ABCDEF', [1,0,1,0,1,1]) => |
| 790 | A, C, E, F |
| 791 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 792 | .. maybe here is better to use >>> list(itertools.compress(...)) instead |
| 793 | |
Benjamin Peterson | 97dd987 | 2009-12-13 01:23:39 +0000 | [diff] [blame] | 794 | New function: ``itertools.combinations_with_replacement(iter, r)`` |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 795 | returns all the possible *r*-length combinations of elements from the |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 796 | iterable *iter*. Unlike :func:`~itertools.combinations`, individual elements |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 797 | can be repeated in the generated combinations:: |
| 798 | |
| 799 | itertools.combinations_with_replacement('abc', 2) => |
| 800 | ('a', 'a'), ('a', 'b'), ('a', 'c'), |
| 801 | ('b', 'b'), ('b', 'c'), ('c', 'c') |
| 802 | |
| 803 | Note that elements are treated as unique depending on their position |
| 804 | in the input, not their actual values. |
| 805 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 806 | The :func:`itertools.count` function now has a *step* argument that |
| 807 | allows incrementing by values other than 1. :func:`~itertools.count` also |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 808 | now allows keyword arguments, and using non-integer values such as |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 809 | floats or :class:`~decimal.Decimal` instances. (Implemented by Raymond |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 810 | Hettinger; :issue:`5032`.) |
| 811 | |
| 812 | :func:`itertools.combinations` and :func:`itertools.product` were |
| 813 | previously raising :exc:`ValueError` for values of *r* larger than |
| 814 | the input iterable. This was deemed a specification error, so they |
| 815 | now return an empty iterator. (Fixed by Raymond Hettinger; :issue:`4816`.) |
| 816 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 817 | * Updated module: The :mod:`json` module was upgraded to version 2.0.9 of the |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 818 | simplejson package, which includes a C extension that makes |
| 819 | encoding and decoding faster. |
| 820 | (Contributed by Bob Ippolito; :issue:`4136`.) |
| 821 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 822 | To support the new :class:`collections.OrderedDict` type, :func:`json.load` |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 823 | now has an optional *object_pairs_hook* parameter that will be called |
| 824 | with any object literal that decodes to a list of pairs. |
| 825 | (Contributed by Raymond Hettinger; :issue:`5381`.) |
| 826 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 827 | * New functions: the :mod:`math` module gained |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 828 | :func:`~math.erf` and :func:`~math.erfc` for the error function and the complementary error function, |
| 829 | :func:`~math.expm1` which computes ``e**x - 1`` with more precision than |
| 830 | using :func:`~math.exp` and subtracting 1, |
| 831 | :func:`~math.gamma` for the Gamma function, and |
| 832 | :func:`~math.lgamma` for the natural log of the Gamma function. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 833 | (Contributed by Mark Dickinson and nirinA raseliarison; :issue:`3366`.) |
| 834 | |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 835 | * The :mod:`multiprocessing` module's :class:`Manager*` classes |
| 836 | can now be passed a callable that will be called whenever |
| 837 | a subprocess is started, along with a set of arguments that will be |
| 838 | passed to the callable. |
| 839 | (Contributed by lekma; :issue:`5585`.) |
| 840 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 841 | The :class:`~multiprocessing.Pool` class, which controls a pool of worker processes, |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 842 | now has an optional *maxtasksperchild* parameter. Worker processes |
| 843 | will perform the specified number of tasks and then exit, causing the |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 844 | :class:`~multiprocessing.Pool` to start a new worker. This is useful if tasks may leak |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 845 | memory or other resources, or if some tasks will cause the worker to |
| 846 | become very large. |
| 847 | (Contributed by Charles Cazabon; :issue:`6963`.) |
| 848 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 849 | * The :mod:`nntplib` module now supports IPv6 addresses. |
| 850 | (Contributed by Derek Morr; :issue:`1664`.) |
| 851 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 852 | * New functions: the :mod:`os` module wraps the following POSIX system |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 853 | calls: :func:`~os.getresgid` and :func:`~os.getresuid`, which return the |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 854 | real, effective, and saved GIDs and UIDs; |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 855 | :func:`~os.setresgid` and :func:`~os.setresuid`, which set |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 856 | real, effective, and saved GIDs and UIDs to new values; |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 857 | :func:`~os.initgroups`. (GID/UID functions |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 858 | contributed by Travis H.; :issue:`6508`. Support for initgroups added |
| 859 | by Jean-Paul Calderone; :issue:`7333`.) |
| 860 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 861 | The :func:`os.fork` function now re-initializes the import lock in |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 862 | the child process; this fixes problems on Solaris when :func:`~os.fork` |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 863 | is called from a thread. (Fixed by Zsolt Cserna; :issue:`7242`.) |
| 864 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 865 | * In the :mod:`os.path` module, the :func:`~os.path.normpath` and |
| 866 | :func:`~os.path.abspath` functions now preserve Unicode; if their input path |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 867 | is a Unicode string, the return value is also a Unicode string. |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 868 | (:meth:`~os.path.normpath` fixed by Matt Giuca in :issue:`5827`; |
| 869 | :meth:`~os.path.abspath` fixed by Ezio Melotti in :issue:`3426`.) |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 870 | |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 871 | * The :mod:`pydoc` module now has help for the various symbols that Python |
| 872 | uses. You can now do ``help('<<')`` or ``help('@')``, for example. |
| 873 | (Contributed by David Laban; :issue:`4739`.) |
| 874 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 875 | * The :mod:`re` module's :func:`~re.split`, :func:`~re.sub`, and :func:`~re.subn` |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 876 | now accept an optional *flags* argument, for consistency with the |
| 877 | other functions in the module. (Added by Gregory P. Smith.) |
| 878 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 879 | * New function: in the :mod:`shutil` module, :func:`~shutil.make_archive` |
| 880 | takes a filename, archive type (zip or tar-format), and a directory |
| 881 | path, and creates an archive containing the directory's contents. |
| 882 | (Added by Tarek Ziadé.) |
| 883 | |
| 884 | :mod:`shutil`'s :func:`~shutil.copyfile` and :func:`~shutil.copytree` |
| 885 | functions now raise a :exc:`~shutil.SpecialFileError` exception when |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 886 | asked to copy a named pipe. Previously the code would treat |
| 887 | named pipes like a regular file by opening them for reading, and |
| 888 | this would block indefinitely. (Fixed by Antoine Pitrou; :issue:`3002`.) |
| 889 | |
| 890 | * New functions: in the :mod:`site` module, three new functions |
| 891 | return various site- and user-specific paths. |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 892 | :func:`~site.getsitepackages` returns a list containing all |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 893 | global site-packages directories, and |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 894 | :func:`~site.getusersitepackages` returns the path of the user's |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 895 | site-packages directory. |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 896 | :func:`~site.getuserbase` returns the value of the :envvar:`USER_BASE` |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 897 | environment variable, giving the path to a directory that can be used |
| 898 | to store data. |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 899 | (Contributed by Tarek Ziadé; :issue:`6693`.) |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 900 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 901 | The :mod:`site` module now reports exceptions occurring |
| 902 | when the :mod:`sitecustomize` module is imported, and will no longer |
Florent Xicluna | 41fe615 | 2010-04-02 18:52:12 +0000 | [diff] [blame] | 903 | catch and swallow the :exc:`KeyboardInterrupt` exception. (Fixed by |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 904 | Victor Stinner; :issue:`3137`.) |
| 905 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 906 | * The :mod:`socket` module's :class:`~ssl.SSL` objects now support the |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 907 | buffer API, which fixed a test suite failure. (Fixed by Antoine |
| 908 | Pitrou; :issue:`7133`.) |
| 909 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 910 | The :func:`~socket.create_connection` function |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 911 | gained a *source_address* parameter, a ``(host, port)`` 2-tuple |
| 912 | giving the source address that will be used for the connection. |
| 913 | (Contributed by Eldon Ziegler; :issue:`3972`.) |
| 914 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 915 | The :meth:`~socket.socket.recv_into` and :meth:`~socket.socket.recvfrom_into` |
| 916 | methods will now write into objects that support the buffer API, most usefully |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 917 | the :class:`bytearray` and :class:`memoryview` objects. (Implemented by |
| 918 | Antoine Pitrou; :issue:`8104`.) |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 919 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 920 | * The :mod:`SocketServer` module's :class:`~SocketServer.TCPServer` class now |
| 921 | has a :attr:`~SocketServer.TCPServer.disable_nagle_algorithm` class attribute. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 922 | The default value is False; if overridden to be True, |
| 923 | new request connections will have the TCP_NODELAY option set to |
| 924 | prevent buffering many small sends into a single TCP packet. |
| 925 | (Contributed by Kristjan Valur Jonsson; :issue:`6192`.) |
| 926 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 927 | * Updated module: the :mod:`sqlite3` module has been updated to |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 928 | 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 |
| 929 | the ability to load SQLite extensions from shared libraries. |
| 930 | Call the ``enable_load_extension(True)`` method to enable extensions, |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 931 | and then call :meth:`~sqlite3.Connection.load_extension` to load a particular shared library. |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 932 | (Updated by Gerhard Häring.) |
| 933 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 934 | * The :mod:`struct` module will no longer silently ignore overflow |
| 935 | errors when a value is too large for a particular integer format |
| 936 | code (one of ``bBhHiIlLqQ``); it now always raises a |
| 937 | :exc:`struct.error` exception. (Changed by Mark Dickinson; |
| 938 | :issue:`1523`.) |
| 939 | |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 940 | * New function: the :mod:`subprocess` module's |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 941 | :func:`~subprocess.check_output` runs a command with a specified set of arguments |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 942 | and returns the command's output as a string when the command runs without |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 943 | error, or raises a :exc:`~subprocess.CalledProcessError` exception otherwise. |
Georg Brandl | 1f01deb | 2009-01-03 22:47:39 +0000 | [diff] [blame] | 944 | |
| 945 | :: |
| 946 | |
| 947 | >>> subprocess.check_output(['df', '-h', '.']) |
| 948 | 'Filesystem Size Used Avail Capacity Mounted on\n |
| 949 | /dev/disk0s2 52G 49G 3.0G 94% /\n' |
| 950 | |
| 951 | >>> subprocess.check_output(['df', '-h', '/bogus']) |
| 952 | ... |
| 953 | subprocess.CalledProcessError: Command '['df', '-h', '/bogus']' returned non-zero exit status 1 |
| 954 | |
| 955 | (Contributed by Gregory P. Smith.) |
| 956 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 957 | The :mod:`subprocess` module will now retry its internal system calls |
| 958 | on receiving an :const:`EINTR` signal. (Reported by several people; final |
| 959 | patch by Gregory P. Smith in :issue:`1068268`.) |
| 960 | |
| 961 | * New function: :func:`~symtable.is_declared_global` in the :mod:`symtable` module |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 962 | returns true for variables that are explicitly declared to be global, |
| 963 | false for ones that are implicitly global. |
| 964 | (Contributed by Jeremy Hylton.) |
| 965 | |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 966 | * The ``sys.version_info`` value is now a named tuple, with attributes |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 967 | named :attr:`major`, :attr:`minor`, :attr:`micro`, |
| 968 | :attr:`releaselevel`, and :attr:`serial`. (Contributed by Ross |
| 969 | Light; :issue:`4285`.) |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 970 | |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 971 | :func:`sys.getwindowsversion` also returns a named tuple, |
Ezio Melotti | 0d85e41 | 2010-03-13 00:39:49 +0000 | [diff] [blame] | 972 | with attributes named :attr:`major`, :attr:`minor`, :attr:`build`, |
| 973 | :attr:`platform`, :attr:`service_pack`, :attr:`service_pack_major`, |
Eric Smith | b086940 | 2010-02-03 14:25:10 +0000 | [diff] [blame] | 974 | :attr:`service_pack_minor`, :attr:`suite_mask`, and |
| 975 | :attr:`product_type`. (Contributed by Brian Curtin; :issue:`7766`.) |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 976 | |
| 977 | * The :mod:`tarfile` module's default error handling has changed, to |
| 978 | no longer suppress fatal errors. The default error level was previously 0, |
| 979 | which meant that errors would only result in a message being written to the |
| 980 | debug log, but because the debug log is not activated by default, |
| 981 | these errors go unnoticed. The default error level is now 1, |
| 982 | which raises an exception if there's an error. |
| 983 | (Changed by Lars Gustäbel; :issue:`7357`.) |
| 984 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 985 | :mod:`tarfile` now supports filtering the :class:`~tarfile.TarInfo` |
| 986 | objects being added to a tar file. When you call :meth:`~tarfile.TarFile.add`, |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 987 | instance, you may supply an optional *filter* argument |
| 988 | that's a callable. The *filter* callable will be passed the |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 989 | :class:`~tarfile.TarInfo` for every file being added, and can modify and return it. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 990 | If the callable returns ``None``, the file will be excluded from the |
| 991 | resulting archive. This is more powerful than the existing |
| 992 | *exclude* argument, which has therefore been deprecated. |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 993 | (Added by Lars Gustäbel; :issue:`6856`.) |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 994 | The :class:`~tarfile.TarFile` class also now supports the context manager protocol. |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 995 | (Added by Lars Gustäbel; :issue:`7232`.) |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 996 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 997 | * The :meth:`~threading.Event.wait` method of the :class:`threading.Event` class |
| 998 | now returns the internal flag on exit. This means the method will usually |
| 999 | return true because :meth:`~threading.Event.wait` is supposed to block until the |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 1000 | internal flag becomes true. The return value will only be false if |
| 1001 | a timeout was provided and the operation timed out. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1002 | (Contributed by Tim Lesher; :issue:`1674032`.) |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 1003 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1004 | * The Unicode database provided by the :mod:`unicodedata` module is |
| 1005 | now used internally to determine which characters are numeric, |
| 1006 | whitespace, or represent line breaks. The database also |
| 1007 | includes information from the :file:`Unihan.txt` data file (patch |
| 1008 | by Anders Chrigström and Amaury Forgeot d'Arc; :issue:`1571184`) |
| 1009 | and has been updated to version 5.2.0 (updated by |
| 1010 | Florent Xicluna; :issue:`8024`). |
Ezio Melotti | 4c5475d | 2010-03-22 23:16:42 +0000 | [diff] [blame] | 1011 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1012 | * The :class:`~UserDict.UserDict` class is now a new-style class. (Changed by |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 1013 | Benjamin Peterson.) |
| 1014 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1015 | * The ElementTree library, :mod:`xml.etree`, no longer escapes |
| 1016 | ampersands and angle brackets when outputting an XML processing |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1017 | instruction (which looks like ``<?xml-stylesheet href="#style1"?>``) |
| 1018 | or comment (which looks like ``<!-- comment -->``). |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1019 | (Patch by Neil Muller; :issue:`2746`.) |
| 1020 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1021 | * The :mod:`zipfile` module's :class:`~zipfile.ZipFile` now supports the context |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 1022 | management protocol, so you can write ``with zipfile.ZipFile(...) as f: ...``. |
| 1023 | (Contributed by Brian Curtin; :issue:`5511`.) |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1024 | |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 1025 | :mod:`zipfile` now supports archiving empty directories and |
| 1026 | extracts them correctly. (Fixed by Kuba Wieczorek; :issue:`4710`.) |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 1027 | Reading files out of an archive is now faster, and interleaving |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1028 | :meth:`~zipfile.ZipFile.read` and :meth:`~zipfile.ZipFile.readline` now works correctly. |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 1029 | (Contributed by Nir Aides; :issue:`7610`.) |
| 1030 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1031 | The :func:`~zipfile.is_zipfile` function now |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 1032 | accepts a file object, in addition to the path names accepted in earlier |
| 1033 | versions. (Contributed by Gabriel Genellina; :issue:`4756`.) |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 1034 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1035 | The :meth:`~zipfile.ZipFile.writestr` method now has an optional *compress_type* parameter |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1036 | that lets you override the default compression method specified in the |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1037 | :class:`~zipfile.ZipFile` constructor. (Contributed by Ronald Oussoren; |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1038 | :issue:`6003`.) |
| 1039 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1040 | |
| 1041 | New module: sysconfig |
| 1042 | --------------------------------- |
| 1043 | |
| 1044 | XXX A new :mod:`sysconfig` module has been extracted from |
| 1045 | :mod:`distutils` and put in the standard library. |
| 1046 | |
| 1047 | The :mod:`sysconfig` module provides access to Python's configuration |
| 1048 | information like the list of installation paths and the configuration |
| 1049 | variables relevant for the current platform. (contributed by Tarek) |
| 1050 | |
| 1051 | Updated module: ElementTree 1.3 |
| 1052 | --------------------------------- |
| 1053 | |
| 1054 | XXX write this. |
Tarek Ziadé | 396fad7 | 2010-02-23 05:30:31 +0000 | [diff] [blame] | 1055 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1056 | .. ====================================================================== |
| 1057 | .. whole new modules get described in subsections here |
| 1058 | |
Tarek Ziadé | ba0eacf | 2010-02-02 23:43:21 +0000 | [diff] [blame] | 1059 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1060 | Distutils Enhancements |
| 1061 | --------------------------------- |
| 1062 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1063 | XXX all of this work has been moved to Distutils2 |
| 1064 | XXX Not sure what we should say here |
| 1065 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1066 | Distutils is being more actively developed, thanks to Tarek Ziadé |
| 1067 | who has taken over maintenance of the package, so there are a number |
| 1068 | of fixes and improvements. |
| 1069 | |
| 1070 | A new :file:`setup.py` subcommand, ``check``, will check that the |
| 1071 | arguments being passed to the :func:`setup` function are complete |
| 1072 | and correct (:issue:`5732`). |
| 1073 | |
| 1074 | Byte-compilation by the ``install_lib`` subcommand is now only done |
| 1075 | if the ``sys.dont_write_bytecode`` setting allows it (:issue:`7071`). |
| 1076 | |
| 1077 | :func:`distutils.sdist.add_defaults` now uses |
| 1078 | *package_dir* and *data_files* to create the MANIFEST file. |
| 1079 | :mod:`distutils.sysconfig` now reads the :envvar:`AR` and |
| 1080 | :envvar:`ARFLAGS` environment variables. |
| 1081 | |
| 1082 | .. ARFLAGS done in #5941 |
| 1083 | |
| 1084 | It is no longer mandatory to store clear-text passwords in the |
| 1085 | :file:`.pypirc` file when registering and uploading packages to PyPI. As long |
| 1086 | as the username is present in that file, the :mod:`distutils` package will |
| 1087 | prompt for the password if not present. (Added by Tarek Ziadé, |
| 1088 | based on an initial contribution by Nathan Van Gheem; :issue:`4394`.) |
| 1089 | |
| 1090 | A Distutils setup can now specify that a C extension is optional by |
| 1091 | setting the *optional* option setting to true. If this optional is |
| 1092 | supplied, failure to build the extension will not abort the build |
| 1093 | process, but instead simply not install the failing extension. |
| 1094 | (Contributed by Georg Brandl; :issue:`5583`.) |
| 1095 | |
| 1096 | The :class:`distutils.dist.DistributionMetadata` class' |
| 1097 | :meth:`read_pkg_file` method will read the contents of a package's |
| 1098 | :file:`PKG-INFO` metadata file. For an example of its use, see |
| 1099 | :ref:`reading-metadata`. |
| 1100 | (Contributed by Tarek Ziadé; :issue:`7457`.) |
| 1101 | |
| 1102 | :file:`setup.py` files will now accept a :option:`--no-user-cfg` switch |
| 1103 | to skip reading the :file:`~/.pydistutils.cfg` file. (Suggested by |
| 1104 | by Michael Hoffman, and implemented by Paul Winkler; :issue:`1180`.) |
| 1105 | |
| 1106 | When creating a tar-format archive, the ``sdist`` subcommand now |
| 1107 | allows specifying the user id and group that will own the files in the |
| 1108 | archives using the :option:`--owner` and :option:`--group` switches |
| 1109 | (:issue:`6516`). |
Tarek Ziadé | ba0eacf | 2010-02-02 23:43:21 +0000 | [diff] [blame] | 1110 | |
| 1111 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1112 | Unit Testing Enhancements |
| 1113 | --------------------------------- |
| 1114 | |
| 1115 | The :mod:`unittest` module was enhanced in several ways. |
| 1116 | The progress messages now shows 'x' for expected failures |
| 1117 | and 'u' for unexpected successes when run in verbose mode. |
| 1118 | (Contributed by Benjamin Peterson.) |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1119 | Test cases can raise the :exc:`~unittest.SkipTest` exception to skip a test. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1120 | (:issue:`1034053`.) |
| 1121 | |
| 1122 | .. XXX describe test discovery (Contributed by Michael Foord; :issue:`6001`.) |
| 1123 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1124 | The error messages for :meth:`~unittest.TestCase.assertEqual`, |
| 1125 | :meth:`~unittest.TestCase.assertTrue`, and :meth:`~unittest.TestCase.assertFalse` |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1126 | failures now provide more information. If you set the |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1127 | :attr:`~unittest.TestCase.longMessage` attribute of your :class:`~unittest.TestCase` classes to |
| 1128 | True, both the standard error message and any additional message you |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1129 | provide will be printed for failures. (Added by Michael Foord; :issue:`5663`.) |
| 1130 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1131 | The :meth:`~unittest.TestCase.assertRaises` method now |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1132 | return a context handler when called without providing a callable |
| 1133 | object to run. For example, you can write this:: |
| 1134 | |
| 1135 | with self.assertRaises(KeyError): |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1136 | {}['foo'] |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1137 | |
| 1138 | (Implemented by Antoine Pitrou; :issue:`4444`.) |
| 1139 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1140 | .. rev 78774 |
| 1141 | |
| 1142 | Module- and class-level setup and teardown fixtures are now supported. |
| 1143 | Modules can contain :func:`~unittest.setUpModule` and :func:`~unittest.tearDownModule` |
| 1144 | functions. Classes can have :meth:`~unittest.TestCase.setUpClass` and |
| 1145 | :meth:`~unittest.TestCase.tearDownClass` methods that must be defined as class methods |
| 1146 | (using ``@classmethod`` or equivalent). These functions and |
| 1147 | methods are invoked when the test runner switches to a test case in a |
| 1148 | different module or class. |
| 1149 | |
| 1150 | The methods :meth:`~unittest.TestCase.addCleanup` and |
| 1151 | :meth:`~unittest.TestCase.doCleanups` were added. |
| 1152 | :meth:`~unittest.TestCase.addCleanup` allows you to add cleanup functions that |
| 1153 | will be called unconditionally (after :meth:`~unittest.TestCase.setUp` if |
| 1154 | :meth:`~unittest.TestCase.setUp` fails, otherwise after :meth:`~unittest.TestCase.tearDown`). This allows |
| 1155 | for much simpler resource allocation and deallocation during tests |
| 1156 | (:issue:`5679`). |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1157 | |
| 1158 | A number of new methods were added that provide more specialized |
| 1159 | tests. Many of these methods were written by Google engineers |
| 1160 | for use in their test suites; Gregory P. Smith, Michael Foord, and |
| 1161 | GvR worked on merging them into Python's version of :mod:`unittest`. |
| 1162 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1163 | * :meth:`~unittest.TestCase.assertIsNone` and :meth:`~unittest.TestCase.assertIsNotNone` take one |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1164 | expression and verify that the result is or is not ``None``. |
| 1165 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1166 | * :meth:`~unittest.TestCase.assertIs` and :meth:`~unittest.TestCase.assertIsNot` |
| 1167 | take two values and check whether the two values evaluate to the same object or not. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1168 | (Added by Michael Foord; :issue:`2578`.) |
| 1169 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1170 | * :meth:`~unittest.TestCase.assertIsInstance` and |
| 1171 | :meth:`~unittest.TestCase.assertNotIsInstance` check whether |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 1172 | the resulting object is an instance of a particular class, or of |
| 1173 | one of a tuple of classes. (Added by Georg Brandl; :issue:`7031`.) |
| 1174 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1175 | * :meth:`~unittest.TestCase.assertGreater`, :meth:`~unittest.TestCase.assertGreaterEqual`, |
| 1176 | :meth:`~unittest.TestCase.assertLess`, and :meth:`~unittest.TestCase.assertLessEqual` compare |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1177 | two quantities. |
| 1178 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1179 | * :meth:`~unittest.TestCase.assertMultiLineEqual` compares two strings, and if they're |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1180 | not equal, displays a helpful comparison that highlights the |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1181 | differences in the two strings. This comparison is now used by |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1182 | default when Unicode strings are compared with :meth:`~unittest.TestCase.assertEqual`. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1183 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1184 | * :meth:`~unittest.TestCase.assertRegexpMatches` checks whether its first argument is a |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1185 | string matching a regular expression provided as its second argument. |
| 1186 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1187 | .. XXX add assertNotRegexpMatches see issue 8038 |
| 1188 | |
| 1189 | * :meth:`~unittest.TestCase.assertRaisesRegexp` checks whether a particular exception |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1190 | is raised, and then also checks that the string representation of |
| 1191 | the exception matches the provided regular expression. |
| 1192 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1193 | * :meth:`~unittest.TestCase.assertIn` and :meth:`~unittest.TestCase.assertNotIn` |
| 1194 | tests whether *first* is or is not in *second*. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1195 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1196 | * :meth:`~unittest.TestCase.assertItemsEqual` tests whether two provided sequences |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1197 | contain the same elements. |
| 1198 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1199 | * :meth:`~unittest.TestCase.assertSetEqual` compares whether two sets are equal, and |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1200 | only reports the differences between the sets in case of error. |
| 1201 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1202 | * Similarly, :meth:`~unittest.TestCase.assertListEqual` and :meth:`~unittest.TestCase.assertTupleEqual` |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1203 | compare the specified types and explain any differences without necessarily |
| 1204 | printing their full values; these methods are now used by default |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1205 | when comparing lists and tuples using :meth:`~unittest.TestCase.assertEqual`. |
| 1206 | More generally, :meth:`~unittest.TestCase.assertSequenceEqual` compares two sequences |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1207 | and can optionally check whether both sequences are of a |
| 1208 | particular type. |
| 1209 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1210 | * :meth:`~unittest.TestCase.assertDictEqual` compares two dictionaries and reports the |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1211 | differences; it's now used by default when you compare two dictionaries |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1212 | using :meth:`~unittest.TestCase.assertEqual`. :meth:`~unittest.TestCase.assertDictContainsSubset` checks whether |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1213 | all of the key/value pairs in *first* are found in *second*. |
| 1214 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1215 | * :meth:`~unittest.TestCase.assertAlmostEqual` and :meth:`~unittest.TestCase.assertNotAlmostEqual` test |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1216 | whether *first* and *second* are approximately equal by computing |
| 1217 | their difference, rounding the result to an optionally-specified number |
| 1218 | of *places* (the default is 7), and comparing to zero. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1219 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1220 | * :meth:`~unittest.TestLoader.loadTestsFromName` properly honors the |
| 1221 | :attr:`~unittest.TestLoader.suiteClass` attribute of |
| 1222 | the :class:`~unittest.TestLoader`. (Fixed by Mark Roddy; :issue:`6866`.) |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1223 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1224 | * A new hook lets you extend the :meth:`~unittest.TestCase.assertEqual` method to handle |
| 1225 | new data types. The :meth:`~unittest.TestCase.addTypeEqualityFunc` method takes a type |
| 1226 | object and a function. The function will be used when both of the |
| 1227 | objects being compared are of the specified type. This function |
| 1228 | should compare the two objects and raise an exception if they don't |
| 1229 | match; it's a good idea for the function to provide additional |
| 1230 | information about why the two objects are matching, much as the new |
| 1231 | sequence comparison methods do. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1232 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1233 | :func:`unittest.main` now takes an optional ``exit`` argument. If |
| 1234 | False, :func:`~unittest.main` doesn't call :func:`sys.exit`, allowing it to be |
| 1235 | used from the interactive interpreter. (Contributed by J. Pablo |
| 1236 | Fernández; :issue:`3379`.) |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1237 | |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1238 | A new command-line switch, :option:`-f` or :option:`--failfast`, makes |
| 1239 | test execution stop immediately when a test fails instead of |
| 1240 | continuing to execute further tests. (Suggested by Cliff Dyer and |
| 1241 | implemented by Michael Foord; :issue:`8074`.) |
| 1242 | |
| 1243 | .. XXX document the other new switches |
| 1244 | |
| 1245 | :class:`~unittest.TestResult` has new :meth:`~unittest.TestResult.startTestRun` and |
| 1246 | :meth:`~unittest.TestResult.stopTestRun` methods that are called immediately before |
| 1247 | and after a test run. (Contributed by Robert Collins; :issue:`5728`.) |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1248 | |
| 1249 | With all these changes, the :file:`unittest.py` was becoming awkwardly |
| 1250 | large, so the module was turned into a package and the code split into |
| 1251 | several files (by Benjamin Peterson). This doesn't affect how the |
| 1252 | module is imported. |
| 1253 | |
| 1254 | |
| 1255 | .. _importlib-section: |
| 1256 | |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 1257 | importlib: Importing Modules |
| 1258 | ------------------------------ |
| 1259 | |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 1260 | Python 3.1 includes the :mod:`importlib` package, a re-implementation |
| 1261 | of the logic underlying Python's :keyword:`import` statement. |
| 1262 | :mod:`importlib` is useful for implementors of Python interpreters and |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 1263 | to users who wish to write new importers that can participate in the |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 1264 | import process. Python 2.7 doesn't contain the complete |
| 1265 | :mod:`importlib` package, but instead has a tiny subset that contains |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1266 | a single function, :func:`~importlib.import_module`. |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 1267 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1268 | ``import_module(name, package=None)`` imports a module. *name* is |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 1269 | a string containing the module or package's name. It's possible to do |
| 1270 | relative imports by providing a string that begins with a ``.`` |
| 1271 | character, such as ``..utils.errors``. For relative imports, the |
| 1272 | *package* argument must be provided and is the name of the package that |
| 1273 | will be used as the anchor for |
Ezio Melotti | 6c96ffe | 2010-04-07 04:27:14 +0000 | [diff] [blame^] | 1274 | the relative import. :func:`~importlib.import_module` both inserts the imported |
Benjamin Peterson | f47ed4a | 2009-04-11 20:45:40 +0000 | [diff] [blame] | 1275 | module into ``sys.modules`` and returns the module object. |
| 1276 | |
| 1277 | Here are some examples:: |
| 1278 | |
| 1279 | >>> from importlib import import_module |
| 1280 | >>> anydbm = import_module('anydbm') # Standard absolute import |
| 1281 | >>> anydbm |
| 1282 | <module 'anydbm' from '/p/python/Lib/anydbm.py'> |
| 1283 | >>> # Relative import |
| 1284 | >>> sysconfig = import_module('..sysconfig', 'distutils.command') |
| 1285 | >>> sysconfig |
| 1286 | <module 'distutils.sysconfig' from '/p/python/Lib/distutils/sysconfig.pyc'> |
| 1287 | |
| 1288 | :mod:`importlib` was implemented by Brett Cannon and introduced in |
| 1289 | Python 3.1. |
| 1290 | |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 1291 | |
Benjamin Peterson | 5c6d787 | 2009-02-06 02:40:07 +0000 | [diff] [blame] | 1292 | ttk: Themed Widgets for Tk |
| 1293 | -------------------------- |
| 1294 | |
| 1295 | Tcl/Tk 8.5 includes a set of themed widgets that re-implement basic Tk |
| 1296 | widgets but have a more customizable appearance and can therefore more |
| 1297 | closely resemble the native platform's widgets. This widget |
| 1298 | set was originally called Tile, but was renamed to Ttk (for "themed Tk") |
| 1299 | on being added to Tcl/Tck release 8.5. |
| 1300 | |
| 1301 | XXX write a brief discussion and an example here. |
| 1302 | |
| 1303 | The :mod:`ttk` module was written by Guilherme Polo and added in |
| 1304 | :issue:`2983`. An alternate version called ``Tile.py``, written by |
| 1305 | Martin Franklin and maintained by Kevin Walzer, was proposed for |
| 1306 | inclusion in :issue:`2618`, but the authors argued that Guilherme |
| 1307 | Polo's work was more comprehensive. |
| 1308 | |
Georg Brandl | 4d131ee | 2009-11-18 18:53:14 +0000 | [diff] [blame] | 1309 | |
| 1310 | Deprecations and Removals |
| 1311 | ========================= |
| 1312 | |
| 1313 | * :func:`contextlib.nested`, which allows handling more than one context manager |
| 1314 | with one :keyword:`with` statement, has been deprecated; :keyword:`with` |
| 1315 | supports multiple context managers syntactically now. |
| 1316 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1317 | .. ====================================================================== |
| 1318 | |
| 1319 | |
| 1320 | Build and C API Changes |
| 1321 | ======================= |
| 1322 | |
| 1323 | Changes to Python's build process and to the C API include: |
| 1324 | |
Georg Brandl | 1f01deb | 2009-01-03 22:47:39 +0000 | [diff] [blame] | 1325 | * If you use the :file:`.gdbinit` file provided with Python, |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1326 | the "pyo" macro in the 2.7 version now works correctly when the thread being |
| 1327 | debugged doesn't hold the GIL; the macro now acquires it before printing. |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 1328 | (Contributed by Victor Stinner; :issue:`3632`.) |
| 1329 | |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 1330 | * :cfunc:`Py_AddPendingCall` is now thread-safe, letting any |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 1331 | worker thread submit notifications to the main Python thread. This |
| 1332 | is particularly useful for asynchronous IO operations. |
| 1333 | (Contributed by Kristjan Valur Jonsson; :issue:`4293`.) |
| 1334 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1335 | * New function: :cfunc:`PyCode_NewEmpty` creates an empty code object; |
| 1336 | only the filename, function name, and first line number are required. |
| 1337 | This is useful to extension modules that are attempting to |
| 1338 | construct a more useful traceback stack. Previously such |
| 1339 | extensions needed to call :cfunc:`PyCode_New`, which had many |
| 1340 | more arguments. (Added by Jeffrey Yasskin.) |
| 1341 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 1342 | * New function: :cfunc:`PyErr_NewExceptionWithDoc` creates a new |
| 1343 | exception class, just as the existing :cfunc:`PyErr_NewException` does, |
| 1344 | but takes an extra ``char *`` argument containing the docstring for the |
| 1345 | new exception class. (Added by the 'lekma' user on the Python bug tracker; |
| 1346 | :issue:`7033`.) |
| 1347 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1348 | * New function: :cfunc:`PyFrame_GetLineNumber` takes a frame object |
| 1349 | and returns the line number that the frame is currently executing. |
| 1350 | Previously code would need to get the index of the bytecode |
| 1351 | instruction currently executing, and then look up the line number |
| 1352 | corresponding to that address. (Added by Jeffrey Yasskin.) |
| 1353 | |
Benjamin Peterson | d69fe2a | 2010-02-03 02:59:43 +0000 | [diff] [blame] | 1354 | * New functions: :cfunc:`PyLong_AsLongAndOverflow` and |
| 1355 | :cfunc:`PyLong_AsLongLongAndOverflow` approximates a Python long |
| 1356 | integer as a C :ctype:`long` or :ctype:`long long`. |
| 1357 | If the number is too large to fit into |
| 1358 | the output type, an *overflow* flag is set and returned to the caller. |
| 1359 | (Contributed by Case Van Horsen; :issue:`7528` and :issue:`7767`.) |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 1360 | |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 1361 | * New function: stemming from the rewrite of string-to-float conversion, |
| 1362 | a new :cfunc:`PyOS_string_to_double` function was added. The old |
| 1363 | :cfunc:`PyOS_ascii_strtod` and :cfunc:`PyOS_ascii_atof` functions |
| 1364 | are now deprecated. |
| 1365 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1366 | * New macros: the Python header files now define the following macros: |
| 1367 | :cmacro:`Py_ISALNUM`, |
| 1368 | :cmacro:`Py_ISALPHA`, |
| 1369 | :cmacro:`Py_ISDIGIT`, |
| 1370 | :cmacro:`Py_ISLOWER`, |
| 1371 | :cmacro:`Py_ISSPACE`, |
| 1372 | :cmacro:`Py_ISUPPER`, |
| 1373 | :cmacro:`Py_ISXDIGIT`, |
| 1374 | and :cmacro:`Py_TOLOWER`, :cmacro:`Py_TOUPPER`. |
| 1375 | All of these functions are analogous to the C |
| 1376 | standard macros for classifying characters, but ignore the current |
| 1377 | locale setting, because in |
| 1378 | several places Python needs to analyze characters in a |
| 1379 | locale-independent way. (Added by Eric Smith; |
| 1380 | :issue:`5793`.) |
| 1381 | |
| 1382 | .. XXX these macros don't seem to be described in the c-api docs. |
| 1383 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 1384 | * New format codes: the :cfunc:`PyFormat_FromString`, |
| 1385 | :cfunc:`PyFormat_FromStringV`, and :cfunc:`PyErr_Format` now |
| 1386 | accepts ``%lld`` and ``%llu`` format codes for displaying values of |
| 1387 | C's :ctype:`long long` types. |
| 1388 | (Contributed by Mark Dickinson; :issue:`7228`.) |
| 1389 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1390 | * The complicated interaction between threads and process forking has |
| 1391 | been changed. Previously, the child process created by |
| 1392 | :func:`os.fork` might fail because the child is created with only a |
| 1393 | single thread running, the thread performing the :func:`os.fork`. |
| 1394 | If other threads were holding a lock, such as Python's import lock, |
| 1395 | when the fork was performed, the lock would still be marked as |
| 1396 | "held" in the new process. But in the child process nothing would |
| 1397 | ever release the lock, since the other threads weren't replicated, |
| 1398 | and the child process would no longer be able to perform imports. |
| 1399 | |
| 1400 | Python 2.7 now acquires the import lock before performing an |
| 1401 | :func:`os.fork`, and will also clean up any locks created using the |
| 1402 | :mod:`threading` module. C extension modules that have internal |
| 1403 | locks, or that call :cfunc:`fork()` themselves, will not benefit |
| 1404 | from this clean-up. |
| 1405 | |
| 1406 | (Fixed by Thomas Wouters; :issue:`1590864`.) |
| 1407 | |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 1408 | * The :cfunc:`Py_Finalize` function now calls the internal |
| 1409 | :func:`threading._shutdown` function; this prevents some exceptions from |
| 1410 | being raised when an interpreter shuts down. |
| 1411 | (Patch by Adam Olsen; :issue:`1722344`.) |
| 1412 | |
Benjamin Peterson | 25c95f1 | 2009-05-08 20:42:26 +0000 | [diff] [blame] | 1413 | * Global symbols defined by the :mod:`ctypes` module are now prefixed |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1414 | with ``Py``, or with ``_ctypes``. (Implemented by Thomas |
Benjamin Peterson | 25c95f1 | 2009-05-08 20:42:26 +0000 | [diff] [blame] | 1415 | Heller; :issue:`3102`.) |
| 1416 | |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 1417 | * New configure option: the :option:`--with-system-expat` switch allows |
| 1418 | building the :mod:`pyexpat` module to use the system Expat library. |
| 1419 | (Contributed by Arfrever Frehtes Taifersar Arahesis; :issue:`7609`.) |
| 1420 | |
| 1421 | * New configure option: Compiling Python with the |
| 1422 | :option:`--with-valgrind` option will now disable the pymalloc |
| 1423 | allocator, which is difficult for the Valgrind to analyze correctly. |
| 1424 | Valgrind will therefore be better at detecting memory leaks and |
| 1425 | overruns. (Contributed by James Henstridge; :issue:`2422`.) |
| 1426 | |
| 1427 | * New configure option: you can now supply no arguments to |
| 1428 | :option:`--with-dbmliborder=` in order to build none of the various |
| 1429 | DBM modules. (Added by Arfrever Frehtes Taifersar Arahesis; |
| 1430 | :issue:`6491`.) |
| 1431 | |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 1432 | * The :program:`configure` script now checks for floating-point rounding bugs |
| 1433 | on certain 32-bit Intel chips and defines a :cmacro:`X87_DOUBLE_ROUNDING` |
| 1434 | preprocessor definition. No code currently uses this definition, |
| 1435 | but it's available if anyone wishes to use it. |
| 1436 | (Added by Mark Dickinson; :issue:`2937`.) |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1437 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1438 | * The build process now creates the necessary files for pkg-config |
| 1439 | support. (Contributed by Clinton Roy; :issue:`3585`.) |
| 1440 | |
| 1441 | * The build process now supports Subversion 1.7. (Contributed by |
| 1442 | Arfrever Frehtes Taifersar Arahesis; :issue:`6094`.) |
| 1443 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 1444 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1445 | .. ====================================================================== |
| 1446 | |
| 1447 | Port-Specific Changes: Windows |
| 1448 | ----------------------------------- |
| 1449 | |
Georg Brandl | 1f01deb | 2009-01-03 22:47:39 +0000 | [diff] [blame] | 1450 | * The :mod:`msvcrt` module now contains some constants from |
| 1451 | the :file:`crtassem.h` header file: |
| 1452 | :data:`CRT_ASSEMBLY_VERSION`, |
| 1453 | :data:`VC_ASSEMBLY_PUBLICKEYTOKEN`, |
| 1454 | and :data:`LIBRARIES_ASSEMBLY_NAME_PREFIX`. |
Benjamin Peterson | 1010bf3 | 2009-01-30 04:00:29 +0000 | [diff] [blame] | 1455 | (Contributed by David Cournapeau; :issue:`4365`.) |
| 1456 | |
| 1457 | * The new :cfunc:`_beginthreadex` API is used to start threads, and |
| 1458 | the native thread-local storage functions are now used. |
| 1459 | (Contributed by Kristjan Valur Jonsson; :issue:`3582`.) |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1460 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1461 | * The :func:`os.listdir` function now correctly fails |
| 1462 | for an empty path. (Fixed by Hirokazu Yamamoto; :issue:`5913`.) |
| 1463 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 1464 | * The :mod:`mimelib` module will now read the MIME database from |
| 1465 | the Windows registry when initializing. |
| 1466 | (Patch by Gabriel Genellina; :issue:`4969`.) |
| 1467 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1468 | .. ====================================================================== |
| 1469 | |
| 1470 | Port-Specific Changes: Mac OS X |
| 1471 | ----------------------------------- |
| 1472 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1473 | * The path ``/Library/Python/2.7/site-packages`` is now appended to |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 1474 | ``sys.path``, in order to share added packages between the system |
| 1475 | installation and a user-installed copy of the same version. |
| 1476 | (Changed by Ronald Oussoren; :issue:`4865`.) |
| 1477 | |
| 1478 | |
| 1479 | Other Changes and Fixes |
| 1480 | ======================= |
| 1481 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1482 | * Two benchmark scripts, :file:`iobench` and :file:`ccbench`, were |
| 1483 | added to the :file:`Tools` directory. :file:`iobench` measures the |
| 1484 | speed of built-in file I/O objects (as returned by :func:`open`) |
| 1485 | while performing various operations, and :file:`ccbench` is a |
| 1486 | concurrency benchmark that tries to measure computing throughput, |
| 1487 | thread switching latency, and IO processing bandwidth when |
| 1488 | performing several tasks using a varying number of threads. |
| 1489 | |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 1490 | * When importing a module from a :file:`.pyc` or :file:`.pyo` file |
| 1491 | with an existing :file:`.py` counterpart, the :attr:`co_filename` |
Benjamin Peterson | 25c95f1 | 2009-05-08 20:42:26 +0000 | [diff] [blame] | 1492 | attributes of the resulting code objects are overwritten when the |
| 1493 | original filename is obsolete. This can happen if the file has been |
| 1494 | renamed, moved, or is accessed through different paths. (Patch by |
| 1495 | Ziga Seilnacht and Jean-Paul Calderone; :issue:`1180193`.) |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 1496 | |
| 1497 | * The :file:`regrtest.py` script now takes a :option:`--randseed=` |
| 1498 | switch that takes an integer that will be used as the random seed |
| 1499 | for the :option:`-r` option that executes tests in random order. |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1500 | The :option:`-r` option also reports the seed that was used |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 1501 | (Added by Collin Winter.) |
| 1502 | |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 1503 | * Another :file:`regrtest.py` switch is :option:`-j`, which |
| 1504 | takes an integer specifying how many tests run in parallel. This |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1505 | allows reducing the total runtime on multi-core machines. |
Antoine Pitrou | 8890954 | 2009-06-29 13:54:42 +0000 | [diff] [blame] | 1506 | This option is compatible with several other options, including the |
| 1507 | :option:`-R` switch which is known to produce long runtimes. |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 1508 | (Added by Antoine Pitrou, :issue:`6152`.) This can also be used |
| 1509 | with a new :option:`-F` switch that runs selected tests in a loop |
| 1510 | until they fail. (Added by Antoine Pitrou; :issue:`7312`.) |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1511 | |
| 1512 | .. ====================================================================== |
| 1513 | |
| 1514 | Porting to Python 2.7 |
| 1515 | ===================== |
| 1516 | |
| 1517 | This section lists previously described changes and other bugfixes |
| 1518 | that may require changes to your code: |
| 1519 | |
Benjamin Peterson | f6489f9 | 2009-11-25 17:46:26 +0000 | [diff] [blame] | 1520 | * When using :class:`Decimal` instances with a string's |
| 1521 | :meth:`format` method, the default alignment was previously |
| 1522 | left-alignment. This has been changed to right-alignment, which might |
| 1523 | change the output of your programs. |
| 1524 | (Changed by Mark Dickinson; :issue:`6857`.) |
| 1525 | |
| 1526 | Another :meth:`format`-related change: the default precision used |
| 1527 | for floating-point and complex numbers was changed from 6 decimal |
| 1528 | places to 12, which matches the precision used by :func:`str`. |
| 1529 | (Changed by Eric Smith; :issue:`5920`.) |
| 1530 | |
Benjamin Peterson | 87c8d87 | 2009-06-11 22:54:11 +0000 | [diff] [blame] | 1531 | * Because of an optimization for the :keyword:`with` statement, the special |
| 1532 | methods :meth:`__enter__` and :meth:`__exit__` must belong to the object's |
| 1533 | type, and cannot be directly attached to the object's instance. This |
| 1534 | affects new-style classes (derived from :class:`object`) and C extension |
| 1535 | types. (:issue:`6101`.) |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1536 | |
Benjamin Peterson | 9eea480 | 2009-12-31 03:31:15 +0000 | [diff] [blame] | 1537 | * The :meth:`readline` method of :class:`StringIO` objects now does |
| 1538 | nothing when a negative length is requested, as other file-like |
| 1539 | objects do. (:issue:`7348`). |
| 1540 | |
Benjamin Peterson | 9895f91 | 2010-03-21 22:05:32 +0000 | [diff] [blame] | 1541 | In the standard library: |
| 1542 | |
| 1543 | * The ElementTree library, :mod:`xml.etree`, no longer escapes |
| 1544 | ampersands and angle brackets when outputting an XML processing |
| 1545 | instruction (which looks like `<?xml-stylesheet href="#style1"?>`) |
| 1546 | or comment (which looks like `<!-- comment -->`). |
| 1547 | (Patch by Neil Muller; :issue:`2746`.) |
| 1548 | |
Benjamin Peterson | a28e702 | 2010-01-09 18:53:06 +0000 | [diff] [blame] | 1549 | For C extensions: |
| 1550 | |
| 1551 | * C extensions that use integer format codes with the ``PyArg_Parse*`` |
| 1552 | family of functions will now raise a :exc:`TypeError` exception |
| 1553 | instead of triggering a :exc:`DeprecationWarning` (:issue:`5080`). |
| 1554 | |
| 1555 | * Use the new :cfunc:`PyOS_string_to_double` function instead of the old |
| 1556 | :cfunc:`PyOS_ascii_strtod` and :cfunc:`PyOS_ascii_atof` functions, |
| 1557 | which are now deprecated. |
| 1558 | |
| 1559 | |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1560 | .. ====================================================================== |
| 1561 | |
| 1562 | |
| 1563 | .. _acks27: |
| 1564 | |
| 1565 | Acknowledgements |
| 1566 | ================ |
| 1567 | |
| 1568 | The author would like to thank the following people for offering |
| 1569 | suggestions, corrections and assistance with various drafts of this |
Benjamin Peterson | 97dd987 | 2009-12-13 01:23:39 +0000 | [diff] [blame] | 1570 | article: Ryan Lovett, Hugh Secker-Walker. |
Benjamin Peterson | f10a79a | 2008-10-11 00:49:57 +0000 | [diff] [blame] | 1571 | |