classification
Title: inspect.getsource weird case
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: inspect.findsource raises undocumented error for code objects with empty filename
View: 17526
Assigned To: Nosy List: Ronny.Pfannschmidt, yselivanov
Priority: normal Keywords:

Created on 2013-11-19 21:25 by Ronny.Pfannschmidt, last changed 2014-01-31 03:01 by berker.peksag. This issue is now closed.

Messages (2)
msg203426 - (view) Author: Ronny Pfannschmidt (Ronny.Pfannschmidt) Date: 2013-11-19 21:25
got:
>>> l = {}
>>> import inspect
>>> exec(compile('def fun(): pass', '', 'exec'), l, l)
>>> inspect.getsource(l['fun'])
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/private/.local/lib/python3.3/inspect.py", line 726, in getsource
    lines, lnum = getsourcelines(object)
  File "/home/private/.local/lib/python3.3/inspect.py", line 715, in getsourcelines
    lines, lnum = findsource(object)
  File "/home/private/.local/lib/python3.3/inspect.py", line 553, in findsource
    if not sourcefile and file[0] + file[-1] != '<>':
IndexError: string index out of range


expected:
>>> l = {}
>>> import inspect
>>> exec(compile('def fun(): pass', '', 'exec'), l, l)
>>> inspect.getsource(l['fun'])
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/private/.local/lib/python3.3/inspect.py", line 726, in getsource
    lines, lnum = getsourcelines(object)
  File "/home/private/.local/lib/python3.3/inspect.py", line 715, in getsourcelines
    lines, lnum = findsource(object)
  File "/home/private/.local/lib/python3.3/inspect.py", line 563, in findsource
    raise IOError('could not get source code')
OSError: could not get source code

this is a extraction, it appears that python in certein circumstances creates code objects with that setup on its own,
im still further investigating
msg209705 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-01-30 05:46
Duplicate of #17526.
History
Date User Action Args
2014-01-31 03:01:00berker.peksagsetsuperseder: inspect.findsource raises undocumented error for code objects with empty filename
stage: resolved
2014-01-30 05:46:19yselivanovsetstatus: open -> closed

nosy: + yselivanov
messages: + msg209705

resolution: duplicate
2013-11-20 07:05:24Ronny.Pfannschmidtsetcomponents: + Library (Lib)
2013-11-19 21:25:43Ronny.Pfannschmidtcreate