[Python-3000] Is this a bug with list comprehensions or not?

Terry Reedy tjreedy at udel.edu
Sat Jul 12 06:29:36 CEST 2008

Greg Ewing wrote:
> Adam Olsen wrote:
>> However, since the genexp considers all improper ones to be in error,
>> it could wrap them with a RuntimeError and pass it through .next()
>> instead.
> Would you do that only for genexps, or for generators
> in general?

For me, the former.  For generators in general, it seems too magical. 
Anyone who writes a generator function that calls an unknown function as 
input and who worries about getting a spurious StopIteration, can choose 
to wrap with try/except in the same way as genexps.  And leaving the 
choice explicit means that it would be an explicit part of the 
definition of genexps.

> The current behaviour seems to be that if you explicitly
> raise StopIteration in a generator, the generator then
> considers itself to be exhausted (i.e. all subsequent
> calls to next() raise StopIteration as well).
> Is that behaviour deliberate? If so, do the reasons for
> it also apply to genexps?

More information about the Python-3000 mailing list