python / python/cpython

Regression: 3.13 `traceback.format_list()` breaking behavior change.

未關閉
#140,456 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

docs
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:

traceback.format_list() no longer works with lines that have breaks in them:

import traceback
import sys

print(f"Python {sys.version_info.major}.{sys.version_info.minor}")

# Frame with multiline text (source + variable annotations)
frames = [('test.py', 10, 'func', 'x = foo + bar\n\t\thello\n\tworld')]

print("\nInput (3 lines):")
print(repr(frames[0][3]))

print("\nOutput from traceback.format_list():")
result = traceback.format_list(frames)[0] # Yes, it't always a 1-element list both on 3.12 adn 3.13.
print(result)
Python 3.12

Input (3 lines):
'x = foo + bar\n\t\thello\n\tworld'

Output from traceback.format_list():
  File "test.py", line 10, in func
    x = foo + bar
                hello
        world
Python 3.13

Input (3 lines):
'x = foo + bar\n\t\thello\n\tworld'

Output from traceback.format_list():
  File "test.py", line 10, in func
    x = foo + bar

This broke bettre_exceptions on 3.13, which was fixed by formatting the traceback manually. Can we either

  • Revert to old behavior in 3.15 and maybe document that it was broken in 3.13 and 3.14?
  • Document the behavior change?

ref: https://github.com/Qix-/better-exceptions/issues/134

CPython versions tested on:

3.13

Operating systems tested on:

No response

Linked PRs
  • gh-153469

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

使用 Python 3.12 和 3.13 重現提供的腳本,然後從 traceback.format_list() 開始。先檢視已連結的 PR gh-153469 以及 traceback 周邊的行為,再決定目標是相容性還是文件。完成的標準是:已接受的行為獲得實作或記錄,且多行情況由相關測試涵蓋。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
tooling
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。