diff options
author | Damien George <damien.p.george@gmail.com> | 2018-02-27 15:39:31 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-02-27 15:39:31 +1100 |
commit | 22ade2f5c4ac88c90a013cbf4b81c8d795487f33 (patch) | |
tree | c764b91e008542db57a923ec502529201f72b188 /tests/basics/gen_yield_from.py | |
parent | c5fe610ba15468e1d92d7b6d5f5962f7595e3324 (diff) |
py/vm: Fix case of handling raised StopIteration within yield from.
This patch concerns the handling of an NLR-raised StopIteration, raised
during a call to mp_resume() which is handling the yield from opcode.
Previously, commit 6738c1dded8e436686f85008ec0a4fc47406ab7a introduced code
to handle this case, along with a test. It seems that it was lucky that
the test worked because the code did not correctly handle the stack pointer
(sp).
Furthermore, commit 79d996a57b351e0ef354eb1e2f644b194433cc73 improved the
way mp_resume() propagated certain exceptions: it changed raising an NLR
value to returning MP_VM_RETURN_EXCEPTION. This change meant that the
test introduced in gen_yield_from_ducktype.py was no longer hitting the
code introduced in 6738c1dded8e436686f85008ec0a4fc47406ab7a.
The patch here does two things:
1. Fixes the handling of sp in the VM for the case that yield from is
interrupted by a StopIteration raised via NLR.
2. Introduces a new test to check this handling of sp and re-covers the
code in the VM.
Diffstat (limited to 'tests/basics/gen_yield_from.py')
-rw-r--r-- | tests/basics/gen_yield_from.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/basics/gen_yield_from.py b/tests/basics/gen_yield_from.py index 5196b48d2..4e68aec63 100644 --- a/tests/basics/gen_yield_from.py +++ b/tests/basics/gen_yield_from.py @@ -40,3 +40,16 @@ def gen6(): g = gen6() print(list(g)) + +# StopIteration from within a Python function, within a native iterator (map), within a yield from +def gen7(x): + if x < 3: + return x + else: + raise StopIteration(444) + +def gen8(): + print((yield from map(gen7, range(100)))) + +g = gen8() +print(list(g)) |