python / python/cpython

Format attribute name with repr() when formatting AttributeError error message

Aperta
#154,610 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Feature or enhancement

Some code paths format the attribute name with str() to format the AttributeError error message. Example:

>>> getattr(object(), "a'b")
AttributeError: 'object' object has no attribute 'a'b'

The quote character ' should be escaped in the error message ('a\'b'), or the attribute name should be quoted with " character ("a'b").

The expected error is:

AttributeError: 'object' object has no attribute "a'b"

I propose replacing str() with repr() to format the attribute name.

This issue is a follow-up of https://github.com/python/cpython/pull/153786#discussion_r3639448620 discussion (another AttributeError change).

Linked PRs
  • gh-154614
  • gh-157685

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

Iniziate con l’esempio getattr(object(), "a'b") ed esaminate i percorsi di formattazione di AttributeError discussi nei PR collegati. Confermate che il comportamento completato esegua l’escape del nome dell’attributo o modifichi le virgolette, in modo da corrispondere al messaggio di errore previsto mostrato nell’issue.

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

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.