This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author thautwarm
Recipients Anthony Sottile, BTaskaya, Jeffrey.Kintscher, Julian, Terry Davis, barry, benjamin.peterson, eric.araujo, ezio.melotti, georg.brandl, gvanrossum, ishimoto, jack1142, lukasz.langa, ncoghlan, pablogsal, r.david.murray, serhiy.storchaka, steven.daprano, thautwarm, ulope
Date 2020-06-25.18:36:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1593110195.12.0.395603453893.issue12782@roundup.psfhosted.org>
In-reply-to
Content
I can confirm Guido's words, now parentheses for continuation across lines are already supported.

Even without parentheses, multiline with items can be supported. I just implemented it here: https://github.com/thautwarm/cpython/blob/bpo-12782/Grammar/python.gram#L180-L187

  from contextlib import contextmanager

  @contextmanager
  def f(x):
    try:
        yield x
    finally:
        pass

# Ok
  with f('c') as a,
       f('a') as b:
       pass


# Ok
  with f('c') as a,
       f('a') as b,
       f('a') as c:
       pass


  # ERROR
  with f('c') as a,
       f('a') as b,
       f('a') as c:
     x = 1 + 1

  # message:
    File "/home/thaut/github/cpython/../a.py", line 49
      x = 1 + 1
             ^
    IndentationError: unindent does not match any outer indentation 
level

  # ERROR
  with f('c') as a,
       f('a') as b,
       f('a') as c:
          x = 1 + 1

  File "/home/thaut/github/cpython/../a.py", line 49
    x = 1 + 1
  
  IndentationError: unexpected indent



The grammar is:


with_stmt[stmt_ty]:
    | ...
    | 'with' a=(',' [NEWLINE ~ INDENT?]).with_item+ ':' tc=[TYPE_COMMENT] NEWLINE b=statements DEDENT {
        _Py_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
    | ...

The restriction here is, since the second 'with_item', until the end of 'statements', the expression and statements have to keep the same indentation.

    with item1,
       item2,
       ...:
       block
    
    The indentation of 'item2', ..., 'block' should be the same.

This implementation leverages the new PEG and how the lexer deals with indent/dedent.
History
Date User Action Args
2020-06-25 18:36:35thautwarmsetrecipients: + thautwarm, gvanrossum, barry, georg.brandl, ishimoto, ncoghlan, benjamin.peterson, ezio.melotti, eric.araujo, steven.daprano, r.david.murray, lukasz.langa, Julian, serhiy.storchaka, ulope, Anthony Sottile, pablogsal, BTaskaya, Terry Davis, Jeffrey.Kintscher, jack1142
2020-06-25 18:36:35thautwarmsetmessageid: <1593110195.12.0.395603453893.issue12782@roundup.psfhosted.org>
2020-06-25 18:36:35thautwarmlinkissue12782 messages
2020-06-25 18:36:34thautwarmcreate