This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Default traceback does not handle PEP302 loaded modules
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: anders.blomdell@control.lth.se, ggenellina, iritkatriel
Priority: normal Keywords:

Created on 2009-08-11 14:26 by anders.blomdell@control.lth.se, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug.tar anders.blomdell@control.lth.se, 2009-08-11 14:26 Tar archive of testcase
Messages (3)
msg91475 - (view) Author: Anders Blomdell (anders.blomdell@control.lth.se) Date: 2009-08-11 14:26
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 <module>
      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 <module>
      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 <module>
      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 <module>
      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 <module>
      # 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.
msg220828 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-17 13:17
Who is best placed to look at an issue about import hooks and default tracebacks?
msg412032 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-28 21:01
This was reported for 2.6, not clear why 3.1 and 3.2 were added later. 

Anyway, I'm not seeing the issue on 3.11 (with a script updated for python-3 prints). 

Also, imp is deprecated now.
History
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50931
2022-01-28 21:01:30iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg412032

resolution: out of date
stage: needs patch -> resolved
2019-03-15 23:20:47BreamoreBoysetnosy: - BreamoreBoy
2014-06-17 13:17:56BreamoreBoysetnosy: + BreamoreBoy
messages: + msg220828
2010-07-11 09:08:43BreamoreBoysetstage: needs patch
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2009-08-14 08:02:52ggenellinasetnosy: + ggenellina
2009-08-11 14:26:30anders.blomdell@control.lth.secreate