mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
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:
parent
9cf960c94f
commit
ac91341333
3 changed files with 51 additions and 4 deletions
|
@ -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():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue