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

Terry Reedy tjreedy at udel.edu
Tue Jul 15 20:52:54 CEST 2008



Guido van Rossum wrote:

>> I don't see how this can be fixed, because there's no way for
>> the list() constructor to know where the StopIteration is coming
>> from.
> 
> Sounds like a good analysis to me. No bug here. Move along, nothing to see here!

I decided a couple of days ago that the easiest 'fix' would be a minor 
doc tweak.  Aftef LibRef/Exceptions:
   "exception StopIteration
   Raised by builtin next() and an iterator‘s __next__() method to signal
   that there are no further values."
add "Do not use this anywhere else."
or perhaps "Using this elsewhere may lead to undefined behavior."

I would include this with other suggestions for that section.

Then one wanting to be exact could write something like "Unless 
StopIteration is abused, list(genexp) == [genexp], and so on."

tjr





More information about the Python-3000 mailing list