sys.monitoring in 3.13+ does not trigger LINE event when there is no line break before
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
In sys.monitoring there seems to be a regression from 3.13+ on where the LINE event does not fire for the first line of a code object if it is on the same line as the def /lambda statement. In Pyhton 3.12 it works. The bug disappears if on all versions if the PY_START event is added to the event mask.
Reproduction code:
import sys
print(f"Python {sys.version}")
TOOL = 1
sys.monitoring.use_tool_id(TOOL, "test")
hits = []
sys.monitoring.register_callback(TOOL, sys.monitoring.events.LINE,
lambda _code, line: hits.append(line))
# A: LINE event never fires in single-line function/lambda on 3.13+
def f(x): return x + 1 #<<<<<<<<<< LINE 12
#f = lambda x: x + 1 # same issue
sys.monitoring.set_local_events(TOOL, f.__code__, sys.monitoring.events.LINE)
f(0)
print(f"Example A: {hits}")
hits.clear()
# B: Adding PY_START makes the LINE fire (even though we have no callback registred for PY_START)
sys.monitoring.set_local_events(TOOL, f.__code__, sys.monitoring.events.LINE | sys.monitoring.events.PY_START)
f(0)
print(f"Example B: {hits}")
hits.clear()
# C: LINE fires but never for first line
def g(x): x = 0; x += 1; \
x += 2; return x #<<<<<<<<<< LNE 30
sys.monitoring.set_local_events(TOOL, g.__code__, sys.monitoring.events.LINE)
g(0)
print(f"Example C: {hits}")
The expected output would be as in Python 3.12, we get line events for line 12 and 29 even if PY_START (example B) is not set:
$ python3.12 cpython_issue_monitoring_line_event.py # Only one that fully works
Python 3.12.3 (main, Jun 19 2026, 12:46:00) [GCC 13.3.0]
Example A: [12]
Example B: [12]
Example C: [29, 30]
But the actual output from 3.13 on is missing the first lines:
$ python3.13 cpython_issue_monitoring_line_event.py
Python 3.13.15 (main, Aug 6 2026, 11:06:22) [GCC 13.3.0]
Example A: []
Example B: [12]
Example C: [30]
I.e., same with:
- Python 3.14.6 (main, Jun 11 2026, 12:32:48) [GCC 13.3.0]
- Python 3.15.0rc1 (main, Aug 5 2026, 11:04:42) [GCC 13.3.0]
CPython versions tested on:
3.12, 3.13, 3.14, 3.15
Operating systems tested on:
Linux
Linked PRs
- gh-155996
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy bản tái hiện được cung cấp trên Python 3.12 đến 3.15 và so sánh đầu ra của các sự kiện LINE cho các ví dụ A, B và C. Sau đó, kiểm tra cách sys.monitoring xử lý các sự kiện LINE và PY_START, cùng với PR được liên kết gh-155996. Công việc được xem là hoàn tất khi các sự kiện của dòng đầu tiên khớp với đầu ra mong đợi mà không yêu cầu PY_START, với độ bao phủ hồi quy cho các trường hợp được báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 25/100