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: help() can't find right source file
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: gregcouch, orsenthil
Priority: normal Keywords: easy, patch

Created on 2007-06-16 00:17 by gregcouch, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
inspect.patch gregcouch, 2007-06-16 00:17 path for Lib/inspect.py
Messages (2)
msg52771 - (view) Author: Greg Couch (gregcouch) Date: 2007-06-16 00:17
The problem occurs when Python modules are precompiled with the the compileall module and the -d option to give a simpiler directory name (we use the application name because when we get error reports, where the application was installed is rarely important).  Then introspection on a function in the inspect module gives a "non-existent" filename, i.e., func.func_code.co_filename gives the name for backtraces, not the actual filename.  The right answer can be found by looking at sys.modules[func.__module__].__file__ and the attached patch does that.

This patch is against Python2.4's Lib/inspect.py, but the bug is still present in SVN (Python 2.5.1+).
msg87958 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2009-05-17 05:33
This is an invalid bug.

python -m 'compileall' -d pdir actdir

all the files in the actdir will be compiled and it will appear as
though the files are getting compiled from pdir. That is the intended
purpose of the -d switch, as I can see from the sourcecode and from the
definition.

So, when you are using inspect module to do inspect.getfile(func_obj),
it would return filename as pdir/filename.py 

To get the actual file, you might want to do inspect.getabsfile(func_obj)

Closing this bug as Invalid.
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 45097
2009-05-17 14:17:04pitrousetstatus: open -> closed
2009-05-17 05:40:08orsenthilsetstage: test needed -> resolved
2009-05-17 05:33:33orsenthilsetresolution: not a bug

messages: + msg87958
nosy: + orsenthil
2009-04-22 05:07:47ajaksu2setkeywords: + easy
2009-04-06 09:42:23ajaksu2setstage: test needed
type: behavior
versions: + Python 3.1, Python 2.7, - Python 2.5
2007-06-16 00:17:58gregcouchcreate