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.

Author Nils.Bruin
Recipients Nils.Bruin
Date 2013-03-23.02:03:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1364004239.34.0.135236485776.issue17526@psf.upfronthosting.co.za>
In-reply-to
Content
It would seem reasonable that an empty filename would be a legitimate way of indicating that a code object does not have a corresponding source file. However, if one does that then inspect.findsource raises an unexpected IndexError rather than the documented IOError.

This seems due to the fix introduced on issue9284

Python 3.2.3 (default, Jun  8 2012, 05:40:07) 
[GCC 4.6.3 20120306 (Red Hat 4.6.3-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect
>>> C=compile("print(1)","<string>","single")
>>> D=compile("print(1)","","single")
>>> inspect.findsource(C)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.2/inspect.py", line 547, in findsource
    raise IOError('could not get source code')
IOError: could not get source code
>>> inspect.findsource(D)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.2/inspect.py", line 537, in findsource
    if not sourcefile and file[0] + file[-1] != '<>':
IndexError: string index out of range
History
Date User Action Args
2013-03-23 02:03:59Nils.Bruinsetrecipients: + Nils.Bruin
2013-03-23 02:03:59Nils.Bruinsetmessageid: <1364004239.34.0.135236485776.issue17526@psf.upfronthosting.co.za>
2013-03-23 02:03:59Nils.Bruinlinkissue17526 messages
2013-03-23 02:03:58Nils.Bruincreate