diff options
author | R. David Murray <rdmurray@bitdance.com> | 2010-06-17 02:06:12 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2010-06-17 02:06:12 (GMT) |
commit | 19d8cc524bb4f6c41b2602c025ce90fe85e1e991 (patch) | |
tree | 1ef514f00fbc1bbae0bd332ccfce716118d25c76 /Lib/inspect.py | |
parent | 991c9f80f99e155d6d7b17a8240abaf8c1a2269f (diff) | |
download | cpython-19d8cc524bb4f6c41b2602c025ce90fe85e1e991.zip cpython-19d8cc524bb4f6c41b2602c025ce90fe85e1e991.tar.gz cpython-19d8cc524bb4f6c41b2602c025ce90fe85e1e991.tar.bz2 |
Merged revisions 82041 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r82041 | r.david.murray | 2010-06-16 22:04:29 -0400 (Wed, 16 Jun 2010) | 16 lines
Merged revisions 82039 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r82039 | r.david.murray | 2010-06-16 21:36:52 -0400 (Wed, 16 Jun 2010) | 10 lines
#8720: fix inspect regression by teaching getsourcefile about linecache.
The fix for issue 4050 caused a regression: before that fix, source
lines in the linecache would eventually be found by inspect. After the
fix inspect reports an error earlier, and the source isn't found.
The fix for the fix is to have getsourcefile look in the linecache for
the file and return the psuedo-filename if the source is there, just as
it already returns it if there is a PEP 302 loader.
........
................
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index c489502..55d5316 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -435,7 +435,9 @@ def getmodulename(path): if info: return info[0] def getsourcefile(object): - """Return the Python source file an object was defined in, if it exists.""" + """Return the filename that can be used to locate an object's source. + Return None if no way can be identified to get the source. + """ filename = getfile(object) if filename[-4:].lower() in ('.pyc', '.pyo'): filename = filename[:-4] + '.py' @@ -448,6 +450,9 @@ def getsourcefile(object): # only return a non-existent filename if the module has a PEP 302 loader if hasattr(getmodule(object, filename), '__loader__'): return filename + # or it is in the linecache + if filename in linecache.cache: + return filename def getabsfile(object, _filename=None): """Return an absolute path to the source or compiled file for an object. |