Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Lib/test/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,25 @@ def b():

self.check_lines(f, [1,3,5,4,2,4])

def test_line_same_line_as_def(self):

def func(): line = 1; line = 2

self.check_lines(func, [0])

def test_line_multi_line_body_starting_on_def_line(self):

def func(): line = 1; \
line = 2

self.check_lines(func, [0, 1])

def test_line_lambda_body(self):

lam = lambda: 1

self.check_lines(lam, [0])

class TestDisable(MonitoringTestBase, unittest.TestCase):

def gen(self, cond):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a regression in ``sys.monitoring`` where the ``LINE`` event did not fire
for the first line of a code object when the line also contains the ``def``
or ``lambda`` statement. The event is emitted again as it was in Python 3.12.
4 changes: 3 additions & 1 deletion Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,9 @@ _Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame,
/* RESUME and INSTRUMENTED_RESUME are needed for the operation of
* instrumentation, so must never be hidden by an INSTRUMENTED_LINE.
*/
if (prev_opcode != RESUME && prev_opcode != INSTRUMENTED_RESUME) {
if (_PyOpcode_Deopt[prev_opcode] != RESUME &&
prev_opcode != INSTRUMENTED_RESUME)
{
goto done;
}
Comment on lines +1352 to 1356
}
Expand Down
Loading