On 20 November 2014 02:24, Chris Angelico <rosuav@gmail.com> wrote:
Does that make for more justification? Unexpected exceptions bubbling
up is better than unexpected exceptions quietly terminating loops?

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.


Nick Coghlan   |   ncoghlan@gmail.com   |   Brisbane, Australia