veekun / pokedex

more than you ever wanted to know about Pokémon
MIT License
1.44k stars 637 forks source link

Prevent throwing StopIteration in the wrong place #264

Closed kipyin closed 5 years ago

kipyin commented 5 years ago

In the following code:

https://github.com/veekun/pokedex/blob/18925edcd3ad71dd912a94ce4b1bc1435943937a/pokedex/db/translations.py#L374-L390

When stream is exhausted, operating next(stream) will throw StopIteration and the entire program will terminate. The expected behavior is yield StopIteration and let the for loop handle the situation.

kipyin commented 5 years ago

I must be on drugs to yield StopIteration...

So it seems like it is a Python 3.7 specific issue. What I was getting was:

RuntimeError: generator raised StopIteration

So I think catching StopIteration and have an empty return for Python 3.7+ should solve this issue.

magical commented 5 years ago

Thanks!