Skip to content

importlib check example can actually import things #92994

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

Closed
hauntsaninja opened this issue May 20, 2022 · 0 comments
Closed

importlib check example can actually import things #92994

hauntsaninja opened this issue May 20, 2022 · 0 comments
Labels
docs Documentation in the Doc dir topic-importlib

Comments

@hauntsaninja
Copy link
Contributor

The example at https://docs.python.org/3/library/importlib.html#checking-if-a-module-can-be-imported is misleading:

Checking if a module can be imported
If you need to find out if a module can be imported without actually doing the import, then you should use importlib.util.find_spec().

But importlib.util.find_spec will import parent modules if a submodule is provided https://docs.python.org/3/library/importlib.html#importlib.util.find_spec

If name is for a submodule (contains a dot), the parent module is automatically imported.

Users reading this example probably do not expect anything to get imported at all

@hauntsaninja hauntsaninja added docs Documentation in the Doc dir topic-importlib labels May 20, 2022
hauntsaninja added a commit to hauntsaninja/cpython that referenced this issue May 20, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 23, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 23, 2022
miss-islington added a commit that referenced this issue May 23, 2022
Fixes GH-92994
(cherry picked from commit e39cd76)

Co-authored-by: Shantanu <[email protected]>
miss-islington added a commit that referenced this issue May 23, 2022
Fixes GH-92994
(cherry picked from commit e39cd76)

Co-authored-by: Shantanu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir topic-importlib
Projects
None yet
Development

No branches or pull requests

1 participant