mirror of
https://github.com/python/cpython.git
synced 2025-09-11 03:07:01 +00:00
fix yield from return value on custom iterators (closes #15568)
This commit is contained in:
parent
a0abb4404a
commit
b37df519c7
3 changed files with 18 additions and 1 deletions
|
@ -940,6 +940,20 @@ class TestPEP380Operation(unittest.TestCase):
|
||||||
for stack in spam(eggs(gen())):
|
for stack in spam(eggs(gen())):
|
||||||
self.assertTrue('spam' in stack and 'eggs' in stack)
|
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():
|
def test_main():
|
||||||
from test import support
|
from test import support
|
||||||
|
|
|
@ -10,6 +10,9 @@ What's New in Python 3.3.0 Beta 2?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #15568: Fix the return value of "yield from" when StopIteration is
|
||||||
|
raised by a custom iterator.
|
||||||
|
|
||||||
- Issue #13119: sys.stdout and sys.stderr are now using "\r\n" newline on
|
- Issue #13119: sys.stdout and sys.stderr are now using "\r\n" newline on
|
||||||
Windows, as Python 2.
|
Windows, as Python 2.
|
||||||
|
|
||||||
|
|
|
@ -1843,7 +1843,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
||||||
} else {
|
} else {
|
||||||
_Py_IDENTIFIER(send);
|
_Py_IDENTIFIER(send);
|
||||||
if (u == Py_None)
|
if (u == Py_None)
|
||||||
retval = PyIter_Next(x);
|
retval = Py_TYPE(x)->tp_iternext(x);
|
||||||
else
|
else
|
||||||
retval = _PyObject_CallMethodId(x, &PyId_send, "O", u);
|
retval = _PyObject_CallMethodId(x, &PyId_send, "O", u);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue