[ python-Bugs-954364 ] 2.3 inspect.getframeinfo wrong tb line numbers

SourceForge.net noreply at sourceforge.net
Sat Jun 5 06:30:17 EDT 2004


Bugs item #954364, was opened at 2004-05-15 08:41
Message generated for change (Comment added) made by rgbecker
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=954364&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Robin Becker (rgbecker)
Assigned to: Nobody/Anonymous (nobody)
Summary: 2.3 inspect.getframeinfo wrong tb line numbers

Initial Comment:
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()
############





----------------------------------------------------------------------

>Comment By: Robin Becker (rgbecker)
Date: 2004-06-05 10:30

Message:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=954364&group_id=5470



More information about the Python-bugs-list mailing list