Skip to content

Fix propagation of StopIteration exception

Marco Clemencic requested to merge clemenci/Gaudi:129-fix-for-py37 into master

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)

Merge request reports