diff options
author | 2022-04-21 23:52:15 +0300 | |
---|---|---|
committer | 2022-04-21 23:52:15 +0300 | |
commit | 486db9918e04afae84ae603ef96181608e70b77e (patch) | |
tree | c89482aceb0bbba95771d23b17559b144d9fd79e /botcore | |
parent | Merge 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.
Diffstat (limited to 'botcore')
-rw-r--r-- | botcore/utils/_extensions.py | 9 |
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: |