Skip to content

importlib check example can actually import things #92994

Closed
@hauntsaninja

Description

@hauntsaninja

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions