diff options
| author | Benjamin Mintz <[email protected]> | 2019-07-18 19:07:44 +0000 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-07-18 18:06:43 -0400 |
| commit | 042a234eac8b2c66b0917379636550e3319618ab (patch) | |
| tree | 0b298b89bf9dc7a46ed10ea276b0a860e48e686c | |
| parent | on_member_leave => on_member_remove (diff) | |
| download | discord.py-042a234eac8b2c66b0917379636550e3319618ab.tar.xz discord.py-042a234eac8b2c66b0917379636550e3319618ab.zip | |
[commands] update sys.modules in load_extension again
6f71552c508c61d9b6bf024fc259063ad056b7c4 introduced a regression: loading a module that is not in a package
does not add it to sys.modules. Updating sys.modules is required after all.
| -rw-r--r-- | discord/ext/commands/bot.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 29897c39..a4b18c64 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -590,19 +590,23 @@ class BotBase(GroupMixin): def _load_from_module_spec(self, spec, key): # precondition: key not in self.__extensions lib = importlib.util.module_from_spec(spec) + sys.modules[key] = lib try: spec.loader.exec_module(lib) except Exception as e: + del sys.modules[key] raise errors.ExtensionFailed(key, e) from e try: setup = getattr(lib, 'setup') except AttributeError: + del sys.modules[key] raise errors.NoEntryPointError(key) try: setup(self) except Exception as e: + del sys.modules[key] self._remove_module_references(lib.__name__) self._call_module_finalizers(lib, key) raise errors.ExtensionFailed(key, e) from e @@ -635,7 +639,7 @@ class BotBase(GroupMixin): NoEntryPointError The extension does not have a setup function. ExtensionFailed - The extension setup function had an execution error. + The extension or its setup function had an execution error. """ if name in self.__extensions: |