circuitpython/tests/basics/gen_yield_from.py
Damien George 3f6ffe059f 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.
2018-09-20 15:36:59 +10:00

28 lines
483 B
Python

# Case of terminating subgen using return with value
def gen():
yield 1
yield 2
return 3
def gen2():
print("here1")
print((yield from gen()))
print("here2")
g = gen2()
print(list(g))
# StopIteration from within a Python function, within a native iterator (map), within a yield from
def gen7(x):
if x < 3:
return x
else:
raise StopIteration(444)
def gen8():
print((yield from map(gen7, range(100))))
g = gen8()
print(list(g))