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, commit6738c1ddedintroduced 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, commit79d996a57bimproved 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 in6738c1dded. 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.
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user