Check spec.loader is not None when importing a plugin.

This commit is contained in:
Valentin Lorentz 2020-02-09 09:53:06 +01:00
parent 0f3264cf26
commit 8f001f8045
1 changed files with 4 additions and 1 deletions

View File

@ -69,7 +69,10 @@ def loadPluginModule(name, ignoreDeprecation=False):
if hasattr(importlib.util, 'module_from_spec'):
# Python >= 3.5
spec = importlib.machinery.PathFinder.find_spec(name, pluginDirs)
if spec is None:
if spec is None or spec.loader is None:
# spec is None if 'name' can't be found; and
# spec.loader might be None in some rare occasions as well
# (eg. for namespace packages)
assert ImportError(name)
module = importlib.util.module_from_spec(spec)
sys.modules[module.__name__] = module