Provide name suggestions for failed attribute deletions
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue ではファイルやテストが指定されていません。まず、属性検索に失敗した場合の既存の名前候補提示の挙動と、失敗する del obj.attr の経路を比較し、次に AttributeError の候補提示に関する CPython の関連テストを見つけてください。既存の検索挙動を変更せずに、スペルミスのある属性の削除に最も近い名前の候補が含まれるようになれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100