Skip to content

Regression: 3.13 traceback.format_list() breaking behavior change. #140456

Open

Description

@xl0

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Oct 22, 2025
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Oct 22, 2025
  3. serhiy-storchaka commented on Oct 22, 2025

    @serhiy-storchaka
    Member

    It was never claimed that line can represent several physical lines. Taking into account that leading and trailing whitespace were stripped, and the line is printed with an indentation, and that an anchor was printed immediately under the line, the code never correctly supported line containing newline characters (and other control characters).

    We can document that line is the single line of the code (it was not obvious after adding end_lineno). But there is no need to document the change -- because the behavior for multi-line line was not specified.

  4. added
    docsDocumentation in the Doc dir
    and removed
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    on Oct 22, 2025
  5. added 5 commits that reference this issue on Jul 10, 2026
  6. added a commit that references this issue on Aug 15, 2026
  7. harjothkhara commented on Aug 23, 2026

    @harjothkhara
    Contributor

    Docs PR for this is open at #153469.

  8. added a commit that references this issue on Oct 27, 2026
  9. added a commit that references this issue on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions