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__``
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 = '> '
('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(
"""\