[Python-ideas] return value of yield expressions

Ron Adam ron3200 at gmail.com
Tue Sep 13 19:23:26 CEST 2011

On Tue, 2011-09-13 at 13:02 +0200, Jacob Holm wrote:

> Your other proposal is really independent of generators I think.  I
> too
> would like to see a way to do "function argument unpacking".
> args, kwds = (yield ret)  # any expression really
> (a1, a2, a3, *args), kwds = (lambda a1,a2,a3=default,*args, **kwds:
>                              (a1,a2,a3)+args, kwds
>                             )(*args, **kwds)
> is about the shortest way I can come up with that works today, and
> that
> is way too much repetition for my taste.  If locals() were writable (a
> change that is unlikely to happen btw), this could be reduced to:
> args, kwds = (yield ret)  # any expression really
> locals().update(
>     (lambda a1,a2,a3=default,*args,**kwds:locals())(*args, **kwds)
>     )
> which would avoid some of the duplication but is really not that more
> readable.

Instead of extending tuple unpacking, I think I'd prefer to go the other
way and improve function data sharing.

If we could get the functions arguments when a function is done instead
of getting the return value.  (The modified function arguments object is
the return value in this case.)

      fargs = &foo(a, b, c, d=4)

Then someplace else use that function argument object directly.

      bar.__with_args__(fargs)    # fargs becomes bar's argument object

It could avoid unpacking and repacking data when it's passed between
compatible functions.


More information about the Python-ideas mailing list