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

Jacob Holm jh at improva.dk
Thu Apr 23 02:20:20 CEST 2009

Hi Jim

Jim Pryor wrote:
>>> I would call that a bug.
>> I agree with that.
> I don't understand why you're both counting this as a bug. It looks like
> exactly the behavior specified in PEP 342. When g.close() is evaluated,
> a GeneratorExit is thrown to the suspended 'yield' expression in foo.
> That exception is is not caught, so g terminates without executing the
> rest of its code. The 'raise ValueError' line is never executed.

You are of course completely right.  What I *should* have tried was the 

 >>> def foo():
...     try:
...         yield 'bar'
...     except:
...         raise ValueError('baz')
 >>> g = foo()
 >>> g.next()
 >>> g.close()
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "<stdin>", line 5, in foo
ValueError: baz

Which works as expected.  No bug in sight.  In that case I am not sure 
what Eriks original problem was.

- Jacob

More information about the Python-ideas mailing list