From: Paresh Joshi Date: Tue, 25 Nov 2025 02:45:16 +0000 (+0530) Subject: gh-141781: Fix pdb.line_prefix binding (#141779) X-Git-Tag: v3.15.0a3~284 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da1d468bea2283032c491b894d3b38b2115ceb70;p=thirdparty%2FPython%2Fcpython.git gh-141781: Fix pdb.line_prefix binding (#141779) --- diff --git a/Lib/pdb.py b/Lib/pdb.py index 8e9502cb9e6b..60b713ebaf3d 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -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 = '> ' diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 418ea79cdd22..34dfc220c7ed 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -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( """\ diff --git a/Misc/ACKS b/Misc/ACKS index f5f15f2eb7ea..ab6b8662d8fc 100644 --- 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 index 000000000000..21db97025a3d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-11-24-06-44-45.gh-issue-141781.MsK27r.rst @@ -0,0 +1 @@ +Fixed an issue where pdb.line_prefix assignment was ignored if assigned after the module was imported.