[New-bugs-announce] [issue14969] Restore sys.exc_clear()?

Nick Coghlan report at bugs.python.org
Thu May 31 15:41:44 CEST 2012

New submission from Nick Coghlan <ncoghlan at gmail.com>:

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)

components: Interpreter Core, Library (Lib)
messages: 161998
nosy: ncoghlan
priority: normal
severity: normal
stage: needs patch
status: open
title: Restore sys.exc_clear()?
type: enhancement
versions: Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list