Provide name suggestions for failed attribute deletions
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
La issue non indica file né test. Inizia confrontando il comportamento esistente dei suggerimenti di nomi per una ricerca di attributo non riuscita con il percorso non riuscito di del obj.attr, quindi individua i test CPython pertinenti per i suggerimenti di AttributeError. Il lavoro è completato quando l’eliminazione di un attributo scritto in modo errato include il suggerimento del nome più vicino senza modificare il comportamento di ricerca esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100