Python implementation of traceback limit does not default to 1000 as documented in 3.13
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
According to the documentation of sys.tracebacklimit, it should default to 1000 if not set, so the following snippet:
import sys
def f():
f()
sys.setrecursionlimit(2000)
f()
produces a traceback of 1000 frames as expected in 3.12:
Traceback (most recent call last):
File "t.py", line 4, in f
f()
~^^
File "t.py", line 4, in f
f()
~^^
File "t.py", line 4, in f
f()
~^^
[Previous line repeated 997 more times]
RecursionError: maximum recursion depth exceeded
But in 3.13 and the current master, it produces a traceback of all 2000 frames:
Traceback (most recent call last):
File "t.py", line 4, in f
f()
~^^
File "t.py", line 4, in f
f()
~^^
File "t.py", line 4, in f
f()
~^^
File "t.py", line 4, in f
f()
~^^
[Previous line repeated 1996 more times]
RecursionError: maximum recursion depth exceeded
This is because with issue #110721, traceback is now printed with the traceback module by default, and the traceback module defaults sys.tracebacklimit to None when not set:
https://github.com/python/cpython/blob/c3ed775899eedd47d37f8f1840345b108920e400/Lib/traceback.py#L458
whereas the C implementation of the traceback printer has a proper default of 1000 for sys.tracebacklimit as documented:
https://github.com/python/cpython/blob/c3ed775899eedd47d37f8f1840345b108920e400/Python/traceback.c#L707
I will submit a PR to make 1000 the default value for sys.tracebacklimit in the Python implementation of the traceback module.
CPython versions tested on:
3.13, CPython main branch
Operating systems tested on:
Linux, Windows
Linked PRs
- gh-125719
- gh-125777
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 Lib/traceback.py 中對 sys.tracebacklimit 的預設處理開始,並將其與 Python/traceback.c 中的 C 實作進行比較。使用 issue 中的遞迴範例驗證文件所述的預設值 1000,確保 Python 的 traceback 列印器以與 C 實作一致的方式限制輸出。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 20/100