Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

fix: Fail loudly if we attempt to perform a setupless load on an extension module that isn't actually an extension #716

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions naff/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1892,11 +1892,15 @@ def load_extension(self, name: str, package: str | None = None, **load_kwargs: A
else:
self.logger.debug("No setup function found in %s", module_name)

found = False
objects = {name: obj for name, obj in inspect.getmembers(module) if isinstance(obj, type)}
for obj_name, obj in objects.items():
if Extension in obj.__bases__:
self.logger.debug(f"Found extension class {obj_name} in {module_name}: Attempting to load")
obj(self, **load_kwargs)
found = True
if not found:
raise Exception(f"{module_name} contains no Extensions")

except ExtensionLoadException:
raise
Expand Down