From 83449e35ad3c9c54068b8521e363fa11d43f5df4 Mon Sep 17 00:00:00 2001 From: Matt Krump <1036969+mkrump@users.noreply.github.com> Date: Fri, 31 Jul 2020 20:27:54 -0600 Subject: [PATCH 1/2] Turn on check_untyped_defs for aqt.main --- qt/aqt/main.py | 18 +++++++++--------- qt/mypy.ini | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/qt/aqt/main.py b/qt/aqt/main.py index f48924850..fca36d22c 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -14,7 +14,7 @@ import weakref import zipfile from argparse import Namespace from threading import Thread -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple +from typing import Any, Callable, Dict, List, Optional, Sequence, TextIO, Tuple, cast import anki import aqt @@ -185,9 +185,9 @@ class AnkiQt(QMainWindow): onClose = pyqtSignal() closeFires = True - def closeEvent(self, evt): + def closeEvent(self, evt: QCloseEvent) -> None: if self.closeFires: - self.onClose.emit() + self.onClose.emit() # type: ignore evt.accept() def closeWithoutQuitting(self): @@ -924,10 +924,10 @@ title="%s" %s>%s""" % ( # Tools ########################################################################## - def raiseMain(self): + def raiseMain(self) -> bool: if not self.app.activeWindow(): # make sure window is shown - self.setWindowState(self.windowState() & ~Qt.WindowMinimized) + self.setWindowState(self.windowState() & ~Qt.WindowMinimized) # type: ignore return True def setupStyle(self) -> None: @@ -1412,7 +1412,7 @@ will be lost. Continue?""" gui_hooks.debug_console_will_show(d) d.show() - def _captureOutput(self, on): + def _captureOutput(self, on: bool) -> None: mw = self class Stream: @@ -1423,7 +1423,7 @@ will be lost. Continue?""" self._output = "" self._oldStderr = sys.stderr self._oldStdout = sys.stdout - s = Stream() + s = cast(TextIO, Stream()) sys.stderr = s sys.stdout = s else: @@ -1547,8 +1547,8 @@ will be lost. Continue?""" for action in self.findChildren(QAction): action.setStatusTip("") - def onMacMinimize(self): - self.setWindowState(self.windowState() | Qt.WindowMinimized) + def onMacMinimize(self) -> None: + self.setWindowState(self.windowState() | Qt.WindowMinimized) # type: ignore # Single instance support ########################################################################## diff --git a/qt/mypy.ini b/qt/mypy.ini index f72a0a039..8efee5828 100644 --- a/qt/mypy.ini +++ b/qt/mypy.ini @@ -96,3 +96,5 @@ check_untyped_defs=true check_untyped_defs=true [mypy-aqt.profiles] check_untyped_defs=true +[mypy-aqt.main] +check_untyped_defs=true From f529124bbffb6869de8bf2d3fa5f288c4abccfa7 Mon Sep 17 00:00:00 2001 From: Matt Krump <1036969+mkrump@users.noreply.github.com> Date: Fri, 31 Jul 2020 20:50:45 -0600 Subject: [PATCH 2/2] Turn on check_untyped_defs for aqt.progress --- qt/aqt/progress.py | 8 ++++---- qt/mypy.ini | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/qt/aqt/progress.py b/qt/aqt/progress.py index 0dc73f032..77e2eb5a5 100644 --- a/qt/aqt/progress.py +++ b/qt/aqt/progress.py @@ -73,7 +73,7 @@ class ProgressManager: self._win.setWindowModality(Qt.ApplicationModal) self._win.setMinimumWidth(300) self._setBusy() - self._shown = 0 + self._shown: float = 0 self._counter = min self._min = min self._max = max @@ -116,7 +116,7 @@ class ProgressManager: if process and elapsed >= 0.2: self._updating = True - self.app.processEvents() + self.app.processEvents() # type: ignore #possibly related to https://github.com/python/mypy/issues/6910 self._updating = False self._lastUpdate = time.time() @@ -146,7 +146,7 @@ class ProgressManager: if delta > 0.5: self._showWin() - def _showWin(self): + def _showWin(self) -> None: self._shown = time.time() self._win.show() @@ -160,7 +160,7 @@ class ProgressManager: elap = time.time() - self._shown if elap >= 0.5: break - self.app.processEvents(QEventLoop.ExcludeUserInputEvents) + self.app.processEvents(QEventLoop.ExcludeUserInputEvents) # type: ignore #possibly related to https://github.com/python/mypy/issues/6910 self._win.cancel() self._win = None self._shown = 0 diff --git a/qt/mypy.ini b/qt/mypy.ini index 8efee5828..e1f93a4e2 100644 --- a/qt/mypy.ini +++ b/qt/mypy.ini @@ -98,3 +98,5 @@ check_untyped_defs=true check_untyped_defs=true [mypy-aqt.main] check_untyped_defs=true +[mypy-aqt.progress] +check_untyped_defs=true