Skip to content

Commit 947517b

Browse files
Commit
1 parent 6954077 commit 947517b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Lib/traceback.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,11 +1107,13 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
11071107
suggestion = _compute_suggestion_error(exc_value, exc_traceback, wrong_name)
11081108
if suggestion:
11091109
self._str += f". Did you mean: '{suggestion}'?"
1110-
elif exc_type and issubclass(exc_type, ModuleNotFoundError) and \
1111-
sys.flags.no_site and \
1112-
getattr(exc_value, "name", None) not in sys.stdlib_module_names:
1113-
self._str += (". Site initialization is disabled, did you forget to "
1114-
+ "add the site-packages directory to sys.path?")
1110+
elif exc_type and issubclass(exc_type, ModuleNotFoundError):
1111+
module_name = getattr(exc_value, "name", None)
1112+
if sys.flags.no_site and module_name not in sys.stdlib_module_names:
1113+
self._str += (". Site initialization is disabled, did you forget to "
1114+
+ "add the site-packages directory to sys.path?")
1115+
elif module_name in sys.stdlib_module_names:
1116+
self._str = f"Standard library module '{module_name}' was not found"
11151117
elif exc_type and issubclass(exc_type, (NameError, AttributeError)) and \
11161118
getattr(exc_value, "name", None) is not None:
11171119
wrong_name = getattr(exc_value, "name", None)

0 commit comments

Comments
 (0)