python / python/cpython

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

Đang mở
#123,596 6 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong Lib/traceback.py, tại phần xử lý mặc định cho sys.tracebacklimit, và so sánh với phần triển khai bằng C trong Python/traceback.c. Xác minh giá trị mặc định được ghi trong tài liệu là 1000 bằng cách sử dụng ví dụ đệ quy từ issue, đảm bảo rằng trình in traceback của Python giới hạn đầu ra nhất quán với phần triển khai bằng C.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
20/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.