mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #23996: Added _PyGen_SetStopIterationValue for safe raising
StopIteration with value. More safely handle non-normalized exceptions in -_PyGen_FetchStopIterationValue.
This commit is contained in:
commit
60e49aa756
7 changed files with 281 additions and 68 deletions
|
@ -277,6 +277,27 @@ class ExceptionTest(unittest.TestCase):
|
|||
# hence no warning.
|
||||
next(g)
|
||||
|
||||
def test_return_tuple(self):
|
||||
def g():
|
||||
return (yield 1)
|
||||
|
||||
gen = g()
|
||||
self.assertEqual(next(gen), 1)
|
||||
with self.assertRaises(StopIteration) as cm:
|
||||
gen.send((2,))
|
||||
self.assertEqual(cm.exception.value, (2,))
|
||||
|
||||
def test_return_stopiteration(self):
|
||||
def g():
|
||||
return (yield 1)
|
||||
|
||||
gen = g()
|
||||
self.assertEqual(next(gen), 1)
|
||||
with self.assertRaises(StopIteration) as cm:
|
||||
gen.send(StopIteration(2))
|
||||
self.assertIsInstance(cm.exception.value, StopIteration)
|
||||
self.assertEqual(cm.exception.value.value, 2)
|
||||
|
||||
|
||||
class YieldFromTests(unittest.TestCase):
|
||||
def test_generator_gi_yieldfrom(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue