Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ def _show_display(self):

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__``
Expand Down Expand Up @@ -2429,7 +2429,9 @@ def print_stack_trace(self, count=None):
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 = '> '
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""\
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an issue where pdb.line_prefix assignment was ignored if assigned after the module was imported.
Loading