restore a generator's caller's exception state both on yield and (last) return

This prevents generator exception state from leaking into the caller.

Closes #12475.
This commit is contained in:
Benjamin Peterson 2011-07-03 13:44:00 -05:00
parent c77eccd608
commit 83195c3f0c
3 changed files with 23 additions and 4 deletions

View file

@ -566,6 +566,21 @@ class ExceptionTests(unittest.TestCase):
del g
self.assertEqual(sys.exc_info()[0], TypeError)
def test_generator_leaking2(self):
# See issue 12475.
def g():
yield
try:
raise RuntimeError
except RuntimeError:
it = g()
next(it)
try:
next(it)
except StopIteration:
pass
self.assertEqual(sys.exc_info(), (None, None, None))
def test_generator_finalizing_and_exc_info(self):
# See #7173
def simple_gen():