Improve suggestion in NameError when deleting builtins
未关闭
还没有人认领这个 Issue。
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用 del next 和 del anext 重现该问题,然后检查 NameError 建议生成路径,并使用 dis 根据 traceback 确定最后一个操作。将此方法与关联的 PR gh-141389 进行比较;完成的标准是删除操作不再将已删除的 builtin 建议为替代项。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100