diff --git a/IPython/ultraTB.py b/IPython/ultraTB.py index be92351..22b5714 100644 --- a/IPython/ultraTB.py +++ b/IPython/ultraTB.py @@ -60,7 +60,7 @@ You can implement other color schemes easily, the syntax is fairly self-explanatory. Please send back new schemes you develop to the author for possible inclusion in future releases. -$Id: ultraTB.py 2480 2007-07-06 19:33:43Z fperez $""" +$Id: ultraTB.py 2883 2007-12-02 02:54:17Z rkern $""" #***************************************************************************** # Copyright (C) 2001 Nathaniel Gray @@ -135,11 +135,18 @@ def findsource(object): FIXED version with which we monkeypatch the stdlib to work around a bug.""" file = getsourcefile(object) or getfile(object) - module = getmodule(object, file) - if module: - lines = linecache.getlines(file, module.__dict__) + # If the object is a frame, then trying to get the globals dict from its + # module won't work. Instead, the frame object itself has the globals + # dictionary. + globals_dict = None + if inspect.isframe(object): + # XXX: can this ever be false? + globals_dict = object.f_globals else: - lines = linecache.getlines(file) + module = getmodule(object, file) + if module: + globals_dict = module.__dict__ + lines = linecache.getlines(file, globals_dict) if not lines: raise IOError('could not get source code') diff --git a/doc/ChangeLog b/doc/ChangeLog index 19fd473..d8d728c 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2007-12-01 Robert Kern + + * IPython/ultraTB.py (findsource): Improve the monkeypatch to + inspect.findsource(). It can now find source lines inside zipped + packages. + 2007-11-29 *** Released version 0.8.2 2007-11-25 Fernando Perez