From bb3db818cf922f422df33a383c4f7d6fe0d7a176 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Sun, 15 Sep 2019 18:24:48 -0700 Subject: [PATCH] Switch to module imports for importlib in utils The present day guidance is to lean towards module imports for the stdlib modules. Switch importlib imports to this instead of plucking out the functions that we need. This makes it more immediately apparent as to where the functions are coming from in the application logic. --- evennia/utils/utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index ad2a500eab..64aa827aeb 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -16,12 +16,12 @@ import textwrap import random import inspect import traceback +import importlib +import importlib.util import importlib.machinery from twisted.internet.task import deferLater from twisted.internet.defer import returnValue # noqa - used as import target from os.path import join as osjoin -from importlib import import_module -from importlib.util import find_spec from inspect import ismodule, trace, getmembers, getmodule, getmro from collections import defaultdict, OrderedDict from twisted.internet import threads, reactor @@ -1216,7 +1216,7 @@ def mod_import(module): return mod_import_from_path(module) try: - return import_module(module) + return importlib.import_module(module) except ImportError: return None @@ -1378,7 +1378,7 @@ def fuzzy_import_from_module(path, variable, default=None, defaultpaths=None): paths = [path] + make_iter(defaultpaths) for modpath in paths: try: - mod = import_module(modpath) + mod = importlib.import_module(modpath) except ImportError as ex: if not str(ex).startswith("No module named %s" % modpath): # this means the module was found but it @@ -1420,13 +1420,13 @@ def class_from_module(path, defaultpaths=None): raise ImportError("the path '%s' is not on the form modulepath.Classname." % path) try: - if not find_spec(testpath, package='evennia'): + if not importlib.util.find_spec(testpath, package='evennia'): continue except ModuleNotFoundError: continue try: - mod = import_module(testpath, package='evennia') + mod = importlib.import_module(testpath, package='evennia') except ModuleNotFoundError: err = traceback.format_exc(30) break