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
gh-85076: Document exceptions that can be raised by importlib.import_module #94662
base: main
Are you sure you want to change the base?
Conversation
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
@FFY00 I didn't because it's just a documentation change. |
If the module cannot be imported, :func:`import_module` will raise an | ||
:exc:`ImportError`. If the module is found and loaded, but the code in the | ||
module raises an exception, :func:`import_module` will pass that exception | ||
to the module that called it. |
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.
If the module cannot be imported, :func:`import_module` will raise an | |
:exc:`ImportError`. If the module is found and loaded, but the code in the | |
module raises an exception, :func:`import_module` will pass that exception | |
to the module that called it. | |
If the module cannot be found or loaded, :func:`import_module` will raise an | |
:exc:`ImportError`. |
"cannot be imported" is very generic and could conceivably apply to explicitly raised exceptions, like in the second half of this paragraph, so makes sense to be more specific.
I think we could just omit the second half of the paragraph. Talking about "passing exceptions" makes it sound more complicated than it is. The behaviour here is intuitive and already documented by the sentence "This means all semantics of the function are derived from :func:importlib.__import__
."
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.
Doesn't "cannot be found or loaded" imply that that's the behavior if the module cannot be loaded because code in the module raised an exception? Maybe "If the module cannot be found or its files cannot be accessed..." instead? That makes it clear that ImportError is raised in cases like the module not being found or being inaccessible due to file permissions, not cases where it is found but not successfully loaded.
Closes #85076