summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-07-03 18:44:00 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-07-03 18:44:00 (GMT)
commit83195c3f0cffc571e265ca7e42cbbe1f27c792e1 (patch)
tree715fce3d966235a79e37a059c7060a2814e62e6b /Lib/test/test_exceptions.py
parentc77eccd608a8a7d74980b2257a2d2721435f7415 (diff)
downloadcpython-83195c3f0cffc571e265ca7e42cbbe1f27c792e1.zip
cpython-83195c3f0cffc571e265ca7e42cbbe1f27c792e1.tar.gz
cpython-83195c3f0cffc571e265ca7e42cbbe1f27c792e1.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r--Lib/test/test_exceptions.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 76f4249..ad9a19e 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -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():