Warn on "raise StopIteration"

Bug #1515396 reported by asmeurer
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Pyflakes
New
Undecided
Unassigned

Bug Description

PEP 479 (https://www.python.org/dev/peps/pep-0479/) changes "raise StopIteration" inside a generator to cause RuntimeError to be raised (previously, it would stop the generator, same as "return None").

This feature is so far only available as a __future__ import in Python 3.5.

Due to the way __future__ imports work, it's not possible to use "from __future__ import generator_stop" and support Python < 3.5 at the same time. Hence, a check on the source, i.e., pyflakes, is a good workaround (I guess there's also a deprecation warning which can be enabled, but checking code without running it is still useful).

One thing I'm still a little unclear about is if you'd ever still want to raise StopIteration legitimately, even with the new behavior. The fact that it's now a RuntimeError + a deprecation warning seems to indicate no to me, but I could be wrong.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.