Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
Open
Description
Feature or enhancement
Proposal:
This was initially mentioned as a comment inissue #130399.
classA:passa=A()a.abcde=1dela.abcdf# typo
Current Output
Traceback (mostrecentcalllast):File"<python-input-0>",line6,in<module>dela.abcdf# typo^^^^^^^AttributeError:'A'objecthasnoattribute'abcdf'
CPython provides name suggestions when an attribute lookup (obj.attr) fails, but it does not provide similar suggestions when an attribute deletion (del obj.attr) fails. This brings about an inconsistency with regards to the developer experience offered by the language.
Expected Output
Traceback (mostrecentcalllast):File"<python-input-0>",line6,in<module>dela.abcdf# typo^^^^^^^AttributeError:'A'objecthasnoattribute'abcdf'.Didyoumean:'abcde'?
Advantages
- Helps users quickly identify typos in attribute deletions.
- CPython already provides name suggestions for failed attribute lookups (obj.attr), so deletions (del obj.attr) should behave similarly.
- Suggestions are only generated when an attribute deletion fails, and hence has a minimal performance impact.
Note
CPython version - CPython main branch
Operating system - Ubuntu 22.04
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response