python / python/cpython

Python implementation of traceback limit does not default to 1000 as documented in 3.13

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

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

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

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

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

はじめの一歩

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

調査の方向性

Lib/traceback.py の sys.tracebacklimit のデフォルト処理から始め、Python/traceback.c の C 実装と比較してください。issue の再帰的な例を使って、文書化されているデフォルト値 1000 を検証し、Python の traceback printer が C 実装と一貫した形で出力を制限することを確認してください。

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

評価

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

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

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