Surprising difference (bug?) between traceback and inspect

Gary Bishop gb at cs.unc.edu
Tue Jun 10 16:17:49 EDT 2003


The following short script illustrates a surprising difference between
the output of traceback.extract_stack and inspect.outerframes().

They look pretty much the same if the program does not change the
working directory, but for programs that internally change their
working directory, inspect loses the file names.

The problem (if it is a problem) originates in inspect.getsourcefile
which insists on a True result from os.path.exists(filename) before it
will return filename.

I encountered this deep in the fancy traceback code in IPython which
is using inspect.innerframes to get the same info (I think) as
traceback.extract_tb. The particular program I was debugging used
chdir at one point and then tracebacks lose their filenames.

I don't see why inspect.getsourcefile should insist on os.path.exists
before returning the name. The name isn't the full path name so why
should this test be required?

gb




More information about the Python-list mailing list