On Mon, Aug 2, 2010 at 9:37 AM, Antoine Pitrou firstname.lastname@example.org wrote:
How would you have benefitted? Is it a problem if the iteration isn't "flattened"?
If it's because of the recursion limit, then it's a general problem and I don't think a generator-specific solution is a good idea. If it's an aesthetical preference then I don't think new syntax is warranted for that.
I think the main reason for wanting the stack of yields flattened is the cost of bumping each next() call all the way up and down the stack. Without an optimized yield-from, yield from G is equivalent to "for X in G: yield X" and that means if you have this nested 3 times on the stack, each next() call incurs the overhead of three for-loop iterations. It would be especially bad if you have a fairly deeply nested stack and then the innermost generator yields a large number of values.
It remains to be seen at which point this becomes prohibitive and when the overhead of wrapping every generator in a From instance (and passing every next() call through a method of that instance) is actually faster, given that a for-loop iteration is just a few bytecode instructions.