cpython: 5400e21e92a7 (original) (raw)

Mercurial > cpython

changeset 97032:5400e21e92a7 3.5

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:49:37 -0500
parents 732de5ba1f2b
children 0e7d64595223 d8229c26dd92
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 @@ -859,21 +859,37 @@ class BlockFinder: self.islambda = False self.started = False self.passline = False

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

@@ -913,8 +929,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 @@ -28,6 +28,9 @@ Core and Builtins Library ------- +- Issue #22485: Fixed an issue that caused inspect.getsource to return incorrect