summaryrefslogtreecommitdiffstats
path: root/Lib/traceback.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r--Lib/traceback.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py
index c46ddaf..bb7856a 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -712,6 +712,13 @@ class TracebackException:
suggestion = _compute_suggestion_error(exc_value, exc_traceback)
if suggestion:
self._str += f". Did you mean: '{suggestion}'?"
+ if issubclass(exc_type, NameError):
+ wrong_name = getattr(exc_value, "name", None)
+ if wrong_name is not None and wrong_name in sys.stdlib_module_names:
+ if suggestion:
+ self._str += f" Or did you forget to import '{wrong_name}'"
+ else:
+ self._str += f". Did you forget to import '{wrong_name}'"
if lookup_lines:
self._load_lines()
self.__suppress_context__ = \