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

Neil Girdhar mistersheik at gmail.com
Mon Feb 16 02:28:51 CET 2015


On Sun, Feb 15, 2015 at 7:27 PM, Terry Reedy <tjreedy at udel.edu> wrote:

> On 2/15/2015 4:52 PM, Neil Girdhar 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.
>>
>
> Untrue.  " Backslashes may still be appropriate at times. For example,
> long, multiple with -statements cannot use implicit continuation, so
> backslashes are acceptable:
>

Where are you looking at that?  The one I see is here:

https://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Line_length

Explicitly says:

Exceptions:

   - Long import statements.
   - URLs in comments.

Do not use backslash line continuation.


>
> with open('/path/to/some/file/you/want/to/read') as file_1, \
>      open('/path/to/some/file/being/written', 'w') as file_2:
>     file_2.write(file_1.read())"
>
>  Other statements like import and if support enclosing their arguments in
>> parentheses to force aligned continuations.  Can we have the same for
>> "with"?
>>
>
> No. Considered and rejected because it would not be trivial.
>
>
If your argument is the amount of work, I might be able to find the time to
do the work  *if someone will promise to review it quickly*.  I think it's
not more than an afternoon to modify cpython.


> --
> Terry Jan Reedy
>
> _______________________________________________
> 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/
>
> --
>
> --- You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/python-ideas/y9rRQhVdMn4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150215/239a6d04/attachment-0001.html>


More information about the Python-ideas mailing list