[Python-ideas] Allow parentheses to be used with "with" block
Terry Reedy
tjreedy at udel.edu
Mon Feb 16 21:00:16 CET 2015
On 2/15/2015 8:19 PM, Steven D'Aprano wrote:
> On Sun, Feb 15, 2015 at 07:27:47PM -0500, Terry Reedy 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.
> ...^^^^^^^^^^^^^^^^^^
Yes, I missed that. Stylistically, the switch from PEP8 to Google is
not nice.
>> Untrue. " Backslashes may still be appropriate at times. For example,
>> long, multiple with -statements cannot use implicit continuation, so
>> backslashes are acceptable:
>>
>> 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())"
>
> Isn't that a quote from PEP 8, rather than Google's style guide?
Yes
>
>>> 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.
'not trivial' is a very short summary of previous discussions, already
alluded to by another responder.
> Many things are not trivial. Surely there should be a better reason than
> *just* "it is hard to do" to reject something?
>
> Do you have a reference for this being rejected?
My memory of discussions here or pydev. I believe the explicit PEP8
quote came from those discussions. Guido can confirm or deny when back
from time off from python.
[snip]
> I don't know enough about Python's parser to do more than guess, but I
> guess that somebody may need to actually try extending the grammar to
> support this and see what happens?
That is certainly the way to disprove 'parser cannot handle this'.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list