-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-136057: Allow step and next to step over for loops #136160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
if self.stop_here(frame) or self.break_here(frame): | ||
# GH-136057 | ||
# For line events, besides whether we should stop at the frame, we | ||
# also need to check if it's the same line as we issue the command. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is very clear: "it's the same line as we issue the command". I think you mean "the same frame and line at which the break command was issued by the user".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the break command, it's either next or step. But yes I'm open to all suggestions to make this clearer.
@@ -548,6 +554,10 @@ def _set_stopinfo(self, stopframe, returnframe, stoplineno=0, opcode=False): | |||
# stoplineno >= 0 means: stop at line >= the stoplineno | |||
# stoplineno -1 means: don't stop at all | |||
self.stoplineno = stoplineno | |||
# startframe/startlineno is the frame/line number when the user does | |||
# step or next. We don't want to stop at the same line for those commands. | |||
self.startframe = startframe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could pick a more informative name, something like "command frame", because it's ambiguous here what exactly started at that frame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we can change it, but there's actually a caveat here - it's not really the command frame. You can do up
to an upper frame and do next
/step
- the behavior is different. next
will next to the line at the upper frame, so the frame we need is the "command frame". step
however, will stop at the innermost frame, no matter which frame you are inspecting - that's just how step
works.
So it's more like a "do not stop here again if it's a line event" frame/lineno. Do you think there's better name to describe it?
Due to historical reasons,
sys.settrace
issues a line event forfor
loops even if the jump target is on the same line:We don't want to touch this behavior, because it's been like this for like forever.
However, it's not desirable to
pdb
. When the user doesnext
orstep
command, they want to step over this line and reach the next line.Our documentation also clearly states such behavior:
So I consider the current behavior as a bug, which we should fix.
A thought might be - why don't we check this in
stop_here
? The reason is becausedispatch_exception
also usesstop_here
and we should triggeruser_exception
even if it's on the same line.An extra check in
dispatch_line
is the cleanest way I can think of to make this happen - only line events should be dealt with. We don't need to worry about the extra reference to a frame because the eventualcontinue
(or anything other thanstep
ornext
) will clear this reference.Let me know if anyone has a better idea of how to implement this.