Provide name suggestions for failed attribute deletions
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
El issue no nombra archivos ni tests. Empieza comparando el comportamiento existente de sugerencia de nombres para una búsqueda de atributo fallida con la ruta fallida de del obj.attr, y después localiza los tests relevantes de CPython para las sugerencias de AttributeError. Se considera terminado cuando la eliminación de un atributo mal escrito incluye la sugerencia de nombre más cercana sin cambiar el comportamiento de búsqueda existente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100