[Python-Dev] nested try..except bug in generators

Yury Selivanov yselivanov.ml at gmail.com
Fri Nov 20 11:30:40 EST 2015


Hi,

For anyone interested in tickling the low-level CPython
internals (in this case eval loop and generators
implementations), here's an interesting bug:
http://bugs.python.org/issue25612.

I have a patch that fixes it, but I'm not sure that it's
correct, and I desperately need someone to review it.

While debugging the issue, I found another oddity:

     class MainError(Exception): pass
     class SubError(Exception): pass

     def main():
         try:
             raise MainError()
         except MainError:
             yield

     coro = main()
     coro.send(None)
     coro.throw(SubError())

On the last line of the above snippet, SubError will
propagate.  However, it won't have it's __context__ set
to MainError.  Martin Panter suggests that it's not a bug,
and after giving this some thought, I now don't think it's
a bug too -- SubError was instantiated outside of MainError
from a code location where there was no error.  Thoughts?
Here's a separate issue for the __context__ bug/feature:
http://bugs.python.org/issue25683

Thanks,
Yury


More information about the Python-Dev mailing list