From 86efe4105e98d311831d673904cb82bf610570a4 Mon Sep 17 00:00:00 2001 From: dgw Date: Thu, 12 Sep 2024 01:57:55 -0500 Subject: [PATCH] plugins.handlers: fix incorrect PyFilePlugin construction Two things: 1. `submodule_search_locations` is expected to be a list, according to Python's documentation for `importlib.machinery.ModuleSpec`. 2. The new `module` being inserted into `sys.modules` before checking if its spec had a valid `loader` bothered me, so I reordered the steps. --- sopel/plugins/handlers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel/plugins/handlers.py b/sopel/plugins/handlers.py index 8a07cb3ad..5fc86adff 100644 --- a/sopel/plugins/handlers.py +++ b/sopel/plugins/handlers.py @@ -471,7 +471,7 @@ def __init__(self, filename): spec = importlib.util.spec_from_file_location( name, os.path.join(filename, '__init__.py'), - submodule_search_locations=filename, + submodule_search_locations=[filename], ) else: raise exceptions.PluginError('Invalid Sopel plugin: %s' % filename) @@ -487,9 +487,9 @@ def __init__(self, filename): def _load(self): module = importlib.util.module_from_spec(self.module_spec) - sys.modules[self.name] = module if not self.module_spec.loader: raise exceptions.PluginError('Could not determine loader for plugin: %s' % self.filename) + sys.modules[self.name] = module self.module_spec.loader.exec_module(module) return module