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

Jean-Paul Calderone report at bugs.python.org
Tue Oct 28 18:51:24 CET 2008


Jean-Paul Calderone <exarkun at divmod.com> added the comment:

It seems to depend on working directory:

exarkun at charm:/tmp$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) 
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('/home/exarkun/foobar.zip')
>>> import foobar, inspect
>>> inspect.getsource(foobar.foo)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/inspect.py", line 629, in getsource
    lines, lnum = getsourcelines(object)
  File "/usr/lib/python2.5/inspect.py", line 618, in getsourcelines
    lines, lnum = findsource(object)
  File "/usr/lib/python2.5/inspect.py", line 468, in findsource
    raise IOError('could not get source code')
IOError: could not get source code
>>> 

versus:

exarkun at charm:~$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) 
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('/home/exarkun/foobar.zip')
>>> import foobar, inspect
>>> inspect.getsource(foobar.foo)
'def foo():\n    pass\n'
>>>

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


More information about the Python-bugs-list mailing list