Issue #23192: Fixed generator lambdas. Patch by Bruno Cauet.

This commit is contained in:
Serhiy Storchaka 2015-03-11 18:20:35 +02:00
parent cf4a2f29ad
commit c775ad615a
4 changed files with 25 additions and 2 deletions

View file

@ -49,6 +49,26 @@ class FinalizationTest(unittest.TestCase):
self.assertTrue(finalized)
self.assertEqual(gc.garbage, old_garbage)
def test_lambda_generator(self):
# Issue #23192: Test that a lambda returning a generator behaves
# like the equivalent function
f = lambda: (yield 1)
def g(): return (yield 1)
# test 'yield from'
f2 = lambda: (yield from g())
def g2(): return (yield from g())
f3 = lambda: (yield from f())
def g3(): return (yield from f())
for gen_fun in (f, g, f2, g2, f3, g3):
gen = gen_fun()
self.assertEqual(next(gen), 1)
with self.assertRaises(StopIteration) as cm:
gen.send(2)
self.assertEqual(cm.exception.value, 2)
class ExceptionTest(unittest.TestCase):
# Tests for the issue #23353: check that the currently handled exception