Skip to content

Improve suggestion in NameError when deleting builtins #153374

Description

@Locked-chess-official

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions