python / python/cpython

Removing unncessary class states in bdb.Breakpoint

Aberta
#127,392 6 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

stdlib type-feature
Linguagem predominante
Python
Estrelas
77.2k
Forks
35.9k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece por Lib/bdb.py, especialmente pela classe Breakpoint e pelos métodos de Bdb mostrados na issue, e depois analise o PR vinculado gh-127410. Determine como o estado dos breakpoints é compartilhado atualmente entre instâncias de Bdb e como a propriedade proposta no nível da instância afetaria Bdb e Pdb. Considera-se concluído quando o design oferecer suporte a instâncias independentes de depuradores ativos sem depender do estado compartilhado da classe Breakpoint.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
devtools
Tipo de issue
Funcionalidade
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Estagnada
Clareza
Precisa de esclarecimento
Facilidade para iniciantes
20/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.