New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect file path reported by inspect.getabsfile() #44604
Comments
|
The following code demonstrates the problem succinctly: ###
import inspect,sysprint 'Version info:',sys.version_info 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 File for File for File for 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,sysprint 'Python version info:',sys.version_info EOFshows the problem: tlon[bin]> ./python2.3 ~/code/python/inspect_bug_details.py tlon[bin]> python2.5 ~/code/python/inspect_bug_details.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. |
|
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 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 |
|
Hi, On a custom-compiled Python 2.5 on Ubuntu Dapper, I get: File for On a system python 2.4.3 on another Ubuntu Dapper system, I get: File for However, I can recreate this issue on another system (CentOS4) with a custom install where a symlink is involved. I get: File for Is a symlink involved on the system where you saw this behaviour? |
|
No, in my case the original tests with 2.4 and 2.5 were done with the Ubuntu-provided (Edgy) versions, unmodified from their apt-get install state. But your comments are interesting. I just rebuilt 2.5 by hand from source on the same system, and this is what I get: tlon[bin]> ./python2.5 ~/code/python/inspect_bug.py File for tlon[bin]> ./python2.5 ~/code/python/inspect_bug_details.py So basically it seems that there's a difference in the value of the func_code.co_filename object attribute depending on how the build was made. At this point I'm not really sure if this should be considered a Python bug or an Ubuntu one... Perhaps the Python build process can be made more robust, I simply don't know. But the end-user behavior /is/ a bug, so it would be nice to know how to fix it. Thanks for your info! |
|
I haven't been able to reproduce this with Python 2.3.5, 2.4.4, 2.5.0 or SVN HEAD (all hand-built on Slackware Linux). What options are you providing to ./configure? |
|
As I mentioned, on hand-built Pythons I don't get the bug at all. So it may be a problem with how Ubuntu builds its Python, since I can reproduce the problem with both 2.4 and 2.5, but only with the default ones provided by Ubuntu Edgy. I don't know enough about their packaging system to know how to retrieve build info. There may be something odd in their build, but it would be nice if this simply couldn't happen at all. If anyone knows how to retrieve the relevant info from an ubuntu build, I'll be happy to try and provide it. |
|
It looks like this is a bug in Ubuntu build process. |
|
Yes, though at least in this report we seem to have narrowed down the problem a little better. I'm perfectly willing to believe that Ubuntu is somehow mis-building their shipped Python, but it would be great if the Python build itself could be hardened against this being possible in the first place. Unfortunately I don't know how to better track the problem, but I'll be glad to provide info from my local system upon request. |
|
Ok, this is the same problem as reported in bug bpo-1180193: http://www.python.org/sf/1180193 The reporter of that bug is willing to write a patch, so |
|
So this bug is referenced when pydevd encounters some problem with 3.11a5+: Since the link to this bug is apparently baked into the error messages printed by pydevd, I am adding this comment to this old, closed bug. I can't seem to reproduce it. I modernized the reproducer script: 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 And the output is: Version info: sys.version_info(major=3, minor=11, micro=0, releaselevel='alpha', serial=5) File for I tried it with the most recent Python built from source and get the same result: Version info: sys.version_info(major=3, minor=11, micro=0, releaselevel='alpha', serial=5) File for So I wonder if the problem that's currently plagueing pydevd in 3.11 alpha releases is slightly different? |
|
When running anything with a freshly installed version of Python 3.11.0a7 on 64-bit Windows, the following message is printed: ------------------------------------------------------------------------------- |
|
@ewout, the current workaround (until pydevd is fixed) is to add -Xfrozen_modules=off to the Python command line. |
ferperez mannequin commentedFeb 23, 2007
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: