Skip to content

Commit

Permalink
Merge pull request ipython#1716 from takluyver/verbose-tb
Browse files Browse the repository at this point in the history
Fix for fake filenames in verbose traceback.

We use in our frames fake filenames of the type `<ipython....>`, and we relied on `abspath` throwing an `OSError` exception with them.  That is no longer the case, and it leads to verbose tracebacks not inspecting IPython frames correctly.

This fixes the issue by simply assuming that any file that starts/ends with `</>` can't be a normal python file, which is a sensible policy (for one thing, such names can't be imported).
  • Loading branch information
fperez committed May 27, 2012
2 parents 170d865 + 40eb0fb commit 496b735
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions IPython/core/ultratb.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,13 +786,19 @@ def nullrepr(value, repr=text_repr): return ''
abspath = os.path.abspath
for frame, file, lnum, func, lines, index in records:
#print '*** record:',file,lnum,func,lines,index # dbg
try:
file = file and abspath(file) or '?'
except OSError:
# if file is '<console>' or something not in the filesystem,
# the abspath call will throw an OSError. Just ignore it and
# keep the original file string.
pass

if not file:
file = '?'
elif not(file.startswith("<") and file.endswith(">")):
# Guess that filenames like <string> aren't real filenames, so
# don't call abspath on them.
try:
file = abspath(file)
except OSError:
# Not sure if this can still happen: abspath now works with
# file names like <string>
pass

link = tpl_link % file
args, varargs, varkw, locals = inspect.getargvalues(frame)

Expand Down

0 comments on commit 496b735

Please sign in to comment.