[Python-ideas] return value of yield expressions
Jacob Holm
jh at improva.dk
Tue Sep 13 21:17:57 CEST 2011
On 2011-09-13 20:53, Guido van Rossum wrote:
> On Tue, Sep 13, 2011 at 11:35 AM, Jacob Holm <jh at improva.dk> wrote:
>> 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 ",".
>
I knew it had to be something like that. :)
>> 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.
>
> But so what?
>
> I am not so convinced that DRY is always the most important rule to invoke.
>
I am sure it isn't. I would also have used "readability counts", but
your earlier comments have shown that that argument is probably not
carrying much weight either in this case. :)
> 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?
>
See that's my main problem. I know I have run into this need several
times in the past, but for the life of me I can't remember the details.
I remember it had something to do with decorators, but nothing beyond that.
At the moment I just like the idea because it seems like this is a case
where something should be really easy, but isn't.
I'll let it rest until and unless I remember what the actual use was.
- Jacob
More information about the Python-ideas
mailing list