From fc1bb51af57d8f01db4b6be231fd851b2016919a Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 27 Sep 2018 15:18:24 +1000 Subject: [PATCH] py/objgenerator: Remove TODO about returning gen being called again. The code implements correct behaviour, as tested by the new test case added in this commit. --- py/objgenerator.c | 2 -- tests/basics/generator_return.py | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/py/objgenerator.c b/py/objgenerator.c index 341967dc02..038c15fc3d 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -128,8 +128,6 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_ // Explicitly mark generator as completed. If we don't do this, // subsequent next() may re-execute statements after last yield // again and again, leading to side effects. - // TODO: check how return with value behaves under such conditions - // in CPython. self->code_state.ip = 0; *ret_val = *self->code_state.sp; break; diff --git a/tests/basics/generator_return.py b/tests/basics/generator_return.py index 5814ce8379..2b3464a02a 100644 --- a/tests/basics/generator_return.py +++ b/tests/basics/generator_return.py @@ -8,3 +8,9 @@ try: print(next(g)) except StopIteration as e: print(type(e), e.args) + +# trying next again should raise StopIteration with no arguments +try: + print(next(g)) +except StopIteration as e: + print(type(e), e.args)