[docs] [issue31156] Stopiteration terminates while-loop

Günter Rote report at bugs.python.org
Wed Aug 9 10:22:02 EDT 2017

Günter Rote added the comment:

Sorry, that was my misinterpretation of what happened.
I had been stumbling over an old program I had written, but
apparently it works because the while-loop is inside
a generator function, and the StopIteration is simply
passed on.

Here is a small demonstration example:
>>> def f():
...   for x in range(5):
...     yield x
>>> def g():
...   h=f()
...   while True:
...      yield next(h)+100
...      yield next(h)
>>> list(g())
[100, 1, 102, 3, 104]

(I am beginning to wonder whether this program will be adversely affected by PEP 479 -- Change StopIteration handling inside generators.)

stage:  -> resolved
status: open -> closed
versions: +Python 3.4 -Python 3.6

Python tracker <report at bugs.python.org>

More information about the docs mailing list