From c01925dce37479fdfb49c171ddc1d7850cb6a86f Mon Sep 17 00:00:00 2001 From: Locked-chess-official <13140752715@163.com> Date: Thu, 26 Mar 2026 00:06:10 +0800 Subject: [PATCH 1/2] just change traceback.py to make it --- Lib/traceback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/traceback.py b/Lib/traceback.py index 1f9f151ebf5d39..bb57e812283efa 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -1755,7 +1755,7 @@ def _compute_suggestion_error(exc_value, tb, wrong_name): parent = importlib.util.find_spec(parent_name) else: parent = None - d = [] + d = list(sys.builtin_module_names) for finder in sys.meta_path: if discover := getattr(finder, 'discover', None): d += [spec.name for spec in discover(parent)] From b57a7e7b75048c5736418370f14749487a007dff Mon Sep 17 00:00:00 2001 From: Locked-chess-official <13140752715@163.com> Date: Thu, 26 Mar 2026 15:59:09 +0800 Subject: [PATCH 2/2] add test (why who added the suggestion for module name didn't add the traceback test?) --- Lib/test/test_traceback.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 5dc11253e0d5c8..b4ab39a869113a 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -5004,6 +5004,26 @@ def func(): actual = self.get_suggestion(func) self.assertIn("forget to import '_io'", actual) + def test_import_builtin_module_typo_suggestion(self): + def func(): + import itertool # noqa: F401 + + actual = self.get_suggestion(func) + self.assertIn("Did you mean: 'itertools'?", actual) + + def test_import_file_module_typo_suggestion(self): + def func(): + import abs # noqa: F401 + + actual = self.get_suggestion(func) + self.assertIn("Did you mean: 'abc'?", actual) + + def test_import_submodule_typo_suggestion(self): + def func(): + import multiprocessing.dumy # noqa: F401 + + actual = self.get_suggestion(func) + self.assertIn("Did you mean: 'multiprocessing.dummy'?", actual) class PurePythonSuggestionFormattingTests(