changeset: 105936:15454cad5f27 branch: 3.5 parent: 105932:4685cd33087b user: Berker Peksag date: Mon Jan 02 06:57:43 2017 +0300 files: Lib/inspect.py Lib/test/test_inspect.py Misc/NEWS description: Issue #15812: inspect.getframeinfo() now correctly shows the first line of a context Patch by Sam Breese. diff -r 4685cd33087b -r 15454cad5f27 Lib/inspect.py --- a/Lib/inspect.py Mon Jan 02 06:13:42 2017 +0300 +++ b/Lib/inspect.py Mon Jan 02 06:57:43 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 4685cd33087b -r 15454cad5f27 Lib/test/test_inspect.py --- a/Lib/test/test_inspect.py Mon Jan 02 06:13:42 2017 +0300 +++ b/Lib/test/test_inspect.py Mon Jan 02 06:57:43 2017 +0300 @@ -391,6 +391,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 4685cd33087b -r 15454cad5f27 Misc/NEWS --- a/Misc/NEWS Mon Jan 02 06:13:42 2017 +0300 +++ b/Misc/NEWS Mon Jan 02 06:57:43 2017 +0300 @@ -140,6 +140,9 @@ 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.