changeset: 105938:803c3c21c3bc parent: 105935:b9c4139a1309 parent: 105937:410caf255a09 user: Berker Peksag date: Mon Jan 02 07:00:29 2017 +0300 files: Lib/test/test_inspect.py Misc/NEWS description: Issue #15812: Merge from 3.6 diff -r b9c4139a1309 -r 803c3c21c3bc Lib/inspect.py --- a/Lib/inspect.py Mon Jan 02 06:38:10 2017 +0300 +++ b/Lib/inspect.py Mon Jan 02 07:00:29 2017 +0300 @@ -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 -r b9c4139a1309 -r 803c3c21c3bc Lib/test/test_inspect.py --- a/Lib/test/test_inspect.py Mon Jan 02 06:38:10 2017 +0300 +++ b/Lib/test/test_inspect.py Mon Jan 02 07:00:29 2017 +0300 @@ -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 -r b9c4139a1309 -r 803c3c21c3bc Misc/NEWS --- a/Misc/NEWS Mon Jan 02 06:38:10 2017 +0300 +++ b/Misc/NEWS Mon Jan 02 07:00:29 2017 +0300 @@ -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.