diff --git a/mypy.ini b/mypy.ini index 2e1d50558..4526e4e48 100644 --- a/mypy.ini +++ b/mypy.ini @@ -62,43 +62,7 @@ disallow_incomplete_defs = True disallow_untyped_defs = True disallow_incomplete_defs = True -[mypy-qutebrowser.config.config] -disallow_untyped_defs = True -disallow_incomplete_defs = True - -[mypy-qutebrowser.config.configcache] -disallow_untyped_defs = True -disallow_incomplete_defs = True - -[mypy-qutebrowser.config.configcommands] -disallow_untyped_defs = True -disallow_incomplete_defs = True - -[mypy-qutebrowser.config.configdata] -disallow_untyped_defs = True -disallow_incomplete_defs = True - -[mypy-qutebrowser.config.configdiff] -disallow_untyped_defs = True -disallow_incomplete_defs = True - -[mypy-qutebrowser.config.configexc] -disallow_untyped_defs = True -disallow_incomplete_defs = True - -[mypy-qutebrowser.config.configfiles] -disallow_untyped_defs = True -disallow_incomplete_defs = True - -[mypy-qutebrowser.config.configinit] -disallow_untyped_defs = True -disallow_incomplete_defs = True - -[mypy-qutebrowser.config.configutils] -disallow_untyped_defs = True -disallow_incomplete_defs = True - -[mypy-qutebrowser.config.configtypes] +[mypy-qutebrowser.config.*] disallow_untyped_defs = True disallow_incomplete_defs = True diff --git a/qutebrowser/config/websettings.py b/qutebrowser/config/websettings.py index e6d19db7e..5a21af7e3 100644 --- a/qutebrowser/config/websettings.py +++ b/qutebrowser/config/websettings.py @@ -19,8 +19,10 @@ """Bridge from QWeb(Engine)Settings to our own settings.""" -import typing # pylint: disable=unused-import +import typing +import argparse +from PyQt5.QtCore import QUrl from PyQt5.QtGui import QFont from qutebrowser.config import config, configutils @@ -34,7 +36,8 @@ class AttributeInfo: """Info about a settings attribute.""" - def __init__(self, *attributes, converter=None): + def __init__(self, *attributes: typing.Any, + converter: typing.Callable = None) -> None: self.attributes = attributes if converter is None: self.converter = lambda val: val @@ -51,10 +54,10 @@ class AbstractSettings: _FONT_FAMILIES = {} # type: typing.Dict[str, typing.Any] _FONT_TO_QFONT = {} # type: typing.Dict[typing.Any, QFont.StyleHint] - def __init__(self, settings): + def __init__(self, settings: typing.Any) -> None: self._settings = settings - def set_attribute(self, name, value): + def set_attribute(self, name: str, value: typing.Any) -> bool: """Set the given QWebSettings/QWebEngineSettings attribute. If the value is configutils.UNSET, the value is reset instead. @@ -75,7 +78,7 @@ class AbstractSettings: return old_value != new_value - def test_attribute(self, name): + def test_attribute(self, name: str) -> bool: """Get the value for the given attribute. If the setting resolves to a list of attributes, only the first @@ -84,7 +87,7 @@ class AbstractSettings: info = self._ATTRIBUTES[name] return self._settings.testAttribute(info.attributes[0]) - def set_font_size(self, name, value): + def set_font_size(self, name: str, value: int) -> bool: """Set the given QWebSettings/QWebEngineSettings font size. Return: @@ -96,7 +99,7 @@ class AbstractSettings: self._settings.setFontSize(family, value) return old_value != value - def set_font_family(self, name, value): + def set_font_family(self, name: str, value: typing.Optional[str]) -> bool: """Set the given QWebSettings/QWebEngineSettings font family. With None (the default), QFont is used to get the default font for the @@ -117,7 +120,7 @@ class AbstractSettings: return value != old_value - def set_default_text_encoding(self, encoding): + def set_default_text_encoding(self, encoding: str) -> bool: """Set the default text encoding to use. Return: @@ -128,7 +131,7 @@ class AbstractSettings: self._settings.setDefaultTextEncoding(encoding) return old_value != encoding - def _update_setting(self, setting, value): + def _update_setting(self, setting: str, value: typing.Any) -> bool: """Update the given setting/value. Unknown settings are ignored. @@ -146,12 +149,12 @@ class AbstractSettings: return self.set_default_text_encoding(value) return False - def update_setting(self, setting): + def update_setting(self, setting: str) -> None: """Update the given setting.""" value = config.instance.get(setting) self._update_setting(setting, value) - def update_for_url(self, url): + def update_for_url(self, url: QUrl) -> typing.Set[str]: """Update settings customized for the given tab. Return: @@ -173,14 +176,14 @@ class AbstractSettings: return changed_settings - def init_settings(self): + def init_settings(self) -> None: """Set all supported settings correctly.""" for setting in (list(self._ATTRIBUTES) + list(self._FONT_SIZES) + list(self._FONT_FAMILIES)): self.update_setting(setting) -def init(args): +def init(args: argparse.Namespace) -> None: """Initialize all QWeb(Engine)Settings.""" if objects.backend == usertypes.Backend.QtWebEngine: from qutebrowser.browser.webengine import webenginesettings @@ -195,7 +198,7 @@ def init(args): pattern=urlmatch.UrlPattern(pattern)) -def shutdown(): +def shutdown() -> None: """Shut down QWeb(Engine)Settings.""" if objects.backend == usertypes.Backend.QtWebEngine: from qutebrowser.browser.webengine import webenginesettings