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

Devin Jeanpierre jeanpierreda at gmail.com
Mon Feb 16 12:00:52 CET 2015


I always say this, and it's already been shot down ("That way lies
Coffeescript"), but it's even simpler to just allow newlines in
between the "with" and the ":", the same way we already allow them
between parentheses.

Adding () arbitrarily around things that aren't expressions, just
because the lexer is special-cased for them, has always confused me.

-- Devin

On Sun, Feb 15, 2015 at 1:52 PM, Neil Girdhar <mistersheik at gmail.com> wrote:
> It's great that multiple context managers can be sent to "with":
>
> with a as b, c as d, e as f:
>      suite
>
> If the context mangers have a lot of text it's very hard to comply with PEP8
> without resorting to "\" continuations, which are proscribed by the Google
> style guide.
>
> Other statements like import and if support enclosing their arguments in
> parentheses to force aligned continuations.  Can we have the same for
> "with"?
>
> E.g.
>
> with (a as b,
>          c as d,
>          e as f):
>     suite
>
> This is a pretty minor change to the grammar and parser.
>
> Best,
>
> Neil
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list