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

Nick Coghlan ncoghlan at gmail.com
Thu Mar 1 03:15:49 CET 2012


On Thu, Mar 1, 2012 at 10:46 AM, Craig Yoshioka <craigyk at me.com> wrote:
> ? I'm just making an observation that there aren't many other places where an 'independent' block is 'guaranteed' to run.  I'm not arguing that something inside a block is magically preventing execution of the block.  The with keyword is 'outside' the block.  From within a block you can always return/break early anyways.

There are two other cases where a suite is guaranteed to at least
start executing, and one of them is the only case that matters here:
"try" blocks. The flow control behaviour of "with:" is consistent with
the behaviour of a "try:" block, and that is not an accident.

Conditional execution of a try block requires a separate if statement
or throwing an exception that is caught and suppressed by one of the
exception handlers. Similarly, conditional execution of a with block
requires a separate if statement or throwing an exception that is
caught and suppressed by one of the context managers. Hence, arguments
of language consistency aren't going to get you anywhere here.

Guido's verdict on PEP 377 was that the payoff (avoiding a separate if
statement or a method call that deliberately throws an appropriate
exception in certain niche use cases) wasn't worth the additional
complexity in the with statement definition. I now agree with him.

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list