python / python/cpython

Improve "not found" error messages in `<sequence>.<method>()` failures

Abierto
#137,508 6 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

interpreter-core type-feature
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

The docstring of list.remove() says value parameter as shown below:

print(help(list.remove))
# remove(self, value, /) unbound builtins.list method
#     Remove first occurrence of value.
#
#     Raises ValueError if the value is not present.

But the error message says x instead of value as shown below and I don't think list.remove(x): is necessary:

v = ['a', 'b', 'c']

v.remove('B')
# ValueError: list.remove(x): x not in list

So, the error message should just say as shown below:

ValueError: value not in list

In addition, the docstring of bytearray.remove() says valueparameter as shown below:

print(help(bytearray.remove))
# remove(self, value, /) unbound builtins.bytearray method
#     Remove the first occurrence of a value in the bytearray.
#
#     value
#       The value to remove.

And, the error message reasonably says value as shown below but I don't think found is necessary:

v = bytearray(b'abc')

v.remove(ord('B'))
# ValueError: value not found in bytearray

So, the error message should just say as shown below:

ValueError: value not in bytearray

Linked PRs
  • gh-137509
  • gh-139696

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza localizando las implementaciones y las pruebas de list.remove() y bytearray.remove(), usando los ejemplos indicados como referencia del comportamiento. Comprueba los PRs vinculados gh-137509 y gh-139696 antes de empezar; se considera terminado cuando los dos mensajes de error coinciden con la redacción solicitada y las pruebas relevantes pasan.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
backend
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.