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 hniksic
Recipients barry, hniksic, ncoghlan
Date 2013-09-28.20:18:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1380399523.66.0.035059633079.issue19092@psf.upfronthosting.co.za>
In-reply-to
Content
Here is the updated patch, with a very minor improvement (no longer unnecessarily holds on to original exc_info), and with new tests. The tests test for the non-suppression of exit-exception (which fails without the fix) and for the correct suppression of body-exception by an outer CM. It was not necessary to write a test for suppression of exit-exception, since this is already tested by test_exit_exception_chaining_suppress().

There is one problem, however: applying my patch mysteriously breaks the existing test_exit_exception_chaining(). It breaks in a peculiar way: the correct exception is propagated , but the exception's context is wrong. Instead of to KeyError, it points to ZeroDivisionError, despite its having been correctly suppressed.

I placed prints in _fix_exception_context right before assignment to __context__, to make sure it wasn't broken by my patch, and the assignment appears correct, it sets the context of IndexError to KeyError instance. The __context__ is correct immediately before the raise statement. However, after the IndexError is caught inside test_exit_exception_chaning(), its __context__ is unexpectedly pointing to ZeroDivisionError.

It would seem that the difference is in the raise syntax. The old code used "raise", while the new code uses "raise exc[1]", which I assume changes the exception's __context__. Changing "raise exc[1]" to "raise exc[1] from None" didn't help.
History
Date User Action Args
2013-09-28 20:18:43hniksicsetrecipients: + hniksic, barry, ncoghlan
2013-09-28 20:18:43hniksicsetmessageid: <1380399523.66.0.035059633079.issue19092@psf.upfronthosting.co.za>
2013-09-28 20:18:43hniksiclinkissue19092 messages
2013-09-28 20:18:43hniksiccreate