Issue 6682: Default traceback does not handle PEP302 loaded modules (original) (raw)

While trying to get a PEP302 import hook to function properly, I found that the default traceback picks up the wrong sourcecode for PEP302 loaded modules.

The testcase pep302_traceback.py tries to emulate the behavior of the files in ordinary, which generates the following output when run:

(cd ordinary ; python2.6.2 main.py )

A.name= a B.name a.b Traceback (most recent call last): File "main.py", line 6, in a.A() File "/tmp/ordinary/a/init.py", line 6, in init b.B() File "/tmp/ordinary/a/b/init.py", line 4, in init raise Exception() Exception

But when i run the testcase, I get the following:

python2.6.2 pep302_traceback.py

Show possible bug in default linecache (works in 2.6.2)

A.name= a B.name= a.b Traceback (most recent call last): File "pep302_traceback.py", line 82, in i.load_module("main") File "pep302_traceback.py", line 58, in load_module exec(code, mod.dict) File "<__main__.Importer>/main.py", line 6, in a.A() File "<__main__.Importer>/a/init.py", line 6, in init b.B() File "<__main__.Importer>/a/b/init.py", line 4, in init raise Exception() Exception

Show possible bug in default traceback (does not work in 2.6.2)

A.name= a B.name= a.b Traceback (most recent call last): File "pep302_traceback.py", line 88, in i.load_module("main") File "pep302_traceback.py", line 58, in load_module exec(code, mod.dict) File "<__main__.Importer>/main.py", line 6, in # main.py picked up from somewhere in sys.path File "<__main__.Importer>/a/init.py", line 6, in init # init.py picked up from somewhere in sys.path File "<__main__.Importer>/a/b/init.py", line 4, in init # init.py picked up from somewhere in sys.path Exception

I.e. in python 2.6 the linecache module correctly picks up PEP302 loaded code, while the default traceback picks up any source file from sys.path that happens to match the name of the file that generated the exception. When run with python2.5.2, the linecache module also locates the wrong file from sys.path.