Skip to content
Snippets Groups Projects

Fix propagation of StopIteration exception

Merged 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

Pipeline #1726712 passed

Pipeline passed for 1d065e2f on clemenci:129-fix-for-py37

Approval is optional

Merged by Marco ClemencicMarco Clemencic 4 years ago (Jun 18, 2020 2:38pm UTC)

Merge details

Pipeline #1727994 passed

Pipeline passed for cc1f2cb7 on master

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading