summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2017-01-02 04:09:18 (GMT)
committerBenjamin Peterson <benjamin@python.org>2017-01-02 04:09:18 (GMT)
commiteb62be12f05cfce17f09709b4340a8a24dd0a1b5 (patch)
tree8143b6abb631bd26ab8750cdc0737d2e9d585201
parent5848e72ee1f85354b023b19b83c88ba57d39b6d0 (diff)
parent01debaccdd1042ecff474637bd8905d6ec3efd60 (diff)
downloadcpython-eb62be12f05cfce17f09709b4340a8a24dd0a1b5.zip
cpython-eb62be12f05cfce17f09709b4340a8a24dd0a1b5.tar.gz
cpython-eb62be12f05cfce17f09709b4340a8a24dd0a1b5.tar.bz2
merge heads
-rw-r--r--Lib/inspect.py2
-rw-r--r--Lib/test/test_inspect.py5
-rw-r--r--Misc/NEWS3
3 files changed, 9 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index e08e9f5..ba7a913 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1416,7 +1416,7 @@ def getframeinfo(frame, context=1):
except OSError:
lines = index = None
else:
- start = max(start, 1)
+ start = max(start, 0)
start = max(0, min(start, len(lines) - context))
lines = lines[start:start+context]
index = lineno - 1 - start
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 97634e5..88eaabe 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -402,6 +402,11 @@ class TestRetrievingSourceCode(GetSourceBase):
# Check filename override
self.assertEqual(inspect.getmodule(None, modfile), mod)
+ def test_getframeinfo_get_first_line(self):
+ frame_info = inspect.getframeinfo(self.fodderModule.fr, 50)
+ self.assertEqual(frame_info.code_context[0], "# line 1\n")
+ self.assertEqual(frame_info.code_context[1], "'A module docstring.'\n")
+
def test_getsource(self):
self.assertSourceEqual(git.abuse, 29, 39)
self.assertSourceEqual(mod.StupidGit, 21, 51)
diff --git a/Misc/NEWS b/Misc/NEWS
index a8d4ee8..c8eacf1 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,9 @@ Core and Builtins
Library
-------
+- Issue #15812: inspect.getframeinfo() now correctly shows the first line of
+ a context. Patch by Sam Breese.
+
- Issue #29094: Offsets in a ZIP file created with extern file object and modes
"w" and "x" now are relative to the start of the file.