Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DeprecationError from ModuleSpec.loader.load_module in Red.load_extension #5956

Open
wants to merge 18 commits into
base: V3/develop
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
46e3a84
Use `module_from_spec` and `exec_module`
Kuro-Rui Mar 24, 2023
d83ee03
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Apr 26, 2023
cc71d0f
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Jun 8, 2023
8be0777
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Jun 16, 2023
c4b96db
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Jun 21, 2023
90a61f7
Merge branch 'V3/develop' into use_exec_module
Kuro-Rui Jul 9, 2023
68dbf36
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Oct 3, 2023
29b8e15
Bugfix
Kuro-Rui Nov 4, 2023
a0211fb
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Dec 19, 2023
37bf42c
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Dec 26, 2023
3e1b1ec
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Jan 5, 2024
d12f6e3
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Mar 2, 2024
7d6c783
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Apr 12, 2024
33b2b11
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui May 6, 2024
d01bcc9
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Jul 2, 2024
8e3eb0c
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Sep 6, 2024
e0a6068
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Oct 6, 2024
56c5968
Merge branch 'Cog-Creators:V3/develop' into use_exec_module
Kuro-Rui Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions redbot/core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from collections import namedtuple, OrderedDict
from datetime import datetime
from importlib.machinery import ModuleSpec
from importlib.util import module_from_spec
from pathlib import Path
from typing import (
Optional,
Expand Down Expand Up @@ -1680,16 +1681,22 @@ async def load_extension(self, spec: ModuleSpec):
name = spec.name.split(".")[-1]
if name in self.extensions:
raise errors.PackageAlreadyLoaded(spec)

lib = spec.loader.load_module()
lib = module_from_spec(spec)
sys.modules[spec.name] = lib
try:
spec.loader.exec_module(lib)
except Exception:
del sys.modules[spec.name]
raise
Kuro-Rui marked this conversation as resolved.
Show resolved Hide resolved
if not hasattr(lib, "setup"):
del lib
raise discord.ClientException(f"extension {name} does not have a setup function")
raise discord.ClientException(f"Extension {name} does not have a setup function.")

try:
await lib.setup(self)
await self.tree.red_check_enabled()
except Exception as e:
except Exception:
del sys.modules[spec.name]
await self._remove_module_references(lib.__name__)
await self._call_module_finalizers(lib, name)
raise
Expand Down
Loading