From fcb39c1d7f41e4067980f8eeb4276c209c5033ce Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 10 Dec 2018 10:06:07 +0100 Subject: [PATCH] Add types to extensions.loader --- mypy.ini | 4 ++++ qutebrowser/extensions/loader.py | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mypy.ini b/mypy.ini index 4526e4e48..8fb8d89ae 100644 --- a/mypy.ini +++ b/mypy.ini @@ -73,3 +73,7 @@ disallow_incomplete_defs = True [mypy-qutebrowser.components.*] disallow_untyped_defs = True disallow_incomplete_defs = True + +[mypy-qutebrowser.extensions.*] +disallow_untyped_defs = True +disallow_incomplete_defs = True diff --git a/qutebrowser/extensions/loader.py b/qutebrowser/extensions/loader.py index 9b5aadd25..9674ad707 100644 --- a/qutebrowser/extensions/loader.py +++ b/qutebrowser/extensions/loader.py @@ -19,7 +19,9 @@ """Loader for qutebrowser extensions.""" +import importlib.abc import pkgutil +import types from qutebrowser import components from qutebrowser.utils import log @@ -27,9 +29,15 @@ from qutebrowser.utils import log def load_components() -> None: """Load everything from qutebrowser.components.""" - for info in pkgutil.walk_packages(components.__path__): - if info.ispkg: + for finder, name, ispkg in pkgutil.walk_packages(components.__path__): + if ispkg: continue - log.extensions.debug("Importing {}".format(info.name)) - loader = info.module_finder.find_module(info.name) - loader.load_module(info.name) + _load_module(finder, name) + + +def _load_module(finder: importlib.abc.PathEntryFinder, + name: str) -> types.ModuleType: + log.extensions.debug("Importing {}".format(name)) + loader = finder.find_module(name) + assert loader is not None + return loader.load_module(name)