GH-103082: Turn on branch events for FOR_ITER instructions. by markshannon · Pull Request #103507 · python/cpython
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line event becomes before any other events for that instruction, but the jumps and branches are for other instructions.
The jump 4 -> 2 is the jump back to the FOR_ITER. The FOR_ITER instruction isn't the first instruction on line 2. The branch 2 -> 2 is the exit from the FOR_ITER.
The final "line 2" event is from the implicit return None which has line number 2.
It is marked as a line event because the previous instruction has a different line number.
TBH, line events aren't that useful for this sort of tracing, their use case is for debuggers.