Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/reference/compound_stmts.rst

    r2 r391  
    239239if the resulting object is "compatible" with the exception.  An object is
    240240compatible with an exception if it is the class or a base class of the exception
    241 object, a tuple containing an item compatible with the exception, or, in the
    242 (deprecated) case of string exceptions, is the raised string itself (note that
    243 the object identities must match, i.e. it must be the same string object, not
    244 just a string with the same value).
     241object, or a tuple containing an item compatible with the exception.
    245242
    246243If no except clause matches the exception, the search for an exception handler
     
    298295:keyword:`finally` clause. If the :keyword:`finally` clause raises another
    299296exception or executes a :keyword:`return` or :keyword:`break` statement, the
    300 saved exception is lost.  The exception information is not available to the
    301 program during execution of the :keyword:`finally` clause.
     297saved exception is discarded::
     298
     299    def f():
     300        try:
     301            1/0
     302        finally:
     303            return 42
     304
     305    >>> f()
     306    42
     307
     308The exception information is not available to the program during execution of
     309the :keyword:`finally` clause.
    302310
    303311.. index::
     
    334342
    335343.. productionlist::
    336    with_stmt: "with" `expression` ["as" `target`] ":" `suite`
    337 
    338 The execution of the :keyword:`with` statement proceeds as follows:
    339 
    340 #. The context expression is evaluated to obtain a context manager.
     344   with_stmt: "with" with_item ("," with_item)* ":" `suite`
     345   with_item: `expression` ["as" `target`]
     346
     347The execution of the :keyword:`with` statement with one "item" proceeds as follows:
     348
     349#. The context expression (the expression given in the :token:`with_item`) is
     350   evaluated to obtain a context manager.
     351
     352#. The context manager's :meth:`__exit__` is loaded for later use.
    341353
    342354#. The context manager's :meth:`__enter__` method is invoked.
     
    350362      returns without an error, then :meth:`__exit__` will always be called. Thus, if
    351363      an error occurs during the assignment to the target list, it will be treated the
    352       same as an error occurring within the suite would be. See step 5 below.
     364      same as an error occurring within the suite would be. See step 6 below.
    353365
    354366#. The suite is executed.
     
    368380   for the kind of exit that was taken.
    369381
     382With more than one item, the context managers are processed as if multiple
     383:keyword:`with` statements were nested::
     384
     385   with A() as a, B() as b:
     386       suite
     387
     388is equivalent to ::
     389
     390   with A() as a:
     391       with B() as b:
     392           suite
     393
    370394.. note::
    371395
     
    374398   Python 2.6.
    375399
     400.. versionchanged:: 2.7
     401   Support for multiple context expressions.
     402
    376403.. seealso::
    377404
     
    380407      statement.
    381408
     409
     410.. index::
     411   single: parameter; function definition
    382412
    383413.. _function:
     
    405435   dotted_name: `identifier` ("." `identifier`)*
    406436   parameter_list: (`defparameter` ",")*
    407                  : (  "*" `identifier` [, "**" `identifier`]
     437                 : (  "*" `identifier` ["," "**" `identifier`]
    408438                 : | "**" `identifier`
    409439                 : | `defparameter` [","] )
     
    441471   func = f1(arg)(f2(func))
    442472
    443 .. index:: triple: default; parameter; value
    444 
    445 When one or more top-level parameters have the form *parameter* ``=``
    446 *expression*, the function is said to have "default parameter values."  For a
    447 parameter with a default value, the corresponding argument may be omitted from a
    448 call, in which case the parameter's default value is substituted.  If a
     473.. index::
     474   triple: default; parameter; value
     475   single: argument; function definition
     476
     477When one or more top-level :term:`parameters <parameter>` have the form
     478*parameter* ``=`` *expression*, the function is said to have "default parameter
     479values."  For a parameter with a default value, the corresponding
     480:term:`argument` may be omitted from a call, in which
     481case the parameter's default value is substituted.  If a
    449482parameter has a default value, all following parameters must also have a default
    450483value --- this is a syntactic restriction that is not expressed by the grammar.
     
    452485**Default parameter values are evaluated when the function definition is
    453486executed.**  This means that the expression is evaluated once, when the function
    454 is defined, and that that same "pre-computed" value is used for each call.  This
     487is defined, and that the same "pre-computed" value is used for each call.  This
    455488is especially important to understand when a default parameter is a mutable
    456489object, such as a list or a dictionary: if the function modifies the object
     
    477510receiving any excess keyword arguments, defaulting to a new empty dictionary.
    478511
    479 .. index:: pair: lambda; form
     512.. index:: pair: lambda; expression
    480513
    481514It is also possible to create anonymous functions (functions not bound to a
    482 name), for immediate use in expressions.  This uses lambda forms, described in
    483 section :ref:`lambda`.  Note that the lambda form is merely a shorthand for a
     515name), for immediate use in expressions.  This uses lambda expressions, described in
     516section :ref:`lambda`.  Note that the lambda expression is merely a shorthand for a
    484517simplified function definition; a function defined in a ":keyword:`def`"
    485518statement can be passed around or assigned to another name just like a function
    486 defined by a lambda form.  The ":keyword:`def`" form is actually more powerful
     519defined by a lambda expression.  The ":keyword:`def`" form is actually more powerful
    487520since it allows the execution of multiple statements.
    488521
     
    544577.. rubric:: Footnotes
    545578
    546 .. [#] The exception is propagated to the invocation stack only if there is no
    547    :keyword:`finally` clause that negates the exception.
     579.. [#] The exception is propagated to the invocation stack unless
     580   there is a :keyword:`finally` clause which happens to raise another
     581   exception. That new exception causes the old one to be lost.
    548582
    549583.. [#] Currently, control "flows off the end" except in the case of an exception or the
Note: See TracChangeset for help on using the changeset viewer.