Format attribute name with repr() when formatting AttributeError error message
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
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
- 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
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