python / python/cpython

Improve suggestion in NameError when deleting builtins

オープン
#153,374 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

interpreter-core type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

When deleting a name, python will only find the name in globals and locals, no builtins. However, the suggestion generating code just combined these dict, which makes the suggestion cycle:

>>> del next
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    del next
        ^^^^
NameError: name 'next' is not defined. Did you mean: 'anext'?
>>> del anext
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    del anext
        ^^^^^
NameError: name 'anext' is not defined. Did you mean: 'next'?

According to DPO, the best way to fix this bug is using dis to analyse the last traceback to get the final operation.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs
  • gh-141389

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

del nextdel anext で問題を再現し、NameError の候補生成パスを調査してから、dis を使って traceback から最後の操作を特定します。リンクされた PR gh-141389 のアプローチと比較します。削除された builtin が代替候補として提案されなくなれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。