Asana/python-asana

Raise StopIteration causes breakage in Python 3.7

tmurph opened this issue · 1 comments

In Python 3.7, due to PEP 479, StopIteration errors raised inside generator functions are converted to RuntimeErrors. (Not talking about StopIteration inside dunder-next methods, just inside functions that use yield.)

The PageIterator.items method raises just such a StopIteration error when it's through, and now in 3.7 when I try to iterate over pages of items I get a RuntimeError at the end.

Here's the line that causes the RuntimeError.

raise StopIteration

Apparently, according to PEP 479, this idiom of "raise a StopIteration error to signal when the generator function finished" was never really necessary, just permissible. But it caused subtle bugs and now it's actively considered harmful.

According to the PEP, the fix in this case is to simply let the function return, a/k/a just remove that line. The PEP claims this is fully compatible with previous versions of Python.

I'm not really set up to test that change, but I hope it's as easy as the PEP makes it sound?

You were precisely right @tmurph - I removed that line and tested on 2.7 and 3.7. Release 0.8.2 should fix this for you. Thanks!