On Tue, Nov 25, 2014 at 4:58 PM, Greg <greg.ew...@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)
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com