NULL and no exception set from tp_iternext means StopIteration

This commit is contained in:
Benjamin Peterson 2012-01-13 14:54:31 -05:00
parent 9a80fa81b0
commit 0296a56520
2 changed files with 7 additions and 1 deletions

View File

@ -831,6 +831,11 @@ class TestPEP380Operation(unittest.TestCase):
"Enter f",
])
def test_yield_from_empty(self):
def g():
yield from ()
self.assertRaises(StopIteration, next, g())
def test_main():
from test import support

View File

@ -1839,7 +1839,8 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
if (!retval) {
/* iter may be exhausted */
Py_CLEAR(x);
if (!PyErr_ExceptionMatches(PyExc_StopIteration)) {
if (PyErr_Occurred() &&
!PyErr_ExceptionMatches(PyExc_StopIteration)) {
/* some other exception */
break;
}