]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-141781: Fix pdb.line_prefix binding (#141779)
authorParesh Joshi <rahulj9223@gmail.com>
Tue, 25 Nov 2025 02:45:16 +0000 (08:15 +0530)
committerGitHub <noreply@github.com>
Tue, 25 Nov 2025 02:45:16 +0000 (18:45 -0800)
Lib/pdb.py
Lib/test/test_pdb.py
Misc/ACKS
Misc/NEWS.d/next/Library/2025-11-24-06-44-45.gh-issue-141781.MsK27r.rst [new file with mode: 0644]

index 8e9502cb9e6bfb76b3bdd7395ec34df421c0aa16..60b713ebaf3d1a85d89b86472768d7bd4bc6494c 100644 (file)
@@ -654,7 +654,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
 
     def _get_tb_and_exceptions(self, tb_or_exc):
         """
-        Given a tracecack or an exception, return a tuple of chained exceptions
+        Given a traceback or an exception, return a tuple of chained exceptions
         and current traceback to inspect.
 
         This will deal with selecting the right ``__cause__`` or ``__context__``
@@ -2429,7 +2429,9 @@ class Pdb(bdb.Bdb, cmd.Cmd):
         except KeyboardInterrupt:
             pass
 
-    def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix):
+    def print_stack_entry(self, frame_lineno, prompt_prefix=None):
+        if prompt_prefix is None:
+            prompt_prefix = line_prefix
         frame, lineno = frame_lineno
         if frame is self.curframe:
             prefix = '> '
index 418ea79cdd22c37d1cc36c96968eff194f2a1571..34dfc220c7ed733f324eb145011a52f7f4a53779 100644 (file)
@@ -3580,6 +3580,20 @@ def quux():
             ('bœr', 5),
         )
 
+    def test_print_stack_entry_uses_dynamic_line_prefix(self):
+        """Test that pdb.line_prefix binding is dynamic (gh-141781)."""
+        stdout = io.StringIO()
+        p = pdb.Pdb(stdout=stdout)
+
+        # Get the current frame to use for printing
+        frame = sys._getframe()
+
+        with support.swap_attr(pdb, 'line_prefix', 'CUSTOM_PREFIX> '):
+            p.print_stack_entry((frame, frame.f_lineno))
+
+        # Check if the custom prefix appeared in the output
+        self.assertIn('CUSTOM_PREFIX> ', stdout.getvalue())
+
     def test_find_function_found_with_encoding_cookie(self):
         self._assert_find_function(
             """\
index f5f15f2eb7ea24341432955e94674ea56f38aad1..ab6b8662d8fc81d25a90a7fef0bd2f5fc1019a7d 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -927,6 +927,7 @@ Kristján Valur Jónsson
 Jens B. Jorgensen
 John Jorgensen
 Sijin Joseph
+Paresh Joshi
 Andreas Jung
 Tattoo Mabonzo K.
 Sarah K.
diff --git a/Misc/NEWS.d/next/Library/2025-11-24-06-44-45.gh-issue-141781.MsK27r.rst b/Misc/NEWS.d/next/Library/2025-11-24-06-44-45.gh-issue-141781.MsK27r.rst
new file mode 100644 (file)
index 0000000..21db970
--- /dev/null
@@ -0,0 +1 @@
+Fixed an issue where pdb.line_prefix assignment was ignored if assigned after the module was imported.