[Python-ideas] Allow with (x as y, z as w):

Ram Rachum ram at rachum.com
Mon Apr 25 04:38:17 EDT 2016


I have a problem: I've got code that has a `with` statement with multiple
long names, so I have to break the line awkwardly using the \ character:

with some_darn_object.my_long_named_method_on_it(argument='yep') as foo, \
     a_different_darn_object.and_yet_another_method() as bar:

I tried wrapping the context managers in parentheses, but it looks like
it's not legal syntax:

  File "<stdin>", line 1

    with (some_darn_object.my_long_named_method_on_it(argument='yep') as

SyntaxError: invalid syntax

Another demonstration from the REPL:

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> with (x as y, z as w): pass

  File "<stdin>", line 1

    with (x as y, z as w): pass


SyntaxError: invalid syntax

I wish this syntax to be legal.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160425/cd2ff494/attachment.html>

More information about the Python-ideas mailing list