Provide name suggestions for failed attribute deletions
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Feature or enhancement
Proposal:
This was initially mentioned as a comment in issue #130399.
class A:
pass
a = A()
a.abcde = 1
del a.abcdf # typo
Current Output
Traceback (most recent call last):
File "<python-input-0>", line 6, in <module>
del a.abcdf # typo
^^^^^^^
AttributeError: 'A' object has no attribute 'abcdf'
CPython provides name suggestions when an attribute lookup (obj.attr) fails, but it does not provide similar suggestions when an attribute deletion (del obj.attr) fails. This brings about an inconsistency with regards to the developer experience offered by the language.
Expected Output
Traceback (most recent call last):
File "<python-input-0>", line 6, in <module>
del a.abcdf # typo
^^^^^^^
AttributeError: 'A' object has no attribute 'abcdf'. Did you mean: 'abcde'?
Advantages
- Helps users quickly identify typos in attribute deletions.
- CPython already provides name suggestions for failed attribute lookups (obj.attr), so deletions (del obj.attr) should behave similarly.
- Suggestions are only generated when an attribute deletion fails, and hence has a minimal performance impact.
Note
CPython version - CPython main branch
Operating system - Ubuntu 22.04
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
- gh-130427
- gh-130799
- gh-136588
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
A issue não nomeia arquivos nem testes. Comece comparando o comportamento existente de sugestão de nomes para uma busca de atributo malsucedida com o caminho malsucedido de del obj.attr e, em seguida, localize os testes relevantes do CPython para sugestões de AttributeError. A tarefa estará concluída quando a exclusão de um atributo escrito incorretamente incluir a sugestão de nome mais próxima sem alterar o comportamento de busca existente.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- compilers
- Tipo de issue
- Funcionalidade
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 25/100