Repository navigation
pdb.line_prefix assignment ignored due to early binding #141781
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Nov 20, 2025 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Nov 20, 2025 The documentation for pdb states that line_prefix can be customized by assigning to pdb.line_prefix
I actually can't find this in pdb documentation. Where did you find it?
Reacted by Paresh JoshiReacted by Paresh Joshi@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!
- added a commit that references this issue
on Nov 25, 2025
Bug Description
, in
pdb.print_stack_entry,line_prefixis 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_prefixby the user is ignored by this function.Fix
Change the default argument to
Noneand assign it inside the function body.CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs