mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 04:00:28 +01:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user