fix yield from return value on custom iterators (closes #15568)

This commit is contained in:
Benjamin Peterson 2012-08-06 17:53:09 -07:00
parent a0abb4404a
commit b37df519c7
3 changed files with 18 additions and 1 deletions

View file

@ -940,6 +940,20 @@ class TestPEP380Operation(unittest.TestCase):
for stack in spam(eggs(gen())):
self.assertTrue('spam' in stack and 'eggs' in stack)
def test_custom_iterator_return(self):
# See issue #15568
class MyIter:
def __iter__(self):
return self
def __next__(self):
raise StopIteration(42)
def gen():
nonlocal ret
ret = yield from MyIter()
ret = None
list(gen())
self.assertEqual(ret, 42)
def test_main():
from test import support