Commit 4ed7b7f7 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

py: iternext() may not return MP_OBJ_NULL, only MP_OBJ_STOP_ITERATION.

Testing for incorrect value led to premature termination of generator
containing yield from for such iterator (e.g. "yield from [1, 2]").
parent a37d13c9
......@@ -1081,7 +1081,7 @@ mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t th
if (type->iternext != NULL && send_value == mp_const_none) {
mp_obj_t ret = type->iternext(self_in);
if (ret != MP_OBJ_NULL) {
if (ret != MP_OBJ_STOP_ITERATION) {
*ret_val = ret;
return MP_VM_RETURN_YIELD;
} else {
......
......@@ -4,5 +4,10 @@ def gen():
def gen2():
yield from gen()
def gen3():
yield from (4, 5)
yield 6
print(list(gen()))
print(list(gen2()))
print(list(gen3()))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment