Complete partial annotations

Unfortunately we can't turn on mypy's --disallow-incomplete-defs (yet) due to
https://github.com/python/mypy/issues/5954
This commit is contained in:
Florian Bruhin 2018-11-26 20:12:03 +01:00
parent fda807ce9a
commit 1f36e56e1c
13 changed files with 44 additions and 34 deletions

View File

@ -10,6 +10,7 @@ warn_unused_ignores = True
disallow_subclassing_any = True disallow_subclassing_any = True
# disallow_untyped_calls = True # disallow_untyped_calls = True
# disallow_untyped_defs = True # disallow_untyped_defs = True
# https://github.com/python/mypy/issues/5954
# disallow_incomplete_defs = True # disallow_incomplete_defs = True
# check_untyped_defs = True # check_untyped_defs = True
# disallow_untyped_decorators = True # disallow_untyped_decorators = True

View File

@ -685,7 +685,7 @@ class AbstractAudio(QObject):
self._widget = None self._widget = None
self._tab = tab self._tab = tab
def set_muted(self, muted: bool, override: bool = False): def set_muted(self, muted: bool, override: bool = False) -> None:
"""Set this tab as muted or not. """Set this tab as muted or not.
Arguments: Arguments:
@ -699,7 +699,7 @@ class AbstractAudio(QObject):
"""Whether this tab is muted.""" """Whether this tab is muted."""
raise NotImplementedError raise NotImplementedError
def toggle_muted(self, *, override: bool = False): def toggle_muted(self, *, override: bool = False) -> None:
self.set_muted(not self.is_muted(), override=override) self.set_muted(not self.is_muted(), override=override)
def is_recently_audible(self): def is_recently_audible(self):

View File

