[Python-ideas] "Iteration stopping" syntax [Was: Is this PEP-able? for X in ListY while conditionZ:]

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Jul 1 00:08:28 CEST 2013


Ron Adam wrote:
> It's the same as in-lineing the generator 
> parts into the iterator that is driving it.
> 
> We don't need to do that because we already have an optimised version of 
> that.  It just needs to catch the StopIteration to be the same.
> 
> I think that it's not uncommon for people to think this is how list 
> comps work.  And I think it is surprising for them that the 
> StopIteration isn't caught.

I tend to feel that the fact that raising StopIteration in a
generator has the same effect as returning from the generator
is a quirk of the implementation that shouldn't be relied on.
I'm not sure we should be giving it official status by going
out of our way to make listcomps behave the same.

-- 
Greg


More information about the Python-ideas mailing list