Merge pull request #721 from mkrump/help-wanted-4-add-type-hints-7

Turn on check_untyped_defs for aqt.main and aqt.progress
This commit is contained in:
Damien Elmes 2020-08-02 10:04:52 +10:00 committed by GitHub
commit 43d03ee3be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 13 deletions

View File

@ -14,7 +14,7 @@ import weakref
import zipfile import zipfile
from argparse import Namespace from argparse import Namespace
from threading import Thread 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 anki
import aqt import aqt
@ -185,9 +185,9 @@ class AnkiQt(QMainWindow):
onClose = pyqtSignal() onClose = pyqtSignal()
closeFires = True closeFires = True
def closeEvent(self, evt): def closeEvent(self, evt: QCloseEvent) -> None:
if self.closeFires: if self.closeFires:
self.onClose.emit() self.onClose.emit() # type: ignore
evt.accept() evt.accept()
def closeWithoutQuitting(self): def closeWithoutQuitting(self):
@ -924,10 +924,10 @@ title="%s" %s>%s</button>""" % (
# Tools # Tools
########################################################################## ##########################################################################
def raiseMain(self): def raiseMain(self) -> bool:
if not self.app.activeWindow(): if not self.app.activeWindow():
# make sure window is shown # make sure window is shown
self.setWindowState(self.windowState() & ~Qt.WindowMinimized) self.setWindowState(self.windowState() & ~Qt.WindowMinimized) # type: ignore
return True return True
def setupStyle(self) -> None: def setupStyle(self) -> None:
@ -1412,7 +1412,7 @@ will be lost. Continue?"""
gui_hooks.debug_console_will_show(d) gui_hooks.debug_console_will_show(d)
d.show() d.show()
def _captureOutput(self, on): def _captureOutput(self, on: bool) -> None:
mw = self mw = self
class Stream: class Stream:
@ -1423,7 +1423,7 @@ will be lost. Continue?"""
self._output = "" self._output = ""
self._oldStderr = sys.stderr self._oldStderr = sys.stderr
self._oldStdout = sys.stdout self._oldStdout = sys.stdout
s = Stream() s = cast(TextIO, Stream())
sys.stderr = s sys.stderr = s
sys.stdout = s sys.stdout = s
else: else:
@ -1547,8 +1547,8 @@ will be lost. Continue?"""
for action in self.findChildren(QAction): for action in self.findChildren(QAction):
action.setStatusTip("") action.setStatusTip("")
def onMacMinimize(self): def onMacMinimize(self) -> None:
self.setWindowState(self.windowState() | Qt.WindowMinimized) self.setWindowState(self.windowState() | Qt.WindowMinimized) # type: ignore
# Single instance support # Single instance support
########################################################################## ##########################################################################

View File

@ -73,7 +73,7 @@ class ProgressManager:
self._win.setWindowModality(Qt.ApplicationModal) self._win.setWindowModality(Qt.ApplicationModal)
self._win.setMinimumWidth(300) self._win.setMinimumWidth(300)
self._setBusy() self._setBusy()
self._shown = 0 self._shown: float = 0
self._counter = min self._counter = min
self._min = min self._min = min
self._max = max self._max = max
@ -116,7 +116,7 @@ class ProgressManager:
if process and elapsed >= 0.2: if process and elapsed >= 0.2:
self._updating = True 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._updating = False
self._lastUpdate = time.time() self._lastUpdate = time.time()
@ -146,7 +146,7 @@ class ProgressManager:
if delta > 0.5: if delta > 0.5:
self._showWin() self._showWin()
def _showWin(self): def _showWin(self) -> None:
self._shown = time.time() self._shown = time.time()
self._win.show() self._win.show()
@ -160,7 +160,7 @@ class ProgressManager:
elap = time.time() - self._shown elap = time.time() - self._shown
if elap >= 0.5: if elap >= 0.5:
break 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.cancel()
self._win = None self._win = None
self._shown = 0 self._shown = 0

View File

@ -96,3 +96,7 @@ check_untyped_defs=true
check_untyped_defs=true check_untyped_defs=true
[mypy-aqt.profiles] [mypy-aqt.profiles]
check_untyped_defs=true check_untyped_defs=true
[mypy-aqt.main]
check_untyped_defs=true
[mypy-aqt.progress]
check_untyped_defs=true