python / python/cpython

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

Open
#140,456 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied script with Python 3.12 and 3.13, then start at traceback.format_list(). Review linked PR gh-153469 and the surrounding traceback behavior before choosing whether compatibility or documentation is intended. Done means the accepted behavior is implemented or documented and the multiline case is covered by the relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.