python / python/cpython

Removing unncessary class states in bdb.Breakpoint

Open
#127,392 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

According to the comment in the Breakpoint class

Keeping state in the class is a mistake -- this means you cannot have more than one active Bdb instance.

I can support this idea further. Currently, Breakpoint has three class states, next, bplist, and bpbynumber.

class Breakpoint:
    ...
    next = 1
    bplist = {}
    bpbynumber = [None]

These states are used to enable the reuse of previously set breakpoint instances across multiple interactive sessions or other use cases. However, relying on class states is not the only way to achieve this goal.

Using class states in this case has several clear limitations. As noted in the comment, it makes it difficult to maintain more than one active Bdb instance. Additionally, logic dependent on class state can make the behavior of a new Bdb instance unpredictable in many scenarios unless the exact states of Breakpoint is fully known. Another drawback of maintaining states in the Breakpoint class is that it tightly couples the behavior of all Bdb instances. For example, the deleteMe method must be called periodically by a Bdb instance to ensure the Breakpoint class remains in a valid state.

# example deleteMe calls in Bdb methods

class Bdb:
    ...
    def clear_break(self, filename, lineno):
        ...
        for bp in Breakpoint.bplist[filename, lineno][:]:
            bp.deleteMe()  # here
        self._prune_breaks(filename, lineno)
        return None
        
    def clear_bpbynumber(self, arg):
        ...
        try:
            bp = self.get_bpbynumber(arg)
        except ValueError as err:
            return str(err)
        bp.deleteMe()  # here
        self._prune_breaks(bp.file, bp.line)
        return None

As an alternative, instance-level state can be maintained within Bdb or derived classes such as Pdb, allowing each instance to manage its own breakpoint data independently. This approach can still support the reuse of previously set breakpoint instances across multiple interactive sessions.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-127410

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Lib/bdb.py, especially the Breakpoint class and the Bdb methods shown in the issue, then review linked PR gh-127410. Determine how breakpoint state is currently shared across Bdb instances and how the proposed instance-level ownership would affect Bdb and Pdb. Done means the design supports independent active debugger instances without relying on shared Breakpoint class state.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.