[Python-ideas] return value of yield expressions

H. Krishnan hetchkay at gmail.com
Tue Sep 13 17:09:34 CEST 2011



> 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.
>

Let us consider from a function point of view:
If suppose there was no support for *args and **kwds and you wrote:
  def func(a):
      do_something_with_a
and this was called with:
func((1,2))

and subsequently, *args, **kwds support was added to functions, will 
anything related to 'func' need to change?

Thus, if 
var = yield <expr>
is used, send() needs to be called with only one argument (or as send(var = 
x) ).
If 
var1, var2 = yield <expr>
is used, send() needs to be called with two arguments.
If 
yield <expr>
is used, send() can be called with any no. of arguments/keywords etc.

Krishnan


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110913/16027063/attachment.html>


More information about the Python-ideas mailing list