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 — gh-153782: Make traceback.print_list() delegate to format_list() by basil · Pull Request #153783 · python/cpython

Conversation

@basil

@basil basil commented Jul 15, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Fixes #153782

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. This PR routes 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().

Testing Done

format_list() is exactly the same expression, so output is identical for every documented input type. Therefore, there is no change in behavior. This PR adds a regression test asserting this equality for tuple, FrameSummary, and StackSummary inputs.

Documentation

I have not proposed an entry in Misc/NEWS.d, as the developer guide says that strictly internal changes with no user-visible effect do not require one. I am happy to add one if a maintainer prefers.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@basil
pythongh-153782: Make traceback.print_list() delegate to format_list()
d151f33
print_list() and format_list() each formatted a StackSummary with the
same expression, so their outputs agreed only by duplication. Route
print_list() through format_list() so print_list(x), keeping the two
public helpers from drifting, and add a regression test that
print_list() matches format_list() for tuple, FrameSummary, and
StackSummary inputs.
@bedevere-app

bedevere-app Bot commented Jul 15, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

moritajavier239-rgb reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added the awaiting review label Jul 15, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Jul 15, 2026
Remove duplicate code by making traceback.print_list() delegate to format_list() #153782
Open
@basil

basil commented Jul 15, 2026

Copy link
Copy Markdown
Author

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

Per my comment from the PR description:

I have not proposed an entry in Misc/NEWS.d, as the developer guide says that strictly internal changes with no user-visible effect do not require one. I am happy to add one if a maintainer prefers.


If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

I will wait for a maintainer to apply the skip news label.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Jul 15, 2026

Copy link
Copy Markdown
Member

I do not think it is really worth it. The current code is working and such change would create a drift in backports. We do not accept such changes in general. I think it is fine as is.

johnslavik reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Jul 15, 2026

Copy link
Copy Markdown
Member

However the tests, if not already there, are worth it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Jul 15, 2026

Copy link
Copy Markdown
Member

If tests do not yet exist, we can accept such changes. Can you confirm that?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@johnslavik

johnslavik commented Jul 15, 2026

Copy link
Copy Markdown
Member

I think the current code is OK.

I understand your reasoning. However, these functions are essentially kept together and they are simple functions. They have not drifted for 11 years.

Test coverage would be cool to have, yes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@basil

basil commented Jul 15, 2026

Copy link
Copy Markdown
Author

Thank you, that makes sense. This PR adds test_print_list_matches_format_list, covering tuple input, FrameSummary input, and StackSummary input. I confirmed that there was not an existing test checking that traceback.print_list() produces the same output as traceback.format_list().

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@basil

basil commented Aug 19, 2026

Copy link
Copy Markdown
Author

If tests do not yet exist, we can accept such changes.

@picnixz Are there any next steps for this PR from your perspective?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Aug 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  1. This PR is unlikely to be merged to reduce friction with other branches.
  2. If you can add improve the coverage of traceback.py that related to these functions we can accept auch PR. But this must be a separate one and you likely won't need an issue unless you plan to work on large parts of traceback.py (i.e if we are severly lacking coverage if would be good to have an issue and know which interface is poorly or not tested)
  3. We can keep your PR if you only keep the tests.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@basil

basil commented Aug 19, 2026

Copy link
Copy Markdown
Author

This PR is unlikely to be merged to reduce friction with other branches.

Thanks @picnixz, would that friction still exist if I proposed this PR against those other branches as well?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Aug 19, 2026

Copy link
Copy Markdown
Member

This is not our policy, so no. We do not backport refactoring changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

basil added 2 commits August 19, 2026 10:09
@basil
Merge remote-tracking branch 'origin/main' into format-list
744dd2a
@basil
https://github.com/python/cpython/pull/153783#issuecomment-5344367230
eb96153
@bedevere-app

bedevere-app Bot commented Aug 19, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@basil

basil commented Aug 19, 2026

Copy link
Copy Markdown
Author

We can keep your PR if you only keep the tests.

Thanks @picnixz, I have done so in commit eb96153.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@basil @picnixz @johnslavik
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.