[Python-ideas] Propagating StopIteration value

Serhiy Storchaka storchaka at gmail.com
Tue Oct 9 17:34:57 CEST 2012


On 09.10.12 10:51, Greg Ewing wrote:
> Where we seem to disagree is on
> whether returning a value with StopIteration is part of the
> iterator protocol or the generator protocol.

Is a generator expression work with the iterator protocol or the 
generator protocol?

A generator expression eats a value with StopIteration:

 >>> def G():
...     return 42
...     yield
...
 >>> next(x for x in G())
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
StopIteration

Is it a bug?




More information about the Python-ideas mailing list