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
Document exceptions raised by importlib.import #85076
Comments
https://docs.python.org/3/library/functions.html#__import__ The two exceptions are listed here Could you add a half-sentence "and raises an ModuleNotFoundError if import was unsuccessful." to the function docs? |
ModuleNotFoundError is a subclass of ImportError, so it's probably enough to just document the functions as raising ImportError on failure, as in the case of https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module. |
Thanks! I've opened a PR for this issue. |
Note that importlib.import_module, and the import statement itself, can raise an arbitrary exception when that exception is raised while executing the module body. This is easily observed by creating a module that just raises an error in its body: # t.py
|
Oh, I didn't realize that. Then maybe we don't need to document ImportError in https://docs.python.org/3/library/importlib.html#importlib.import_module? |
Good question. Hopefully one of the documentation or importlib experts can chime in about that. I may also have uncovered a new issue in importlib ;-) Personally I'd say that documenting raising ImportError is still useful because that's the common exception, and an exception that's not mentioned in the rest of the documentation for importlib. That does require a careful formulation to avoid implying that this the only exception that can be raised. |
Maybe we can add something like:
|
I've tested |
So.. maybe changing |
Added in gh-94662 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: