[Python-Dev] Please reconsider PEP 479.

Guido van Rossum guido at python.org
Wed Nov 26 02:08:46 CET 2014


On Tue, Nov 25, 2014 at 4:58 PM, Greg <greg.ewing at canterbury.ac.nz> wrote:

> I'm not particularly opposed to PEP 479, but the Abstract and
> Rationale could do with considerable clarification.


I know.


> They currently
> appear to promise things that are in disagreement with what the PEP
> actually delivers.
>
> The Abstract claims that the proposal will "unify the behaviour of
> list comprehensions and generator expressions", but it doesn't do
> that. What it actually does is provide special protection against
> escaped StopIteration exceptions in one particular context (the
> body of a generator). It doesn't prevent StopIteration from
> escaping anywhere else, including from list comprehensions, so if
> anything it actually *increases* the difference between generators
> and comprehensions.
>

Hm, that sounds like you're either being contrarian or Chris and I have
explained it even worse than I thought.

Currently, there are cases where list(x for x in xs if P(x)) works while [x
for x in xs if P(x)] fails (when P(x) raises StopIteration). With the PEP,
both cases will raise some exception -- though you (and several others
who've pointed this out) are right that the exception raised is different
(RuntimeError vs. StopIteration) and if this occurs inside a __next__()
method (not a generator) the StopIteration will cause the outer iteration
to terminate silently.


> There may be merit in preventing rogue StopIterations escaping
> from generators, but the PEP should sell the idea on that basis, not
> on what sounds like a false promise that it will make comprehensions
> and generators behave identically.
>

I will weaken that language.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20141125/b09c0910/attachment.html>


More information about the Python-Dev mailing list