[IPython-dev] Custom exception handling

Mateusz Paprocki mattpap at gmail.com
Thu Oct 13 23:31:48 EDT 2011


Hi,

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 [1]) 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 [2]. 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` [3] (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 [1], I'm
looking forward to your suggestions.

Mateusz

[1] https://github.com/sympy/sympy/pull/643
[2]
https://github.com/ipython/ipython/blob/master/IPython/core/interactiveshell.py#L2438
[3]
https://github.com/ipython/ipython/blob/master/IPython/core/interactiveshell.py#L1562
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20111013/ec2c33f6/attachment.html>


More information about the IPython-dev mailing list