GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Remove duplicate code by making `traceback.print_list()` delegate to `format_list()` · Issue #153782 · python/cpython

Remove duplicate code by making traceback.print_list() delegate to format_list() #153782

New issue
Copy link
New issue
Copy link
Open
#153783
Open
Remove duplicate code by making traceback.print_list() delegate to format_list()#153782
#153783
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)

Description

@basil
basil
opened on Jul 15, 2026
Issue body actions

In Lib/traceback.py, the public helpers print_list() and format_list() independently contain the same formatting expression, so their outputs agree only by duplication. We propose routing print_list() through format_list() so that they share a single formatting path, with no change in behavior.

Problem

format_list() returns the formatted lines:

def format_list(extracted_list):
    return StackSummary.from_list(extracted_list).format()

print_list() writes those same lines, but re-derives them with the identical expression instead of reusing format_list():

def print_list(extracted_list, file=None):
    if file is None:
        file = sys.stderr
    for item in StackSummary.from_list(extracted_list).format():
        print(item, file=file, end="")

The outputs match only because StackSummary.from_list(extracted_list).format() is duplicated in both. Any future change to how a frame list is formatted has to be applied in both places to prevent the two public helpers from silently diverging.

Solution

Have print_list() iterate format_list():

def print_list(extracted_list, file=None):
    if file is None:
        file = sys.stderr
    for item in format_list(extracted_list):
        print(item, file=file, end="")

This eliminates the possibility of drift and mirrors the delegation already used in this module; for example, print_tb() calls print_list() rather than re-deriving extract_tb(...).format().

Linked PRs

  • gh-153782: Make traceback.print_list() delegate to format_list() #153783

Activity

  1. picnixz
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    type-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)
    on Jul 15, 2026
  2. picnixz commented on Jul 15, 2026

    @picnixz
    picnixz
    on Jul 15, 2026
    Member
    More actions

    As explained on the PR this is borderline cosmetic and we do not accept such changes. But the PR includes tests that may be relevant so I am willing to make an exception for the sake of other functions that follow that pattern.

  3. StanFromIreland
    added this to Traceback issues 🐾on Jul 17, 2026
  4. github-project-automation
    moved this to Todo in Traceback issues 🐾on Jul 17, 2026
  5. github-project-automation
    moved this from Todo to In Progress in Traceback issues 🐾on Jul 17, 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

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)

    Projects

    • Traceback issues 🐾
      Status
      In Progress
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.