[Python-ideas] Revised**11 PEP on Yield-From

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Apr 17 23:26:00 CEST 2009

Jacob Holm wrote:

>   1. Throwing StopIteration to an iterator without a throw() method.

Guido seems happy not to care what happens if you
throw StopIteration in, so I'm happy to do so as
well -- it saves considerable complication.

>   2. Calling an iterator.close() that raises a StopIteration.      
> Arguably, such a close() is an error, so getting an exception in
>      the caller is better than swallowing it

There are plenty of other ways to get strange
results by raising StopIteration in places where
you shouldn't, so I'm not worried about this either.

 > What should happen with an iterator that has a
> throw or close attribute that just happens to have the value None?
 > The expansion handles it as if the attribute wasn't there

That's a good point -- I hadn't intended that.

>    * An implicit catch of GeneratorExit, followed by "return Value". 
>      By an "implicit catch", I mean either a catch of "BaseException"
>      or a "finally" clause.  In both cases, "return Value" will hide
>      the original exception and that is almost certainly a bug.

Doing either of those things *anywhere* is likely to hide
a bug. I don't see a strong reason to single out this
particular case and try to detect it.

 > I have now changed my mind.  I think giving more power to
> experienced users is more important.

My reasoning is more along the lines that it's not worth
the bother of trying to detect this error, even if it's
an error at all, which isn't entirely certain.


More information about the Python-ideas mailing list