summaryrefslogtreecommitdiff
path: root/py/runtime.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c7
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;
}
}