[Python-ideas] Possible PEP 380 tweak

Nick Coghlan ncoghlan at gmail.com
Sat Oct 30 08:25:36 CEST 2010

On Sat, Oct 30, 2010 at 4:13 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Nick Coghlan wrote:
>> 1. Send in a sentinel value (often None, but you could easily reuse
>> the exception types as sentinel values  as well)
>> 2. Throw in GeneratorExit explicitly
>> 3. Throw in StopIteration explicitly
>> 4. Throw in a different specific exception
>> 5. Call g.close()
>> Yield from also
>> isn't innately set up to unwind correctly in any of these cases,
> On the contrary, I think it works perfectly well with 1, and
> also with 4 as long as the inner generator catches it in the
> right place.

Yeah, I'd agree with that. Unwinding the stack correctly requires
cooperation from all of the intervening layers and the logic for that
is likely to be a little clumsy, but the issues are not insurmountable
(my own "return from" suggestion requires cooperation as well, since
the layers have to explicitly invoke the alternate semantics to
indicate that return values should be passed through).

"return from" would make more sense as its own PEP, with the construct
possibly given a meaning in ordinary functions as well (e.g. the
occasionally sought tail-call optimisation in recursive functions).


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

More information about the Python-ideas mailing list