[Python-Dev] PEP 3142: Add a "while" clause to generator expressions

Terry Reedy tjreedy at udel.edu
Wed Jan 21 00:27:58 CET 2009


Gerald Britton wrote:
> I wonder if this is a bug?

It is a known glitch reported last summer.  Devs decided not to fix 
because doing so would, in the patches tried, slow list comps 
significantly.  Also, the documented intent and expected usage of 
StopIteration is this

"exception StopIteration
Raised by builtin next() and an iterator‘s __next__() method to signal 
that there are no further values."

The second clause includes usage in the body of a generator function 
since that body becomes the __next__ method of the generator-iterator 
produced by calling the generator function.

The meaning of any other usage, such as in the body of a standard 
function other than next(),(as in the example producing the glitch), is 
undefined and leads to undefined behavior, which could be different in 
other implementations and change in future implementations.

Terry Jan Reedy



More information about the Python-Dev mailing list