[IPython-dev] Custom exception handling
Thu Oct 13 22:31:48 CDT 2011
I was working on an extension to SymPy that would allow us to automatically
construct missing symbols in interactive isympy sessions (IPython based)
(see here ) and I found some confusing to me code in
IPython/core/interactiveshell.py. The docstring of
InteractiveShell.set_custom_exc says that `handler` argument must be a
function that returns a structured traceback. However, in
InteractiveShell.run_code the code for handling custom exceptions simply
calls self.CustomTB(...) and ignores the result . This code also shadows
custom exception handling code from InteractiveShell.showtraceback, which
doesn't ignore return value from self.CustomTB(), but contains undefined
variable `ctb`  (should be `stb`).
I wanted to submit a pull request fixing this, but I'm not sure how to
proceed. I wanted to remove custom exception handling code from
InteractiveShell.run_code and in InteractiveShell.showtraceback add a case
for None return value from self.CustomTB(...) (which would mean "do nothing
and return immediately", to maintain compatibility), and of course fix
`ctb`. I was also thinking about another special case where custom exception
handler decides that IPython should proceed with displaying a traceback
(False return value would be used for this). This would be useful in my
case, because I don't want to do any traceback formatting in the handler,
just construct and injects symbols if necessary.
btw. If you see a better way to solve the problem that is solved by , I'm
looking forward to your suggestions.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-dev