Skip to content

gh-155992: Fix missing LINE event for first line of a code object - #155996

Open
PrathamGhaywat wants to merge 1 commit into
python:mainfrom
PrathamGhaywat:fix-gh-155992
Open

gh-155992: Fix missing LINE event for first line of a code object#155996
PrathamGhaywat wants to merge 1 commit into
python:mainfrom
PrathamGhaywat:fix-gh-155992

Conversation

@PrathamGhaywat

@PrathamGhaywat PrathamGhaywat commented Aug 18, 2026

Copy link
Copy Markdown

Fixes #155992.

The sys.monitoring LINE event did not fire for the first line of a
code object when the def/lambda body shared that line. Since 3.13,
RESUME is specialized to RESUME_CHECK, so the special case in
_Py_call_instrumentation_line() that forces the first LINE event
(when the previous instruction is RESUME/INSTRUMENTED_RESUME) no
longer matched. The check now uses _PyOpcode_Deopt, covering all
RESUME specializations.

Tests were added to LineMonitoringTest in Lib/test/test_monitoring.py
for single-line def bodies, multi-line bodies starting on the def
line, and lambda. All of test_monitoring, test_trace,
test_profile, and test_sys_settrace pass.

Copilot AI lite review requested due to automatic review settings August 18, 2026 10:08
@python-cla-bot

python-cla-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression in CPython’s sys.monitoring LINE event emission where the first line of a code object could be skipped when the function/lambda body starts on the same physical line as def/lambda. The core fix updates the instrumentation logic to recognize specialized RESUME opcodes by comparing against _PyOpcode_Deopt, and adds regression tests plus a NEWS entry.

Changes:

  • Update _Py_call_instrumentation_line() to treat all RESUME specializations as RESUME via _PyOpcode_Deopt.
  • Add LineMonitoringTest cases covering single-line def, multi-line bodies starting on the def line, and lambda.
  • Add a Core/Builtins NEWS entry documenting the regression fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
Python/instrumentation.c Adjusts the “force first LINE event” special-case to account for specialized RESUME opcodes via deopt mapping.
Lib/test/test_monitoring.py Adds regression tests ensuring LINE events include the first line for def/lambda bodies sharing the header line.
Misc/NEWS.d/next/Core_and_Builtins/2026-08-18-12-01-47.gh-issue-155992.Yl4gI2.rst Documents the sys.monitoring LINE-event regression fix in the NEWS stream.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

self.check_lines(func, [0, 1])
Comment thread Python/instrumentation.c
Comment on lines +1352 to 1356
if (_PyOpcode_Deopt[prev_opcode] != RESUME &&
prev_opcode != INSTRUMENTED_RESUME)
{
goto done;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sys.monitoring in 3.13+ does not trigger LINE event when there is no line break before

2 participants