Skip to content
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

Fix debug() in notebook #14338

Closed
nbruin opened this issue Mar 22, 2013 · 10 comments
Closed

Fix debug() in notebook #14338

nbruin opened this issue Mar 22, 2013 · 10 comments

Comments

@nbruin
Copy link
Contributor

nbruin commented Mar 22, 2013

On sage-devel it was observed that at least in 5.7 and 5.8 we have in the notebook:

sage: 1/0
ZeroDivideError

(as expected)

sage: debug()
IndexError: string index out of range

due to inspect.getinnerframes failing on a seemingly otherwise valid traceback object.

Component: notebook

Author: Nils Bruin

Reviewer: Andrey Novoseltsev

Merged: sage-5.9.beta2

Issue created by migration from https://trac.sagemath.org/ticket/14338

@nbruin nbruin added this to the sage-5.9 milestone Mar 22, 2013
@nbruin
Copy link
Contributor Author

nbruin commented Mar 22, 2013

strip notebook frames prior to processing

@nbruin
Copy link
Contributor Author

nbruin commented Mar 22, 2013

Author: Nils Bruin

@nbruin
Copy link
Contributor Author

nbruin commented Mar 22, 2013

comment:1

Attachment: trac_14338-strip_frames.patch.gz

One fix is to avoid the frames on which inspect.findsource chokes, since those are frames that have to do with the notebook, not with the user code, so they don't get displayed anyway.

The other fix would be to

python/inspect.py:526

     file = getfile(object)
     sourcefile = getsourcefile(object)
-    if not sourcefile and file[0] + file[-1] != '<>':
+    if not sourcefile and (not file or file[0] + file[-1] != '<>'):
         raise IOError('source code not available')
     file = sourcefile if sourcefile else file

but that's a change to python, not to sage.

@novoselt
Copy link
Member

Reviewer: Andrey Novoseltsev

@novoselt
Copy link
Member

comment:2

Thanks for looking into it! The patch works for me and does what was done before in a slightly different way.

@novoselt
Copy link
Member

comment:3

OK, I was too fast:

**********************************************************************
5 items had failures:
   2 of   4 in sage.interacts.debugger.Debug
   1 of   3 in sage.interacts.debugger.Debug.__init__
   2 of   4 in sage.interacts.debugger.Debug.curframe
   1 of   4 in sage.interacts.debugger.Debug.evaluate
   3 of   7 in sage.interacts.debugger.Debug.listing
    [23 tests, 9 failures, 1.7 s]
----------------------------------------------------------------------
sage -t --long sage/interacts/debugger.py  # 9 doctests failed
----------------------------------------------------------------------

@nbruin
Copy link
Contributor Author

nbruin commented Mar 23, 2013

Attachment: trac_14338-doctest_fix.patch.gz

fix doctest

@nbruin
Copy link
Contributor Author

nbruin commented Mar 23, 2013

comment:4

OK, the doctest uses a stacktrace that's shallower than will ever happen in the notebook, so when we strip off the 5 outer frames that should be removed in the notebook, we have nothing left (hence the error). Attached patch makes a deeper backtrace so that stripping off the first 5 still leaves something to test. Doctest text needs to be changed in some spots.

@novoselt
Copy link
Member

comment:5

Looks good and all long tests pass now.

@jdemeyer
Copy link

Merged: sage-5.9.beta2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants