[Python-ideas] x=(yield from) confusion [was:Yet another alternative name for yield-from]

Jacob Holm jh at improva.dk
Fri Apr 10 09:42:57 CEST 2009


Jim Jewett wrote:
> On 4/9/09, Jacob Holm <jh at improva.dk> wrote:
>   
>>> ... does suggest that yield-from *should* accept pre-started
>>> generators, if only because the previous line (or a decorator) may
>>> have primed it.
>>>       
>
>   
>> That was my argument, but since there is no sane way of handling
>> pre-primed generators without extending the PEP in a direction that
>> Guido has forbidden,
>>     
>
> Huh?  All you need to do is to not care whether the generator is fresh
> or not (let alone primed vs half-used).
>   

By no sane way I mean that there is no way to avoid that the first call 
made by the yield-from construct is a
next().  If the pre-primed generator is expecting a send() at that point 
you are screwed.

> If it won't be primed, *and* you can't afford to send back an extra
> junk yield, then you need to prime it yourself.  

And then the yield-from is still starting out by calling next() so you 
are still screwed.

> That can be awkward,
> but so are all the syntax extensions that boil down to "and implicitly
> call next for me once".  (And the "oops, just this once, don't prime
> it after all" extensions are even worse.)
>
>   

The only syntax extension that was really interesting was intended to 
*avoid* this call to next() by providing a different value to yield the 
first time.  Avoiding the call to next() allows you to create all kinds 
of wrappers that manipulate the start of the sequence, and covers all 
other cases I had considered syntax for.

Anyway, this syntax discussion is moot since Guido has already ruled 
that we will have no syntax for this.


- Jacob



More information about the Python-ideas mailing list