From 486db9918e04afae84ae603ef96181608e70b77e Mon Sep 17 00:00:00 2001 From: mbaruh Date: Thu, 21 Apr 2022 23:52:15 +0300 Subject: 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. --- botcore/utils/_extensions.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'botcore/utils/_extensions.py') 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: -- cgit v1.2.3