[Python-Dev] PEP 377 - allow __enter__() methods to skip the statement body

Nick Coghlan ncoghlan at gmail.com
Tue Mar 17 15:11:44 CET 2009


Greg Ewing wrote:
> Um, no -- it says explicitly right at the very top of
> PEP 343 that it's only about factoring out try/finally
> statements.
> 
> There's no way that
> 
>   try:
>     code_block
>   finally:
>     ...
> 
> can fail to enter the code block if you get as far as
> the "try". So it's not reasonable to expect the with
> statement to provide this ability.

We were working on the PEP for over a year though - expectations changed
a bit when the ability to suppress exceptions was added (that wasn't in
the original version of the PEP which was when most of the first few
sections was written).

I agree that try/finally was by far the main use case - it just isn't
the only use case or we would never have included the option to suppress
exceptions at all.

Still, I'm happy to let this rest indefinitely - I doubt the
daemonisation use case is going to be enough to change Guido's mind, and
it really is rather difficult to come up with practical examples where
the current behaviour is a genuine problem.

Cheers,
Nick.

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


More information about the Python-Dev mailing list