An error occurred while fetching this tab.
Fix propagation of StopIteration exception
- Jun 18, 2020
-
-
Marco Clemencic authored
-
Marco Clemencic authored
-
Python 3.7 improved the handling of exceptions in loops, so this piece of code
def generator():
# this raises a StopIteration
yield next(_ for _ in [])
for x in generator():
pass
was working with Python <= 3.6 because the StopIteration
exception was bubbling up from inside generator
and stopping the loop for x in generator()
(and I did it like that on purpose!).
As of Python 3.7 the exceptions are handled properly, and that code does not work anymore because it properly reports that generator
raised an exception.
Closes #129 (closed)