-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-127598: Improve ModuleNotFoundError when -S is passed #136821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
34c29cf
05ad9ce
c31694a
c14ce27
df7df73
ca64ada
2ba6351
29aad1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1106,6 +1106,11 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None, | |||||
suggestion = _compute_suggestion_error(exc_value, exc_traceback, wrong_name) | ||||||
if suggestion: | ||||||
self._str += f". Did you mean: '{suggestion}'?" | ||||||
elif exc_type and issubclass(exc_type, ModuleNotFoundError) and \ | ||||||
sys.flags.no_site and \ | ||||||
getattr(exc_value, "name", None) not in sys.builtin_module_names: | ||||||
|
getattr(exc_value, "name", None) not in sys.builtin_module_names: | |
getattr(exc_value, "name", None) not in sys.stdlib_module_names: |
(It could be tested by importing a non-existent stdlib module, like msvcrt
on *nix or grp
on Windows. The note should not be added for those -- you can't solve a "wrong platform" issue by adding the site-packages directory.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented the feedback, and it case stdlib the message it's not thrown :)
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,2 @@ | ||||||
Improve :exc:`ModuleNotFoundError` by adding flavour text to exception when the | ||||||
|
Improve :exc:`ModuleNotFoundError` by adding flavour text to exception when the | |
Improve :exc:`ModuleNotFoundError` by adding flavour text to the exception when the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a helper for doing this:
test.support.assert_python_ok
. Would you mind switching to that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I've changed the to use it, although the version assert_python_failure as we looking for an exception