[Python-ideas] x=(yield from) confusion [was:Yet another alternative name for yield-from]

Nick Coghlan ncoghlan at gmail.com
Sat Apr 4 02:39:46 CEST 2009

Jacob Holm wrote:
> Since you are no longer pushing an alternative syntax for return but
> still want a different exception, I'll assume there is some other
> beginner mistake you are worried about.  My guess is it is some mistake
> at the places where the generator is used, but I am having a hard time
> figuring out where the mistake could be in ignoring the returned value. 
> Perhaps you (or someone who has more time) can provide an example where
> this is a bad thing?

I can't speak for Guido, but the two easy beginner mistakes I think are
worth preventing:

- using 'return' where you meant 'yield' (however, if even 'return
finally' doesn't appeal to Guido as alternative syntax for "no, this is
a coroutine, I really mean it" then I'm fine with that)

- trying to iterate normally over a coroutine instead of calling it
appropriately (raising GeneratorReturn instead of StopIteration means
that existing iterative code will let the new exception escape rather
than silently suppressing the return exception)


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

More information about the Python-ideas mailing list