[Python-ideas] return value of yield expressions

Jacob Holm jh at improva.dk
Tue Sep 13 16:33:07 CEST 2011


On 2011-09-13 15:03, H. Krishnan wrote:
>> To start with the latter, I don't think that is going to fly.  All
>> arguments to send must be returned as a single value by yield or cause
>> most of the examples in the PEP380 discussion to fail.  Allowing
>> arbitrary arguments to send would have to change that value in a
>> backward-incompatible way when sending a single argument.
> Actually, the issue is with how the return value is gathered rather than in 
> send() itself, right? If the return value is specially gathered for 
> unpacking (as you suggested), would there be any other issue with backward 
> compatibility?

Not quite sure I understand the question, but I'll try to answer anyway.

You need to be able to use "var1 = yield var2" in the generator
independent on what send is called with, or you can't wrap a generator
using another generator (different ways of doing that was a large part
of the PEP380 discussion).

So what should "var1" be in each of the following cases?

g.send()           # currently illegal
g.send(None)       # None
g.send((), {})     # currently illegal
g.send(((), {}))   # ((), {})

I suppose you could change it so passing exactly one argument did
something different from passing zero or multiple arguments, but then
you have a problem distinguishing when you actually want to use the
value in the other end.

Hope this helps.

- Jacob

More information about the Python-ideas mailing list