https://github.com/python/cpython/commit/8d58070d7eaf20654da96562e1ea1568b42d2784
commit: 8d58070d7eaf20654da96562e1ea1568b42d2784
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: iritkatriel <[email protected]>
date: 2025-02-19T22:01:32Z
summary:

[3.12] gh-130250: fix regression in traceback.print_last (GH-130318) (#130326)

gh-130250: fix regression in traceback.print_last (GH-130318)
(cherry picked from commit 6c982aeb547528174f8bc843267f584d8b133d14)

Co-authored-by: Irit Katriel <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-02-19-19-29-19.gh-issue-130250.T00tql.rst
M Doc/library/traceback.rst
M Lib/test/test_traceback.py
M Lib/traceback.py

diff --git a/Doc/library/traceback.rst b/Doc/library/traceback.rst
index 0a2b9c5cfb10c4..d7e9dadf9ca2e2 100644
--- a/Doc/library/traceback.rst
+++ b/Doc/library/traceback.rst
@@ -111,14 +111,14 @@ Module-Level Functions
 
 .. function:: print_exc(limit=None, file=None, chain=True)
 
-   This is a shorthand for ``print_exception(sys.exception(), limit, file,
-   chain)``.
+   This is a shorthand for ``print_exception(sys.exception(), limit=limit, 
file=file,
+   chain=chain)``.
 
 
 .. function:: print_last(limit=None, file=None, chain=True)
 
-   This is a shorthand for ``print_exception(sys.last_exc, limit, file,
-   chain)``.  In general it will work only after an exception has reached
+   This is a shorthand for ``print_exception(sys.last_exc, limit=limit, 
file=file,
+   chain=chain)``.  In general it will work only after an exception has reached
    an interactive prompt (see :data:`sys.last_exc`).
 
 
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index 86d509744517ad..be431cc5631fbf 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -328,6 +328,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)
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 8247d8ff8cd1e7..6de428bf59bba8 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -176,7 +176,7 @@ def _safe_string(value, what, func=str):
 # --
 
 def print_exc(limit=None, file=None, chain=True):
-    """Shorthand for 'print_exception(sys.exception(), limit, file, chain)'."""
+    """Shorthand for 'print_exception(sys.exception(), limit=limit, file=file, 
chain=chain)'."""
     print_exception(sys.exception(), limit=limit, file=file, chain=chain)
 
 def format_exc(limit=None, chain=True):
@@ -184,15 +184,15 @@ def format_exc(limit=None, chain=True):
     return "".join(format_exception(sys.exception(), limit=limit, chain=chain))
 
 def print_last(limit=None, file=None, chain=True):
-    """This is a shorthand for 'print_exception(sys.last_exc, limit, file, 
chain)'."""
+    """This is a shorthand for 'print_exception(sys.last_exc, limit=limit, 
file=file, chain=chain)'."""
     if not hasattr(sys, "last_exc") and not hasattr(sys, "last_type"):
         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)
 
 
 #
diff --git 
a/Misc/NEWS.d/next/Library/2025-02-19-19-29-19.gh-issue-130250.T00tql.rst 
b/Misc/NEWS.d/next/Library/2025-02-19-19-29-19.gh-issue-130250.T00tql.rst
new file mode 100644
index 00000000000000..10ffb9dc1ee6a1
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-02-19-19-29-19.gh-issue-130250.T00tql.rst
@@ -0,0 +1 @@
+Fix regression in ``traceback.print_last()``.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to