gh-155992: Fix missing LINE event for first line of a code object - #155996
Open
PrathamGhaywat wants to merge 1 commit into
Open
gh-155992: Fix missing LINE event for first line of a code object#155996PrathamGhaywat wants to merge 1 commit into
PrathamGhaywat wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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 allRESUMEspecializations asRESUMEvia_PyOpcode_Deopt. - Add
LineMonitoringTestcases covering single-linedef, multi-line bodies starting on thedefline, andlambda. - 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 on lines
+1352
to
1356
| if (_PyOpcode_Deopt[prev_opcode] != RESUME && | ||
| prev_opcode != INSTRUMENTED_RESUME) | ||
| { | ||
| goto done; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #155992.
The
sys.monitoringLINEevent did not fire for the first line of acode object when the
def/lambdabody shared that line. Since 3.13,RESUMEis specialized toRESUME_CHECK, so the special case in_Py_call_instrumentation_line()that forces the firstLINEevent(when the previous instruction is
RESUME/INSTRUMENTED_RESUME) nolonger matched. The check now uses
_PyOpcode_Deopt, covering allRESUMEspecializations.Tests were added to
LineMonitoringTestinLib/test/test_monitoring.pyfor single-line
defbodies, multi-line bodies starting on thedefline, and
lambda. All oftest_monitoring,test_trace,test_profile, andtest_sys_settracepass.