Format attribute name with repr() when formatting AttributeError error message
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the getattr(object(), "a'b") example and inspect the AttributeError formatting paths discussed in the linked PRs. Confirm that the completed behavior escapes or changes quoting for the attribute name, matching the expected error message shown in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100