summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2015-04-14 22:41:29 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2015-04-14 22:41:29 (GMT)
commita8723a02ea109beabe2dfe1bbe18958afc5b7af9 (patch)
treebea4acb5ca96a4fd4387461f365f477eb77d5ced /Lib/test
parent97100c0e3d0e2bd907b41e5583b1f9cb6d9c1a36 (diff)
downloadcpython-a8723a02ea109beabe2dfe1bbe18958afc5b7af9.zip
cpython-a8723a02ea109beabe2dfe1bbe18958afc5b7af9.tar.gz
cpython-a8723a02ea109beabe2dfe1bbe18958afc5b7af9.tar.bz2
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.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/inspect_fodder2.py10
-rw-r--r--Lib/test/test_inspect.py11
2 files changed, 19 insertions, 2 deletions
diff --git a/Lib/test/inspect_fodder2.py b/Lib/test/inspect_fodder2.py
index e452235..ab1cd9f 100644
--- a/Lib/test/inspect_fodder2.py
+++ b/Lib/test/inspect_fodder2.py
@@ -110,6 +110,14 @@ def annotated(arg1: list):
def keyword_only_arg(*, arg):
pass
+@wrap(lambda: None)
+def func114():
+ return 115
+
+class ClassWithMethod:
+ def method(self):
+ pass
+
from functools import wraps
def decorator(func):
@@ -118,7 +126,7 @@ def decorator(func):
return 42
return fake
-#line 121
+#line 129
@decorator
def real():
return 20
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 76f2b47..9e1f546 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -392,6 +392,9 @@ class TestRetrievingSourceCode(GetSourceBase):
finally:
linecache.getlines = getlines
+ def test_getsource_on_code_object(self):
+ self.assertSourceEqual(mod.eggs.__code__, 12, 18)
+
class TestDecorators(GetSourceBase):
fodderModule = mod2
@@ -402,7 +405,10 @@ class TestDecorators(GetSourceBase):
self.assertSourceEqual(mod2.gone, 9, 10)
def test_getsource_unwrap(self):
- self.assertSourceEqual(mod2.real, 122, 124)
+ self.assertSourceEqual(mod2.real, 130, 132)
+
+ def test_decorator_with_lambda(self):
+ self.assertSourceEqual(mod2.func114, 113, 115)
class TestOneliners(GetSourceBase):
fodderModule = mod2
@@ -497,6 +503,9 @@ class TestBuggyCases(GetSourceBase):
self.assertRaises(IOError, inspect.findsource, co)
self.assertRaises(IOError, inspect.getsource, co)
+ def test_getsource_on_method(self):
+ self.assertSourceEqual(mod2.ClassWithMethod.method, 118, 119)
+
class TestNoEOL(GetSourceBase):
def __init__(self, *args, **kwargs):
self.tempdir = TESTFN + '_dir'