File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -402,6 +402,11 @@ def test_getmodule(self):
402402 # Check filename override
403403 self .assertEqual (inspect .getmodule (None , modfile ), mod )
404404
405+ def test_getframeinfo_get_first_line (self ):
406+ frame_info = inspect .getframeinfo (self .fodderModule .fr , 50 )
407+ self .assertEqual (frame_info .code_context [0 ], "# line 1\n " )
408+ self .assertEqual (frame_info .code_context [1 ], "'A module docstring.'\n " )
409+
405410 def test_getsource (self ):
406411 self .assertSourceEqual (git .abuse , 29 , 39 )
407412 self .assertSourceEqual (mod .StupidGit , 21 , 51 )
Original file line number Diff line number Diff line change @@ -40,6 +40,9 @@ Core and Builtins
4040Library
4141-------
4242
43+ - Issue #15812: inspect.getframeinfo() now correctly shows the first line of
44+ a context. Patch by Sam Breese.
45+
4346- Issue #29094: Offsets in a ZIP file created with extern file object and modes
4447 "w" and "x" now are relative to the start of the file.
4548
You can’t perform that action at this time.
0 commit comments