never retain a generator's caller's exception state on the generator after a yield/return

This requires some trickery to properly save the exception state if the
generator creates its own exception state.
This commit is contained in:
Benjamin Peterson 2011-07-03 16:25:11 -05:00
parent 9cf960c94f
commit ac91341333
3 changed files with 51 additions and 4 deletions

View file

@ -581,6 +581,18 @@ class ExceptionTests(unittest.TestCase):
pass
self.assertEqual(sys.exc_info(), (None, None, None))
def test_generator_doesnt_retain_old_exc(self):
def g():
self.assertIsInstance(sys.exc_info()[1], RuntimeError)
yield
self.assertEqual(sys.exc_info(), (None, None, None))
it = g()
try:
raise RuntimeError
except RuntimeError:
next(it)
self.assertRaises(StopIteration, next, it)
def test_generator_finalizing_and_exc_info(self):
# See #7173
def simple_gen():