[Python-ideas] return value of yield expressions

David Townshend aquavitae69 at gmail.com
Wed Sep 14 00:26:49 CEST 2011


On Sep 13, 2011 8:53 PM, "Guido van Rossum" <guido at python.org> wrote:
>
> On Tue, Sep 13, 2011 at 11:35 AM, Jacob Holm <jh at improva.dk> wrote:
> > The '*(argument list) = <expression>' syntax was my attempt at fixing
> > some of the problems in the original proposal.  I.e. to remove the
> > restriction that it only should work with "= yield", and distinguish the
> > "function argument unpacking" from the regular tuple unpacking.
> >
> > My idea was to allow
> >
> >  *(argument list) = (args, kwds)
> >
> > where the LHS follows all the rules of a function argument list (the
> > part of a function definition between the name and the colon), and
> > the RHS may be any expression that returns a 2-tuple consisting of a
> > sequence and a dictionary.
> >
> > The intended semantics was to compute the arguments that a function with
> > the given argument list would see when called with (*args, **kwds), and
> > make the necessary assignments in the local scope.  Any way I can think
> > of that works today violates DRY.
> >
> >
> > A simple example:
> >
> > *(a, b, c=42, *args, **kwds) = ((1,), {'b':2, 'd':3})
> >
> > assigns a=1, b=2, c=42, args=(), kwds={'d':3}
>
> Thanks, I finally understand. Part of the reason why it was unclear to
> me was that I was reading the form inside *(...) as having the same
> priority rules as a regular assignment, where "," binds tighter than
> "="; whereas in a function argument list "=" binds tighter than ",".
>
> > And my best hack so far to get the same effect today is:
> >
> > args, kwds = ((1,), {'b':2, 'd':3})
> > a, b, c, args, kwds = \
> >  (lambda a, b, c=42, *args, **kwds:a, b, c, args, kwds)(*args, **kwds)
> >
> >
> > I am not wed to the particular suggested syntax, but I would like to see
> > the functionality available *somehow* in a way where you don't have to
> > repeat the sequence of variable names.  And I don't think that is
> > possible without *some* syntax change.
>
> I agree that you can't do this today.

I've only skimmed this so I might be way off track, but isn't this
capability (although not the syntax) already covered to an extent by PEP
362?

>
> But so what?
>
> I am not so convinced that DRY is always the most important rule to
invoke.
>
> Apart from the extremely esoteric example of wanting to call g.send()
> with a mix of positional and keyword arguments that are somehow
> interpreted as a completely general function parameter list by the
> receiving yield expression, what is the use case?
>
> --
> --Guido van Rossum (python.org/~guido)
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110914/8c65f3d5/attachment.html>


More information about the Python-ideas mailing list