summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-05-25 21:10:36 (GMT)
committerGeorg Brandl <georg@python.org>2009-05-25 21:10:36 (GMT)
commit0c31562a913e9a49842bd73c04847861c23774f1 (patch)
treef5fb007402b1a1863c4d317b08be6de4f5547b66 /Doc
parent0c1829b919cce6f6823e843a16c52e104f28c7f9 (diff)
downloadcpython-0c31562a913e9a49842bd73c04847861c23774f1.zip
cpython-0c31562a913e9a49842bd73c04847861c23774f1.tar.gz
cpython-0c31562a913e9a49842bd73c04847861c23774f1.tar.bz2
Merged revisions 72924 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r72924 | georg.brandl | 2009-05-25 23:02:56 +0200 (Mo, 25 Mai 2009) | 6 lines Allow multiple context managers in one with statement, as proposed in http://codereview.appspot.com/53094 and accepted by Guido. The construct is transformed into multiple With AST nodes so that there should be no problems with the semantics. ........
Diffstat (limited to 'Doc')
-rw-r--r--Doc/reference/compound_stmts.rst20
1 files changed, 18 insertions, 2 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst
index 61e3067..214143b 100644
--- a/Doc/reference/compound_stmts.rst
+++ b/Doc/reference/compound_stmts.rst
@@ -347,9 +347,10 @@ This allows common :keyword:`try`...\ :keyword:`except`...\ :keyword:`finally`
usage patterns to be encapsulated for convenient reuse.
.. productionlist::
- with_stmt: "with" `expression` ["as" `target`] ":" `suite`
+ with_stmt: "with" with_item ("," with_item)* ":" `suite`
+ with_item: `expression` ["as" `target`]
-The execution of the :keyword:`with` statement proceeds as follows:
+The execution of the :keyword:`with` statement with one "item" proceeds as follows:
#. The context expression is evaluated to obtain a context manager.
@@ -382,6 +383,21 @@ The execution of the :keyword:`with` statement proceeds as follows:
value from :meth:`__exit__` is ignored, and execution proceeds at the normal
location for the kind of exit that was taken.
+With more than one item, the context managers are processed as if multiple
+:keyword:`with` statements were nested::
+
+ with A() as a, B() as b:
+ suite
+
+is equivalent to ::
+
+ with A() as a:
+ with B() as b:
+ suite
+
+.. versionchanged:: 3.1
+ Support for multiple context expressions.
+
.. seealso::
:pep:`0343` - The "with" statement