[Python-Dev] Another PEP 343 contextmanager glitch

Guido van Rossum guido at python.org
Sat Mar 25 01:34:36 CET 2006


On 3/24/06, Phillip J. Eby <pje at telecommunity.com> wrote:
> At 03:50 PM 3/24/2006 -0800, Guido van Rossum wrote:
> >I'm not against recommending in the PEP that __exit__ shouldn't
> >re-raise but instead should return False to signal a re-raise, and
> >fixing any existing code that re-raises in __exit__. But I'm still
> >questioning your use case; why is it important not to call the outer
> >__exit__ methods in your case?
>
> I didn't say it was important not to call them; I said it was important to
> be able to *tell* whether any of the __exit__ methods had actually failed,
> since this indicates a critical failure of transaction rollback.  That is,
> there was some part of the transaction that could not be rolled back.  This
> is a distinct issue from whatever caused the transaction to be
> aborted.  Also, the __exit__ methods that failed should be logged, but not
> the __exit__ methods that are simply propagating an exception after
> performing their rollback behavior.

You could probably tell the difference by comparing the exception it
raises to the exception you pass it. But by all means update the PEP
to discourage or disallow re-raising and fix any re-raising code you
find.

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list