[Python-ideas] Revised**10 PEP on Yield-From
Nick Coghlan
ncoghlan at gmail.com
Sat Apr 18 13:55:00 CEST 2009
Jacob Holm wrote:
> * The "what should close() do if it catches StopIteration with a
> value" issue I don't think we have resolved either way. Since we
> are not going to store the value, only the first close() would be
> able to return it. Under those conditions, I no longer think that
> returning the value is a good idea. If we are not storing or
> returning the value, I think close() should raise an exception.
> Either reraise the StopIteration, so that the caller has a chance
> to get the value that way, or raise a RuntimeError, because it is
> meaningless to return a value as response to a GeneratorExit when
> that value cannot later be accessed by anything and it is
> therefore most likely a bug.
If you care about a generator's return value *don't* just call "close()"
on it. Use "throw(GeneratorExit)" instead so you can catch the exception
and interrogate the return value yourself.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-ideas
mailing list