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.

Author rockyb
Recipients
Date 2007-03-31.10:32:54
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Although a single file unit test would be nice, below is a short simple program that I think clearly shows the bug. Alas, as a follow-up comment I don't see a way to attach files so I have to paste it inline. However with this example and the information from Duncan Booth, I think the problem and how to fix it is pretty clear.

file: jumpbug.py

#!/usr/bin/env python
import inspect, linecache, sys
def tracer(frame, event, arg):
    global z
    (filename, line_no) = inspect.getframeinfo(frame)[0:2]
    print "Event %s at line %d:" % (event, line_no)
    print "\t", linecache.getline(filename, line_no),
    print "----------------------"
    try: 
        if z == 0:
            if line_no == 4:
                print "***We jumped back to line 4 but should have gone to 2**"
                sys.exit(1)
            frame.f_lineno = 2 # And 3 is broken too.
    except NameError:
        pass
    return tracer # This helps emacs figure indentation out
sys.settrace(tracer)
execfile("jumpbug2.py")
#END first file

file jumpbug2.py:

#!/usr/bin/env python
x = 2  # This statement gets skipped the 2nd time around
q = 1  # This statement gets skipped too!
try:   # tracer() will exit here if z == 0 and line_no == 4
    y = z   
except NameError:
    z = 0
print "When tracing via tracer(), f_lineno will be set to 2 here."
print "You should never get here when tracing"


file jumpbug2.py:
History
Date User Action Args
2007-08-23 14:52:46adminlinkissue1689458 messages
2007-08-23 14:52:46admincreate