diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-08-03 10:10:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-03 10:10:38 (GMT) |
commit | 8ce7f2f4ef04e19209f1dfd2a0cf50ddcd0e999f (patch) | |
tree | ff2643fb5de8c15ad3b1b123be5abc338df0bc4e /Lib/test | |
parent | 2b8d4eaec9a8f7e022295efd86105b19e359d2a4 (diff) | |
download | cpython-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.py | 26 |
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. |