New submission from Nick Coghlan <ncogh...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue14969>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to