summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2021-01-25 23:15:51 (GMT)
committerGitHub <noreply@github.com>2021-01-25 23:15:51 (GMT)
commit7c8e0b03366e053e0673f1f2ae31eb464fae8c57 (patch)
treec25449e12e7a82bcf121cec0b56fd9278289b675 /Doc/reference
parentc7c3b7db29c4dda0519acdf7450e20d47a6409f4 (diff)
downloadcpython-7c8e0b03366e053e0673f1f2ae31eb464fae8c57.zip
cpython-7c8e0b03366e053e0673f1f2ae31eb464fae8c57.tar.gz
cpython-7c8e0b03366e053e0673f1f2ae31eb464fae8c57.tar.bz2
Document new parenthesized with statements (GH-24281)
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/compound_stmts.rst15
1 files changed, 14 insertions, 1 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst
index 5bba3ee..f22af8b 100644
--- a/Doc/reference/compound_stmts.rst
+++ b/Doc/reference/compound_stmts.rst
@@ -411,7 +411,8 @@ This allows common :keyword:`try`...\ :keyword:`except`...\ :keyword:`finally`
usage patterns to be encapsulated for convenient reuse.
.. productionlist:: python-grammar
- with_stmt: "with" `with_item` ("," `with_item`)* ":" `suite`
+ with_stmt: "with" ( "(" `with_stmt_contents` ","? ")" | `with_stmt_contents` ) ":" `suite`
+ with_stmt_contents: `with_item` ("," `with_item`)*
with_item: `expression` ["as" `target`]
The execution of the :keyword:`with` statement with one "item" proceeds as follows:
@@ -488,9 +489,21 @@ is semantically equivalent to::
with B() as b:
SUITE
+You can also write multi-item context managers in multiple lines if
+the items are surrounded by parentheses. For example::
+
+ with (
+ A() as a,
+ B() as b,
+ ):
+ SUITE
+
.. versionchanged:: 3.1
Support for multiple context expressions.
+.. versionchanged:: 3.10
+ Support for using grouping parentheses to break the statement in multiple lines.
+
.. seealso::
:pep:`343` - The "with" statement