You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pdb.line_prefix assignment ignored due to early binding #141781
, in pdb.print_stack_entry, line_prefix is used as a default argument: def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix):
This causes the value to be bound at definition time (when the module is imported). Any subsequent assignment to pdb.line_prefix by the user is ignored by this function.
Fix
Change the default argument to None and assign it inside the function body.
@gaogaotiantian You're completely right — that first sentence is wrong and should never have been there. The official documentation does not say anything about customizing pdb.line_prefix. It was an undocumented implementation detail that some people (including me) mistakenly treated as a supported feature. I apologize for the misleading wording in the issue; that’s on me.
I'will edited the issue description to remove the incorrect claim.
The actual bug (the default-argument binding in print_stack_entry capturing the value of line_prefix at import time instead of at call time) is still real and reproducible. After this fix, assigning to pdb.line_prefix at runtime finally affects the arrow prefix in list, where, etc., which is the expected behavior for anyone who was already monkey-patching that variable.
Activity
gaogaotiantian commentedon Nov 21, 2025
I actually can't find this in pdb documentation. Where did you find it?
pareshjoshij commentedon Nov 21, 2025
@gaogaotiantian You're completely right — that first sentence is wrong and should never have been there. The official documentation does not say anything about customizing
pdb.line_prefix. It was an undocumented implementation detail that some people (including me) mistakenly treated as a supported feature. I apologize for the misleading wording in the issue; that’s on me.I'will edited the issue description to remove the incorrect claim.
The actual bug (the default-argument binding in
print_stack_entrycapturing the value ofline_prefixat import time instead of at call time) is still real and reproducible. After this fix, assigning topdb.line_prefixat runtime finally affects the arrow prefix inlist,where, etc., which is the expected behavior for anyone who was already monkey-patching that variable.Thank you for pointing it out — much appreciated!
Add regression test for pythongh-141781
Fix regression test spacing and add pythongh-141781 test
gh-141781: Fix pdb.line_prefix binding (#141779)
pythongh-141781: Fix pdb.line_prefix binding (python#141779)
pythongh-141781: Fix pdb.line_prefix binding (python#141779)