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