diff options
Diffstat (limited to 'botcore/utils/_extensions.py')
-rw-r--r-- | botcore/utils/_extensions.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/botcore/utils/_extensions.py b/botcore/utils/_extensions.py index 6848fae6..d90a25dd 100644 --- a/botcore/utils/_extensions.py +++ b/botcore/utils/_extensions.py @@ -22,19 +22,20 @@ def unqualify(name: str) -> str: def walk_extensions(module: types.ModuleType) -> frozenset[str]: """ - Yield extension names from the given module. + Return all extension names from the given module. Args: module (types.ModuleType): The module to look for extensions in. Returns: - An iterator object, that returns a string that can be passed directly to - :obj:`discord.ext.commands.Bot.load_extension` on call to next(). + A set of strings that can be passed directly to :obj:`discord.ext.commands.Bot.load_extension`. """ def on_error(name: str) -> NoReturn: raise ImportError(name=name) # pragma: no cover + modules = set() + for module_info in pkgutil.walk_packages(module.__path__, f"{module.__name__}.", onerror=on_error): if unqualify(module_info.name).startswith("_"): # Ignore module/package names starting with an underscore. @@ -46,4 +47,6 @@ def walk_extensions(module: types.ModuleType) -> frozenset[str]: # If it lacks a setup function, it's not an extension. continue - yield module_info.name + modules.add(module_info.name) + + return frozenset(modules) |