Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1 | **************************** |
| 2 | What's New in Python 2.6 |
| 3 | **************************** |
| 4 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 5 | .. XXX mention switch to Roundup for bug tracking |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 6 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 7 | :Author: A.M. Kuchling |
| 8 | :Release: |release| |
| 9 | :Date: |today| |
| 10 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 11 | .. $Id: whatsnew26.tex 55746 2007-06-02 18:33:53Z neal.norwitz $ |
| 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 as a comment: |
| 44 | |
| 45 | % Patch 12345 |
| 46 | XXX Describe the transmogrify() function added to the socket |
| 47 | module. |
| 48 | (Contributed by P.Y. Developer.) |
| 49 | |
| 50 | This saves the maintainer the effort of going through the SVN log |
| 51 | when researching a change. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 52 | |
| 53 | This article explains the new features in Python 2.6. No release date for |
| 54 | Python 2.6 has been set; it will probably be released in mid 2008. |
| 55 | |
| 56 | This article doesn't attempt to provide a complete specification of the new |
| 57 | features, but instead provides a convenient overview. For full details, you |
| 58 | should refer to the documentation for Python 2.6. If you want to understand the |
| 59 | complete implementation and design rationale, refer to the PEP for a particular |
| 60 | new feature. |
| 61 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 62 | .. Compare with previous release in 2 - 3 sentences here. |
| 63 | add hyperlink when the documentation becomes available online. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 64 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 65 | .. ======================================================================== |
| 66 | .. Large, PEP-level features and changes should be described here. |
| 67 | .. Should there be a new section here for 3k migration? |
| 68 | .. Or perhaps a more general section describing module changes/deprecation? |
| 69 | .. ======================================================================== |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 70 | |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 71 | Python 3.0 |
| 72 | ================ |
| 73 | |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 74 | The development cycle for Python 2.6 also saw the release of the first |
| 75 | alphas of Python 3.0, and the development of 3.0 has influenced |
| 76 | a number of features in 2.6. |
| 77 | |
| 78 | Python 3.0 is a far-ranging redesign of Python that breaks |
| 79 | compatibility with the 2.x series. This means that existing Python |
| 80 | code will need a certain amount of conversion in order to run on |
| 81 | Python 3.0. However, not all the changes in 3.0 necessarily break |
| 82 | compatibility. In cases where new features won't cause existing code |
| 83 | to break, they've been backported to 2.6 and are described in this |
| 84 | document in the appropriate place. Some of the 3.0-derived features |
| 85 | are: |
| 86 | |
| 87 | * A :meth:`__complex__` method for converting objects to a complex number. |
| 88 | * Alternate syntax for catching exceptions: ``except TypeError as exc``. |
| 89 | * The addition of :func:`functools.reduce` as a synonym for the built-in |
| 90 | :func:`reduce` function. |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 91 | |
| 92 | A new command-line switch, :option:`-3`, enables warnings |
| 93 | about features that will be removed in Python 3.0. You can run code |
| 94 | with this switch to see how much work will be necessary to port |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 95 | code to 3.0. The value of this switch is available |
| 96 | to Python code as the boolean variable ``sys.py3kwarning``, |
| 97 | and to C extension code as :cdata:`Py_Py3kWarningFlag`. |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 98 | |
| 99 | .. seealso:: |
| 100 | |
| 101 | The 3xxx series of PEPs, which describes the development process for |
| 102 | Python 3.0 and various features that have been accepted, rejected, |
| 103 | or are still under consideration. |
| 104 | |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 105 | |
| 106 | Development Changes |
| 107 | ================================================== |
| 108 | |
| 109 | While 2.6 was being developed, the Python development process |
| 110 | underwent two significant changes: the developer group |
| 111 | switched from SourceForge's issue tracker to a customized |
| 112 | Roundup installation, and the documentation was converted from |
| 113 | LaTeX to reStructured Text. |
| 114 | |
| 115 | |
| 116 | New Issue Tracker: Roundup |
| 117 | -------------------------------------------------- |
| 118 | |
| 119 | XXX write this. |
| 120 | |
| 121 | |
| 122 | New Documentation Format: ReStructured Text |
| 123 | -------------------------------------------------- |
| 124 | |
| 125 | Python's documentation had been written using LaTeX since the |
| 126 | project's inception around 1989. At that time, most documentation was |
| 127 | printed out for later study, not viewed online. LaTeX was widely used |
| 128 | because it provided attractive printed output while |
| 129 | remaining straightforward to write, once the basic rules |
| 130 | of the markup have been learned. |
| 131 | |
| 132 | LaTeX is still used today for writing technical publications destined |
| 133 | for printing, but the landscape for programming tools has shifted. We |
| 134 | no longer print out reams of documentation; instead, we browse through |
| 135 | it online and HTML is the most important format to support. |
| 136 | Unfortunately, converting LaTeX to HTML is fairly complicated, and |
| 137 | Fred L. Drake Jr., the Python documentation editor for many years, |
| 138 | spent a lot of time wrestling the conversion process into shape. |
| 139 | Occasionally people would suggest converting the documentation into |
| 140 | SGML or, later, XML, but performing a good conversion is a major task |
| 141 | and no one pursued the task to completion. |
| 142 | |
| 143 | During the 2.6 development cycle, Georg Brandl put a substantial |
| 144 | effort into building a new toolchain called Sphinx |
| 145 | for processing the documentation. |
| 146 | The input format is reStructured Text, |
| 147 | a markup commonly used in the Python community that supports |
| 148 | custom extensions and directives. Sphinx concentrates |
Andrew M. Kuchling | 2d60cf7 | 2007-12-22 17:27:02 +0000 | [diff] [blame] | 149 | on HTML output, producing attractively styled |
| 150 | and modern HTML, but printed output is still supported through |
| 151 | conversion to LaTeX as an output format. |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 152 | |
| 153 | .. seealso:: |
| 154 | |
| 155 | `Docutils <http://docutils.sf.net>`__: The fundamental |
| 156 | reStructured Text parser and toolset. |
| 157 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 158 | :ref:`documenting-index`: Describes how to write for |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 159 | Python's documentation. |
| 160 | |
| 161 | |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 162 | PEP 343: The 'with' statement |
| 163 | ============================= |
| 164 | |
| 165 | The previous version, Python 2.5, added the ':keyword:`with`' |
| 166 | statement an optional feature, to be enabled by a ``from __future__ |
Andrew M. Kuchling | 6e751f4 | 2007-12-03 21:28:41 +0000 | [diff] [blame] | 167 | import with_statement`` directive. In 2.6 the statement no longer needs to |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 168 | be specially enabled; this means that :keyword:`with` is now always a |
| 169 | keyword. The rest of this section is a copy of the corresponding |
| 170 | section from "What's New in Python 2.5" document; if you read |
| 171 | it back when Python 2.5 came out, you can skip the rest of this |
| 172 | section. |
| 173 | |
| 174 | The ':keyword:`with`' statement clarifies code that previously would use |
| 175 | ``try...finally`` blocks to ensure that clean-up code is executed. In this |
| 176 | section, I'll discuss the statement as it will commonly be used. In the next |
| 177 | section, I'll examine the implementation details and show how to write objects |
| 178 | for use with this statement. |
| 179 | |
| 180 | The ':keyword:`with`' statement is a new control-flow structure whose basic |
| 181 | structure is:: |
| 182 | |
| 183 | with expression [as variable]: |
| 184 | with-block |
| 185 | |
| 186 | The expression is evaluated, and it should result in an object that supports the |
| 187 | context management protocol (that is, has :meth:`__enter__` and :meth:`__exit__` |
| 188 | methods. |
| 189 | |
| 190 | The object's :meth:`__enter__` is called before *with-block* is executed and |
| 191 | therefore can run set-up code. It also may return a value that is bound to the |
| 192 | name *variable*, if given. (Note carefully that *variable* is *not* assigned |
| 193 | the result of *expression*.) |
| 194 | |
| 195 | After execution of the *with-block* is finished, the object's :meth:`__exit__` |
| 196 | method is called, even if the block raised an exception, and can therefore run |
| 197 | clean-up code. |
| 198 | |
| 199 | Some standard Python objects now support the context management protocol and can |
| 200 | be used with the ':keyword:`with`' statement. File objects are one example:: |
| 201 | |
| 202 | with open('/etc/passwd', 'r') as f: |
| 203 | for line in f: |
| 204 | print line |
| 205 | ... more processing code ... |
| 206 | |
| 207 | After this statement has executed, the file object in *f* will have been |
| 208 | automatically closed, even if the :keyword:`for` loop raised an exception part- |
| 209 | way through the block. |
| 210 | |
| 211 | .. note:: |
| 212 | |
| 213 | In this case, *f* is the same object created by :func:`open`, because |
| 214 | :meth:`file.__enter__` returns *self*. |
| 215 | |
| 216 | The :mod:`threading` module's locks and condition variables also support the |
| 217 | ':keyword:`with`' statement:: |
| 218 | |
| 219 | lock = threading.Lock() |
| 220 | with lock: |
| 221 | # Critical section of code |
| 222 | ... |
| 223 | |
| 224 | The lock is acquired before the block is executed and always released once the |
| 225 | block is complete. |
| 226 | |
| 227 | The new :func:`localcontext` function in the :mod:`decimal` module makes it easy |
| 228 | to save and restore the current decimal context, which encapsulates the desired |
| 229 | precision and rounding characteristics for computations:: |
| 230 | |
| 231 | from decimal import Decimal, Context, localcontext |
| 232 | |
| 233 | # Displays with default precision of 28 digits |
| 234 | v = Decimal('578') |
| 235 | print v.sqrt() |
| 236 | |
| 237 | with localcontext(Context(prec=16)): |
| 238 | # All code in this block uses a precision of 16 digits. |
| 239 | # The original context is restored on exiting the block. |
| 240 | print v.sqrt() |
| 241 | |
| 242 | |
| 243 | .. _new-26-context-managers: |
| 244 | |
| 245 | Writing Context Managers |
| 246 | ------------------------ |
| 247 | |
| 248 | Under the hood, the ':keyword:`with`' statement is fairly complicated. Most |
| 249 | people will only use ':keyword:`with`' in company with existing objects and |
| 250 | don't need to know these details, so you can skip the rest of this section if |
| 251 | you like. Authors of new objects will need to understand the details of the |
| 252 | underlying implementation and should keep reading. |
| 253 | |
| 254 | A high-level explanation of the context management protocol is: |
| 255 | |
| 256 | * The expression is evaluated and should result in an object called a "context |
| 257 | manager". The context manager must have :meth:`__enter__` and :meth:`__exit__` |
| 258 | methods. |
| 259 | |
| 260 | * The context manager's :meth:`__enter__` method is called. The value returned |
Georg Brandl | d41b8dc | 2007-12-16 23:15:07 +0000 | [diff] [blame] | 261 | is assigned to *VAR*. If no ``as VAR`` clause is present, the value is simply |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 262 | discarded. |
| 263 | |
| 264 | * The code in *BLOCK* is executed. |
| 265 | |
| 266 | * If *BLOCK* raises an exception, the :meth:`__exit__(type, value, traceback)` |
| 267 | is called with the exception details, the same values returned by |
| 268 | :func:`sys.exc_info`. The method's return value controls whether the exception |
| 269 | is re-raised: any false value re-raises the exception, and ``True`` will result |
| 270 | in suppressing it. You'll only rarely want to suppress the exception, because |
| 271 | if you do the author of the code containing the ':keyword:`with`' statement will |
| 272 | never realize anything went wrong. |
| 273 | |
| 274 | * If *BLOCK* didn't raise an exception, the :meth:`__exit__` method is still |
| 275 | called, but *type*, *value*, and *traceback* are all ``None``. |
| 276 | |
| 277 | Let's think through an example. I won't present detailed code but will only |
| 278 | sketch the methods necessary for a database that supports transactions. |
| 279 | |
| 280 | (For people unfamiliar with database terminology: a set of changes to the |
| 281 | database are grouped into a transaction. Transactions can be either committed, |
| 282 | meaning that all the changes are written into the database, or rolled back, |
| 283 | meaning that the changes are all discarded and the database is unchanged. See |
| 284 | any database textbook for more information.) |
| 285 | |
| 286 | Let's assume there's an object representing a database connection. Our goal will |
| 287 | be to let the user write code like this:: |
| 288 | |
| 289 | db_connection = DatabaseConnection() |
| 290 | with db_connection as cursor: |
| 291 | cursor.execute('insert into ...') |
| 292 | cursor.execute('delete from ...') |
| 293 | # ... more operations ... |
| 294 | |
| 295 | The transaction should be committed if the code in the block runs flawlessly or |
| 296 | rolled back if there's an exception. Here's the basic interface for |
| 297 | :class:`DatabaseConnection` that I'll assume:: |
| 298 | |
| 299 | class DatabaseConnection: |
| 300 | # Database interface |
Georg Brandl | 9f72d23 | 2007-12-16 23:13:29 +0000 | [diff] [blame] | 301 | def cursor(self): |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 302 | "Returns a cursor object and starts a new transaction" |
Georg Brandl | 9f72d23 | 2007-12-16 23:13:29 +0000 | [diff] [blame] | 303 | def commit(self): |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 304 | "Commits current transaction" |
Georg Brandl | 9f72d23 | 2007-12-16 23:13:29 +0000 | [diff] [blame] | 305 | def rollback(self): |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 306 | "Rolls back current transaction" |
| 307 | |
| 308 | The :meth:`__enter__` method is pretty easy, having only to start a new |
| 309 | transaction. For this application the resulting cursor object would be a useful |
| 310 | result, so the method will return it. The user can then add ``as cursor`` to |
| 311 | their ':keyword:`with`' statement to bind the cursor to a variable name. :: |
| 312 | |
| 313 | class DatabaseConnection: |
| 314 | ... |
Georg Brandl | 9f72d23 | 2007-12-16 23:13:29 +0000 | [diff] [blame] | 315 | def __enter__(self): |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 316 | # Code to start a new transaction |
| 317 | cursor = self.cursor() |
| 318 | return cursor |
| 319 | |
| 320 | The :meth:`__exit__` method is the most complicated because it's where most of |
| 321 | the work has to be done. The method has to check if an exception occurred. If |
| 322 | there was no exception, the transaction is committed. The transaction is rolled |
| 323 | back if there was an exception. |
| 324 | |
| 325 | In the code below, execution will just fall off the end of the function, |
| 326 | returning the default value of ``None``. ``None`` is false, so the exception |
| 327 | will be re-raised automatically. If you wished, you could be more explicit and |
| 328 | add a :keyword:`return` statement at the marked location. :: |
| 329 | |
| 330 | class DatabaseConnection: |
| 331 | ... |
Georg Brandl | 9f72d23 | 2007-12-16 23:13:29 +0000 | [diff] [blame] | 332 | def __exit__(self, type, value, tb): |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 333 | if tb is None: |
| 334 | # No exception, so commit |
| 335 | self.commit() |
| 336 | else: |
| 337 | # Exception occurred, so rollback. |
| 338 | self.rollback() |
| 339 | # return False |
| 340 | |
| 341 | |
| 342 | .. _module-contextlib: |
| 343 | |
| 344 | The contextlib module |
| 345 | --------------------- |
| 346 | |
| 347 | The new :mod:`contextlib` module provides some functions and a decorator that |
| 348 | are useful for writing objects for use with the ':keyword:`with`' statement. |
| 349 | |
| 350 | The decorator is called :func:`contextmanager`, and lets you write a single |
| 351 | generator function instead of defining a new class. The generator should yield |
| 352 | exactly one value. The code up to the :keyword:`yield` will be executed as the |
| 353 | :meth:`__enter__` method, and the value yielded will be the method's return |
| 354 | value that will get bound to the variable in the ':keyword:`with`' statement's |
| 355 | :keyword:`as` clause, if any. The code after the :keyword:`yield` will be |
| 356 | executed in the :meth:`__exit__` method. Any exception raised in the block will |
| 357 | be raised by the :keyword:`yield` statement. |
| 358 | |
| 359 | Our database example from the previous section could be written using this |
| 360 | decorator as:: |
| 361 | |
| 362 | from contextlib import contextmanager |
| 363 | |
| 364 | @contextmanager |
Georg Brandl | 9f72d23 | 2007-12-16 23:13:29 +0000 | [diff] [blame] | 365 | def db_transaction(connection): |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 366 | cursor = connection.cursor() |
| 367 | try: |
| 368 | yield cursor |
| 369 | except: |
| 370 | connection.rollback() |
| 371 | raise |
| 372 | else: |
| 373 | connection.commit() |
| 374 | |
| 375 | db = DatabaseConnection() |
| 376 | with db_transaction(db) as cursor: |
| 377 | ... |
| 378 | |
| 379 | The :mod:`contextlib` module also has a :func:`nested(mgr1, mgr2, ...)` function |
| 380 | that combines a number of context managers so you don't need to write nested |
| 381 | ':keyword:`with`' statements. In this example, the single ':keyword:`with`' |
| 382 | statement both starts a database transaction and acquires a thread lock:: |
| 383 | |
| 384 | lock = threading.Lock() |
| 385 | with nested (db_transaction(db), lock) as (cursor, locked): |
| 386 | ... |
| 387 | |
| 388 | Finally, the :func:`closing(object)` function returns *object* so that it can be |
| 389 | bound to a variable, and calls ``object.close`` at the end of the block. :: |
| 390 | |
| 391 | import urllib, sys |
| 392 | from contextlib import closing |
| 393 | |
| 394 | with closing(urllib.urlopen('http://www.yahoo.com')) as f: |
| 395 | for line in f: |
| 396 | sys.stdout.write(line) |
| 397 | |
| 398 | |
| 399 | .. seealso:: |
| 400 | |
| 401 | :pep:`343` - The "with" statement |
| 402 | PEP written by Guido van Rossum and Nick Coghlan; implemented by Mike Bland, |
| 403 | Guido van Rossum, and Neal Norwitz. The PEP shows the code generated for a |
| 404 | ':keyword:`with`' statement, which can be helpful in learning how the statement |
| 405 | works. |
| 406 | |
| 407 | The documentation for the :mod:`contextlib` module. |
| 408 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 409 | .. ====================================================================== |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 410 | |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 411 | .. _pep-0366: |
| 412 | |
| 413 | PEP 366: Explicit Relative Imports From a Main Module |
| 414 | ============================================================ |
| 415 | |
| 416 | Python's :option:`-m` switch allows running a module as a script. |
| 417 | When you ran a module that was located inside a package, relative |
| 418 | imports didn't work correctly. |
| 419 | |
| 420 | The fix in Python 2.6 adds a :attr:`__package__` attribute to modules. |
| 421 | When present, relative imports will be relative to the value of this |
| 422 | attribute instead of the :attr:`__name__` attribute. PEP 302-style |
| 423 | importers can then set :attr:`__package__`. The :mod:`runpy` module |
| 424 | that implements the :option:`-m` switch now does this, so relative imports |
| 425 | can now be used in scripts running from inside a package. |
| 426 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 427 | .. ====================================================================== |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 428 | |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 429 | .. :: |
| 430 | |
| 431 | .. _pep-0370: |
| 432 | |
| 433 | PEP 370: XXX |
| 434 | ===================================================== |
| 435 | |
| 436 | When you run Python, the module search page ``sys.modules`` usually |
| 437 | includes a directory whose path ends in ``"site-packages"``. This |
| 438 | directory is intended to hold locally-installed packages available to |
| 439 | all users on a machine or using a particular site installation. |
| 440 | |
| 441 | Python 2.6 introduces a convention for user-specific site directories. |
| 442 | |
| 443 | .. seealso:: |
| 444 | |
| 445 | :pep:`370` - XXX |
| 446 | |
| 447 | PEP written by XXX; implemented by Christian Heimes. |
| 448 | |
| 449 | |
| 450 | .. ====================================================================== |
| 451 | |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 452 | .. _pep-3110: |
| 453 | |
| 454 | PEP 3110: Exception-Handling Changes |
| 455 | ===================================================== |
| 456 | |
| 457 | One error that Python programmers occasionally make |
| 458 | is the following:: |
| 459 | |
| 460 | try: |
| 461 | ... |
| 462 | except TypeError, ValueError: |
| 463 | ... |
| 464 | |
| 465 | The author is probably trying to catch both |
| 466 | :exc:`TypeError` and :exc:`ValueError` exceptions, but this code |
| 467 | actually does something different: it will catch |
| 468 | :exc:`TypeError` and bind the resulting exception object |
| 469 | to the local name ``"ValueError"``. The correct code |
| 470 | would have specified a tuple:: |
| 471 | |
| 472 | try: |
| 473 | ... |
| 474 | except (TypeError, ValueError): |
| 475 | ... |
| 476 | |
| 477 | This error is possible because the use of the comma here is ambiguous: |
| 478 | does it indicate two different nodes in the parse tree, or a single |
| 479 | node that's a tuple. |
| 480 | |
| 481 | Python 3.0 changes the syntax to make this unambiguous by replacing |
| 482 | the comma with the word "as". To catch an exception and store the |
| 483 | exception object in the variable ``exc``, you must write:: |
| 484 | |
| 485 | try: |
| 486 | ... |
| 487 | except TypeError as exc: |
| 488 | ... |
| 489 | |
| 490 | Python 3.0 will only support the use of "as", and therefore interprets |
| 491 | the first example as catching two different exceptions. Python 2.6 |
| 492 | supports both the comma and "as", so existing code will continue to |
| 493 | work. |
| 494 | |
| 495 | .. seealso:: |
| 496 | |
| 497 | :pep:`3110` - Catching Exceptions in Python 3000 |
| 498 | PEP written and implemented by Collin Winter. |
| 499 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 500 | .. ====================================================================== |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 501 | |
| 502 | .. _pep-3119: |
| 503 | |
| 504 | PEP 3119: Abstract Base Classes |
| 505 | ===================================================== |
| 506 | |
| 507 | XXX |
| 508 | |
Andrew M. Kuchling | 3b55470 | 2008-01-04 02:31:40 +0000 | [diff] [blame] | 509 | How to identify a file object? |
| 510 | |
| 511 | ABCs are a collection of classes describing various interfaces. |
| 512 | Classes can derive from an ABC to indicate they support that ABC's |
| 513 | interface. Concrete classes should obey the semantics specified by |
| 514 | an ABC, but Python can't check this; it's up to the implementor. |
| 515 | |
| 516 | A metaclass lets you declare that an existing class or type |
| 517 | derives from a particular ABC. You can even |
| 518 | |
| 519 | class AppendableSequence: |
| 520 | __metaclass__ = ABCMeta |
| 521 | |
| 522 | AppendableSequence.register(list) |
| 523 | assert issubclass(list, AppendableSequence) |
| 524 | assert isinstance([], AppendableSequence) |
| 525 | |
| 526 | @abstractmethod decorator -- you can't instantiate classes w/ |
| 527 | an abstract method. |
| 528 | |
Andrew M. Kuchling | 73835bd | 2008-01-04 18:24:41 +0000 | [diff] [blame] | 529 | :: |
| 530 | |
| 531 | @abstractproperty decorator |
| 532 | @abstractproperty |
| 533 | def readonly(self): |
| 534 | return self._x |
Andrew M. Kuchling | 3b55470 | 2008-01-04 02:31:40 +0000 | [diff] [blame] | 535 | |
| 536 | |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 537 | .. seealso:: |
| 538 | |
| 539 | :pep:`3119` - Introducing Abstract Base Classes |
| 540 | PEP written by Guido van Rossum and Talin. |
| 541 | Implemented by XXX. |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 542 | Backported to 2.6 by Benjamin Aranguren, with Alex Martelli. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 543 | |
Andrew M. Kuchling | aa35554 | 2008-01-16 03:17:25 +0000 | [diff] [blame] | 544 | .. ====================================================================== |
| 545 | |
| 546 | .. _pep-3141: |
| 547 | |
| 548 | PEP 3141: A Type Hierarchy for Numbers |
| 549 | ===================================================== |
| 550 | |
| 551 | In Python 3.0, several abstract base classes for numeric types, |
Andrew M. Kuchling | d221956 | 2008-01-17 12:00:15 +0000 | [diff] [blame] | 552 | inspired by Scheme's numeric tower, are being added. |
Andrew M. Kuchling | aa35554 | 2008-01-16 03:17:25 +0000 | [diff] [blame] | 553 | This change was backported to 2.6 as the :mod:`numbers` module. |
| 554 | |
| 555 | The most general ABC is :class:`Number`. It defines no operations at |
| 556 | all, and only exists to allow checking if an object is a number by |
| 557 | doing ``isinstance(obj, Number)``. |
| 558 | |
| 559 | Numbers are further divided into :class:`Exact` and :class:`Inexact`. |
| 560 | Exact numbers can represent values precisely and operations never |
| 561 | round off the results or introduce tiny errors that may break the |
| 562 | communtativity and associativity properties; inexact numbers may |
| 563 | perform such rounding or introduce small errors. Integers, long |
| 564 | integers, and rational numbers are exact, while floating-point |
| 565 | and complex numbers are inexact. |
| 566 | |
| 567 | :class:`Complex` is a subclass of :class:`Number`. Complex numbers |
| 568 | can undergo the basic operations of addition, subtraction, |
| 569 | multiplication, division, and exponentiation, and you can retrieve the |
| 570 | real and imaginary parts and obtain a number's conjugate. Python's built-in |
| 571 | complex type is an implementation of :class:`Complex`. |
| 572 | |
| 573 | :class:`Real` further derives from :class:`Complex`, and adds |
| 574 | operations that only work on real numbers: :func:`floor`, :func:`trunc`, |
| 575 | rounding, taking the remainder mod N, floor division, |
| 576 | and comparisons. |
| 577 | |
| 578 | :class:`Rational` numbers derive from :class:`Real`, have |
| 579 | :attr:`numerator` and :attr:`denominator` properties, and can be |
| 580 | converted to floats. Python 2.6 adds a simple rational-number class |
| 581 | in the :mod:`rational` module. |
| 582 | |
| 583 | :class:`Integral` numbers derive from :class:`Rational`, and |
| 584 | can be shifted left and right with ``<<`` and ``>>``, |
| 585 | combined using bitwise operations such as ``&`` and ``|``, |
| 586 | and can be used as array indexes and slice boundaries. |
| 587 | |
Andrew M. Kuchling | d221956 | 2008-01-17 12:00:15 +0000 | [diff] [blame] | 588 | In Python 3.0, the PEP slightly redefines the existing built-ins |
| 589 | :func:`math.floor`, :func:`math.ceil`, :func:`round`, and adds a new |
| 590 | one, :func:`trunc`, that's been backported to Python 2.6. |
| 591 | :func:`trunc` rounds toward zero, returning the closest |
| 592 | :class:`Integral` that's between the function's argument and zero. |
Andrew M. Kuchling | aa35554 | 2008-01-16 03:17:25 +0000 | [diff] [blame] | 593 | |
Andrew M. Kuchling | d221956 | 2008-01-17 12:00:15 +0000 | [diff] [blame] | 594 | .. seealso:: |
Andrew M. Kuchling | aa35554 | 2008-01-16 03:17:25 +0000 | [diff] [blame] | 595 | |
Andrew M. Kuchling | d221956 | 2008-01-17 12:00:15 +0000 | [diff] [blame] | 596 | XXX link: Discusses Scheme's numeric tower. |
Andrew M. Kuchling | aa35554 | 2008-01-16 03:17:25 +0000 | [diff] [blame] | 597 | |
Andrew M. Kuchling | d221956 | 2008-01-17 12:00:15 +0000 | [diff] [blame] | 598 | |
Andrew M. Kuchling | aa35554 | 2008-01-16 03:17:25 +0000 | [diff] [blame] | 599 | |
| 600 | The Rational Module |
| 601 | -------------------------------------------------- |
| 602 | |
| 603 | To fill out the hierarchy of numeric types, a rational-number class |
| 604 | has been added as the :mod:`rational` module. Rational numbers are |
| 605 | represented as a fraction; rational numbers can exactly represent |
| 606 | numbers such as two-thirds that floating-point numbers can only |
| 607 | approximate. |
| 608 | |
| 609 | The :class:`Rational` constructor takes two :class:`Integral` values |
| 610 | that will be the numerator and denominator of the resulting fraction. :: |
| 611 | |
| 612 | >>> from rational import Rational |
| 613 | >>> a = Rational(2, 3) |
| 614 | >>> b = Rational(2, 5) |
| 615 | >>> float(a), float(b) |
| 616 | (0.66666666666666663, 0.40000000000000002) |
| 617 | >>> a+b |
| 618 | rational.Rational(16,15) |
| 619 | >>> a/b |
| 620 | rational.Rational(5,3) |
| 621 | |
| 622 | The :mod:`rational` module is based upon an implementation by Sjoerd |
| 623 | Mullender that was in Python's :file:`Demo/classes/` directory for a |
| 624 | long time. This implementation was significantly updated by Jeffrey |
| 625 | Yaskin. |
| 626 | |
| 627 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 628 | Other Language Changes |
| 629 | ====================== |
| 630 | |
| 631 | Here are all of the changes that Python 2.6 makes to the core Python language. |
| 632 | |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 633 | * When calling a function using the ``**`` syntax to provide keyword |
| 634 | arguments, you are no longer required to use a Python dictionary; |
| 635 | any mapping will now work:: |
| 636 | |
| 637 | >>> def f(**kw): |
| 638 | ... print sorted(kw) |
| 639 | ... |
| 640 | >>> ud=UserDict.UserDict() |
| 641 | >>> ud['a'] = 1 |
| 642 | >>> ud['b'] = 'string' |
| 643 | >>> f(**ud) |
| 644 | ['a', 'b'] |
| 645 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 646 | .. Patch 1686487 |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 647 | |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 648 | * The built-in types now have improved support for extended slicing syntax, |
| 649 | where various combinations of ``(start, stop, step)`` are supplied. |
| 650 | Previously, the support was partial and certain corner cases wouldn't work. |
| 651 | (Implemented by Thomas Wouters.) |
| 652 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 653 | .. Revision 57619 |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 654 | |
Christian Heimes | ff6cc6b | 2008-01-17 23:01:44 +0000 | [diff] [blame] | 655 | * Properties now have three attributes, :attr:`getter`, |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 656 | :attr:`setter` and :attr:`deleter`, that are useful shortcuts for |
Christian Heimes | ff6cc6b | 2008-01-17 23:01:44 +0000 | [diff] [blame] | 657 | adding or modifying a getter, setter or deleter function to an |
| 658 | existing property. You would use them like this:: |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 659 | |
| 660 | class C(object): |
| 661 | @property |
| 662 | def x(self): |
| 663 | return self._x |
| 664 | |
| 665 | @x.setter |
| 666 | def x(self, value): |
| 667 | self._x = value |
| 668 | |
| 669 | @x.deleter |
| 670 | def x(self): |
| 671 | del self._x |
| 672 | |
Christian Heimes | ff6cc6b | 2008-01-17 23:01:44 +0000 | [diff] [blame] | 673 | class D(C): |
| 674 | @C.x.getter |
| 675 | def x(self): |
| 676 | return self._x * 2 |
| 677 | |
| 678 | @x.setter |
| 679 | def x(self, value): |
| 680 | self._x = value / 2 |
| 681 | |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 682 | |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 683 | * C functions and methods that use |
| 684 | :cfunc:`PyComplex_AsCComplex` will now accept arguments that |
| 685 | have a :meth:`__complex__` method. In particular, the functions in the |
| 686 | :mod:`cmath` module will now accept objects with this method. |
| 687 | This is a backport of a Python 3.0 change. |
| 688 | (Contributed by Mark Dickinson.) |
| 689 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 690 | .. Patch #1675423 |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 691 | |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 692 | A numerical nicety: when creating a complex number from two floats |
| 693 | on systems that support signed zeros (-0 and +0), the |
| 694 | :func:`complex()` constructor will now preserve the sign |
| 695 | of the zero. |
| 696 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 697 | .. Patch 1507 |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 698 | |
Andrew M. Kuchling | 654ede7 | 2008-01-04 01:16:12 +0000 | [diff] [blame] | 699 | * More floating-point features were also added. The :func:`float` function |
| 700 | will now turn the strings ``+nan`` and ``-nan`` into the corresponding |
Andrew M. Kuchling | 3b55470 | 2008-01-04 02:31:40 +0000 | [diff] [blame] | 701 | IEEE 754 Not A Number values, and ``+inf`` and ``-inf`` into |
Andrew M. Kuchling | 654ede7 | 2008-01-04 01:16:12 +0000 | [diff] [blame] | 702 | positive or negative infinity. This works on any platform with |
Christian Heimes | d0d7d87 | 2008-01-04 02:03:25 +0000 | [diff] [blame] | 703 | IEEE 754 semantics. (Contributed by Christian Heimes.) |
Andrew M. Kuchling | 654ede7 | 2008-01-04 01:16:12 +0000 | [diff] [blame] | 704 | |
| 705 | .. Patch 1635. |
| 706 | |
Andrew M. Kuchling | 3b55470 | 2008-01-04 02:31:40 +0000 | [diff] [blame] | 707 | Other functions in the :mod:`math` module, :func:`isinf` and |
| 708 | :func:`isnan`, return true if their floating-point argument is |
| 709 | infinite or Not A Number. |
| 710 | .. Patch 1640 |
| 711 | The ``math.copysign(x, y)`` function |
| 712 | copies the sign bit of an IEEE 754 number, returning the absolute |
| 713 | value of *x* combined with the sign bit of *y*. For example, |
| 714 | ``math.copysign(1, -0.0)`` returns -1.0. (Contributed by Christian |
| 715 | Heimes.) |
| 716 | |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 717 | * Changes to the :class:`Exception` interface |
| 718 | as dictated by :pep:`352` continue to be made. For 2.6, |
| 719 | the :attr:`message` attribute is being deprecated in favor of the |
| 720 | :attr:`args` attribute. |
| 721 | |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 722 | * The :exc:`GeneratorExit` exception now subclasses |
| 723 | :exc:`BaseException` instead of :exc:`Exception`. This means |
| 724 | that an exception handler that does ``except Exception:`` |
| 725 | will not inadvertently catch :exc:`GeneratorExit`. |
| 726 | (Contributed by Chad Austin.) |
| 727 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 728 | .. Patch #1537 |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 729 | |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 730 | * The :func:`compile` built-in function now accepts keyword arguments |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 731 | as well as positional parameters. (Contributed by Thomas Wouters.) |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 732 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 733 | .. Patch 1444529 |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 734 | |
Andrew M. Kuchling | 6c066dd | 2007-09-01 20:43:36 +0000 | [diff] [blame] | 735 | * The :func:`complex` constructor now accepts strings containing |
| 736 | parenthesized complex numbers, letting ``complex(repr(cmplx))`` |
| 737 | will now round-trip values. For example, ``complex('(3+4j)')`` |
| 738 | now returns the value (3+4j). |
| 739 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 740 | .. Patch 1491866 |
Andrew M. Kuchling | 6c066dd | 2007-09-01 20:43:36 +0000 | [diff] [blame] | 741 | |
Andrew M. Kuchling | b4c6295 | 2007-09-01 21:18:31 +0000 | [diff] [blame] | 742 | * The string :meth:`translate` method now accepts ``None`` as the |
| 743 | translation table parameter, which is treated as the identity |
| 744 | transformation. This makes it easier to carry out operations |
| 745 | that only delete characters. (Contributed by Bengt Richter.) |
| 746 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 747 | .. Patch 1193128 |
Andrew M. Kuchling | b4c6295 | 2007-09-01 21:18:31 +0000 | [diff] [blame] | 748 | |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 749 | * The built-in :func:`dir` function now checks for a :meth:`__dir__` |
| 750 | method on the objects it receives. This method must return a list |
| 751 | of strings containing the names of valid attributes for the object, |
| 752 | and lets the object control the value that :func:`dir` produces. |
| 753 | Objects that have :meth:`__getattr__` or :meth:`__getattribute__` |
Facundo Batista | bd5b623 | 2007-12-03 19:49:54 +0000 | [diff] [blame] | 754 | methods can use this to advertise pseudo-attributes they will honor. |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 755 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 756 | .. Patch 1591665 |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 757 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 758 | * An obscure change: when you use the the :func:`locals` function inside a |
| 759 | :keyword:`class` statement, the resulting dictionary no longer returns free |
| 760 | variables. (Free variables, in this case, are variables referred to in the |
| 761 | :keyword:`class` statement that aren't attributes of the class.) |
| 762 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 763 | .. ====================================================================== |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 764 | |
| 765 | |
| 766 | Optimizations |
| 767 | ------------- |
| 768 | |
Georg Brandl | af30b28 | 2008-01-15 06:55:56 +0000 | [diff] [blame] | 769 | * Type objects now have a cache of methods that can reduce |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 770 | the amount of work required to find the correct method implementation |
Andrew M. Kuchling | a01ed03 | 2008-01-15 01:55:32 +0000 | [diff] [blame] | 771 | for a particular class; once cached, the interpreter doesn't need to |
| 772 | traverse base classes to figure out the right method to call. |
| 773 | The cache is cleared if a base class or the class itself is modified, |
| 774 | so the cache should remain correct even in the face of Python's dynamic |
| 775 | nature. |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 776 | (Original optimization implemented by Armin Rigo, updated for |
| 777 | Python 2.6 by Kevin Jacobs.) |
| 778 | |
| 779 | .. % Patch 1700288 |
| 780 | |
Andrew M. Kuchling | 3b55470 | 2008-01-04 02:31:40 +0000 | [diff] [blame] | 781 | * All of the functions in the :mod:`struct` module have been rewritten in |
| 782 | C, thanks to work at the Need For Speed sprint. |
| 783 | (Contributed by Raymond Hettinger.) |
| 784 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 785 | * Internally, a bit is now set in type objects to indicate some of the standard |
| 786 | built-in types. This speeds up checking if an object is a subclass of one of |
| 787 | these types. (Contributed by Neal Norwitz.) |
| 788 | |
| 789 | The net result of the 2.6 optimizations is that Python 2.6 runs the pystone |
| 790 | benchmark around XX% faster than Python 2.5. |
| 791 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 792 | .. ====================================================================== |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 793 | |
| 794 | |
| 795 | New, Improved, and Deprecated Modules |
| 796 | ===================================== |
| 797 | |
| 798 | As usual, Python's standard library received a number of enhancements and bug |
| 799 | fixes. Here's a partial list of the most notable changes, sorted alphabetically |
| 800 | by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more |
| 801 | complete list of changes, or look through the CVS logs for all the details. |
| 802 | |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 803 | * The :mod:`bsddb.dbshelve` module now uses the highest pickling protocol |
| 804 | available, instead of restricting itself to protocol 1. |
| 805 | (Contributed by W. Barnes.) |
| 806 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 807 | .. Patch 1551443 |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 808 | |
Andrew M. Kuchling | 6d57c82 | 2007-10-23 20:55:47 +0000 | [diff] [blame] | 809 | * A new data type in the :mod:`collections` module: :class:`namedtuple(typename, |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 810 | fieldnames)` is a factory function that creates subclasses of the standard tuple |
| 811 | whose fields are accessible by name as well as index. For example:: |
| 812 | |
Andrew M. Kuchling | 6d57c82 | 2007-10-23 20:55:47 +0000 | [diff] [blame] | 813 | >>> var_type = collections.namedtuple('variable', |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 814 | ... 'id name type size') |
| 815 | # Names are separated by spaces or commas. |
| 816 | # 'id, name, type, size' would also work. |
Raymond Hettinger | 366523c | 2007-12-14 18:12:21 +0000 | [diff] [blame] | 817 | >>> var_type._fields |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 818 | ('id', 'name', 'type', 'size') |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 819 | |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 820 | >>> var = var_type(1, 'frequency', 'int', 4) |
| 821 | >>> print var[0], var.id # Equivalent |
| 822 | 1 1 |
| 823 | >>> print var[2], var.type # Equivalent |
| 824 | int int |
Raymond Hettinger | 366523c | 2007-12-14 18:12:21 +0000 | [diff] [blame] | 825 | >>> var._asdict() |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 826 | {'size': 4, 'type': 'int', 'id': 1, 'name': 'frequency'} |
Raymond Hettinger | 366523c | 2007-12-14 18:12:21 +0000 | [diff] [blame] | 827 | >>> v2 = var._replace('name', 'amplitude') |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 828 | >>> v2 |
| 829 | variable(id=1, name='amplitude', type='int', size=4) |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 830 | |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 831 | Where the new :class:`namedtuple` type proved suitable, the standard |
| 832 | library has been modified to return them. For example, |
| 833 | the :meth:`Decimal.as_tuple` method now returns a named tuple with |
| 834 | :attr:`sign`, :attr:`digits`, and :attr:`exponent` fields. |
| 835 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 836 | (Contributed by Raymond Hettinger.) |
| 837 | |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 838 | * Another change to the :mod:`collections` module is that the |
Georg Brandl | e7d118a | 2007-12-08 11:05:05 +0000 | [diff] [blame] | 839 | :class:`deque` type now supports an optional *maxlen* parameter; |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 840 | if supplied, the deque's size will be restricted to no more |
Georg Brandl | e7d118a | 2007-12-08 11:05:05 +0000 | [diff] [blame] | 841 | than *maxlen* items. Adding more items to a full deque causes |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 842 | old items to be discarded. |
| 843 | |
| 844 | :: |
| 845 | |
| 846 | >>> from collections import deque |
| 847 | >>> dq=deque(maxlen=3) |
| 848 | >>> dq |
| 849 | deque([], maxlen=3) |
| 850 | >>> dq.append(1) ; dq.append(2) ; dq.append(3) |
| 851 | >>> dq |
| 852 | deque([1, 2, 3], maxlen=3) |
| 853 | >>> dq.append(4) |
| 854 | >>> dq |
| 855 | deque([2, 3, 4], maxlen=3) |
| 856 | |
| 857 | (Contributed by Raymond Hettinger.) |
| 858 | |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 859 | * The :mod:`ctypes` module now supports a :class:`c_bool` datatype |
| 860 | that represents the C99 ``bool`` type. (Contributed by David Remahl.) |
| 861 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 862 | .. Patch 1649190 |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 863 | |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 864 | The :mod:`ctypes` string, buffer and array types also have improved |
| 865 | support for extended slicing syntax, |
| 866 | where various combinations of ``(start, stop, step)`` are supplied. |
| 867 | (Implemented by Thomas Wouters.) |
| 868 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 869 | .. Revision 57769 |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 870 | |
| 871 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 872 | * A new method in the :mod:`curses` module: for a window, :meth:`chgat` changes |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 873 | the display characters for a certain number of characters on a single line. |
| 874 | :: |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 875 | |
| 876 | # Boldface text starting at y=0,x=21 |
| 877 | # and affecting the rest of the line. |
| 878 | stdscr.chgat(0,21, curses.A_BOLD) |
| 879 | |
| 880 | (Contributed by Fabian Kreutz.) |
| 881 | |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 882 | * The :mod:`decimal` module was updated to version 1.66 of |
| 883 | `the General Decimal Specification <http://www2.hursley.ibm.com/decimal/decarith.html>`__. New features |
| 884 | include some methods for some basic mathematical functions such as |
| 885 | :meth:`exp` and :meth:`log10`:: |
| 886 | |
| 887 | >>> Decimal(1).exp() |
| 888 | Decimal("2.718281828459045235360287471") |
| 889 | >>> Decimal("2.7182818").ln() |
| 890 | Decimal("0.9999999895305022877376682436") |
| 891 | >>> Decimal(1000).log10() |
| 892 | Decimal("3") |
| 893 | |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 894 | The :meth:`as_tuple` method of :class:`Decimal` objects now returns a |
| 895 | named tuple with :attr:`sign`, :attr:`digits`, and :attr:`exponent` fields. |
| 896 | |
| 897 | (Implemented by Facundo Batista and Mark Dickinson. Named tuple |
| 898 | support added by Raymond Hettinger.) |
| 899 | |
| 900 | * The :mod:`difflib` module's :class:`SequenceMatcher` class |
| 901 | now returns named tuples representing matches. |
| 902 | In addition to behaving like tuples, the returned values |
| 903 | also have :attr:`a`, :attr:`b`, and :attr:`size` attributes. |
| 904 | (Contributed by Raymond Hettinger.) |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 905 | |
Andrew M. Kuchling | b4c6295 | 2007-09-01 21:18:31 +0000 | [diff] [blame] | 906 | * An optional ``timeout`` parameter was added to the |
| 907 | :class:`ftplib.FTP` class constructor as well as the :meth:`connect` |
| 908 | method, specifying a timeout measured in seconds. (Added by Facundo |
| 909 | Batista.) |
| 910 | |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 911 | * The :func:`reduce` built-in function is also available in the |
| 912 | :mod:`functools` module. In Python 3.0, the built-in is dropped and it's |
| 913 | only available from :mod:`functools`; currently there are no plans |
| 914 | to drop the built-in in the 2.x series. (Patched by |
| 915 | Christian Heimes.) |
| 916 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 917 | .. Patch 1739906 |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 918 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 919 | * The :func:`glob.glob` function can now return Unicode filenames if |
| 920 | a Unicode path was used and Unicode filenames are matched within the directory. |
| 921 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 922 | .. Patch #1001604 |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 923 | |
| 924 | * The :mod:`gopherlib` module has been removed. |
| 925 | |
| 926 | * A new function in the :mod:`heapq` module: ``merge(iter1, iter2, ...)`` |
| 927 | takes any number of iterables that return data *in sorted order*, and returns |
| 928 | a new iterator that returns the contents of all the iterators, also in sorted |
| 929 | order. For example:: |
| 930 | |
| 931 | heapq.merge([1, 3, 5, 9], [2, 8, 16]) -> |
| 932 | [1, 2, 3, 5, 8, 9, 16] |
| 933 | |
| 934 | (Contributed by Raymond Hettinger.) |
| 935 | |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 936 | * An optional ``timeout`` parameter was added to the |
| 937 | :class:`httplib.HTTPConnection` and :class:`HTTPSConnection` |
| 938 | class constructors, specifying a timeout measured in seconds. |
| 939 | (Added by Facundo Batista.) |
| 940 | |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 941 | * Most of the :mod:`inspect` module's functions, such as |
| 942 | :func:`getmoduleinfo` and :func:`getargs`, now return named tuples. |
| 943 | In addition to behaving like tuples, the elements of the return value |
| 944 | can also be accessed as attributes. |
| 945 | (Contributed by Raymond Hettinger.) |
| 946 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 947 | * A new function in the :mod:`itertools` module: ``izip_longest(iter1, iter2, |
| 948 | ...[, fillvalue])`` makes tuples from each of the elements; if some of the |
| 949 | iterables are shorter than others, the missing values are set to *fillvalue*. |
| 950 | For example:: |
| 951 | |
| 952 | itertools.izip_longest([1,2,3], [1,2,3,4,5]) -> |
| 953 | [(1, 1), (2, 2), (3, 3), (None, 4), (None, 5)] |
| 954 | |
| 955 | (Contributed by Raymond Hettinger.) |
| 956 | |
| 957 | * The :mod:`macfs` module has been removed. This in turn required the |
| 958 | :func:`macostools.touched` function to be removed because it depended on the |
| 959 | :mod:`macfs` module. |
| 960 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 961 | .. Patch #1490190 |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 962 | |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 963 | * The :mod:`new` module has been removed from Python 3.0. |
| 964 | Importing it therefore |
| 965 | triggers a warning message when Python is running in 3.0-warning |
| 966 | mode. |
| 967 | |
| 968 | * New functions in the :mod:`os` module include |
| 969 | ``fchmod(fd, mode)``, ``fchown(fd, uid, gid)``, |
| 970 | and ``lchmod(path, mode)``, on operating systems that support these |
| 971 | functions. :func:`fchmod` and :func:`fchown` let you change the mode |
| 972 | and ownership of an opened file, and :func:`lchmod` changes the mode |
| 973 | of a symlink. |
| 974 | |
| 975 | (Contributed by Georg Brandl and Christian Heimes.) |
| 976 | |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 977 | * The :func:`os.walk` function now has a ``followlinks`` parameter. If |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 978 | set to True, it will follow symlinks pointing to directories and |
| 979 | visit the directory's contents. For backward compatibility, the |
| 980 | parameter's default value is false. Note that the function can fall |
| 981 | into an infinite recursion if there's a symlink that points to a |
| 982 | parent directory. |
| 983 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 984 | .. Patch 1273829 |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 985 | |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 986 | * The ``os.environ`` object's :meth:`clear` method will now unset the |
| 987 | environment variables using :func:`os.unsetenv` in addition to clearing |
Andrew M. Kuchling | e34d289 | 2007-10-20 19:35:18 +0000 | [diff] [blame] | 988 | the object's keys. (Contributed by Martin Horcicka.) |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 989 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 990 | .. Patch #1181 |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 991 | |
Andrew M. Kuchling | 6c066dd | 2007-09-01 20:43:36 +0000 | [diff] [blame] | 992 | * In the :mod:`os.path` module, the :func:`splitext` function |
| 993 | has been changed to not split on leading period characters. |
| 994 | This produces better results when operating on Unix's dot-files. |
| 995 | For example, ``os.path.splitext('.ipython')`` |
| 996 | now returns ``('.ipython', '')`` instead of ``('', '.ipython')``. |
| 997 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 998 | .. Bug #115886 |
Andrew M. Kuchling | 6c066dd | 2007-09-01 20:43:36 +0000 | [diff] [blame] | 999 | |
Andrew M. Kuchling | b4c6295 | 2007-09-01 21:18:31 +0000 | [diff] [blame] | 1000 | A new function, :func:`relpath(path, start)` returns a relative path |
| 1001 | from the ``start`` path, if it's supplied, or from the current |
| 1002 | working directory to the destination ``path``. (Contributed by |
| 1003 | Richard Barran.) |
| 1004 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1005 | .. Patch 1339796 |
Andrew M. Kuchling | b4c6295 | 2007-09-01 21:18:31 +0000 | [diff] [blame] | 1006 | |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 1007 | On Windows, :func:`os.path.expandvars` will now expand environment variables |
| 1008 | in the form "%var%", and "~user" will be expanded into the |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 1009 | user's home directory path. (Contributed by Josiah Carlson.) |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 1010 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1011 | .. Patch 957650 |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 1012 | |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 1013 | * The Python debugger provided by the :mod:`pdb` module |
| 1014 | gained a new command: "run" restarts the Python program being debugged, |
| 1015 | and can optionally take new command-line arguments for the program. |
| 1016 | (Contributed by Rocky Bernstein.) |
| 1017 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1018 | .. Patch #1393667 |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 1019 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1020 | * New functions in the :mod:`posix` module: :func:`chflags` and :func:`lchflags` |
| 1021 | are wrappers for the corresponding system calls (where they're available). |
| 1022 | Constants for the flag values are defined in the :mod:`stat` module; some |
| 1023 | possible values include :const:`UF_IMMUTABLE` to signal the file may not be |
| 1024 | changed and :const:`UF_APPEND` to indicate that data can only be appended to the |
| 1025 | file. (Contributed by M. Levinson.) |
| 1026 | |
Andrew M. Kuchling | e0a49b6 | 2008-01-08 14:30:55 +0000 | [diff] [blame] | 1027 | * The :mod:`pyexpat` module's :class:`Parser` objects now allow setting |
| 1028 | their :attr:`buffer_size` attribute to change the size of the buffer |
| 1029 | used to hold character data. |
| 1030 | (Contributed by Achim Gaedke.) |
| 1031 | |
| 1032 | .. Patch 1137 |
| 1033 | |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 1034 | * The :mod:`random` module's :class:`Random` objects can |
| 1035 | now be pickled on a 32-bit system and unpickled on a 64-bit |
| 1036 | system, and vice versa. Unfortunately, this change also means |
| 1037 | that Python 2.6's :class:`Random` objects can't be unpickled correctly |
| 1038 | on earlier versions of Python. |
| 1039 | (Contributed by Shawn Ligocki.) |
| 1040 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1041 | .. Issue 1727780 |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 1042 | |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 1043 | * Long regular expression searches carried out by the :mod:`re` |
| 1044 | module will now check for signals being delivered, so especially |
| 1045 | long searches can now be interrupted. |
| 1046 | (Contributed by Josh Hoyt and Ralf Schmitt.) |
| 1047 | |
| 1048 | .. % Patch 846388 |
| 1049 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1050 | * The :mod:`rgbimg` module has been removed. |
| 1051 | |
Andrew M. Kuchling | e34d289 | 2007-10-20 19:35:18 +0000 | [diff] [blame] | 1052 | * The :mod:`sets` module has been deprecated; it's better to |
| 1053 | use the built-in :class:`set` and :class:`frozenset` types. |
| 1054 | |
Andrew M. Kuchling | 2d60cf7 | 2007-12-22 17:27:02 +0000 | [diff] [blame] | 1055 | * Integrating signal handling with GUI handling event loops |
| 1056 | like those used by Tkinter or GTk+ has long been a problem; most |
| 1057 | software ends up polling, waking up every fraction of a second. Thi |
| 1058 | The :mod:`signal` module can now make this more efficient. |
| 1059 | Calling ``signal.set_wakeup_fd(fd)`` sets a file descriptor |
| 1060 | to be used; when a signal is received, a byte is written to that |
| 1061 | file descriptor. There's also a C-level function, |
| 1062 | :cfunc:`PySignal_SetWakeupFd`, for setting the descriptor. |
| 1063 | |
| 1064 | Event loops will use this by opening a pipe to create two descriptors, |
| 1065 | one for reading and one for writing. The writeable descriptor |
| 1066 | will be passed to :func:`set_wakeup_fd`, and the readable descriptor |
| 1067 | will be added to the list of descriptors monitored by the event loop via |
| 1068 | :cfunc:`select` or :cfunc:`poll`. |
| 1069 | On receiving a signal, a byte will be written and the main event loop |
| 1070 | will be woken up, without the need to poll. |
| 1071 | |
| 1072 | Contributed by Adam Olsen. |
| 1073 | |
| 1074 | .. % Patch 1583 |
| 1075 | |
Andrew M. Kuchling | 6c066dd | 2007-09-01 20:43:36 +0000 | [diff] [blame] | 1076 | * The :mod:`smtplib` module now supports SMTP over SSL thanks to the |
| 1077 | addition of the :class:`SMTP_SSL` class. This class supports an |
Andrew M. Kuchling | b4c6295 | 2007-09-01 21:18:31 +0000 | [diff] [blame] | 1078 | interface identical to the existing :class:`SMTP` class. Both |
| 1079 | class constructors also have an optional ``timeout`` parameter |
| 1080 | that specifies a timeout for the initial connection attempt, measured in |
| 1081 | seconds. |
| 1082 | |
| 1083 | An implementation of the LMTP protocol (:rfc:`2033`) was also added to |
Andrew M. Kuchling | 6c066dd | 2007-09-01 20:43:36 +0000 | [diff] [blame] | 1084 | the module. LMTP is used in place of SMTP when transferring e-mail |
| 1085 | between agents that don't manage a mail queue. |
Andrew M. Kuchling | b4c6295 | 2007-09-01 21:18:31 +0000 | [diff] [blame] | 1086 | |
| 1087 | (SMTP over SSL contributed by Monty Taylor; timeout parameter |
| 1088 | added by Facundo Batista; LMTP implemented by Leif |
Andrew M. Kuchling | 6c066dd | 2007-09-01 20:43:36 +0000 | [diff] [blame] | 1089 | Hedstrom.) |
| 1090 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1091 | .. Patch #957003 |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1092 | |
Gregory P. Smith | 63bfc1d | 2008-01-17 07:43:20 +0000 | [diff] [blame] | 1093 | * In the :mod:`smtplib` module, SMTP.starttls() now complies with :rfc:`3207` |
| 1094 | and forgets any knowledge obtained from the server not obtained from |
| 1095 | the TLS negotiation itself. Patch contributed by Bill Fenner. |
| 1096 | |
| 1097 | .. Issue 829951 |
| 1098 | |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 1099 | * The :mod:`socket` module now supports TIPC (http://tipc.sf.net), |
| 1100 | a high-performance non-IP-based protocol designed for use in clustered |
| 1101 | environments. TIPC addresses are 4- or 5-tuples. |
| 1102 | (Contributed by Alberto Bertogli.) |
| 1103 | |
| 1104 | .. Patch #1646 |
Andrew M. Kuchling | f60b641 | 2008-01-19 16:34:09 +0000 | [diff] [blame^] | 1105 | |
| 1106 | * The base classes in the :mod:`SocketServer` module now support |
| 1107 | calling a :meth:`handle_timeout` method after a span of inactivity |
| 1108 | specified by the server's :attr:`timeout` attribute. (Contributed |
| 1109 | by Michael Pomraning.) |
| 1110 | |
| 1111 | .. Patch #742598 |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 1112 | |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 1113 | * A new variable in the :mod:`sys` module, |
Andrew M. Kuchling | 5d8b379 | 2008-01-14 14:48:43 +0000 | [diff] [blame] | 1114 | :attr:`float_info`, is an object |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 1115 | containing information about the platform's floating-point support |
Andrew M. Kuchling | 5d8b379 | 2008-01-14 14:48:43 +0000 | [diff] [blame] | 1116 | derived from the :file:`float.h` file. Attributes of this object |
| 1117 | include |
| 1118 | :attr:`mant_dig` (number of digits in the mantissa), :attr:`epsilon` |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 1119 | (smallest difference between 1.0 and the next largest value |
| 1120 | representable), and several others. (Contributed by Christian Heimes.) |
| 1121 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1122 | .. Patch 1534 |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 1123 | |
Andrew M. Kuchling | 7b1e917 | 2008-01-15 14:38:05 +0000 | [diff] [blame] | 1124 | Another new variable, :attr:`dont_write_bytecode`, controls whether Python |
| 1125 | writes any :file:`.pyc` or :file:`.pyo` files on importing a module. |
| 1126 | If this variable is true, the compiled files are not written. The |
| 1127 | variable is initially set on start-up by supplying the :option:`-B` |
| 1128 | switch to the Python interpreter, or by setting the |
| 1129 | :envvar:`PYTHONDONTWRITEBYTECODE` environment variable before |
| 1130 | running the interpreter. Python code can subsequently |
| 1131 | change the value of this variable to control whether bytecode files |
| 1132 | are written or not. |
| 1133 | (Contributed by Neal Norwitz and Georg Brandl.) |
| 1134 | |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 1135 | Information about the command-line arguments supplied to the Python |
| 1136 | interpreter are available as attributes of a ``sys.flags`` named |
| 1137 | tuple. For example, the :attr:`verbose` attribute is true if Python |
| 1138 | was executed in verbose mode, :attr:`debug` is true in debugging mode, etc. |
| 1139 | These attributes are all read-only. |
| 1140 | (Contributed by Christian Heimes.) |
| 1141 | |
Andrew M. Kuchling | de37a8c | 2007-09-18 01:36:16 +0000 | [diff] [blame] | 1142 | * The :mod:`tarfile` module now supports POSIX.1-2001 (pax) and |
| 1143 | POSIX.1-1988 (ustar) format tarfiles, in addition to the GNU tar |
| 1144 | format that was already supported. The default format |
| 1145 | is GNU tar; specify the ``format`` parameter to open a file |
| 1146 | using a different format:: |
| 1147 | |
| 1148 | tar = tarfile.open("output.tar", "w", format=tarfile.PAX_FORMAT) |
| 1149 | |
| 1150 | The new ``errors`` parameter lets you specify an error handling |
| 1151 | scheme for character conversions: the three standard ways Python can |
| 1152 | handle errors ``'strict'``, ``'ignore'``, ``'replace'`` , or the |
| 1153 | special value ``'utf-8'``, which replaces bad characters with their |
| 1154 | UTF-8 representation. Character conversions occur because the PAX |
| 1155 | format supports Unicode filenames, defaulting to UTF-8 encoding. |
| 1156 | |
| 1157 | The :meth:`TarFile.add` method now accepts a ``exclude`` argument that's |
| 1158 | a function that can be used to exclude certain filenames from |
| 1159 | an archive. |
| 1160 | The function must take a filename and return true if the file |
| 1161 | should be excluded or false if it should be archived. |
| 1162 | The function is applied to both the name initially passed to :meth:`add` |
| 1163 | and to the names of files in recursively-added directories. |
| 1164 | |
| 1165 | (All changes contributed by Lars Gustäbel). |
| 1166 | |
| 1167 | * An optional ``timeout`` parameter was added to the |
| 1168 | :class:`telnetlib.Telnet` class constructor, specifying a timeout |
| 1169 | measured in seconds. (Added by Facundo Batista.) |
| 1170 | |
| 1171 | * The :class:`tempfile.NamedTemporaryFile` class usually deletes |
| 1172 | the temporary file it created when the file is closed. This |
| 1173 | behaviour can now be changed by passing ``delete=False`` to the |
| 1174 | constructor. (Contributed by Damien Miller.) |
| 1175 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1176 | .. Patch #1537850 |
Andrew M. Kuchling | de37a8c | 2007-09-18 01:36:16 +0000 | [diff] [blame] | 1177 | |
| 1178 | * The :mod:`test.test_support` module now contains a |
| 1179 | :func:`EnvironmentVarGuard` |
| 1180 | context manager that supports temporarily changing environment variables and |
| 1181 | automatically restores them to their old values. |
| 1182 | |
| 1183 | Another context manager, :class:`TransientResource`, can surround calls |
| 1184 | to resources that may or may not be available; it will catch and |
| 1185 | ignore a specified list of exceptions. For example, |
| 1186 | a network test may ignore certain failures when connecting to an |
| 1187 | external web site:: |
| 1188 | |
| 1189 | with test_support.TransientResource(IOError, errno=errno.ETIMEDOUT): |
| 1190 | f = urllib.urlopen('https://sf.net') |
| 1191 | ... |
| 1192 | |
| 1193 | (Contributed by Brett Cannon.) |
| 1194 | |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 1195 | * The :mod:`textwrap` module can now preserve existing whitespace |
| 1196 | at the beginnings and ends of the newly-created lines |
| 1197 | by specifying ``drop_whitespace=False`` |
| 1198 | as an argument:: |
| 1199 | |
| 1200 | >>> S = """This sentence has a bunch of extra whitespace.""" |
| 1201 | >>> print textwrap.fill(S, width=15) |
| 1202 | This sentence |
| 1203 | has a bunch |
| 1204 | of extra |
| 1205 | whitespace. |
| 1206 | >>> print textwrap.fill(S, drop_whitespace=False, width=15) |
| 1207 | This sentence |
| 1208 | has a bunch |
| 1209 | of extra |
| 1210 | whitespace. |
| 1211 | >>> |
| 1212 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1213 | .. Patch #1581073 |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 1214 | |
Andrew M. Kuchling | 6c066dd | 2007-09-01 20:43:36 +0000 | [diff] [blame] | 1215 | * The :mod:`timeit` module now accepts callables as well as strings |
| 1216 | for the statement being timed and for the setup code. |
| 1217 | Two convenience functions were added for creating |
| 1218 | :class:`Timer` instances: |
| 1219 | ``repeat(stmt, setup, time, repeat, number)`` and |
| 1220 | ``timeit(stmt, setup, time, number)`` create an instance and call |
| 1221 | the corresponding method. (Contributed by Erik Demaine.) |
| 1222 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1223 | .. Patch #1533909 |
Andrew M. Kuchling | 6c066dd | 2007-09-01 20:43:36 +0000 | [diff] [blame] | 1224 | |
Andrew M. Kuchling | f10878b | 2007-09-13 22:49:34 +0000 | [diff] [blame] | 1225 | * An optional ``timeout`` parameter was added to the |
| 1226 | :func:`urllib.urlopen` function and the |
| 1227 | :class:`urllib.ftpwrapper` class constructor, as well as the |
| 1228 | :func:`urllib2.urlopen` function. The parameter specifies a timeout |
| 1229 | measured in seconds. For example:: |
| 1230 | |
| 1231 | >>> u = urllib2.urlopen("http://slow.example.com", timeout=3) |
| 1232 | Traceback (most recent call last): |
| 1233 | ... |
| 1234 | urllib2.URLError: <urlopen error timed out> |
| 1235 | >>> |
| 1236 | |
| 1237 | (Added by Facundo Batista.) |
| 1238 | |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 1239 | * The XML-RPC classes :class:`SimpleXMLRPCServer` and :class:`DocXMLRPCServer` |
Andrew M. Kuchling | e34d289 | 2007-10-20 19:35:18 +0000 | [diff] [blame] | 1240 | classes can now be prevented from immediately opening and binding to |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 1241 | their socket by passing True as the ``bind_and_activate`` |
| 1242 | constructor parameter. This can be used to modify the instance's |
| 1243 | :attr:`allow_reuse_address` attribute before calling the |
| 1244 | :meth:`server_bind` and :meth:`server_activate` methods to |
| 1245 | open the socket and begin listening for connections. |
| 1246 | (Contributed by Peter Parente.) |
| 1247 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1248 | .. Patch 1599845 |
Andrew M. Kuchling | 99479eb | 2007-09-25 00:09:42 +0000 | [diff] [blame] | 1249 | |
Andrew M. Kuchling | e34d289 | 2007-10-20 19:35:18 +0000 | [diff] [blame] | 1250 | :class:`SimpleXMLRPCServer` also has a :attr:`_send_traceback_header` |
| 1251 | attribute; if true, the exception and formatted traceback are returned |
| 1252 | as HTTP headers "X-Exception" and "X-Traceback". This feature is |
| 1253 | for debugging purposes only and should not be used on production servers |
| 1254 | because the tracebacks could possibly reveal passwords or other sensitive |
| 1255 | information. (Contributed by Alan McIntyre as part of his |
| 1256 | project for Google's Summer of Code 2007.) |
| 1257 | |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 1258 | * The :mod:`zipfile` module's :class:`ZipFile` class now has |
| 1259 | :meth:`extract` and :meth:`extractall` methods that will unpack |
| 1260 | a single file or all the files in the archive to the current directory, or |
| 1261 | to a specified directory:: |
| 1262 | |
| 1263 | z = zipfile.ZipFile('python-251.zip') |
| 1264 | |
| 1265 | # Unpack a single file, writing it relative to the /tmp directory. |
| 1266 | z.extract('Python/sysmodule.c', '/tmp') |
| 1267 | |
| 1268 | # Unpack all the files in the archive. |
| 1269 | z.extractall() |
| 1270 | |
| 1271 | (Contributed by Alan McIntyre.) |
| 1272 | .. % Patch 467924 |
| 1273 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1274 | .. ====================================================================== |
| 1275 | .. whole new modules get described in subsections here |
Andrew M. Kuchling | e34d289 | 2007-10-20 19:35:18 +0000 | [diff] [blame] | 1276 | |
| 1277 | Improved SSL Support |
Andrew M. Kuchling | 27a4498 | 2007-10-20 19:39:35 +0000 | [diff] [blame] | 1278 | -------------------------------------------------- |
Andrew M. Kuchling | e34d289 | 2007-10-20 19:35:18 +0000 | [diff] [blame] | 1279 | |
| 1280 | Bill Janssen made extensive improvements to Python 2.6's support for |
| 1281 | SSL. |
| 1282 | |
| 1283 | XXX use ssl.sslsocket - subclass of socket.socket. |
| 1284 | |
| 1285 | XXX Can specify if certificate is required, and obtain certificate info |
| 1286 | by calling getpeercert method. |
| 1287 | |
| 1288 | XXX sslwrap() behaves like socket.ssl |
| 1289 | |
| 1290 | XXX Certain features require the OpenSSL package to be installed, notably |
| 1291 | the 'openssl' binary. |
| 1292 | |
| 1293 | .. seealso:: |
| 1294 | |
| 1295 | SSL module documentation. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1296 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1297 | .. ====================================================================== |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1298 | |
| 1299 | |
| 1300 | Build and C API Changes |
| 1301 | ======================= |
| 1302 | |
| 1303 | Changes to Python's build process and to the C API include: |
| 1304 | |
Andrew M. Kuchling | f7b462f | 2007-11-23 13:37:39 +0000 | [diff] [blame] | 1305 | * Python 2.6 can be built with Microsoft Visual Studio 2008. |
| 1306 | See the :file:`PCbuild9` directory for the build files. |
| 1307 | (Implemented by Christian Heimes.) |
| 1308 | |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 1309 | * The BerkeleyDB module now has a C API object, available as |
| 1310 | ``bsddb.db.api``. This object can be used by other C extensions |
| 1311 | that wish to use the :mod:`bsddb` module for their own purposes. |
| 1312 | (Contributed by Duncan Grisby.) |
| 1313 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1314 | .. Patch 1551895 |
Andrew M. Kuchling | 6edff59 | 2007-10-16 22:58:03 +0000 | [diff] [blame] | 1315 | |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 1316 | * Several functions return information about the platform's |
| 1317 | floating-point support. :cfunc:`PyFloat_GetMax` returns |
| 1318 | the maximum representable floating point value, |
| 1319 | and :cfunc:`PyFloat_GetMin` returns the minimum |
| 1320 | positive value. :cfunc:`PyFloat_GetInfo` returns a dictionary |
| 1321 | containing more information from the :file:`float.h` file, such as |
| 1322 | ``"mant_dig"`` (number of digits in the mantissa), ``"epsilon"`` |
| 1323 | (smallest difference between 1.0 and the next largest value |
| 1324 | representable), and several others. |
Christian Heimes | d0d7d87 | 2008-01-04 02:03:25 +0000 | [diff] [blame] | 1325 | (Contributed by Christian Heimes.) |
Andrew M. Kuchling | d586559 | 2007-12-19 02:02:04 +0000 | [diff] [blame] | 1326 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1327 | .. Issue 1534 |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1328 | |
Andrew M. Kuchling | 654ede7 | 2008-01-04 01:16:12 +0000 | [diff] [blame] | 1329 | * Python's C API now includes two functions for case-insensitive string |
| 1330 | comparisions, ``PyOS_stricmp(char*, char*)`` |
| 1331 | and ``PyOS_strnicmp(char*, char*, Py_ssize_t)``. |
Christian Heimes | d0d7d87 | 2008-01-04 02:03:25 +0000 | [diff] [blame] | 1332 | (Contributed by Christian Heimes.) |
Andrew M. Kuchling | 654ede7 | 2008-01-04 01:16:12 +0000 | [diff] [blame] | 1333 | |
| 1334 | .. Issue 1635 |
| 1335 | |
Andrew M. Kuchling | 3b55470 | 2008-01-04 02:31:40 +0000 | [diff] [blame] | 1336 | * Some macros were renamed to make it clearer that they are macros, |
| 1337 | not functions. :cmacro:`Py_Size()` became :cmacro:`Py_SIZE()`, |
Andrew M. Kuchling | 654ede7 | 2008-01-04 01:16:12 +0000 | [diff] [blame] | 1338 | :cmacro:`Py_Type()` became :cmacro:`Py_TYPE()`, and |
| 1339 | :cmacro:`Py_Refcnt()` became :cmacro:`Py_REFCNT()`. Macros for backward |
Christian Heimes | d0d7d87 | 2008-01-04 02:03:25 +0000 | [diff] [blame] | 1340 | compatibility are still available for Python 2.6. |
Andrew M. Kuchling | 654ede7 | 2008-01-04 01:16:12 +0000 | [diff] [blame] | 1341 | |
Andrew M. Kuchling | 3b55470 | 2008-01-04 02:31:40 +0000 | [diff] [blame] | 1342 | .. Issue 1629 |
Andrew M. Kuchling | 654ede7 | 2008-01-04 01:16:12 +0000 | [diff] [blame] | 1343 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1344 | .. ====================================================================== |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1345 | |
| 1346 | |
Andrew M. Kuchling | 654ede7 | 2008-01-04 01:16:12 +0000 | [diff] [blame] | 1347 | Port-Specific Changes: Windows |
| 1348 | ----------------------------------- |
| 1349 | |
| 1350 | * The :mod:`msvcrt` module now supports |
| 1351 | both the normal and wide char variants of the console I/O |
| 1352 | API. The :func:`getwch` function reads a keypress and returns a Unicode |
| 1353 | value, as does the :func:`getwche` function. The :func:`putwch` function |
| 1354 | takes a Unicode character and writes it to the console. |
Christian Heimes | ff6cc6b | 2008-01-17 23:01:44 +0000 | [diff] [blame] | 1355 | (Contributed by Christian Heimes.) |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1356 | |
Andrew M. Kuchling | d221956 | 2008-01-17 12:00:15 +0000 | [diff] [blame] | 1357 | * :func:`os.path.expandvars` will now expand environment variables |
| 1358 | in the form "%var%", and "~user" will be expanded into the |
| 1359 | user's home directory path. (Contributed by Josiah Carlson.) |
| 1360 | |
| 1361 | * The :mod:`socket` module's socket objects now have an |
| 1362 | :meth:`ioctl` method that provides a limited interface to the |
| 1363 | :cfunc:`WSAIoctl` system interface. |
| 1364 | |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 1365 | * The :mod:`_winreg` module now has a function, |
| 1366 | :func:`ExpandEnvironmentStrings`, |
| 1367 | that expands environment variable references such as ``%NAME%`` |
| 1368 | in an input string. The handle objects provided by this |
| 1369 | module now support the context protocol, so they can be used |
Christian Heimes | ff6cc6b | 2008-01-17 23:01:44 +0000 | [diff] [blame] | 1370 | in :keyword:`with` statements. (Contributed by Christian Heimes.) |
| 1371 | |
| 1372 | * The new default compiler on Windows is Visual Studio 2008 (VS 9.0). The |
| 1373 | build directories for Visual Studio 2003 (VS7.1) and 2005 (VS8.0) |
| 1374 | were moved into the PC/ directory. The new PCbuild directory supports |
| 1375 | cross compilation for X64, debug builds and Profile Guided Optimization |
| 1376 | (PGO). PGO builds are roughly 10% faster than normal builds. |
| 1377 | (Contributed by Christian Heimes with help from Amaury Forgeot d'Arc and |
| 1378 | Martin von Loewis.) |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1379 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1380 | .. ====================================================================== |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1381 | |
| 1382 | |
| 1383 | .. _section-other: |
| 1384 | |
| 1385 | Other Changes and Fixes |
| 1386 | ======================= |
| 1387 | |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 1388 | As usual, there were a bunch of other improvements and bugfixes |
| 1389 | scattered throughout the source tree. A search through the change |
| 1390 | logs finds there were XXX patches applied and YYY bugs fixed between |
| 1391 | Python 2.5 and 2.6. Both figures are likely to be underestimates. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1392 | |
| 1393 | Some of the more notable changes are: |
| 1394 | |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 1395 | * It's now possible to prevent Python from writing any :file:`.pyc` |
| 1396 | or :file:`.pyo` files by either supplying the :option:`-B` switch |
| 1397 | or setting the :envvar:`PYTHONDONTWRITEBYTECODE` environment variable |
| 1398 | to any non-empty string when running the Python interpreter. These |
Georg Brandl | ca9c6e4 | 2008-01-15 06:58:15 +0000 | [diff] [blame] | 1399 | are also used to set the :data:`sys.dont_write_bytecode` attribute; |
| 1400 | Python code can change this variable to control whether bytecode |
| 1401 | files are subsequently written. |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 1402 | (Contributed by Neal Norwitz and Georg Brandl.) |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1403 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1404 | .. ====================================================================== |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1405 | |
| 1406 | |
| 1407 | Porting to Python 2.6 |
| 1408 | ===================== |
| 1409 | |
Andrew M. Kuchling | 654ede7 | 2008-01-04 01:16:12 +0000 | [diff] [blame] | 1410 | This section lists previously described changes, and a few |
| 1411 | esoteric bugfixes, that may require changes to your |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1412 | code: |
| 1413 | |
Andrew M. Kuchling | 73835bd | 2008-01-04 18:24:41 +0000 | [diff] [blame] | 1414 | * The :meth:`__init__` method of :class:`collections.deque` |
Andrew M. Kuchling | 654ede7 | 2008-01-04 01:16:12 +0000 | [diff] [blame] | 1415 | now clears any existing contents of the deque |
| 1416 | before adding elements from the iterable. This change makes the |
| 1417 | behavior match that of ``list.__init__()``. |
| 1418 | |
Andrew M. Kuchling | 2e46355 | 2008-01-15 01:47:32 +0000 | [diff] [blame] | 1419 | * The :class:`Decimal` constructor now accepts leading and trailing |
| 1420 | whitespace when passed a string. Previously it would raise an |
| 1421 | :exc:`InvalidOperation` exception. On the other hand, the |
| 1422 | :meth:`create_decimal` method of :class:`Context` objects now |
| 1423 | explicitly disallows extra whitespace, raising a |
| 1424 | :exc:`ConversionSyntax` exception. |
| 1425 | |
| 1426 | * Due to an implementation accident, if you passed a file path to |
| 1427 | the built-in :func:`__import__` function, it would actually import |
| 1428 | the specified file. This was never intended to work, however, and |
| 1429 | the implementation now explicitly checks for this case and raises |
| 1430 | an :exc:`ImportError`. |
| 1431 | |
Andrew M. Kuchling | e34d289 | 2007-10-20 19:35:18 +0000 | [diff] [blame] | 1432 | * The :mod:`socket` module exception :exc:`socket.error` now inherits |
| 1433 | from :exc:`IOError`. Previously it wasn't a subclass of |
| 1434 | :exc:`StandardError` but now it is, through :exc:`IOError`. |
| 1435 | (Implemented by Gregory P. Smith.) |
| 1436 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1437 | .. Issue 1706815 |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1438 | |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 1439 | .. ====================================================================== |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 1440 | |
| 1441 | |
| 1442 | .. _acks: |
| 1443 | |
| 1444 | Acknowledgements |
| 1445 | ================ |
| 1446 | |
| 1447 | The author would like to thank the following people for offering suggestions, |
| 1448 | corrections and assistance with various drafts of this article: . |
| 1449 | |