Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kj7rrv
Copy link
Contributor

@kj7rrv kj7rrv commented Jul 7, 2022

Closes #85076

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Jul 7, 2022

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@bedevere-bot bedevere-bot added the docs label Jul 7, 2022
FFY00
FFY00 approved these changes Jul 7, 2022
Copy link
Member

@FFY00 FFY00 left a comment

Hi @kj7rrv this looks good, thank you! Can you add the missing news entry, as the bot requested?

@kj7rrv
Copy link
Contributor Author

@kj7rrv kj7rrv commented Jul 7, 2022

@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.
Copy link
Contributor

@hauntsaninja hauntsaninja Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested 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.
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__."

Copy link
Contributor Author

@kj7rrv kj7rrv Jul 8, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants