summaryrefslogtreecommitdiff
path: root/qutebrowser/api
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-05-19 13:15:09 +0200
committerFlorian Bruhin <me@the-compiler.org>2021-05-19 13:15:09 +0200
commitc01b47f27b46a8568096977363b38b01d138749c (patch)
treed0b47c3e9bebc757638f57a17a20e2cbc0332d15 /qutebrowser/api
parent06e49efd3d9f21058893a0c3751aa05caaf0e2f8 (diff)
downloadqutebrowser-c01b47f27b46a8568096977363b38b01d138749c.tar.gz
qutebrowser-c01b47f27b46a8568096977363b38b01d138749c.zip
mypy: Set disallow_any_generics
See #6100
Diffstat (limited to 'qutebrowser/api')
-rw-r--r--qutebrowser/api/cmdutils.py7
-rw-r--r--qutebrowser/api/hook.py11
2 files changed, 12 insertions, 6 deletions
diff --git a/qutebrowser/api/cmdutils.py b/qutebrowser/api/cmdutils.py
index 85a700c43..73c6a1bc5 100644
--- a/qutebrowser/api/cmdutils.py
+++ b/qutebrowser/api/cmdutils.py
@@ -105,6 +105,9 @@ def check_exclusive(flags: Iterable[bool], names: Iterable[str]) -> None:
raise CommandError("Only one of {} can be given!".format(argstr))
+_CmdHandlerType = Callable[..., Any]
+
+
class register: # noqa: N801,N806 pylint: disable=invalid-name
"""Decorator to register a new command handler."""
@@ -130,7 +133,7 @@ class register: # noqa: N801,N806 pylint: disable=invalid-name
# The arguments to pass to Command.
self._kwargs = kwargs
- def __call__(self, func: Callable) -> Callable:
+ def __call__(self, func: _CmdHandlerType) -> _CmdHandlerType:
"""Register the command before running the function.
Gets called when a function should be decorated.
@@ -222,7 +225,7 @@ class argument: # noqa: N801,N806 pylint: disable=invalid-name
self._argname = argname # The name of the argument to handle.
self._kwargs = kwargs # Valid ArgInfo members.
- def __call__(self, func: Callable) -> Callable:
+ def __call__(self, func: _CmdHandlerType) -> _CmdHandlerType:
funcname = func.__name__
if self._argname not in inspect.signature(func).parameters:
diff --git a/qutebrowser/api/hook.py b/qutebrowser/api/hook.py
index eadc310f3..884d6c67f 100644
--- a/qutebrowser/api/hook.py
+++ b/qutebrowser/api/hook.py
@@ -22,13 +22,13 @@
"""Hooks for extensions."""
import importlib
-from typing import Callable
+from typing import Callable, Any
from qutebrowser.extensions import loader
-def _add_module_info(func: Callable) -> loader.ModuleInfo:
+def _add_module_info(func: Callable[..., Any]) -> loader.ModuleInfo:
"""Add module info to the given function."""
module = importlib.import_module(func.__module__)
return loader.add_module_info(module)
@@ -48,7 +48,7 @@ class init:
message.info("Extension initialized.")
"""
- def __call__(self, func: Callable) -> Callable:
+ def __call__(self, func: loader.InitHookType) -> loader.InitHookType:
info = _add_module_info(func)
if info.init_hook is not None:
raise ValueError("init hook is already registered!")
@@ -86,7 +86,10 @@ class config_changed:
def __init__(self, option_filter: str = None) -> None:
self._filter = option_filter
- def __call__(self, func: Callable) -> Callable:
+ def __call__(
+ self,
+ func: loader.ConfigChangedHookType,
+ ) -> loader.ConfigChangedHookType:
info = _add_module_info(func)
info.config_changed_hooks.append((self._filter, func))
return func