Skip to content

Commit

Permalink
Being more explicit with the import of importlib.util. (#181)
Browse files Browse the repository at this point in the history
* Being more explicit with the import of importlib.util.

* Importing importlib.util in the one other place it is used.
  • Loading branch information
drewoldag authored Jan 23, 2025
1 parent c829885 commit 50ba387
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/fibad/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import random
import re
from importlib import util as importlib_util
from pathlib import Path
from typing import Optional, Union

Expand Down Expand Up @@ -155,7 +156,7 @@ def _find_external_library_default_config_paths(runtime_config: dict) -> set:
else:
if key == "name" and "." in value:
external_library = value.split(".")[0]
if importlib.util.find_spec(external_library) is not None:
if importlib_util.find_spec(external_library) is not None:
try:
lib = importlib.import_module(external_library)
if lib.__file__ is None:
Expand Down
7 changes: 4 additions & 3 deletions src/fibad/plugin_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib
from importlib import util as importlib_util
from typing import Any, Optional, TypeVar, Union

T = TypeVar("T")
Expand Down Expand Up @@ -71,10 +72,10 @@ def import_module_from_string(module_path: str) -> Any:
try:
# Attempt to find the module spec, i.e. `module.submodule.`.
# Will raise exception if `submodule`, 'subsubmodule', etc. is not found.
importlib.util.find_spec(module_name)
importlib_util.find_spec(module_name)

# `importlib.util.find_spec()` will return None if `module` is not found.
if (importlib.util.find_spec(module_name)) is not None:
# `importlib_util.find_spec()` will return None if `module` is not found.
if (importlib_util.find_spec(module_name)) is not None:
# Load the requested module
module = importlib.import_module(module_name)

Expand Down

0 comments on commit 50ba387

Please sign in to comment.