[issue6700] inspect.getsource() returns incorrect source lines

Gabriel Genellina report at bugs.python.org
Fri Aug 14 06:19:22 CEST 2009


New submission from Gabriel Genellina <gagsl-py2 at yahoo.com.ar>:

inspect.getsource(obj) returns incorrect results when obj is a 
traceback or frame object outside any function (that is, at the module 
level).

This demo script shows the problem. The correct output should contain 
all source lines in the module, but it only returns the first two:


D:\temp>type show_inspect_bug.py
def foo(x):
  return y + z

import inspect
frame = inspect.currentframe()
print inspect.getsource(frame)


D:\temp>python show_inspect_bug.py
def foo(x):
  return y + z


The attached patch fixes the problem and adds some missing test cases.
Originally reported by Juanjo Conti at the local Python group.

----------
components: Library (Lib)
files: inspect.diff
keywords: patch
messages: 91541
nosy: gagenellina
severity: normal
status: open
title: inspect.getsource() returns incorrect source lines
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2
Added file: http://bugs.python.org/file14716/inspect.diff

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


More information about the Python-bugs-list mailing list