[Bug #954364] inspect.getframeinfo() sometimes produces incorrect traceback line #s; fix is to look at tb.tb_lineno, not tb.frame.f_lineno. Patch from Robin Becker and me.
This commit is contained in:
parent
39aef79821
commit
ba8b6bc86f
@ -740,12 +740,14 @@ def getframeinfo(frame, context=1):
|
|||||||
The optional second argument specifies the number of lines of context
|
The optional second argument specifies the number of lines of context
|
||||||
to return, which are centered around the current line."""
|
to return, which are centered around the current line."""
|
||||||
if istraceback(frame):
|
if istraceback(frame):
|
||||||
|
lineno = frame.tb_lineno
|
||||||
frame = frame.tb_frame
|
frame = frame.tb_frame
|
||||||
|
else:
|
||||||
|
lineno = frame.f_lineno
|
||||||
if not isframe(frame):
|
if not isframe(frame):
|
||||||
raise TypeError('arg is not a frame or traceback object')
|
raise TypeError('arg is not a frame or traceback object')
|
||||||
|
|
||||||
filename = getsourcefile(frame) or getfile(frame)
|
filename = getsourcefile(frame) or getfile(frame)
|
||||||
lineno = frame.f_lineno
|
|
||||||
if context > 0:
|
if context > 0:
|
||||||
start = lineno - 1 - context//2
|
start = lineno - 1 - context//2
|
||||||
try:
|
try:
|
||||||
|
@ -158,8 +158,8 @@ istest(inspect.istraceback, 'git.ex[2]')
|
|||||||
istest(inspect.isframe, 'mod.fr')
|
istest(inspect.isframe, 'mod.fr')
|
||||||
|
|
||||||
test(len(git.tr) == 3, 'trace() length')
|
test(len(git.tr) == 3, 'trace() length')
|
||||||
test(git.tr[0][1:] == (TESTFN, 46, 'argue',
|
test(git.tr[0][1:] == (TESTFN, 43, 'argue',
|
||||||
[' self.tr = inspect.trace()\n'], 0),
|
[' spam(a, b, c)\n'], 0),
|
||||||
'trace() row 2')
|
'trace() row 2')
|
||||||
test(git.tr[1][1:] == (TESTFN, 9, 'spam', [' eggs(b + d, c + f)\n'], 0),
|
test(git.tr[1][1:] == (TESTFN, 9, 'spam', [' eggs(b + d, c + f)\n'], 0),
|
||||||
'trace() row 2')
|
'trace() row 2')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user