Skip to content

Commit 1f73b79

Browse files
gh-155992: Fix missing LINE event for first line of a code object
1 parent f2eaf17 commit 1f73b79

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

Lib/test/test_monitoring.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,25 @@ def b():
702702

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

705+
def test_line_same_line_as_def(self):
706+
707+
def func(): line = 1; line = 2
708+
709+
self.check_lines(func, [0])
710+
711+
def test_line_multi_line_body_starting_on_def_line(self):
712+
713+
def func(): line = 1; \
714+
line = 2
715+
716+
self.check_lines(func, [0, 1])
717+
718+
def test_line_lambda_body(self):
719+
720+
lam = lambda: 1
721+
722+
self.check_lines(lam, [0])
723+
705724
class TestDisable(MonitoringTestBase, unittest.TestCase):
706725

707726
def gen(self, cond):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a regression in ``sys.monitoring`` where the ``LINE`` event did not fire
2+
for the first line of a code object when the line also contains the ``def``
3+
or ``lambda`` statement. The event is emitted again as it was in Python 3.12.

Python/instrumentation.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,9 @@ _Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame,
13491349
/* RESUME and INSTRUMENTED_RESUME are needed for the operation of
13501350
* instrumentation, so must never be hidden by an INSTRUMENTED_LINE.
13511351
*/
1352-
if (prev_opcode != RESUME && prev_opcode != INSTRUMENTED_RESUME) {
1352+
if (_PyOpcode_Deopt[prev_opcode] != RESUME &&
1353+
prev_opcode != INSTRUMENTED_RESUME)
1354+
{
13531355
goto done;
13541356
}
13551357
}

0 commit comments

Comments
 (0)