@ -513,7 +513,8 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('win_id', completion=miscmodels.window) @cmdutils.argument('win_id', completion=miscmodels.window)
@cmdutils.argument('count', count=True) @cmdutils.argument('count', count=True)
def tab_give(self, win_id: int = None, keep=False, count=None): def tab_give(self, win_id: int = None, keep: bool = False,
count: int = None) -> None:
"""Give the current tab to a new or existing window if win_id given. """Give the current tab to a new or existing window if win_id given.
If no win_id is given, the tab will get detached into a new window. If no win_id is given, the tab will get detached into a new window.
@ -601,7 +602,8 @@ class CommandDispatcher:
@cmdutils.argument('where', choices=['prev', 'next', 'up', 'increment', @cmdutils.argument('where', choices=['prev', 'next', 'up', 'increment',
'decrement']) 'decrement'])
@cmdutils.argument('count', count=True) @cmdutils.argument('count', count=True)
def navigate(self, where: str, tab=False, bg=False, window=False, count=1): def navigate(self, where: str, tab: bool = False, bg: bool = False,
window: bool = False, count: int = 1) -> None:
"""Open typical prev/next links or navigate using the URL path. """Open typical prev/next links or navigate using the URL path.
This tries to automatically click on typical _Previous Page_ or This tries to automatically click on typical _Previous Page_ or
@ -665,7 +667,7 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('count', count=True) @cmdutils.argument('count', count=True)
def scroll_px(self, dx: int, dy: int, count=1): def scroll_px(self, dx: int, dy: int, count: int = 1) -> None:
"""Scroll the current tab by 'count * dx/dy' pixels. """Scroll the current tab by 'count * dx/dy' pixels.
Args: Args:
@ -681,7 +683,7 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('count', count=True) @cmdutils.argument('count', count=True)
def scroll(self, direction: str, count=1): def scroll(self, direction: str, count: int = 1) -> None:
"""Scroll the current tab in the given direction. """Scroll the current tab in the given direction.
Note you can use `:run-with-count` to have a keybinding with a bigger Note you can use `:run-with-count` to have a keybinding with a bigger
@ -719,7 +721,8 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('count', count=True) @cmdutils.argument('count', count=True)
@cmdutils.argument('horizontal', flag='x') @cmdutils.argument('horizontal', flag='x')
def scroll_to_perc(self, perc: float = None, horizontal=False, count=None): def scroll_to_perc(self, perc: float = None, horizontal: bool = False,
count: int = None) -> None:
"""Scroll to a specific percentage of the page. """Scroll to a specific percentage of the page.
The percentage can be given either as argument or as count. The percentage can be given either as argument or as count.
@ -764,7 +767,7 @@ class CommandDispatcher:
choices=('next', 'increment')) choices=('next', 'increment'))
def scroll_page(self, x: float, y: float, *, def scroll_page(self, x: float, y: float, *,
top_navigate: str = None, bottom_navigate: str = None, top_navigate: str = None, bottom_navigate: str = None,
count=1): count: int = 1) -> None:
"""Scroll the frame page-wise. """Scroll the frame page-wise.
Args: Args:
@ -1120,7 +1123,7 @@ class CommandDispatcher:
@cmdutils.argument('index', choices=['last']) @cmdutils.argument('index', choices=['last'])
@cmdutils.argument('count', count=True) @cmdutils.argument('count', count=True)
def tab_focus(self, index: typing.Union[str, int] = None, def tab_focus(self, index: typing.Union[str, int] = None,
count=None, no_last=False): count: int = None, no_last: bool = False) -> None:
"""Select the tab given as argument/[count]. """Select the tab given as argument/[count].
If neither count nor index are given, it behaves like tab-next. If neither count nor index are given, it behaves like tab-next.
@ -1161,7 +1164,8 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('index', choices=['+', '-']) @cmdutils.argument('index', choices=['+', '-'])
@cmdutils.argument('count', count=True) @cmdutils.argument('count', count=True)
def tab_move(self, index: typing.Union[str, int] = None, count=None): def tab_move(self, index: typing.Union[str, int] = None,
count: int = None) -> None:
"""Move the current tab according to the argument and [count]. """Move the current tab according to the argument and [count].
If neither is given, move it to the first position. If neither is given, move it to the first position.
@ -1718,10 +1722,10 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('filter_', choices=['id']) @cmdutils.argument('filter_', choices=['id'])
def click_element(self, filter_: str, value, *, def click_element(self, filter_: str, value: str, *,
target: usertypes.ClickTarget = target: usertypes.ClickTarget =
usertypes.ClickTarget.normal, usertypes.ClickTarget.normal,
force_event=False): force_event: bool = False) -> None:
"""Click the element matching the given filter. """Click the element matching the given filter.
The given filter needs to result in exactly one element, otherwise, an The given filter needs to result in exactly one element, otherwise, an
@ -2070,8 +2074,8 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window', @cmdutils.register(instance='command-dispatcher', scope='window',
maxsplit=0, no_cmd_split=True) maxsplit=0, no_cmd_split=True)
def jseval(self, js_code, file=False, quiet=False, *, def jseval(self, js_code: str, file: bool = False, quiet: bool = False, *,
world: typing.Union[usertypes.JsWorld, int] = None): world: typing.Union[usertypes.JsWorld, int] = None) -> None:
"""Evaluate a JavaScript string. """Evaluate a JavaScript string.
Args: Args:

View File

@ -1062,7 +1062,7 @@ class DownloadModel(QAbstractListModel):
@cmdutils.register(instance='download-model', scope='window', maxsplit=0) @cmdutils.register(instance='download-model', scope='window', maxsplit=0)
@cmdutils.argument('count', count=True) @cmdutils.argument('count', count=True)
def download_open(self, cmdline: str = None, count=0): def download_open(self, cmdline: str = None, count: int = 0) -> None:
"""Open the last/[count]th download. """Open the last/[count]th download.
If no specific command is given, this will use the system's default If no specific command is given, this will use the system's default

View File

@ -670,7 +670,7 @@ class WebEngineAudio(browsertab.AbstractAudio):
self._tab.url_changed.connect(self._on_url_changed) self._tab.url_changed.connect(self._on_url_changed)
config.instance.changed.connect(self._on_config_changed) config.instance.changed.connect(self._on_config_changed)
def set_muted(self, muted: bool, override: bool = False): def set_muted(self, muted: bool, override: bool = False) -> None:
self._overridden = override self._overridden = override
page = self._widget.page() page = self._widget.page()
page.setAudioMuted(muted) page.setAudioMuted(muted)

