yield_all needed in Python

Terry Reedy tjreedy at udel.edu
Wed Mar 2 12:23:36 EST 2005


"Steven Bethard" <steven.bethard at gmail.com> wrote in message 
news:aNSdnYFA69ICiLjfRVn-ow at comcast.com...
> Douglas Alan wrote:
>> In this case, that is great, since I'd much prefer
>>
>>    yield *gen1(arg)
>>
>> than
>>
>>    yield_all gen1(arg)
>
> I'm guessing the * syntax is pretty unlikely to win Guido's approval. 
> There have been a number of requests[1][2][3] for syntax like:
>
>     x, y, *rest = iterable
>
> for unpacking a variable sized list (where *rest would work in an 
> analogous way to what it does in the args of a def.)  Guido has 
> consistently rejected these proposals, e.g.:
>
> "I think it's not worth adding now, and if you don't hear from me again 
> on this topic it's because I haven't changed my mind..."
>
> My suspicion is that if he doesn't like the * syntax when there's a close 
> parallel to the argument parsing usage, he's not likely to like it when 
> there isn't one.

Hmm.  My impression is that Guido did not like x,*y=iterable because he 
does *not* see it as a 'close parallel' but as a strained analogy.  To me, 
yield *iterable is closer to the use in function calling.  It would mean 
'unpack in time' rather than 'unpack in space' but that is natural (to me, 
anyway) since that is what generators are about.

In any case, I also like this better than yield_all and would estimate that 
it a higher chance of accceptance, even if still under 50%.  Part of the 
justification could be that the abbreviated form is much easier to speed up 
than the expanded form.  If the ref count of the iterator is just 1, then 
it might be reasonable to assume that iterator.next will not be called from 
anywhere else.  (IE, I can't think of an exception, but know that there 
might be one somehow.)

Terry J. Reedy


Terry J. Reedy






More information about the Python-list mailing list