From 5ac39e145ebaa1b00961af448477e855125edbbf Mon Sep 17 00:00:00 2001 From: Locked-chess-official <13140752715@163.com> Date: Tue, 11 Nov 2025 14:19:59 +0800 Subject: [PATCH 1/2] clear builtins in suggestion when deleting --- Lib/traceback.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/traceback.py b/Lib/traceback.py index 9b4b8c7d566fe8..f7484b8f6e9148 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -11,6 +11,7 @@ import tokenize import io import _colorize +import dis from contextlib import suppress @@ -1677,8 +1678,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('DELETE_'): + d += list(frame.f_builtins) d = [x for x in d if isinstance(x, str)] # Check first if we are in a method and the instance From d16cb294b92ee0266f6780f6e234bf9daef02587 Mon Sep 17 00:00:00 2001 From: Locked-chess-official <13140752715@163.com> Date: Tue, 11 Nov 2025 14:22:25 +0800 Subject: [PATCH 2/2] add News --- .../2025-11-11-14-21-33.gh-issue-138890.QwN0EU.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-11-11-14-21-33.gh-issue-138890.QwN0EU.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-11-11-14-21-33.gh-issue-138890.QwN0EU.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-11-14-21-33.gh-issue-138890.QwN0EU.rst new file mode 100644 index 00000000000000..2c8ff7b9ef869d --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-11-14-21-33.gh-issue-138890.QwN0EU.rst @@ -0,0 +1 @@ +Use a more simple way to forbidden the builtins name suggestion in deleting