summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-08-03 10:10:38 (GMT)
committerGitHub <noreply@github.com>2021-08-03 10:10:38 (GMT)
commit8ce7f2f4ef04e19209f1dfd2a0cf50ddcd0e999f (patch)
treeff2643fb5de8c15ad3b1b123be5abc338df0bc4e /Lib/test
parent2b8d4eaec9a8f7e022295efd86105b19e359d2a4 (diff)
downloadcpython-8ce7f2f4ef04e19209f1dfd2a0cf50ddcd0e999f.zip
cpython-8ce7f2f4ef04e19209f1dfd2a0cf50ddcd0e999f.tar.gz
cpython-8ce7f2f4ef04e19209f1dfd2a0cf50ddcd0e999f.tar.bz2
bpo-39091: Fix segfault when Exception constructor returns non-exception for gen.throw. (GH-17658) (GH-27572)
Co-authored-by: Benjamin Peterson <benjamin@python.org> (cherry picked from commit 83ca46b7784b7357d82ec47b33295e09ed7380cb) Co-authored-by: Noah <33094578+coolreader18@users.noreply.github.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_generators.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
index ebf8bb7..53d579e 100644
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -270,6 +270,32 @@ class ExceptionTest(unittest.TestCase):
self.assertEqual(next(g), "done")
self.assertEqual(sys.exc_info(), (None, None, None))
+ def test_except_throw_bad_exception(self):
+ class E(Exception):
+ def __new__(cls, *args, **kwargs):
+ return cls
+
+ def boring_generator():
+ yield
+
+ gen = boring_generator()
+
+ err_msg = 'should have returned an instance of BaseException'
+
+ with self.assertRaisesRegex(TypeError, err_msg):
+ gen.throw(E)
+
+ self.assertRaises(StopIteration, next, gen)
+
+ def generator():
+ with self.assertRaisesRegex(TypeError, err_msg):
+ yield
+
+ gen = generator()
+ next(gen)
+ with self.assertRaises(StopIteration):
+ gen.throw(E)
+
def test_stopiteration_error(self):
# See also PEP 479.