python / python/cpython

TracebackException.format_exception_only() mutates attributes on keyword typo suggestion

オープン
#154,544 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

traceback.TracebackException.format_exception_only() と、issue に記載されているエントリーポイント _find_keyword_typos() から始めます。提供された SyntaxError の例を再現し、format_exception_only() を 2 回呼び出して結果を比較します。繰り返し呼び出しても、行番号やその他の例外の詳細を含め、同一の出力が生成されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
compilers
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。