py/objgenerator: Implement PEP479, StopIteration convs to RuntimeError.

This commit implements PEP479 which disallows raising StopIteration inside
a generator to signal that it should be finished.  Instead, the generator
should simply return when it is complete.

See https://www.python.org/dev/peps/pep-0479/ for details.
This commit is contained in:
Damien George
2018-09-14 00:44:06 +10:00
parent 17f7c683d2
commit 3f6ffe059f
12 changed files with 63 additions and 98 deletions

View File

@@ -31,13 +31,14 @@ except StopIteration:
print("StopIteration")
# Throwing StopIteration in response to close() is ok
# Throwing GeneratorExit in response to close() is ok
def gen2():
try:
yield 1
yield 2
except:
raise StopIteration
print('raising GeneratorExit')
raise GeneratorExit
g = gen2()
next(g)