[Python-ideas] Allow parentheses to be used with "with" block

Neil Girdhar mistersheik at gmail.com
Tue Feb 17 00:49:00 CET 2015


Looks fine to me:

In [1]: with (a as b,
   ...: c as d):
   ...:
  File "<ipython-input-1-cb4fbac821e5>", line 1
    with (a as b,
             ^
SyntaxError: invalid syntax

It knows about bracket continuations and doesn't realize it's a syntax
error until after the fact.

Best,

Neil

On Mon, Feb 16, 2015 at 6:46 PM, Paul Moore <p.f.moore at gmail.com> wrote:

> On 16 February 2015 at 21:30, Greg Ewing <greg.ewing at canterbury.ac.nz>
> wrote:
> > How about adopting a version of the dangling-operator
> > rule suggested earlier, but *only* for commas?
> >
> > I think it could be handled entirely in the lexer: if
> > you sees a comma followed by a newline, and the next
> > line is indented further than the current indentation
> > level, absorb the newline and indentation.
> >
> > This would take care of all the statements I can think
> > of that can't currently be parenthesised.
>
> One thing that's not been discussed much here is that *any*
> line-continuation rules (even the ones that already exist) make the
> interactive interpreter's job harder. I don't know exactly how it
> works, and whether there's special code in the REPL for things like
> backslash continuation, but interactive use (and in particular error
> handling) need to be considered in all this.
>
> As well as the standard interpreter, would new rules like this affect
> tools like IPython?
>
> (Maybe all the interactive tools work by magic, and the changes can be
> isolated to the parser and lexer. That would be nice, and if so my
> above comments are irrelevant. But someone should probably check).
>
> Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150216/c91030fa/attachment-0001.html>


More information about the Python-ideas mailing list