[Python-ideas] revisit pep 377: good use case?

Calvin Spealman ironfroggy at gmail.com
Wed Feb 29 23:23:05 CET 2012

On Feb 29, 2012 4:56 PM, "Ethan Furman" <ethan at stoneleaf.us> wrote:
> Craig Yoshioka wrote:
>> On Feb 29, 2012, at 11:55 AM, Ethan Furman wrote:
>>> From PEP 343:
>>>   But the final blow came when I read Raymond Chen's rant about
>>>   flow-control macros[1].  Raymond argues convincingly that hiding
>>>   flow control in macros makes your code inscrutable, and I find
>>>   that his argument applies to Python as well as to C.
>>> So it is explicitly stated that the with statement should not be
>>> capable of controlling the flow.
>> I read the rant, and I agree in principle, but I think it's also a far
stretch to draw a line between a very confusing non-standard example of
macros in C, and documentable behavior of a built-in statement.  That is,
the only reason you might say with would be hiding flow-control is because
people don't currently expect it to.  I also think that when people use
non-builtin contextmanagers it's usually within a very specific... context
(*dammit*), and so they are likely to look up why they are using an object
as a context manager.  That's where you would document the behavior:
>> with uncached(path):
>>  # code here only executes if the path does not exist
> I am -1 on the idea.
> if / while / for / try   are *always* flow control.
> Your proposal would have 'with' sometimes being flow control, and
sometimes not, and the only way to know is look at the object's code and/or
docs.  This makes for a lot more complication for very little gain.
> ~Ethan~

I like the general idea, but a conditionally conditional control syntax is
a readability nightmare., however, I wonder if the case in which the with
statement act as a conditional could be explicit so a reader can
distinguish between those that will always execute their body and those
which may or may not.

with cached(key):
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120229/269a2926/attachment.html>

More information about the Python-ideas mailing list