ITADN

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

#154610Openvstinner 创建于 27 天前
type-featureinterpreter-corestdlib
V
vstinnercommented
# 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). <!-- gh-linked-prs --> ### Linked PRs * gh-154614 <!-- /gh-linked-prs -->
6 条评论