Skip to content

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

Open
@blhsing

Description

@blhsing

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:

limit = getattr(sys, 'tracebacklimit', None)

whereas the C implementation of the traceback printer has a proper default of 1000 for sys.tracebacklimit as documented:

#define PyTraceBack_LIMIT 1000

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions