[Python-checkins] cpython (merge 3.6 -> default): Issue #15812: Merge from 3.6

berker.peksag python-checkins at python.org
Sun Jan 1 22:58:06 EST 2017


https://hg.python.org/cpython/rev/803c3c21c3bc
changeset:   105938:803c3c21c3bc
parent:      105935:b9c4139a1309
parent:      105937:410caf255a09
user:        Berker Peksag <berker.peksag at gmail.com>
date:        Mon Jan 02 07:00:29 2017 +0300
summary:
  Issue #15812: Merge from 3.6

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