Skip to content

Commit c9d4c60

Browse files
committed
merge heads
2 parents 4365833 + ff0e3b7 commit c9d4c60

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Lib/inspect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ def getframeinfo(frame, context=1):
14161416
except OSError:
14171417
lines = index = None
14181418
else:
1419-
start = max(start, 1)
1419+
start = max(start, 0)
14201420
start = max(0, min(start, len(lines) - context))
14211421
lines = lines[start:start+context]
14221422
index = lineno - 1 - start

Lib/test/test_inspect.py

+5
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ def test_getmodule(self):
391391
# Check filename override
392392
self.assertEqual(inspect.getmodule(None, modfile), mod)
393393

394+
def test_getframeinfo_get_first_line(self):
395+
frame_info = inspect.getframeinfo(self.fodderModule.fr, 50)
396+
self.assertEqual(frame_info.code_context[0], "# line 1\n")
397+
self.assertEqual(frame_info.code_context[1], "'A module docstring.'\n")
398+
394399
def test_getsource(self):
395400
self.assertSourceEqual(git.abuse, 29, 39)
396401
self.assertSourceEqual(mod.StupidGit, 21, 51)

Misc/NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ Core and Builtins
140140
Library
141141
-------
142142

143+
- Issue #15812: inspect.getframeinfo() now correctly shows the first line of
144+
a context. Patch by Sam Breese.
145+
143146
- Issue #29094: Offsets in a ZIP file created with extern file object and modes
144147
"w" and "x" now are relative to the start of the file.
145148

0 commit comments

Comments
 (0)