Xavier de Gaye added the comment: The top level frame line number is not updated because it has a local trace function while the global trace function is None. This is related to issue 7238.
The following patch fixes the issue. The patch removes the local trace at the top level frame and makes sure it is not reinstalled when returning from the current trace function. diff --git a/Lib/bdb.py b/Lib/bdb.py --- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -64,6 +64,10 @@ if self.stop_here(frame) or self.break_here(frame): self.user_line(frame) if self.quitting: raise BdbQuit + # Do not re-install the local trace when we are finished debugging, + # see issues 16482 and 7238. + if not sys.gettrace(): + return None return self.trace_dispatch def dispatch_call(self, frame, arg): @@ -231,8 +235,10 @@ # no breakpoints; run without debugger overhead sys.settrace(None) frame = sys._getframe().f_back - while frame and frame is not self.botframe: + while frame: del frame.f_trace + if frame is self.botframe: + break frame = frame.f_back def set_quit(self): The following code is a minimum implementation of pdb with the patch applied and the associated code to test it. class Bdb: def trace_dispatch(self, frame, event, arg): self.set_continue() if sys.gettrace(): return self.trace_dispatch def set_trace(self, frame): self.botframe = frame frame.f_trace = self.trace_dispatch sys.settrace(self.trace_dispatch) def set_continue(self): sys.settrace(None) del self.botframe.f_trace frame = sys._getframe() d = Bdb() d.set_trace(frame) y = "line of code not triggering an error" x = 1 assert x != 1 ---------- nosy: +xdegaye _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue16482> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com