-
-
Notifications
You must be signed in to change notification settings - Fork 866
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
Use a more robust method to improve our ModuleNotFound errors #3263
Conversation
for more information, see https://pre-commit.ci
…nto module-not-found-hook
I also made a thread about this on discuss.python.org: |
Thanks for the fix @hoodmane! What do think of modifying def pyodide_except_hook(type, value, traceback):
orig_excepthook = sys.excepthook
if isinstance(type, ModuleNotFoundError):
...
else:
return orig_excepthook(...)
sys.excepthook = pyodide_except_hook I think this won't require patching CPython. |
We currently never call |
Oh, okay. You are right. I was able to check that |
No objection to this change, but it would be worth opening a feature request at Cpython to ask to make it possible change this message without patching. Or if they don't want to update the public API of importlib for this, maybe at least they would be OK with adding this patch upstream so that it can be modified via monkeypatching (instead of real patching). As the patch to |
Well it's autogenerated, you just have to run |
I bet they would accept that, I'll try. |
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 am okay with merging this, and would prefer to include this in 0.22.
* main: (45 commits) Remove pre-built docker image support (pyodide#3342) Remove "Python initialization complete" log line (pyodide#3247) Use a more robust method to improve our ModuleNotFound errors (pyodide#3263) Distinguish between sync and async JavaScript iterators when possible (pyodide#3339) [pre-commit.ci] pre-commit autoupdate (pyodide#3345) NFC Place js_flags in separate dict (pyodide#3338) NFC Use initialization function to load _pyodide_core (pyodide#3333) Make fs timestamps have millisecond resolution rather than second resolution (pyodide#3313) Add gensim package pyodide#2545 (pyodide#3326) [pre-commit.ci] pre-commit autoupdate (pyodide#3325) Update scikit-learn to 1.1.3 (pyodide#3324) Fix markdown in doc (pyodide#3323) Emscripten 3.1.27 (pyodide#3314) [pre-commit.ci] pre-commit autoupdate (pyodide#3254) Add a typeshed for the js module (pyodide#3298) Unpin host Python patch versions in GHA (pyodide#3309) Package pyinstrument (pyodide#3258) Add athrow and aclose to JsProxy of an AsyncGenerator (pyodide#3299) Add test for MutableMapping methods on object_maps and fix bug (pyodide#3297) Bump minimatch from 3.0.4 to 3.1.2 in /src/js (pyodide#3306) ...
@ryanking13 added these very nice error messages to the
ModuleNotFound
errors. However they introduce a few problems:find_spec
is supposed to returnNone
or a spec and not to raise an error. If it raises errors, it can cause trouble in code that tries to check if a module is installed or not.See the discussion in #3262.
This instead patches
importlib._bootstrap
to create a function called_get_module_not_found_error
. We then can monkey patch this to modify the error messages thatimportlib
raises.Checklists