diff -r 4fc7bc1a4e25 Doc/reference/executionmodel.rst --- a/Doc/reference/executionmodel.rst Sun Mar 07 06:50:34 2010 +0100 +++ b/Doc/reference/executionmodel.rst Sun Mar 07 07:20:12 2010 +0100 @@ -22,9 +22,10 @@ Naming and binding single: name pair: binding; name -:dfn:`Names` refer to objects. Names are introduced by name binding operations. -Each occurrence of a name in the program text refers to the :dfn:`binding` of -that name established in the innermost function block containing the use. +:dfn:`Names` refer to objects. Names are introduced by name binding +operations. Each occurrence of a name in the program text refers to the +:dfn:`binding` of that name established in the innermost function block +containing the use. .. index:: single: block @@ -234,14 +235,15 @@ be raised along with the identifying str .. note:: Messages to exceptions are not part of the Python API. Their contents may - change from one version of Python to the next without warning and should not be - relied on by code which will run under multiple versions of the interpreter. + change from one version of Python to the next without warning and should not + be relied on by code which will run under multiple versions of the + interpreter. See also the description of the :keyword:`try` statement in section :ref:`try` and :keyword:`raise` statement in section :ref:`raise`. .. rubric:: Footnotes -.. [#] This limitation occurs because the code that is executed by these operations is - not available at the time the module is compiled. +.. [#] This limitation occurs because the code that is executed by these + operations is not available at the time the module is compiled. diff -r 4fc7bc1a4e25 Doc/whatsnew/2.6.rst --- a/Doc/whatsnew/2.6.rst Sun Mar 07 06:50:34 2010 +0100 +++ b/Doc/whatsnew/2.6.rst Sun Mar 07 07:20:12 2010 +0100 @@ -347,13 +347,13 @@ A high-level explanation of the context * The code in *BLOCK* is executed. * If *BLOCK* raises an exception, the context manager's :meth:`__exit__` method - is called with three arguments, the exception details (``type, value, traceback``, - the same values returned by :func:`sys.exc_info`, which can also be ``None`` - if no exception occurred). The method's return value controls whether an exception - is re-raised: any false value re-raises the exception, and ``True`` will result - in suppressing it. You'll only rarely want to suppress the exception, because - if you do the author of the code containing the ':keyword:`with`' statement will - never realize anything went wrong. + is called with three arguments, the exception details (``type, value, + traceback``, the same values returned by :func:`sys.exc_info`, which can also + be ``None`` if no exception occurred). The method's return value controls + whether an exception is re-raised: any false value re-raises the exception, + and ``True`` will result in suppressing it. You'll only rarely want to + suppress the exception, because if you do the author of the code containing + the ':keyword:`with`' statement will never realize anything went wrong. * If *BLOCK* didn't raise an exception, the :meth:`__exit__` method is still called, but *type*, *value*, and *traceback* are all ``None``. @@ -367,8 +367,8 @@ meaning that all the changes are written meaning that the changes are all discarded and the database is unchanged. See any database textbook for more information.) -Let's assume there's an object representing a database connection. Our goal will -be to let the user write code like this:: +Let's assume there's an object representing a database connection. Our goal +will be to let the user write code like this:: db_connection = DatabaseConnection() with db_connection as cursor: @@ -390,9 +390,10 @@ rolled back if there's an exception. Her "Rolls back current transaction" The :meth:`__enter__` method is pretty easy, having only to start a new -transaction. For this application the resulting cursor object would be a useful -result, so the method will return it. The user can then add ``as cursor`` to -their ':keyword:`with`' statement to bind the cursor to a variable name. :: +transaction. For this application the resulting cursor object would be a +useful result, so the method will return it. The user can then add +``as cursor`` to their ':keyword:`with`' statement to bind the cursor to a +variable name. :: class DatabaseConnection: ... @@ -403,8 +404,8 @@ their ':keyword:`with`' statement to bin The :meth:`__exit__` method is the most complicated because it's where most of the work has to be done. The method has to check if an exception occurred. If -there was no exception, the transaction is committed. The transaction is rolled -back if there was an exception. +there was no exception, the transaction is committed. The transaction is +rolled back if there was an exception. In the code below, execution will just fall off the end of the function, returning the default value of ``None``. ``None`` is false, so the exception @@ -437,8 +438,8 @@ exactly one value. The code up to the : :meth:`__enter__` method, and the value yielded will be the method's return value that will get bound to the variable in the ':keyword:`with`' statement's :keyword:`as` clause, if any. The code after the :keyword:`yield` will be -executed in the :meth:`__exit__` method. Any exception raised in the block will -be raised by the :keyword:`yield` statement. +executed in the :meth:`__exit__` method. Any exception raised in the block +will be raised by the :keyword:`yield` statement. Using this decorator, our database example from the previous section could be written as:: @@ -484,10 +485,10 @@ of the block. :: .. seealso:: :pep:`343` - The "with" statement - PEP written by Guido van Rossum and Nick Coghlan; implemented by Mike Bland, - Guido van Rossum, and Neal Norwitz. The PEP shows the code generated for a - ':keyword:`with`' statement, which can be helpful in learning how the statement - works. + PEP written by Guido van Rossum and Nick Coghlan; implemented by Mike + Bland, Guido van Rossum, and Neal Norwitz. The PEP shows the code + generated for a ':keyword:`with`' statement, which can be helpful in + learning how the statement works. The documentation for the :mod:`contextlib` module. @@ -1114,8 +1115,8 @@ treat memory-mapped files as a string of The primary users of the buffer protocol are numeric-processing packages such as NumPy, which expose the internal representation of arrays so that callers can write data directly into an array instead -of going through a slower API. This PEP updates the buffer protocol in light of experience -from NumPy development, adding a number of new features +of going through a slower API. This PEP updates the buffer protocol in +light of experience from NumPy development, adding a number of new features such as indicating the shape of an array or locking a memory region. The most important new C API function is @@ -1173,8 +1174,8 @@ dictionary-style access. The phrase "di It probably means that accessing items with ``obj[1]`` works. Does it imply that setting items with ``obj[2] = value`` works? Or that the object will have :meth:`keys`, :meth:`values`, and :meth:`items` -methods? What about the iterative variants such as :meth:`iterkeys`? :meth:`copy` -and :meth:`update`? Iterating over the object with :func:`iter`? +methods? What about the iterative variants such as :meth:`iterkeys`? +:meth:`copy` and :meth:`update`? Iterating over the object with :func:`iter`? The Python 2.6 :mod:`collections` module includes a number of different ABCs that represent these distinctions. :class:`Iterable` @@ -1511,8 +1512,8 @@ Some smaller changes made to the core Py (Contributed by Alexander Belopolsky; :issue:`1686487`.) - It's also become legal to provide keyword arguments after a ``*args`` argument - to a function call. :: + It's also become legal to provide keyword arguments after a ``*args`` + argument to a function call. :: >>> def f(*args, **kw): ... print args, kw @@ -1845,9 +1846,10 @@ changes, or look through the Subversion special values and floating-point exceptions in a manner consistent with Annex 'G' of the C99 standard. -* A new data type in the :mod:`collections` module: :class:`namedtuple(typename, - fieldnames)` is a factory function that creates subclasses of the standard tuple - whose fields are accessible by name as well as index. For example:: +* A new data type in the :mod:`collections` module: + :class:`namedtuple(typename, fieldnames)` is a factory function that creates + subclasses of the standard tuple whose fields are accessible by name as well + as index. For example:: >>> var_type = collections.namedtuple('variable', ... 'id name type size') @@ -1921,7 +1923,8 @@ changes, or look through the Subversion the left to six places. (Contributed by Skip Montanaro; :issue:`1158`.) * The :mod:`decimal` module was updated to version 1.66 of - `the General Decimal Specification `__. New features + `the General Decimal Specification + `__. New features include some methods for some basic mathematical functions such as :meth:`exp` and :meth:`log10`::