Fix mypy issues
This commit is contained in:
parent
a96c6efc34
commit
b41005d487
@ -48,9 +48,10 @@ class config_changed:
|
||||
|
||||
"""Decorator to get notified about changed configs."""
|
||||
|
||||
def __init__(self, option_filter=None):
|
||||
def __init__(self, option_filter: str = None) -> None:
|
||||
self._filter = option_filter
|
||||
|
||||
def __call__(self, func: typing.Callable) -> typing.Callable:
|
||||
info = _add_module_info(func)
|
||||
info.config_changed_hooks.append((self._filter, func))
|
||||
return func
|
||||
|
@ -34,6 +34,11 @@ from qutebrowser import components
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.utils import log, standarddir, objreg
|
||||
|
||||
MYPY = False
|
||||
if MYPY:
|
||||
# pylint: disable=unused-import,useless-suppression
|
||||
import argparse
|
||||
|
||||
|
||||
# ModuleInfo objects for all loaded plugins
|
||||
_module_infos = []
|
||||
@ -57,7 +62,8 @@ class ModuleInfo:
|
||||
This gets used by qutebrowser.api.hook.
|
||||
"""
|
||||
|
||||
_ConfigChangedHooksType = typing.List[typing.Tuple[str, typing.Callable]]
|
||||
_ConfigChangedHooksType = typing.List[typing.Tuple[typing.Optional[str],
|
||||
typing.Callable]]
|
||||
|
||||
init_hook = attr.ib(None) # type: typing.Optional[typing.Callable]
|
||||
config_changed_hooks = attr.ib(
|
||||
@ -156,10 +162,13 @@ def _on_config_changed(changed_name: str) -> None:
|
||||
"""Call config_changed hooks if the config changed."""
|
||||
for mod_info in _module_infos:
|
||||
for option, hook in mod_info.config_changed_hooks:
|
||||
cfilter = config.change_filter(option)
|
||||
cfilter.validate()
|
||||
if cfilter.check_match(changed_name):
|
||||
if option is None:
|
||||
hook()
|
||||
else:
|
||||
cfilter = config.change_filter(option)
|
||||
cfilter.validate()
|
||||
if cfilter.check_match(changed_name):
|
||||
hook()
|
||||
|
||||
|
||||
def init() -> None:
|
||||
|
@ -23,6 +23,11 @@ import typing
|
||||
|
||||
import attr
|
||||
|
||||
MYPY = False
|
||||
if MYPY:
|
||||
# pylint: disable=unused-import,useless-suppression
|
||||
from PyQt5.QtCore import QUrl
|
||||
|
||||
|
||||
@attr.s
|
||||
class Request:
|
||||
@ -33,7 +38,7 @@ class Request:
|
||||
request_url = attr.ib() # type: QUrl
|
||||
is_blocked = attr.ib(False) # type: bool
|
||||
|
||||
def block(self):
|
||||
def block(self) -> None:
|
||||
"""Block this request."""
|
||||
self.is_blocked = True
|
||||
|
||||
@ -48,6 +53,6 @@ def register_filter(reqfilter: RequestFilterType) -> None:
|
||||
_request_filters.append(reqfilter)
|
||||
|
||||
|
||||
def run_filters(info):
|
||||
def run_filters(info: Request) -> None:
|
||||
for reqfilter in _request_filters:
|
||||
reqfilter(info)
|
||||
|
Loading…
Reference in New Issue
Block a user