Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0296a56

Browse files
committed
NULL and no exception set from tp_iternext means StopIteration
1 parent 9a80fa8 commit 0296a56

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

Lib/test/test_pep380.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,11 @@ def g():
831831
"Enter f",
832832
])
833833

834+
def test_yield_from_empty(self):
835+
def g():
836+
yield from ()
837+
self.assertRaises(StopIteration, next, g())
838+
834839

835840
def test_main():
836841
from test import support

Python/ceval.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,8 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
18391839
if (!retval) {
18401840
/* iter may be exhausted */
18411841
Py_CLEAR(x);
1842-
if (!PyErr_ExceptionMatches(PyExc_StopIteration)) {
1842+
if (PyErr_Occurred() &&
1843+
!PyErr_ExceptionMatches(PyExc_StopIteration)) {
18431844
/* some other exception */
18441845
break;
18451846
}

0 commit comments

Comments
 (0)