I have updated my prototype yield-from implementation
to work with Python 3.1.2.
I've also fixed a small bug that was affecting one of
the corner cases concerning exceptions thrown into
a subgenerator.
Interested parties can obtain it here:
http://www.cosc.canterbury.ac.nz/greg.ewing/python/yield-from/
--
Greg
While updating my yield-from impementation for Python
3.1.2, I came across a quirk in the way that the new
exception chaining feature interacts with generators.
If you close() a generator, and it raises an exception
inside a finally clause, you get a double-barrelled
traceback that first reports a GeneratorExit, then
"During handling of the above exception, another
exception occurred", followed by the traceback for
the exception raised by the generator.
To my mind, the fact that GeneratorExit …
[View More]is involved
is an implementation detail that shouldn't be leaking
through like this.
Does anyone think this ought to be fixed, and if so,
how? Should GeneratorExit be exempt from being
implicitly set as the context of another exception?
Should any other exceptions also be exempt?
Demonstration follows:
Python 3.1.2 (r312:79147, Jul 31 2010, 21:23:14)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def g():
... try:
... yield 1
... finally:
... raise ValueError("Spanish inquisition")
...
>>> gi = g()
>>> next(gi)
1
>>> gi.close()
Traceback (most recent call last):
File "<stdin>", line 3, in g
GeneratorExit
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in g
ValueError: Spanish inquisition
--
Greg
[View Less]