]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-130250: fix regression in traceback.print_last (GH-130318) (#130325)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 19 Feb 2025 22:06:43 +0000 (23:06 +0100)
committerGitHub <noreply@github.com>
Wed, 19 Feb 2025 22:06:43 +0000 (22:06 +0000)
gh-130250: fix regression in traceback.print_last (GH-130318)
(cherry picked from commit 6c982aeb547528174f8bc843267f584d8b133d14)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Doc/library/traceback.rst
Lib/test/test_traceback.py
Lib/traceback.py
Misc/NEWS.d/next/Library/2025-02-19-19-29-19.gh-issue-130250.T00tql.rst [new file with mode: 0644]

index 301cf225a51d37c9bfcaed88a509a9404d7dfea9..3beeb49755b5332c9bb546705c36d8b9ab8d15f8 100644 (file)
@@ -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(), limitfile,
-   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, limitfile,
-   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`).
 
 
index f89fe8b26dc1bfd603f08149d2770972a39a2bda..5d24f6850d01e1bbba23de2887778ccf2bfb8871 100644 (file)
@@ -516,6 +516,13 @@ class TracebackCases(unittest.TestCase):
         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)
index f5e054190eaf1e2e28602e8dbff1e8d83dcf9ce9..c748e4bc849c434b1ebc28f61bc8b6a0d23c3179 100644 (file)
@@ -204,7 +204,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):
@@ -212,15 +212,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 (file)
index 0000000..10ffb9d
--- /dev/null
@@ -0,0 +1 @@
+Fix regression in ``traceback.print_last()``.