GeezerVison is showing github.com — gh-153782: Make traceback.print_list() delegate to format_list() by basil · Pull Request #153783 · python/cpython
Conversation
basil
commented
Jul 15, 2026
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
|
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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
However the tests, if not already there, are worth it.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
If tests do not yet exist, we can accept such changes. Can you confirm that?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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().
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
If tests do not yet exist, we can accept such changes.
@picnixz Are there any next steps for this PR from your perspective?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
picnixz
commented
Aug 19, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
- This PR is unlikely to be merged to reduce friction with other branches.
- 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)
- We can keep your PR if you only keep the tests.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This is not our policy, so no. We do not backport refactoring changes.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
We can keep your PR if you only keep the tests.
Thanks @picnixz, I have done so in commit eb96153.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|