TracebackException.format_exception_only() mutates attributes on keyword typo suggestion
未關閉
還沒有人認領這個 Issue。
stdlib
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 traceback.TracebackException.format_exception_only() 和 issue 中描述的 _find_keyword_typos() 進入點開始。重現提供的 SyntaxError 範例,呼叫 format_exception_only() 兩次並比較結果。當重複呼叫產生完全相同的輸出(包括行號和其他例外詳細資訊)時,即視為完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- compilers
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100