Skip to content

Commit 6b2ac1d

Browse files
committed
pythongh-130250: fix regression in traceback.print_last
1 parent 2498c22 commit 6b2ac1d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Lib/test/test_traceback.py

+7
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,13 @@ def test_print_exception_exc(self):
510510
traceback.print_exception(Exception("projector"), file=output)
511511
self.assertEqual(output.getvalue(), "Exception: projector\n")
512512

513+
def test_print_last(self):
514+
self.assertIsNone(getattr(sys, "last_exc", None))
515+
sys.last_exc = ValueError(42)
516+
output = StringIO()
517+
traceback.print_last(file=output)
518+
self.assertEqual(output.getvalue(), "ValueError: 42\n")
519+
513520
def test_format_exception_exc(self):
514521
e = Exception("projector")
515522
output = traceback.format_exception(e)

Lib/traceback.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ def print_last(limit=None, file=None, chain=True):
217217
raise ValueError("no last exception")
218218

219219
if hasattr(sys, "last_exc"):
220-
print_exception(sys.last_exc, limit, file, chain)
220+
print_exception(sys.last_exc, limit=limit, file=file, chain=chain)
221221
else:
222222
print_exception(sys.last_type, sys.last_value, sys.last_traceback,
223-
limit, file, chain)
223+
limit=limit, file=file, chain=chain)
224224

225225

226226
#
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix regression in `traceback.print_last()`.

0 commit comments

Comments
 (0)