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

SourceForge.net noreply at sourceforge.net
Sat Jun 5 10:16:08 EDT 2004


Bugs item #954364, was opened at 2004-05-15 04:41
Message generated for change (Comment added) made by akuchling
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: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Robin Becker (rgbecker)
>Assigned to: A.M. Kuchling (akuchling)
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: A.M. Kuchling (akuchling)
Date: 2004-06-05 10:16

Message:
Logged In: YES 
user_id=11375

Applied to both CVS HEAD and the 2.3 branch.  Thanks!


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

Comment By: A.M. Kuchling (akuchling)
Date: 2004-06-05 09:37

Message:
Logged In: YES 
user_id=11375

Alternative version of the patch.


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

Comment By: A.M. Kuchling (akuchling)
Date: 2004-06-05 09:20

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


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

Comment By: Robin Becker (rgbecker)
Date: 2004-06-05 08:44

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

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

Comment By: Robin Becker (rgbecker)
Date: 2004-06-05 06: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