aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar mbaruh <[email protected]>2022-04-21 23:52:15 +0300
committerGravatar mbaruh <[email protected]>2022-04-21 23:52:15 +0300
commit486db9918e04afae84ae603ef96181608e70b77e (patch)
treec89482aceb0bbba95771d23b17559b144d9fd79e
parentMerge pull request #66 from python-discord/load-extensions-in-tasks (diff)
Don't look for extensions in packages prefixed with an underscore
Before this, even if a package is prefixed with an underscore, `walk_extensions` will ignore the package itself, but will still look for extensions inside it.
-rw-r--r--botcore/utils/_extensions.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/botcore/utils/_extensions.py b/botcore/utils/_extensions.py
index d90a25dd..5614b7ec 100644
--- a/botcore/utils/_extensions.py
+++ b/botcore/utils/_extensions.py
@@ -20,6 +20,11 @@ def unqualify(name: str) -> str:
return name.rsplit(".", maxsplit=1)[-1]
+def ignore_module(module) -> bool:
+ """Return whether the module with name `name` should be ignored."""
+ return any(name.startswith("_") for name in module.name.split("."))
+
+
def walk_extensions(module: types.ModuleType) -> frozenset[str]:
"""
Return all extension names from the given module.
@@ -37,8 +42,8 @@ def walk_extensions(module: types.ModuleType) -> frozenset[str]:
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.
+ if ignore_module(module_info):
+ # Ignore modules/packages that have a name starting with an underscore anywhere in their trees.
continue
if module_info.ispkg: