New submission from Nils Bruin:
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
----------
components: Library (Lib)
messages: 185025
nosy: Nils.Bruin
priority: normal
severity: normal
status: open
title: inspect.findsource raises undocumented error for code objects with empty
filename
type: behavior
versions: Python 2.7, Python 3.2
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue17526>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com