]> granicus.if.org Git - python/commitdiff
Issue #24485: Revert backwards compatibility breaking changes of #21217.
authorYury Selivanov <yselivanov@sprymix.com>
Thu, 23 Jul 2015 14:10:00 +0000 (17:10 +0300)
committerYury Selivanov <yselivanov@sprymix.com>
Thu, 23 Jul 2015 14:10:00 +0000 (17:10 +0300)
Lib/inspect.py
Lib/test/inspect_fodder2.py
Lib/test/test_inspect.py
Misc/NEWS

index 4c1ac1f283d006e6cad60cd4e7a56f0c46f5f227..24c8df722513a51b40eb8454d5cc4b522562ac57 100644 (file)
@@ -902,14 +902,6 @@ def getblock(lines):
         pass
     return lines[:blockfinder.last]
 
-def _line_number_helper(code_obj, lines, lnum):
-    """Return a list of source lines and starting line number for a code object.
-
-    The arguments must be a code object with lines and lnum from findsource.
-    """
-    _, end_line = list(dis.findlinestarts(code_obj))[-1]
-    return lines[lnum:end_line], lnum + 1
-
 def getsourcelines(object):
     """Return a list of source lines and starting line number for an object.
 
@@ -921,16 +913,8 @@ def getsourcelines(object):
     object = unwrap(object)
     lines, lnum = findsource(object)
 
-    if ismodule(object):
-        return lines, 0
-    elif iscode(object):
-        return _line_number_helper(object, lines, lnum)
-    elif isfunction(object):
-        return _line_number_helper(object.__code__, lines, lnum)
-    elif ismethod(object):
-        return _line_number_helper(object.__func__.__code__, lines, lnum)
-    else:
-        return getblock(lines[lnum:]), lnum + 1
+    if ismodule(object): return lines, 0
+    else: return getblock(lines[lnum:]), lnum + 1
 
 def getsource(object):
     """Return the text of the source code for an object.
index ab1cd9f50024bbf1a21147b9ef4d8d94b041e2ce..c6987ea2c9e485117f20e74899fd0a265a93e7ee 100644 (file)
@@ -130,3 +130,10 @@ def decorator(func):
 @decorator
 def real():
     return 20
+
+#line 134
+class cls135:
+    def func136():
+        def func137():
+            never_reached1
+            never_reached2
index e6208935a7d382b1a2b195575e9f3d47ec88b69e..042617b60dc1c80e61a1cd317617ddd2870c77fe 100644 (file)
@@ -464,6 +464,7 @@ class TestDecorators(GetSourceBase):
     def test_getsource_unwrap(self):
         self.assertSourceEqual(mod2.real, 130, 132)
 
+    @unittest.expectedFailure
     def test_decorator_with_lambda(self):
         self.assertSourceEqual(mod2.func114, 113, 115)
 
@@ -563,6 +564,10 @@ class TestBuggyCases(GetSourceBase):
     def test_getsource_on_method(self):
         self.assertSourceEqual(mod2.ClassWithMethod.method, 118, 119)
 
+    def test_nested_func(self):
+        self.assertSourceEqual(mod2.cls135.func136, 136, 139)
+
+
 class TestNoEOL(GetSourceBase):
     def setUp(self):
         self.tempdir = TESTFN + '_dir'
index 98b60e8718cf0527cc558e0185ff482bb42e9f5e..a1c29dd8ba788b97778458263c0d099ea65c7683 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -551,10 +551,6 @@ Library
 - Issue #23342: Add a subprocess.run() function than returns a CalledProcess
   instance for a more consistent API than the existing call* functions.
 
-- Issue #21217: inspect.getsourcelines() now tries to compute the start and end
-  lines from the code object, fixing an issue when a lambda function is used as
-  decorator argument. Patch by Thomas Ballinger and Allison Kaptur.
-
 - Issue #24521: Fix possible integer overflows in the pickle module.
 
 - Issue #22931: Allow '[' and ']' in cookie values.