diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-07-03 21:25:11 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-07-03 21:25:11 (GMT) |
commit | ac91341333d27bf39dd8b8c1c3164b5bdc19f03b (patch) | |
tree | 39cbb66e8f46780439a8ce370a46a92deb1a7d99 /Lib | |
parent | 9cf960c94fcd2ec044e1525bb8c51f85c9048f35 (diff) | |
download | cpython-ac91341333d27bf39dd8b8c1c3164b5bdc19f03b.zip cpython-ac91341333d27bf39dd8b8c1c3164b5bdc19f03b.tar.gz cpython-ac91341333d27bf39dd8b8c1c3164b5bdc19f03b.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_exceptions.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index ad9a19e..46ddc82 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -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(): |