File tree 3 files changed +9
-1
lines changed
3 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -1416,7 +1416,7 @@ def getframeinfo(frame, context=1):
1416
1416
except OSError :
1417
1417
lines = index = None
1418
1418
else :
1419
- start = max (start , 1 )
1419
+ start = max (start , 0 )
1420
1420
start = max (0 , min (start , len (lines ) - context ))
1421
1421
lines = lines [start :start + context ]
1422
1422
index = lineno - 1 - start
Original file line number Diff line number Diff line change @@ -391,6 +391,11 @@ def test_getmodule(self):
391
391
# Check filename override
392
392
self .assertEqual (inspect .getmodule (None , modfile ), mod )
393
393
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
+
394
399
def test_getsource (self ):
395
400
self .assertSourceEqual (git .abuse , 29 , 39 )
396
401
self .assertSourceEqual (mod .StupidGit , 21 , 51 )
Original file line number Diff line number Diff line change @@ -140,6 +140,9 @@ Core and Builtins
140
140
Library
141
141
-------
142
142
143
+ - Issue #15812: inspect.getframeinfo() now correctly shows the first line of
144
+ a context. Patch by Sam Breese.
145
+
143
146
- Issue #29094: Offsets in a ZIP file created with extern file object and modes
144
147
"w" and "x" now are relative to the start of the file.
145
148
You can’t perform that action at this time.
0 commit comments