diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2021-01-25 23:15:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-25 23:15:51 (GMT) |
commit | 7c8e0b03366e053e0673f1f2ae31eb464fae8c57 (patch) | |
tree | c25449e12e7a82bcf121cec0b56fd9278289b675 /Doc/whatsnew | |
parent | c7c3b7db29c4dda0519acdf7450e20d47a6409f4 (diff) | |
download | cpython-7c8e0b03366e053e0673f1f2ae31eb464fae8c57.zip cpython-7c8e0b03366e053e0673f1f2ae31eb464fae8c57.tar.gz cpython-7c8e0b03366e053e0673f1f2ae31eb464fae8c57.tar.bz2 |
Document new parenthesized with statements (GH-24281)
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/3.10.rst | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 30a8281..16bb8fb 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -72,6 +72,59 @@ New Features .. _whatsnew310-pep563: +Parenthesized context managers +------------------------------ + +Using enclosing parentheses for continuation across multiple lines +in context managers is now supported. This allows formatting a long +collection of context managers in multiple lines in a similar way +as it was previously possible with import statements. For instance, +all these examples are now valid: + +.. code-block:: python + + with (CtxManager() as example): + ... + + with ( + CtxManager1(), + CtxManager2() + ): + ... + + with (CtxManager1() as example, + CtxManager2()): + ... + + with (CtxManager1(), + CtxManager2() as example): + ... + + with ( + CtxManager1() as example1, + CtxManager2() as example2 + ): + ... + +it is also possible to use a trailing comma at the end of the +enclosed group: + +.. code-block:: python + + with ( + CtxManager1() as example1, + CtxManager2() as example2, + CtxManager3() as example3, + ): + ... + +This new syntax uses the non LL(1) capacities of the new parser. +Check :pep:`617` for more details. + +(Contributed by Guido van Rossum, Pablo Galindo and Lysandros Nikolaou +in :issue:`12782` and :issue:`40334`.) + + PEP 563: Postponed Evaluation of Annotations Becomes Default ------------------------------------------------------------ |