From 11f972f817eaf8f5260546596911293a48974725 Mon Sep 17 00:00:00 2001 From: Kip Yin <28321392+kipyin@users.noreply.github.com> Date: Tue, 16 Jul 2019 04:23:37 +0800 Subject: [PATCH] Catch StopIteration explicitly in group_by_object generator (#264) Python 3.7 changed the behaviour of generators so that a StopIteration exception which bubbles up inside a generator is transformed into a RuntimeException. This means that when calling next() inside a generator, we have to explicitly catch the StopIteration and exit the function instead of relying on it to implicitly stop the generator. Otherwise the program will crash. Sigh. For more information, see PEP 479. https://www.python.org/dev/peps/pep-0479/ https://stackoverflow.com/questions/51700960/runtimeerror-generator-raised-stopiteration-every-time-i-try-to-run-app/51701040#51701040 --- pokedex/db/translations.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pokedex/db/translations.py b/pokedex/db/translations.py index 8f55473..d3ea35f 100755 --- a/pokedex/db/translations.py +++ b/pokedex/db/translations.py @@ -377,7 +377,10 @@ def group_by_object(stream): Yields ((class name, object ID), (list of messages)) pairs. """ stream = iter(stream) - current = next(stream) + try: + current = next(stream) + except StopIteration: + return current_key = current.cls, current.id group = [current] for message in stream: