mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
closes bpo-39091: Fix segfault when Exception constructor returns non-exception for gen.throw. (#17658)
Co-authored-by: Benjamin Peterson <benjamin@python.org>
This commit is contained in:
parent
54f185b6d3
commit
83ca46b778
4 changed files with 44 additions and 4 deletions
|
@ -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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue