[Python-ideas] Revised**5 PEP on yield-from

Ron Adam rrr at ronadam.com
Fri Mar 6 03:58:17 CET 2009



Greg Ewing wrote:
> Ron Adam wrote:
> 
>> Could it be possible to design it so that the yield path of generators 
>> are passed down or forwarded to sub-generators when they are called?
> 
> It's really the other way around -- you would need some way
> of passing the yield path *up* to a generator's caller.
 >
> E.g. if A is yielding from B is yielding from C, then A needs
> a direct path to C.

So when A.next() is called it in effect does a C.next() instead. Is that 
correct?  And when C's yield statement is executed, it needs to return the 
value to A's caller.

So the .next() methods need to be passed up, while the yield return path 
needs to be passed down?

OK, I guess I need to look at some byte/source code. ;-)


> Possibly some scheme could be devised to do this, but I don't
> feel like spending any brain cycles on it until the current
> scheme is shown to be too slow in practice. Premature
> optimisation and all that.

Right I agree.  I have an intuitive feeling that being able to expose and 
redirect caller and return values may useful in more ways than just 
generators.  ie.. general functions, translators, encoders, decorators, and 
possibly method resolution.  <shrug> then again, there may not be any easy 
obvious way to do it.

Ron









More information about the Python-ideas mailing list