On Sat, Apr 4, 2009 at 4:27 PM, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
Let's not lose sight of the fundamental motivation for all this, the way I see it at least: yield-from is primarily to permit factoring of generator code. Any proposals for enhancements or extensions ought to be justified in relation to that.
I still don't think that refactoring should drive the design exclusively. Refactoring is *one* thing that becomes easier with yield-from. But I want the design to look pretty from as many angles as possible.
I don't believe that once the generator has raised StopIteration or ReturnFromGenerator, the return value should be saved somewhere to be retrieved with an explicit close() call -- I want to be able to free all resources once the generator frame is dead.
I agree with that.
As a corollary, I *don't* think that close() should return the value of a ReturnFromGenerator even if it gets one, because unless the value is stored, you'll only get it the first time close() is called, and only if the generator has not already completed normally. That would make it too unreliable for any practical use as far as I can see.
Throwing in GeneratorExit and catching the ReturnFromGenerator exception would have the same problem though, so I'm not sure I buy this argument. -- --Guido van Rossum (home page: http://www.python.org/~guido/)