View File

@ -240,7 +240,7 @@ class WebEnginePage(QWebEnginePage):
def acceptNavigationRequest(self, def acceptNavigationRequest(self,
url: QUrl, url: QUrl,
typ: QWebEnginePage.NavigationType, typ: QWebEnginePage.NavigationType,
is_main_frame: bool): is_main_frame: bool) -> bool:
"""Override acceptNavigationRequest to forward it to the tab API.""" """Override acceptNavigationRequest to forward it to the tab API."""
type_map = { type_map = {
QWebEnginePage.NavigationTypeLinkClicked: QWebEnginePage.NavigationTypeLinkClicked:

View File

@ -641,7 +641,7 @@ class WebKitAudio(browsertab.AbstractAudio):
"""Dummy handling of audio status for QtWebKit.""" """Dummy handling of audio status for QtWebKit."""
def set_muted(self, muted: bool, override: bool = False): def set_muted(self, muted: bool, override: bool = False) -> None:
raise browsertab.WebTabError('Muting is not supported on QtWebKit!') raise browsertab.WebTabError('Muting is not supported on QtWebKit!')
def is_muted(self): def is_muted(self):

View File

@ -469,7 +469,7 @@ class BrowserPage(QWebPage):
def acceptNavigationRequest(self, def acceptNavigationRequest(self,
frame: QWebFrame, frame: QWebFrame,
request: QNetworkRequest, request: QNetworkRequest,
typ: QWebPage.NavigationType): typ: QWebPage.NavigationType) -> bool:
"""Override acceptNavigationRequest to handle clicked links. """Override acceptNavigationRequest to handle clicked links.
Setting linkDelegationPolicy to DelegateAllLinks and using a slot bound Setting linkDelegationPolicy to DelegateAllLinks and using a slot bound

View File

@ -45,7 +45,7 @@ class ConfigCache:
if attr in self._cache: if attr in self._cache:
self._cache[attr] = config.instance.get(attr) self._cache[attr] = config.instance.get(attr)
def __getitem__(self, attr: str): def __getitem__(self, attr: str) -> typing.Any:
if attr not in self._cache: if attr not in self._cache:
assert not config.instance.get_opt(attr).supports_pattern assert not config.instance.get_opt(attr).supports_pattern
self._cache[attr] = config.instance.get(attr) self._cache[attr] = config.instance.get(attr)

View File

@ -391,7 +391,8 @@ class PromptContainer(QWidget):
@cmdutils.register(instance='prompt-container', scope='window', @cmdutils.register(instance='prompt-container', scope='window',
modes=[usertypes.KeyMode.prompt], maxsplit=0) modes=[usertypes.KeyMode.prompt], maxsplit=0)
def prompt_open_download(self, cmdline: str = None, pdfjs=False): def prompt_open_download(self, cmdline: str = None,
pdfjs: bool = False) -> None:
"""Immediately open a download. """Immediately open a download.
If no specific command is given, this will use the system's default If no specific command is given, this will use the system's default

View File

@ -342,7 +342,7 @@ class TabWidget(QTabWidget):
qtutils.ensure_valid(url) qtutils.ensure_valid(url)
return url return url
def update_tab_favicon(self, tab: QWidget): def update_tab_favicon(self, tab: QWidget) -> None:
"""Update favicon of the given tab.""" """Update favicon of the given tab."""
idx = self.indexOf(tab) idx = self.indexOf(tab)
@ -400,7 +400,7 @@ class TabBar(QTabBar):
return self.parent().currentWidget() return self.parent().currentWidget()
@pyqtSlot(str) @pyqtSlot(str)
def _on_config_changed(self, option: str): def _on_config_changed(self, option: str) -> None:
if option == 'fonts.tabs': if option == 'fonts.tabs':
self._set_font() self._set_font()
elif option == 'tabs.favicons.scale': elif option == 'tabs.favicons.scale':
@ -543,7 +543,7 @@ class TabBar(QTabBar):
return return
super().mousePressEvent(e) super().mousePressEvent(e)
def minimumTabSizeHint(self, index, ellipsis: bool = True) -> QSize: def minimumTabSizeHint(self, index: int, ellipsis: bool = True) -> QSize:
"""Set the minimum tab size to indicator/icon/... text. """Set the minimum tab size to indicator/icon/... text.
Args: Args:
@ -623,7 +623,7 @@ class TabBar(QTabBar):
return False return False
return widget.data.pinned return widget.data.pinned
def tabSizeHint(self, index: int): def tabSizeHint(self, index: int) -> QSize:
"""Override tabSizeHint to customize qb's tab size. """Override tabSizeHint to customize qb's tab size.
https://wiki.python.org/moin/PyQt/Customising%20tab%20bars https://wiki.python.org/moin/PyQt/Customising%20tab%20bars

View File

@ -511,9 +511,12 @@ class SessionManager(QObject):
@cmdutils.argument('win_id', win_id=True) @cmdutils.argument('win_id', win_id=True)
@cmdutils.argument('with_private', flag='p') @cmdutils.argument('with_private', flag='p')
def session_save(self, name: typing.Union[str, Sentinel] = default, def session_save(self, name: typing.Union[str, Sentinel] = default,
current=False, quiet=False, force=False, current: bool = False,
only_active_window=False, with_private=False, quiet: bool = False,
win_id=None): force: bool = False,
only_active_window: bool = False,
with_private: bool = False,
win_id: int = None) -> None:
"""Save a session. """Save a session.
Args: Args:

View File

@ -44,7 +44,7 @@ from qutebrowser.qt import sip
@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True) @cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)
@cmdutils.argument('win_id', win_id=True) @cmdutils.argument('win_id', win_id=True)
def later(ms: int, command, win_id): def later(ms: int, command: str, win_id: int) -> None:
"""Execute a command after some time. """Execute a command after some time.
Args: Args:
@ -75,7 +75,7 @@ def later(ms: int, command, win_id):
@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True) @cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)
@cmdutils.argument('win_id', win_id=True) @cmdutils.argument('win_id', win_id=True)
@cmdutils.argument('count', count=True) @cmdutils.argument('count', count=True)
def repeat(times: int, command, win_id, count=None): def repeat(times: int, command: str, win_id: int, count: int = None) -> None:
"""Repeat a given command. """Repeat a given command.
Args: Args:
@ -96,7 +96,8 @@ def repeat(times: int, command, win_id, count=None):
@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True) @cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)
@cmdutils.argument('win_id', win_id=True) @cmdutils.argument('win_id', win_id=True)
@cmdutils.argument('count', count=True) @cmdutils.argument('count', count=True)
def run_with_count(count_arg: int, command, win_id, count=1): def run_with_count(count_arg: int, command: str, win_id: int,
count: int = 1) -> None:
"""Run a command with the given count. """Run a command with the given count.
If run_with_count itself is run with a count, it multiplies count_arg. If run_with_count itself is run with a count, it multiplies count_arg.
@ -303,7 +304,7 @@ def repeat_command(win_id, count=None):
@cmdutils.register(debug=True, name='debug-log-capacity') @cmdutils.register(debug=True, name='debug-log-capacity')
def log_capacity(capacity: int): def log_capacity(capacity: int) -> None:
"""Change the number of log lines to be stored in RAM. """Change the number of log lines to be stored in RAM.
Args: Args:
@ -320,7 +321,7 @@ def log_capacity(capacity: int):
@cmdutils.argument('level', choices=sorted( @cmdutils.argument('level', choices=sorted(
(level.lower() for level in log.LOG_LEVELS), (level.lower() for level in log.LOG_LEVELS),
key=lambda e: log.LOG_LEVELS[e.upper()])) key=lambda e: log.LOG_LEVELS[e.upper()]))
def debug_log_level(level: str): def debug_log_level(level: str) -> None:
"""Change the log level for console logging. """Change the log level for console logging.
Args: Args:
@ -332,7 +333,7 @@ def debug_log_level(level: str):
@cmdutils.register(debug=True) @cmdutils.register(debug=True)
def debug_log_filter(filters: str): def debug_log_filter(filters: str) -> None:
"""Change the log filter for console logging. """Change the log filter for console logging.
Args: Args: