[Python-Dev] [Python-ideas] PEP 479: Change StopIteration handling inside generators
Chris Angelico
rosuav at gmail.com
Wed Nov 19 22:44:33 CET 2014
On Thu, Nov 20, 2014 at 3:45 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> The part I found most compelling was when you pointed out that in the
> special method implementations, the normal return path was always spelled
> with "return", while the "value missing" result was indicated with a special
> kind of exception (StopIteration, AttributeError, IndexError or KeyError),
> and then any other exception was consider unexpected.
>
> Generators add the third notion of being able to suspend execution via
> "yield", which then left them with two different ways of spelling
> termination inside the frame: "return" OR "raise StopIteration". The second
> spelling ("raise StopIteration") is then inherently surprising, as it's
> entirely redundant, *except* in that it allows you to effectively have a
> "hidden return" in a generator frame that can't be done anywhere else.
(The above was said on -ideas, but discussion is now moving to -dev,
so I hope it's okay to send the response there.)
Added a paragraph to the PEP draft:
https://github.com/Rosuav/GenStopIter/commit/695961
Should today's date be added to the Post-History?
ChrisA
More information about the Python-Dev
mailing list