cpython: 0e7d64595223 (original) (raw)

Mercurial > cpython

changeset 97033:0e7d64595223

Issue #24485: Function source inspection fails on closures. The fix for Issue #21217 introduced a regression that caused `inspect.getsource` to return incorrect results on nested functions. The root cause of the regression was due to switching the implementation to analyze the underlying bytecode instead of the source code. This commit switches things back to analyzing the source code in a more complete way. The original bug and the regression are both fixed by the new source code analysis. [#24485]

Meador Inge meadori@gmail.com
date Thu, 23 Jul 2015 22:52:49 -0500
parents 262c43c71927(current diff)5400e21e92a7(diff)
children 3bbd0cbfe836
files Lib/inspect.py Lib/test/test_inspect.py Misc/NEWS
diffstat 3 files changed, 29 insertions(+), 5 deletions(-)[+] [-] Lib/inspect.py 26 Lib/test/test_inspect.py 1 Misc/NEWS 7

line wrap: on

line diff

--- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -842,21 +842,37 @@ class BlockFinder: self.islambda = False self.started = False self.passline = False

def tokeneater(self, type, token, srowcol, erowcol, line):

@@ -896,8 +912,10 @@ def getsourcelines(object): object = unwrap(object) lines, lnum = findsource(object)

def getsource(object): """Return the text of the source code for an object.

--- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -464,7 +464,6 @@ class TestDecorators(GetSourceBase): def test_getsource_unwrap(self): self.assertSourceEqual(mod2.real, 130, 132)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -57,6 +57,9 @@ Core and Builtins Library ------- +- Issue #22485: Fixed an issue that caused inspect.getsource to return incorrect