This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 2.3 inspect.getframeinfo wrong tb line numbers
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, rgbecker
Priority: normal Keywords:

Created on 2004-05-15 08:41 by rgbecker, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
python-2.4a0-954364.patch rgbecker, 2004-06-05 12:36 patch for 2.4a0 inspect.py test/test_inspect.py
inspect_getinnerframes_bug.py rgbecker, 2004-06-05 13:10 Demonstrate inspect.getinnerframes bug
inspect.patch2 akuchling, 2004-06-05 13:37
inspect.patch3 rgbecker, 2004-06-05 13:58 Merged amk's patch & delta to test_inspect.py
Messages (6)
msg20807 - (view) Author: Robin Becker (rgbecker) Date: 2004-05-15 08:41
inspect.getframeinfo always uses f_lineno even when
passed a tb. In practice it is not always true that

tb.tb_frame.f_lineno==tb.tb_lineno

so user functions like inspect.getinnerframes (and
hence cgitb) will get wrong information back sometimes.

I fixed this using the attached patch.

This script illustrates via cgitb.
############
def raise_an_error():
    a = 3
    b = 4
    c = 0
    try:
        a = a/c
    except:
        import sys, cgitb, traceback, inspect
        tbt,tbv,tb = sys.exc_info()
        print
'traceback\n',''.join(traceback.format_exception(tbt,tbv,tb))
        print '\n\ncgitb\n',cgitb.text((tbt,tbv,tb),1)

raise_an_error()
############



msg20808 - (view) Author: Robin Becker (rgbecker) Date: 2004-06-05 10:30
Logged In: YES 
user_id=6946

Whoops tabs and all that the above script should look like
#####start
def raise_an_error():
    a = 3
    b = 4
    c = 0
    try:
        a = a/c
    except:
        import sys, cgitb, traceback, inspect
        tbt,tbv,tb = sys.exc_info()
        print \
'traceback\n',''.join(traceback.format_exception(tbt,tbv,tb))
        print '\n\ncgitb\n',cgitb.text((tbt,tbv,tb),1)

raise_an_error()
#####finish


The same problem occurs with inspect.trace. this code
#####start
import inspect
try:
    raise ValueError
except:
    print inspect.trace()
#####finish produces
[(<frame object at 0x007BFC60>, 'C:\\tmp\\ttt.py', 5, '?',
['    print inspect.trace()\n'], 0)]

ie the returned trace doesn't reflect the current traceback,
but rather the current frame location. This is also fixed by
the same patch. Still present in 2.4a0. This is a semantic
issue. The current test_inspect.py insists that the above
behaviour is correct so it will also need modifying if the
fix goes in.
msg20809 - (view) Author: Robin Becker (rgbecker) Date: 2004-06-05 12:44
Logged In: YES 
user_id=6946

python-2.4a0-954364.patch affects inspect.py,
test_inspect.py fixes this for me in 2.4a0 and 2.3.3, but
the semantics of inspect.trace changed so that
test_inspect.py must alter. If inspect.trace() should always
return something starting at the call of inspect.trace then
this patch is *WRONG*
msg20810 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-06-05 13:20
Logged In: YES 
user_id=11375

In the test program, the exception is raised at line 3, but the .trace() call 
says it was at line 5.
msg20811 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-06-05 13:37
Logged In: YES 
user_id=11375

Alternative version of the patch.
msg20812 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-06-05 14:16
Logged In: YES 
user_id=11375

Applied to both CVS HEAD and the 2.3 branch.  Thanks!
History
Date User Action Args
2022-04-11 14:56:04adminsetgithub: 40257
2004-05-15 08:41:29rgbeckercreate