Skip to content

Commit c31694a

Browse files
committed
improve code
1 parent 05ad9ce commit c31694a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Lib/traceback.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,10 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
11071107
if suggestion:
11081108
self._str += f". Did you mean: '{suggestion}'?"
11091109
elif exc_type and issubclass(exc_type, ModuleNotFoundError) and \
1110-
sys.flags.no_site:
1111-
self._str += ". Site initialization is disabled, did you forget to add the \
1112-
site-package directory to sys.path?"
1110+
sys.flags.no_site and \
1111+
getattr(exc_value, "name", None) not in sys.builtin_module_names:
1112+
self._str += (". Site initialization is disabled, did you forget to "
1113+
+ "add the site-package directory to sys.path?")
11131114
elif exc_type and issubclass(exc_type, (NameError, AttributeError)) and \
11141115
getattr(exc_value, "name", None) is not None:
11151116
wrong_name = getattr(exc_value, "name", None)

0 commit comments

Comments
 (0)