diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2015-07-23 14:10:00 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2015-07-23 14:10:00 (GMT) |
commit | 4f4913b38bba5e01fc0e7a26f4840bf342365d3d (patch) | |
tree | 559751c3ceeeb5494a193a6e56b7e0e0ee70ca7a /Lib | |
parent | 4887523c038bc3449fe87a10828355e624de6565 (diff) | |
download | cpython-4f4913b38bba5e01fc0e7a26f4840bf342365d3d.zip cpython-4f4913b38bba5e01fc0e7a26f4840bf342365d3d.tar.gz cpython-4f4913b38bba5e01fc0e7a26f4840bf342365d3d.tar.bz2 |
Issue #24485: Revert backwards compatibility breaking changes of #21217.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/inspect.py | 20 | ||||
-rw-r--r-- | Lib/test/inspect_fodder2.py | 7 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 5 |
3 files changed, 14 insertions, 18 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 4c1ac1f..24c8df7 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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. diff --git a/Lib/test/inspect_fodder2.py b/Lib/test/inspect_fodder2.py index ab1cd9f..c6987ea 100644 --- a/Lib/test/inspect_fodder2.py +++ b/Lib/test/inspect_fodder2.py @@ -130,3 +130,10 @@ def decorator(func): @decorator def real(): return 20 + +#line 134 +class cls135: + def func136(): + def func137(): + never_reached1 + never_reached2 diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index e620893..042617b 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -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' |