Message31661
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: |
|
Date |
User |
Action |
Args |
2007-08-23 14:52:46 | admin | link | issue1689458 messages |
2007-08-23 14:52:46 | admin | create | |
|