TracebackException.lineno changes from str to int after format() when a keyword typo suggestion is found
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 67/100
Hướng nghiên cứu
Bắt đầu với TracebackException._find_keyword_typos() và kiểm tra cách hàm gán lineno và end_lineno; issue nêu rằng việc chuyển đổi sang chuỗi của hàm khởi tạo là hành vi được mong đợi. Đọc các bài kiểm thử traceback về gợi ý lỗi chính tả trong từ khóa và bổ sung kiểm thử cho kiểu của các thuộc tính trước và sau khi định dạng. Công việc hoàn tất khi việc định dạng giữ nguyên các kiểu đã được tài liệu hóa hoặc thiết lập và bài kiểm thử hồi quy chạy thành công.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug report
For a SyntaxError, TracebackException stores lineno and end_lineno as strings. When the keyword typo suggestion ("Did you mean 'while'?") triggers during formatting, both attributes are replaced with ints.
import sys
import traceback
print(sys.version)
try:
compile("whille True:\n pass\n", "example.py", "exec")
except SyntaxError as exc:
te = traceback.TracebackException.from_exception(exc)
print("before format():", repr(te.lineno), repr(te.end_lineno))
"".join(te.format())
print("after format(): ", repr(te.lineno), repr(te.end_lineno))
On main:
3.16.0a2+dev (remotes/origin/HEAD:d456158, Nov 19 2026, 22:08:35) [GCC 13.3.0]
before format(): '1' '1'
after format(): 1 1
On 3.14:
3.14.6 (main, Jul 18 2026, 17:01:31) [Clang 22.1.3 ]
before format(): '1' '1'
after format(): 1 1
On 3.13.18 both stay '1', since there are no keyword suggestions there.
The constructor does self.lineno = str(lno), but TracebackException._find_keyword_typos() later assigns self.lineno = start[0] and self.end_lineno = end[0], which are ints from the tokenizer.
The printed traceback is fine, so most people won't notice this. It only shows up if your code reads the attributes directly. For example, te.lineno == '1' is True before calling format() and False after.
It also affects equality: two TracebackException objects created from the same exception compare equal, but stop being equal after you format one of them.
I think the two assignments should be wrapped in str() to match the constructor. I'm happy to send a PR with a test if that's the right direction. The docs don't currently state the type of these attributes, so that could be clarified at the same time.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
- Ngôn ngữ chính
- Python
- Star
- 78.4k
- Fork
- 36.6k
- Merge trung bình
- 23 giờ 34 phút
- Pull request đã merge (30 ngày)
- 610
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc 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.
Issue khác của python/cpython
-
interpreter-core type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
stdlib topic-subprocess type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
corner case: base64.b32decode ignorechars=b'=' miscounts paddingCó thể đã có người làm @ElDShell đã nhận hôm nay. Đang mở3.15 easy type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
python/cpython#162353 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[HACL] The `HACL_CAN_COMPILE_VEC128` macro is not defined when building Python with `-Wundef`Có thể đã có người làm @tamaki0575-cloud đã nhận 1 ngày trước. Đang mởbuild extension-modules topic-C-API type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
python/cpython#162219 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
zipfile: ZipInfo.comment exceeding 65535 bytes causes struct.error in ZipFile.close() without proper validationCó thể đã có người làm @1cbyc đã nhận 5 ngày trước. Đang mởstdlib type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của python/cpython
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
vllm-project/vllm#69304 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
pydanty:is-working
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
pydantic/pydantic-ai#14187 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
test
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
prebid/salesagent#2676 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 62/100
sunososobro-hub/cloudball#339 ·
Maintainer thường phản hồi trong vòng 1 ngày