From fe2463c63bd06c1a2a0c0a9326b166908a42101f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 15 Oct 2019 18:48:12 +0200 Subject: [PATCH] mypy: check_untyped_defs for qutebrowser.mainwindow --- mypy.ini | 4 ++-- qutebrowser/commands/command.py | 5 +++-- qutebrowser/mainwindow/mainwindow.py | 12 ++++++++---- qutebrowser/mainwindow/messageview.py | 3 ++- qutebrowser/mainwindow/prompt.py | 18 +++++++++++------- qutebrowser/mainwindow/tabbedbrowser.py | 12 ++++++++---- qutebrowser/mainwindow/tabwidget.py | 6 +++--- qutebrowser/misc/objects.py | 4 ++++ 8 files changed, 41 insertions(+), 23 deletions(-) diff --git a/mypy.ini b/mypy.ini index 1e0aa6480..789ec02eb 100644 --- a/mypy.ini +++ b/mypy.ini @@ -138,8 +138,8 @@ check_untyped_defs = True [mypy-qutebrowser.javascript.*] check_untyped_defs = True -# [mypy-qutebrowser.mainwindow.*] -# check_untyped_defs = True +[mypy-qutebrowser.mainwindow.*] +check_untyped_defs = True # [mypy-qutebrowser.misc.*] # check_untyped_defs = True diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index 41d4c1e54..a813bd123 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -244,8 +244,9 @@ class Command: args = self._param_to_argparse_args(param, is_bool) callsig = debug_utils.format_call(self.parser.add_argument, args, kwargs, full=False) - log.commands.vdebug('Adding arg {} of type {} -> {}' # type: ignore - .format(param.name, typ, callsig)) + log.commands.vdebug( # type: ignore + 'Adding arg {} of type {} -> {}' + .format(param.name, typ, callsig)) self.parser.add_argument(*args, **kwargs) if param.kind == inspect.Parameter.VAR_POSITIONAL: self._has_vararg = True diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index 5ee2148cb..8ecf82c06 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -23,8 +23,9 @@ import binascii import base64 import itertools import functools +import typing -from PyQt5.QtCore import (pyqtSlot, QRect, QPoint, QTimer, Qt, +from PyQt5.QtCore import (pyqtSignal, pyqtSlot, QRect, QPoint, QTimer, Qt, QCoreApplication, QEventLoop) from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QSizePolicy @@ -101,7 +102,7 @@ def raise_window(window, alert=True): window.setWindowState(window.windowState() | Qt.WindowActive) window.raise_() # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-69568 - QCoreApplication.processEvents( + QCoreApplication.processEvents( # type: ignore QEventLoop.ExcludeUserInputEvents | QEventLoop.ExcludeSocketNotifiers) window.activateWindow() @@ -127,6 +128,9 @@ def get_target_window(): return None +_OverlayInfoType = typing.Tuple[QWidget, pyqtSignal, bool, str] + + class MainWindow(QWidget): """The main window of qutebrowser. @@ -174,7 +178,7 @@ class MainWindow(QWidget): self.setAttribute(Qt.WA_DeleteOnClose) self._commandrunner = None - self._overlays = [] + self._overlays = [] # type: typing.Sequence[_OverlayInfoType] self.win_id = next(win_id_gen) self.registry = objreg.ObjectRegistry() objreg.window_registry[self.win_id] = self @@ -542,7 +546,7 @@ class MainWindow(QWidget): def _set_decoration(self, hidden): """Set the visibility of the window decoration via Qt.""" - window_flags = Qt.Window + window_flags = Qt.Window # type: int refresh_window = self.isVisible() if hidden: window_flags |= Qt.CustomizeWindowHint | Qt.NoDropShadowWindowHint diff --git a/qutebrowser/mainwindow/messageview.py b/qutebrowser/mainwindow/messageview.py index b00ae6202..3a209720d 100644 --- a/qutebrowser/mainwindow/messageview.py +++ b/qutebrowser/mainwindow/messageview.py @@ -19,6 +19,7 @@ """Showing messages above the statusbar.""" +import typing from PyQt5.QtCore import pyqtSlot, pyqtSignal, QTimer, Qt, QSize from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QSizePolicy @@ -77,7 +78,7 @@ class MessageView(QWidget): def __init__(self, parent=None): super().__init__(parent) - self._messages = [] + self._messages = [] # type: typing.Iterable[Message] self._vbox = QVBoxLayout(self) self._vbox.setContentsMargins(0, 0, 0, 0) self._vbox.setSpacing(0) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 81538a68a..7fd68148e 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -102,8 +102,9 @@ class PromptQueue(QObject): super().__init__(parent) self._question = None self._shutting_down = False - self._loops = [] - self._queue = collections.deque() + self._loops = [] # type: typing.Iterable[qtutils.EventLoop] + self._queue = collections.deque( + ) # type: typing.Sequence[usertypes.Question] message.global_bridge.mode_left.connect(self._on_mode_left) def __repr__(self): @@ -191,7 +192,8 @@ class PromptQueue(QObject): if blocking: loop = qtutils.EventLoop() self._loops.append(loop) - loop.destroyed.connect(lambda: self._loops.remove(loop)) + loop.destroyed.connect( # type: ignore + lambda: self._loops.remove(loop)) question.completed.connect(loop.quit) question.completed.connect(loop.deleteLater) log.prompt.debug("Starting loop.exec_() for {}".format(question)) @@ -286,7 +288,7 @@ class PromptContainer(QWidget): self._layout = QVBoxLayout(self) self._layout.setContentsMargins(10, 10, 10, 10) self._win_id = win_id - self._prompt = None + self._prompt = None # type: typing.Optional[_BasePrompt] self.setObjectName('PromptContainer') self.setAttribute(Qt.WA_StyledBackground, True) @@ -327,7 +329,7 @@ class PromptContainer(QWidget): usertypes.PromptMode.alert: AlertPrompt, } klass = classes[question.mode] - prompt = klass(question) + prompt = typing.cast(_BasePrompt, klass(question)) log.prompt.debug("Displaying prompt {}".format(prompt)) self._prompt = prompt @@ -419,6 +421,7 @@ class PromptContainer(QWidget): cmdline. pdfjs: Open the download via PDF.js. """ + assert self._prompt is not None try: self._prompt.download_open(cmdline, pdfjs=pdfjs) except UnsupportedOperationError: @@ -784,7 +787,8 @@ class DownloadFilenamePrompt(FilenamePrompt): def download_open(self, cmdline, pdfjs): if pdfjs: - target = downloads.PDFJSDownloadTarget() + target = downloads.PDFJSDownloadTarget( + ) # type: downloads._DownloadTarget else: target = downloads.OpenFileDownloadTarget(cmdline) @@ -950,5 +954,5 @@ def init(): """Initialize global prompt objects.""" global prompt_queue prompt_queue = PromptQueue() - message.global_bridge.ask_question.connect( + message.global_bridge.ask_question.connect( # type: ignore prompt_queue.ask_question, Qt.DirectConnection) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 1900070b5..dd757920c 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -217,14 +217,18 @@ class TabbedBrowser(QWidget): # This init is never used, it is immediately thrown away in the next # line. - self._undo_stack = collections.deque() + self._undo_stack = ( + collections.deque() + ) # type: typing.Sequence[typing.Sequence[UndoEntry]] self._update_stack_size() self._filter = signalfilter.SignalFilter(win_id, self) self._now_focused = None self.search_text = None - self.search_options = {} - self._local_marks = {} - self._global_marks = {} + self.search_options = {} # type: typing.Mapping[str, typing.Any] + self._local_marks = { + } # type: typing.Mapping[QUrl, typing.Mapping[str, int]] + self._global_marks = { + } # type: typing.Mapping[str, typing.Tuple[QUrl, int]] self.default_window_icon = self.widget.window().windowIcon() self.is_private = private self.tab_deque = TabDeque() diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 43b194159..24d108506 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -60,10 +60,10 @@ class TabWidget(QTabWidget): bar = TabBar(win_id, self) self.setStyle(TabBarStyle()) self.setTabBar(bar) - bar.tabCloseRequested.connect(self.tabCloseRequested) - bar.tabMoved.connect(functools.partial( + bar.tabCloseRequested.connect(self.tabCloseRequested) # type: ignore + bar.tabMoved.connect(functools.partial( # type: ignore QTimer.singleShot, 0, self.update_tab_titles)) - bar.currentChanged.connect(self._on_current_changed) + bar.currentChanged.connect(self._on_current_changed) # type: ignore bar.new_tab_requested.connect(self._on_new_tab_requested) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.setDocumentMode(True) diff --git a/qutebrowser/misc/objects.py b/qutebrowser/misc/objects.py index 5415ab453..a96e9f754 100644 --- a/qutebrowser/misc/objects.py +++ b/qutebrowser/misc/objects.py @@ -34,6 +34,10 @@ class NoBackend: """Special object when there's no backend set so we notice that.""" + @property + def name(self) -> str: + raise AssertionError("No backend set!") + def __eq__(self, other: typing.Any) -> bool: raise AssertionError("No backend set!")