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

Ethan Furman ethan at stoneleaf.us
Wed Feb 29 23:03:00 CET 2012


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~



More information about the Python-ideas mailing list