diff options
author | Damien George <damien.p.george@gmail.com> | 2019-09-30 16:06:20 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-10-04 23:27:00 +1000 |
commit | 809d89c794ceb44760ab997ff9a496488b4a2c0c (patch) | |
tree | 73d64b0977c0bc078144cbff18a47e4db86ff0ca /py/runtime.c | |
parent | 82c494a97e874912e7eb23d2f03f39212e343fb3 (diff) |
py/runtime: Fix PEP479 behaviour throwing StopIteration into yield from.
Commit 3f6ffe059f64b3ebc44dc0bbc63452cb8850702b implemented PEP479 but did
not catch the case fixed in this commit. Found by coverage analysis, that
the VM had uncovered code.
Diffstat (limited to 'py/runtime.c')
-rw-r--r-- | py/runtime.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/py/runtime.c b/py/runtime.c index 2657e7cc2..6b7a9ce3c 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1319,7 +1319,12 @@ mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t th // will be propagated up. This behavior is approved by test_pep380.py // test_delegation_of_close_to_non_generator(), // test_delegating_throw_to_non_generator() - *ret_val = mp_make_raise_obj(throw_value); + if (mp_obj_exception_match(throw_value, MP_OBJ_FROM_PTR(&mp_type_StopIteration))) { + // PEP479: if StopIteration is raised inside a generator it is replaced with RuntimeError + *ret_val = mp_obj_new_exception_msg(&mp_type_RuntimeError, "generator raised StopIteration"); + } else { + *ret_val = mp_make_raise_obj(throw_value); + } return MP_VM_RETURN_EXCEPTION; } } |