[Python-3000] Is this a bug with list comprehensions or not?
rhamph at gmail.com
Sat Jul 12 05:02:11 CEST 2008
On Fri, Jul 11, 2008 at 7:10 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> 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()
> Would you do that only for genexps, or for generators
> in general?
> 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?
My intent was to only do so for genexps - the behaviour there seems
accidental, has no use case, and shouldn't have many people dependent
Although, upon rereading PEP 255 it seems that despite being
documented, the behaviour of raising StopIteration is an accident
there too. "return" doesn't use it and no use case is given. Since
the current behaviour is confusing, I would like to see it changed
here too. Might need to be a warning first though.
Adam Olsen, aka Rhamphoryncus
More information about the Python-3000