Skip to content

pdb.line_prefix assignment ignored due to early binding #141781

Description

@pareshjoshij

Bug Description

, 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.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 20, 2025
  2. gaogaotiantian commented on Nov 21, 2025

    @gaogaotiantian
    Member

    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?

  3. pareshjoshij commented on Nov 21, 2025

    @pareshjoshij
    ContributorAuthor

    @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.

    Thank you for pointing it out — much appreciated!

  4. added a commit that references this issue on Nov 25, 2025
  5. added a commit that references this issue on Dec 6, 2025
  6. added a commit that references this issue on Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions