Provide name suggestions for failed attribute deletions
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Feature or enhancement
Proposal:
This was initially mentioned as a comment in issue #130399.
class A:
pass
a = A()
a.abcde = 1
del a.abcdf # typo
Current Output
Traceback (most recent call last):
File "<python-input-0>", line 6, in <module>
del a.abcdf # typo
^^^^^^^
AttributeError: 'A' object has no attribute '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 (most recent call last):
File "<python-input-0>", line 6, in <module>
del a.abcdf # typo
^^^^^^^
AttributeError: 'A' object has no attribute 'abcdf'. Did you mean: '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
Linked PRs
- gh-130427
- gh-130799
- gh-136588
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Issue không nêu tên tệp hoặc test. Trước tiên, hãy so sánh hành vi đề xuất tên hiện có đối với việc tra cứu thuộc tính thất bại với đường dẫn del obj.attr thất bại, sau đó xác định các test CPython liên quan đến đề xuất cho AttributeError. Hoàn thành khi thao tác xóa một thuộc tính bị viết sai bao gồm đề xuất tên gần nhất mà không thay đổi hành vi tra cứu hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- compilers
- Loại issue
- Tính năng
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100