TracebackException.format_exception_only() mutates attributes on keyword typo suggestion
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 description
TracebackException.format_exception_only() is not idempotent when _find_keyword_typos() finds a suggestion. The method directly mutates self.text, self.offset, self.end_offset, self.lineno, self.end_lineno, and self.msg, so a second call produces different output (e.g. wrong line number).
import traceback
code = "fr x in range(10):\n pass\n"
try:
compile(code, "<test>", "exec")
except SyntaxError as exc:
te = traceback.TracebackException(type(exc), exc, None)
r1 = list(te.format_exception_only()) # correct
r2 = list(te.format_exception_only()) # different output
assert r1 == r2 # fails
_find_keyword_typos was added in gh-132449.
CPython versions tested on
main
Operating systems tested on
macOS
Linked PRs
- gh-154545
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 từ traceback.TracebackException.format_exception_only() và điểm vào _find_keyword_typos() được mô tả trong issue. Tái hiện ví dụ SyntaxError đã cung cấp, gọi format_exception_only() hai lần và so sánh kết quả. Hoàn thành khi các lần gọi lặp lại tạo ra đầu ra giống hệt nhau, bao gồm số dòng và các chi tiết khác của exception.
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
- compilers
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- 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
- 35/100