[Python-ideas] Revised**6 PEP on yield-from

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Mon Feb 23 14:05:09 CET 2009

Given that the expansion is quite complicated...

Imagine that we want to alter the values while passing them from the
inner generator. For example:
   for x in expr:
      yield x+1
How to let this be as transparent to send/close/etc. as yield from?

If the transformation is an expression, one can use a generator comprehension:
   yield from (x+1 for x in expr)
but this does not work if we have some statements inside:
   seen = set()
   for x in expr:
      if x not in seen:
         yield x

(I'm not familiar with the details of how send works, but I hope the
point is valid.)

Marcin Kowalczyk
qrczak at knm.org.pl

More information about the Python-ideas mailing list