[Python-Dev] PEP 380 (yield from a subgenerator) comments

P.J. Eby pje at telecommunity.com
Sat Mar 21 17:25:05 CET 2009

At 04:45 PM 3/21/2009 +1000, Nick Coghlan wrote:
>I really like the PEP - it's a solid extension of the ideas introduced
>by PEP 342.

(Replying to you since I haven't seen any other thread on this)

My concern is that allowing 'return value' in generators is going to 
be confusing, since it effectively causes the return value to 
"disappear" if you're not using it in this special way with some 
framework that takes advantage.

However, if you *do* have some framework that takes advantage of 
generators to do microthreads, then it is most likely already written 
so as to have things like 'yield Return(value)' to signal a return, 
and to handle 'yield subgenerator()' without the use of additional syntax.

So, I don't really see the point of the PEP.  'yield from' seems 
marginally useful, but I really dislike making it an expression, 
rather than a statement.  The difference seems just a little too 
subtle, considering how radically different the behavior 
is.   Overall, it has the feel of jamming a framework into the 
language, when doing the same thing in a library is pretty trivial.

I'd almost rather see a standard or "reference" trampoline added to 
the stdlib (preferably with a way to register handling for 
specialized yielded types IO/scheduling hooks), than try to cram half 
a trampoline into the language itself.

More information about the Python-Dev mailing list