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