-
-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ipython support #10
Comments
Hi - can you post exact errors so I know Im reproducing correctly? Thanks! |
There's just no difference when I import it, it's not actually an error. Try running ipython and importing better_exceptions |
Ah, iPython uses a different means to hook into exceptions... I'll have to do a bit of research about this. iPython doesn't seem to want to install for me at the moment. |
+1 on this |
You may find some inspiration in the following projects working on exception hooks as well:
The trick is probably to call set_custom_exc(exc_tuple, handler). (By the way, awesome project!) |
If you put this in from __future__ import print_function
import better_exceptions, sys
ip = get_ipython()
old_show = ip.showtraceback
def exception_thunk(exc_tuple=None, filename=None,
tb_offset=None, exception_only=False):
print("Thunk: %r %r %r %r" % (exc_tuple, filename, tb_offset, exception_only),
file=sys.stderr)
notuple = False
if exc_tuple is None:
notuple = True
exc_tuple = sys.exc_info()
use_better = True
use_better = use_better and (filename is None)
use_better = use_better and (tb_offset is None)
use_better = use_better and (not exception_only)
use_better = use_better and (not isinstance(exc_tuple[0], SyntaxError))
if use_better:
return better_exceptions.excepthook(*exc_tuple)
else:
return old_show(None if notuple else exc_tuple,
filename, tb_offset, exception_only)
ip.showtraceback = exception_thunk |
doesnt work with python3
|
example by @Omnifarious rewritten for IPython with python3
WARNING: |
Re-writing the example above to work with IPython 3.2.1 and also to handle the case where better_exceptions_module is not present in the system
I've added |
And now to make it work with |
@kootenpv It already does. def foo(a):
import pdb; pdb.set_trace()
assert a == 10
foo(12) EDIT: ah I see, it doesn't with stepping. |
Hi, |
Hi~ if you don't want to see ipython's exception in the Traceback, you can use this one:
example: before:
after:
i don't know how to pop the exception in the Traceback...so i just delete the line 1 to 6 |
To make it work with IPython debug, use this improved version: from __future__ import print_function
import better_exceptions, sys, types
ip = get_ipython()
old_show = ip.showtraceback
def exception_thunk(self, exc_tuple=None, filename=None,
tb_offset=None, exception_only=False, **kwargs):
notuple = False
if exc_tuple is None:
notuple = True
exc_tuple = sys.exc_info()
etype, value, tb = self._get_exc_info(exc_tuple)
use_better = not any ([filename, tb_offset, exception_only, issubclass(etype, SyntaxError)])
if use_better:
return better_exceptions.excepthook(etype, value, tb)
else:
return old_show(None if notuple else exc_tuple,
filename, tb_offset, exception_only, **kwargs)
ip.showtraceback = types.MethodType(exception_thunk, ip) |
@issuehunt has funded $70.00 to this issue.
|
There are a number of code snippets posted in this issue. It seems like this may already work, but not out of the box. Is there a canonical workaround for ipython's different way of handling tracebacks Ideally one that doesn't require messing with creating a personal ipython startup script. My personal preference would be registering an ipython magic like many other ipython related libraries do. Something like |
Someone mentioned Going a little off-track, it's possible to do better than either in some cases. In GUI environments like Jupyter notebooks and Jupyterlab, one can create an interactive traceback that only shows variables when requested. Django puts them in a collapsible panel: Flask/werkzeug lets you open a console in any frame: I don't know if anyone does this, but I think it might be awesome if hovering over a variable name in a traceback displays it. There's an open issue about this: jupyter/notebook#1247 |
OK, somewhat coincidentally, an alternative possibility has come up here: ipython/ipython#11827 (comment) In particular:
Essentially it would be good if there was a package which had a lower level API that returned information about a traceback which a user could easily format in different ways. IPython would be interested in such a package, as would I, and potentially other packages such as Django and Flask. @Qix- are you interested in this package being refactored to offer such an API? It would then power the existing higher level API which does the formatting, hooks, REPL, etc. The higher level API could also still be useful to other packages, e.g. @Carreau was probably mainly interested in the variable formatting. I would be happy to work on the coding, and I'm guessing others would too. But I'm concerned by the PRs that are starting to queue up with little/no response. @Qix-, do you still have the time and energy to maintain this repository and review contributions? Would you be able to handle the increased pressure if this became a dependency of IPython? If not, would you be willing to hand the responsibility over to others such as @Delgan? Otherwise I am tempted to write such a package myself from scratch and borrowing bits of code from here. |
Hey @alexmojaki, I'm still around - moved around the world about 8 months ago and have just lately been getting back into OSS. I appreciate the heads up about the ipython issue - I'd be very interested in a more comprehensive package. As for the neglect, I will be rectifying that in the coming week. |
Thanks that is great ! Hope you enjoyed your trip around the world ! Some notes: IPython also support showing variables values in stacktraces; it is disabled by default because we had issues where this was leaking secrets in tracebacks during talks, or to notebooks published on github. Though the way you show it is way nicer than ours! There are also 2 things that we do, which I believe this does not do yet is 1) show more than 1 line context, and 2) elide when there is a recursion error with A more comprehensive package and single-stop-shop is always good. Even better if we can at some point justify movin some of the functionality to core Python :-) |
Does not appear to work in ipython (at least in emacs)
IssueHunt Summary
Backers (Total: $70.00)
Become a backer now!
Or submit a pull request to get the deposits!
Tips
IssueHunt has been backed by the following sponsors. Become a sponsor
The text was updated successfully, but these errors were encountered: