Skip to content

Commit d151f33

Browse files
committed
gh-153782: Make traceback.print_list() delegate to format_list()
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.
1 parent b4662e8 commit d151f33

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lib/test/test_traceback.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,6 +3431,23 @@ def test_format_smoke(self):
34313431
[' File "foo.py", line 1, in fred\n line\n'],
34323432
s.format())
34333433

3434+
def test_print_list_matches_format_list(self):
3435+
frame = traceback.FrameSummary('foo.py', 1, 'fred', line='line')
3436+
inputs = [
3437+
('tuple', [('foo.py', 1, 'fred', 'line')]),
3438+
('FrameSummary', [frame]),
3439+
('StackSummary',
3440+
traceback.StackSummary.from_list([('foo.py', 1, 'fred', 'line')])),
3441+
]
3442+
for input_type, extracted_list in inputs:
3443+
with self.subTest(input_type=input_type):
3444+
file = StringIO()
3445+
traceback.print_list(extracted_list, file=file)
3446+
self.assertEqual(
3447+
file.getvalue(),
3448+
''.join(traceback.format_list(extracted_list)),
3449+
)
3450+
34343451
def test_locals(self):
34353452
linecache.updatecache('/foo.py', globals())
34363453
c = test_code('/foo.py', 'method')

Lib/traceback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def print_list(extracted_list, file=None):
7272
extract_stack() as a formatted stack trace to the given file."""
7373
if file is None:
7474
file = sys.stderr
75-
for item in StackSummary.from_list(extracted_list).format():
75+
for item in format_list(extracted_list):
7676
print(item, file=file, end="")
7777

7878
def format_list(extracted_list):

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ Laura Creighton
404404
Nick Crews
405405
Tyler Crompton
406406
Simon Cross
407+
Basil Crow
407408
Felipe Cruz
408409
Drew Csillag
409410
Alessandro Cucci

0 commit comments

Comments
 (0)