Bugs item #1666807, was opened at 2007-02-23 00:08
Message generated for change (Comment added) made by jseutter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1666807&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Fernando P�rez (fer_perez)
Assigned to: Nobody/Anonymous (nobody)
Summary: Incorrect file path reported by inspect.getabsfile()

Initial Comment:
The following code demonstrates the problem succinctly:

###
import inspect,sys

print 'Version info:',sys.version_info
print

f1 = inspect.getabsfile(inspect)
f2 = inspect.getabsfile(inspect.iscode)
print 'File for `inspect`       :',f1
print 'File for `inspect.iscode`:',f2
print 'Do these match?',f1==f2
if f1==f2:
    print 'OK'
else:
    print 'BUG - this is a bug in this version of Python'

###  EOF

Running this on my system (Linux, Ubuntu Edgy) with 2.3, 2.4 and 2.5 produces:

tlon[bin]> ./python2.3 ~/code/python/inspect_bug.py
Version info: (2, 3, 6, 'final', 0)

File for `inspect`       : /home/fperez/tmp/local/lib/python2.3/inspect.py
File for `inspect.iscode`: /home/fperez/tmp/local/lib/python2.3/inspect.py
Do these match? True
OK
tlon[bin]> python2.4 ~/code/python/inspect_bug.py
Version info: (2, 4, 4, 'candidate', 1)

File for `inspect`       : /usr/lib/python2.4/inspect.py
File for `inspect.iscode`: /home/fperez/tmp/local/bin/inspect.py
Do these match? False
BUG - this is a bug in this version of Python
tlon[bin]> python2.5 ~/code/python/inspect_bug.py
Version info: (2, 5, 0, 'final', 0)

File for `inspect`       : /usr/lib/python2.5/inspect.py
File for `inspect.iscode`: /home/fperez/tmp/local/bin/inspect.py
Do these match? False
BUG - this is a bug in this version of Python


###

The problem arises in the fact that inspect relies, for functions (at least), 
on the func_code.co_filename attribute to contain a complete path.  This 
changed between 2.3 and 2.4, but the inspect module was never updated.  This 
code:

###
import inspect,sys

print 'Python version info:',sys.version_info
print 'File info for `inspect.iscode function`:'
print ' ',inspect.iscode.func_code.co_filename
print
### EOF

shows the problem:

tlon[bin]> ./python2.3 ~/code/python/inspect_bug_details.py
Python version info: (2, 3, 6, 'final', 0)
File info for `inspect.iscode function`:
  /home/fperez/tmp/local//lib/python2.3/inspect.py

tlon[bin]> python2.5 ~/code/python/inspect_bug_details.py
Python version info: (2, 5, 0, 'final', 0)
File info for `inspect.iscode function`:
  inspect.py

###

(2.4 has the same issue).

Basically, if the func_code.co_filename attribute now stores only the final 
filename without the full path, then the logic in the inspect module needs to 
be changed to accomodate this so that correct paths are reported to the user 
like they were in the 2.3 days.

----------------------------------------------------------------------

Comment By: Jerry Seutter (jseutter)
Date: 2007-02-23 23:51

Message:
Logged In: YES 
user_id=1727609
Originator: NO

Hi,

On a custom-compiled Python 2.5 on Ubuntu Dapper, I get:
[EMAIL PROTECTED]:~/code/python $ python bug_1666807.py
Version info: (2, 5, 0, 'final', 0)

File for `inspect` : /usr/local/lib/python2.5/inspect.py
File for `inspect.iscode`: /usr/local/lib/python2.5/inspect.py
Do these match? True
OK


On a system python 2.4.3 on another Ubuntu Dapper system, I get:
[EMAIL PROTECTED]:~/code/python $ python bug_1666807.py
Version info: (2, 4, 3, 'final', 0)

File for `inspect` : /usr/lib/python2.4/inspect.py
File for `inspect.iscode`: /usr/lib/python2.4/inspect.py
Do these match? True
OK

However, I can recreate this issue on another system (CentOS4) with a
custom install where a symlink is involved.  I get: 
[prompt goes here python]$ python bug_1666807.py
Version info: (2, 2, 3, 'final', 0)

File for `inspect` : /xxx/yyyy/PythonHome/lib/python2.2/inspect.py
File for `inspect.iscode`: /xxx/yyyy/Python-2.2/lib/python2.2/inspect.py
Do these match? 0
BUG - this is a bug in this version of Python

Is a symlink involved on the system where you saw this behaviour?

----------------------------------------------------------------------

Comment By: Fernando P�rez (fer_perez)
Date: 2007-02-23 09:57

Message:
Logged In: YES 
user_id=395388
Originator: YES

Note: a colleague just tested this under Python 2.4 for Mac OSX (intel),
and the problem didn't show up there:

import inspect
print 'File for `code`         :',inspect.getabsfile(code)
print 'File for `code.interact`:',inspect.getabsfile(code.interact)

Gives:

File for `code`         :
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/code.py
File for `code.interact`:
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/code.py

My original tests were done under Ubuntu Edgy Eft, using the
Ubuntu-provided 2.4 and 2.5, and a hand-compiled 2.3.6 from the source
download at python.org.

HTH,

f

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1666807&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to