Skip to content

Conversation

@pareshjoshij
Copy link
Contributor

@pareshjoshij pareshjoshij commented Nov 20, 2025

Description

This PR fixes a logic issue in pdb.print_stack_entry. Previously, prompt_prefix used line_prefix as a default argument, which caused the value to be bound at definition time (when the module is imported).

This prevented users from customizing pdb.line_prefix dynamically after import, as the function would continue using the initial value.

Changes:

  • Changed the default argument of prompt_prefix to None.
  • Added a check inside the function to assign line_prefix if prompt_prefix is None.
  • Fixed a typo in the docstring of _get_tb_and_exceptions ("tracecack" -> "traceback").

Linked Issue

Fixes #141781

@bedevere-app
Copy link

bedevere-app bot commented Nov 20, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Nov 20, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@pareshjoshij pareshjoshij changed the title Fix pdb line prefix binding gh-141781: Fix pdb line prefix binding Nov 20, 2025
@gaogaotiantian
Copy link
Member

Okay even though this is not an officially documented behavior, it has been like this for a long time and there is some comments in the source code about it. Also it does not cost us too much to revert the behavior back (the old behavior also makes more sense).

In order to prevent cases like this happen in the future, could you also add a quick regression test on it? To make sure changing pdb.line_prefix can change the print out.

Also, even though minor, this still is still a behavior change. You need to add a news entry to it. Click the failed bedevere/news action will guide you to blurbit where you can log in with your github account and add a news entry easily.

Let me know if you are stuck.

@pareshjoshij
Copy link
Contributor Author

Thank you @gaogaotiantian sir for the guidance.
I’ve now added the regression test to ensure that updating pdb.line_prefix at runtime affects the output of print_stack_entry. The test swaps the value using support.swap_attr, calls print_stack_entry(frame, frame.f_lineno), and checks that the custom prefix appears in stdout.
I also added the required news entry

Please let me know if anything needs to be adjusted or improved. Thank you again for your help.❤️

@gaogaotiantian
Copy link
Member

Okay this behavior has been like this since the beginning, at least 25 years ago. However I still don't think it makes sense to be like this. I won't backport this because it's hardly a bug fix and it's definitely not a regression. Let's just silently fix this and keep this as an unsupported undocumented thing.

@gaogaotiantian gaogaotiantian merged commit da1d468 into python:main Nov 25, 2025
46 checks passed
@pareshjoshij pareshjoshij deleted the fix-pdb-line-prefix-binding branch November 25, 2025 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pdb.line_prefix assignment ignored due to early binding

2 participants