[Python-ideas] Another attempt at a sum() alternative: the concatenation protocol

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue Jul 16 17:44:54 CEST 2013


On 16 July 2013 16:31, Joshua Landau <joshua at landau.ws> wrote:
>> Set and dict comps presumably use .update. And the generator expression
>>     (*a for b in c)
>> becomes
>>     for b in c:
>>         for x in a:
>>             yield x
>> or is it actually (this is not equivalent):
>>     for b in c:
>>        yield from a
>
> I imagine it would use "yield from", although it is not actually
> defined in the PEP. I see no reason to prefer the explicit loop. If
> this matters enough, I can add it to the PEP, but I'd need a consensus
> in order to dictate a specific methodology over others.

There are other implications to using 'yield from' such as delegating
to subgenerators for .send() et al. I think that it would be good to
be able to delegate but the syntax might be seen as cryptic compared
to an explicit 'yield from'. The explicit 'yield from' currently
unrolls as the weird 'yield (yield from x)'  though, which is less
useful.


Oscar


More information about the Python-ideas mailing list