Add types to extensions.loader

This commit is contained in:
Florian Bruhin 2018-12-10 10:06:07 +01:00
parent 411c5171a2
commit fcb39c1d7f
2 changed files with 17 additions and 5 deletions

View File

@ -73,3 +73,7 @@ disallow_incomplete_defs = True
[mypy-qutebrowser.components.*] [mypy-qutebrowser.components.*]
disallow_untyped_defs = True disallow_untyped_defs = True
disallow_incomplete_defs = True disallow_incomplete_defs = True
[mypy-qutebrowser.extensions.*]
disallow_untyped_defs = True
disallow_incomplete_defs = True

View File

@ -19,7 +19,9 @@
"""Loader for qutebrowser extensions.""" """Loader for qutebrowser extensions."""
import importlib.abc
import pkgutil import pkgutil
import types
from qutebrowser import components from qutebrowser import components
from qutebrowser.utils import log from qutebrowser.utils import log
@ -27,9 +29,15 @@ from qutebrowser.utils import log
def load_components() -> None: def load_components() -> None:
"""Load everything from qutebrowser.components.""" """Load everything from qutebrowser.components."""
for info in pkgutil.walk_packages(components.__path__): for finder, name, ispkg in pkgutil.walk_packages(components.__path__):
if info.ispkg: if ispkg:
continue continue
log.extensions.debug("Importing {}".format(info.name)) _load_module(finder, name)
loader = info.module_finder.find_module(info.name)
loader.load_module(info.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)