[Python-checkins] cpython (merge default -> default): merge heads

benjamin.peterson python-checkins at python.org
Sun Jan 1 23:09:51 EST 2017


https://hg.python.org/cpython/rev/eca90bbfe317
changeset:   105948:eca90bbfe317
parent:      105944:d510213532af
parent:      105938:803c3c21c3bc
user:        Benjamin Peterson <benjamin at python.org>
date:        Sun Jan 01 22:09:30 2017 -0600
summary:
  merge heads

files:
  Lib/inspect.py           |  2 +-
  Lib/test/test_inspect.py |  5 +++++
  Misc/NEWS                |  3 +++
  3 files changed, 9 insertions(+), 1 deletions(-)


diff --git a/Lib/inspect.py b/Lib/inspect.py
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1416,7 +1416,7 @@
         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
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -399,6 +399,11 @@
         # 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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -208,6 +208,9 @@
 Library
 -------
 
+- Issue #15812: inspect.getframeinfo() now correctly shows the first line of
+  a context.  Patch by Sam Breese.
+
 - Issue #28985: Update authorizer constants in sqlite3 module.
   Patch by Dingyuan Wang.
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list