gh-119897: Add test for lambda generator invocation (#120658)

gh-120467: Add test for lambda generator invocation
This commit is contained in:
Irit Katriel 2024-06-18 10:45:23 +01:00 committed by GitHub
parent 2cf47389e2
commit 73dc1c678e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,7 @@ import doctest
import unittest import unittest
import weakref import weakref
import inspect import inspect
import types
from test import support from test import support
@ -89,9 +90,12 @@ class FinalizationTest(unittest.TestCase):
self.assertEqual(gc.garbage, old_garbage) self.assertEqual(gc.garbage, old_garbage)
def test_lambda_generator(self): def test_lambda_generator(self):
# Issue #23192: Test that a lambda returning a generator behaves # bpo-23192, gh-119897: Test that a lambda returning a generator behaves
# like the equivalent function # like the equivalent function
f = lambda: (yield 1) f = lambda: (yield 1)
self.assertIsInstance(f(), types.GeneratorType)
self.assertEqual(next(f()), 1)
def g(): return (yield 1) def g(): return (yield 1)
# test 'yield from' # test 'yield from'