This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients ncoghlan
Date 2012-05-31.13:41:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1338471704.64.0.423710323237.issue14969@psf.upfronthosting.co.za>
In-reply-to
Content
When adding the test case for #14963, I discovered that contextlib.ExitStack can't *quite* reproduce the exception handling of nested with statements.

The problem arises when the original exception gets suppressed by one of the handlers, but an outer handler raises a *new* exception, then nested with statements will correctly indicate that there was no exception context active when the new exception was raised (since the inner with statement will fully clear the exception state).

By contrast, when using ExitStack, the interpreter will add the original exception from inside the body of the with statement as the context for the *new* exception, even though the inner exception had been suppressed before the outer one was encountered.

Restoring sys.exc_clear() *might* allow this discrepancy to be resolved by explicitly clearing the exception state when one of the callbacks indicates that the current exception has been handled (although it might be trickier than that, if the problem is actually due to caching the exception state inside the with cleanup code in the eval loop)
History
Date User Action Args
2012-05-31 13:41:44ncoghlansetrecipients: + ncoghlan
2012-05-31 13:41:44ncoghlansetmessageid: <1338471704.64.0.423710323237.issue14969@psf.upfronthosting.co.za>
2012-05-31 13:41:43ncoghlanlinkissue14969 messages
2012-05-31 13:41:43ncoghlancreate