[Python-Dev] Another PEP 343 contextmanager glitch

Phillip J. Eby pje at telecommunity.com
Sat Mar 25 00:43:14 CET 2006

At 03:27 PM 3/24/2006 -0800, Guido van Rossum wrote:
>I guess I like the ambiguity -- to the outer __exit__, it shouldn't
>make any difference whether the exception was re-raised by the inner
>__exit__ or by the finally clause containing it. After all, if there
>*wasn't* an outer __exit__, there wouldn't be any difference to the
>user either, whether the re-raise came from __exit__ or from finally.
>If you still disagree, can you produce a test case that's currently broken?

I discovered the issue when I updated to the latest implementation and it 
broke the tests for a context manager I had written.  This context manager 
is basically a transaction manager that accumulates context managers for 
resources used in the transaction, then calls all their __exit__() methods 
from its __exit__.  It has to be able to distinguish between an __exit__() 
that failed (which means a critical failure of the overall transaction!) 
and an exit that's merely allowing the original exception to propagate 
(which means that the other handlers should still be invoked, and that 
everything's working normally).

More information about the Python-Dev mailing list