8000 gh-130250: fix regression in traceback.print_last by iritkatriel · Pull Request #130318 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-130250: fix regression in traceback.print_last #130318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-130250: fix regression in traceback.print_last
  • Loading branch information
iritkatriel committed Feb 19, 2025
commit 6b2ac1d67793c40e1d4d7fe39bf39eca4a26e9a5
7 changes: 7 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,13 @@ def test_print_exception_exc(self):
traceback.print_exception(Exception("projector"), file=output)
self.assertEqual(output.getvalue(), "Exception: projector\n")

def test_print_last(self):
self.assertIsNone(getattr(sys, "last_exc", None))
sys.last_exc = ValueError(42)
output = StringIO()
traceback.print_last(file=output)
self.assertEqual(output.getvalue(), "ValueError: 42\n")

def test_format_exception_exc(self):
e = Exception("projector")
output = traceback.format_exception(e)
Expand Down
4 changes: 2 additions & 2 deletions Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ def print_last(limit=None, file=None, chain=True):
raise ValueError("no last exception")

if hasattr(sys, "last_exc"):
print_exception(sys.last_exc, limit, file, chain)
print_exception(sys.last_exc, limit=limit, file=file, chain=chain)
else:
print_exception(sys.last_type, sys.last_value, sys.last_traceback,
limit, file, chain)
limit=limit, file=file, chain=chain)


#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix regression in `traceback.print_last()`.
Loading
0