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]").
This commit is contained in:
Paul Sokolovsky 2015-05-10 00:41:34 +03:00
parent a37d13c95d
commit 4ed7b7f751
2 changed files with 6 additions and 1 deletions

View File

@ -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 {

View File

@ -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()))