diff options
| author | 2020-08-19 12:17:22 -0700 | |
|---|---|---|
| committer | 2020-08-19 12:17:22 -0700 | |
| commit | 57f5f1089bed9971e79458ea0d2a40be90d7d3e5 (patch) | |
| tree | 8e5d62735605c3c6a239edc1f87430b9e327e903 | |
| parent | Replace relative imports with absolute ones (diff) | |
Extensions: beautify name unqualification
Yes, that's a real word.
| -rw-r--r-- | bot/exts/utils/extensions.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/bot/exts/utils/extensions.py b/bot/exts/utils/extensions.py index 671397650..7ad6b1fdd 100644 --- a/bot/exts/utils/extensions.py +++ b/bot/exts/utils/extensions.py @@ -19,6 +19,11 @@ from bot.utils.checks import with_role_check log = logging.getLogger(__name__) +def unqualify(name: str) -> str: + """Return an unqualified name given a qualified module/package `name`.""" + return name.rsplit(".", maxsplit=1)[-1] + + def walk_extensions() -> t.Iterator[str]: """Yield extension names from the bot.exts subpackage.""" @@ -26,7 +31,7 @@ def walk_extensions() -> t.Iterator[str]: raise ImportError(name=name) # pragma: no cover for module in pkgutil.walk_packages(exts.__path__, f"{exts.__name__}.", onerror=on_error): - if module.name.rsplit(".", maxsplit=1)[-1].startswith("_"): + if unqualify(module.name).startswith("_"): # Ignore module/package names starting with an underscore. continue @@ -75,8 +80,7 @@ class Extension(commands.Converter): matches = [] for ext in EXTENSIONS: - name = ext.rsplit(".", maxsplit=1)[-1] - if argument == name: + if argument == unqualify(ext): matches.append(ext) if len(matches) > 1: |