Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -5109,6 +5109,26 @@ def func():
actual = self.get_suggestion(func)
self.assertIn("forget to import '_io'", actual)

def test_name_error_do_not_suggest_builtin_name_in_delete(self):
def func():
del next

actual = self.get_suggestion(func)
self.assertNotIn("Did you mean: 'anext'", actual)

def test_name_error_suggest_builtin_name_in_delete_if_not_delete_the_name_itself(self):
def func1():
del nxt[1]

actual = self.get_suggestion(func1)
self.assertIn("Did you mean: 'next'", actual)

def func2():
del nxt.__name__

actual = self.get_suggestion(func2)
self.assertIn("Did you mean: 'next'", actual)



class PurePythonSuggestionFormattingTests(
Expand Down
4 changes: 3 additions & 1 deletion Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import keyword
import tokenize
import io
import dis
import importlib.util
import pathlib

Expand Down Expand Up @@ -1963,8 +1964,9 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
d = (
list(frame.f_locals)
+ list(frame.f_globals)
+ list(frame.f_builtins)
)
if not dis.opname[frame.f_code.co_code[frame.f_lasti]].startswith(('STORE_', 'DELETE_')):
d += list(frame.f_builtins)
d = [x for x in d if isinstance(x, str)]
if not_normalized and wrong_name in d:
return wrong_name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use a more simple way to forbidden the builtins name suggestion in deleting
Loading