[issue4223] inspect.getsource doesn't work on functions imported from a zipfile

Alexander Belopolsky report at bugs.python.org
Tue Oct 28 23:47:00 CET 2008


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

Thanks, Jean-Paul, I can now reproduce your problem and I think I found 
the culprit.

I believe the file name check in linecache.updatecache is unnecessary 
and is responsible for this problem.  With the following patch:

--- Lib/linecache.py	(revision 67040)
+++ Lib/linecache.py	(working copy)
@@ -88,7 +88,7 @@
             get_source = getattr(loader, 'get_source', None)
 
             if name and get_source:
-                if basename.startswith(name.split('.')[-1]+'.'):
+#                if basename.startswith(name.split('.')[-1]+'.'):
                     try:
                         data = get_source(name)
                     except (ImportError, IOError):


and Jean-Paul's foobar:

$ PYTHONPATH=/tmp/foobar.zip ./python.exe  -c "import inspect,foobar; 
print inspect.getsource(foobar)"
def foo(): pass


Martin, is there a chance for this issue and  #4197, #4201  to make it 
to 2.5.3?  If so, I'll prepare a combined patch with tests for your 
consideration shortly.

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4223>
_______________________________________


More information about the Python-bugs-list mailing list