Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment thread
picnixz marked this conversation as resolved.
Outdated
for finder in sys.meta_path:
if discover := getattr(finder, 'discover', None):
d += [spec.name for spec in discover(parent)]
Expand Down
Loading