python / python/cpython

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

Aperta
#137,508 6 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

interpreter-core type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia individuando le implementazioni e i test per list.remove() e bytearray.remove(), usando gli esempi riportati come riferimento del comportamento. Controlla le PR collegati gh-137509 e gh-139696 prima di iniziare; il lavoro è completo quando i due messaggi di errore corrispondono alla formulazione richiesta e i test pertinenti passano.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.