diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index a40c2064f..33469bc45 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -9,7 +9,7 @@ import time from dataclasses import dataclass from enum import Enum from operator import itemgetter -from typing import Callable, List, Optional, Sequence, Tuple, Union +from typing import Callable, List, Optional, Sequence, Tuple, Union, cast import anki import aqt @@ -27,6 +27,7 @@ from aqt import AnkiQt, gui_hooks from aqt.editor import Editor from aqt.exporting import ExportDialog from aqt.previewer import BrowserPreviewer as PreviewDialog +from aqt.previewer import Previewer from aqt.qt import * from aqt.theme import theme_manager from aqt.utils import ( @@ -103,7 +104,7 @@ class DataModel(QAbstractTableModel): del self.cardObjs[c.id] refresh = True if refresh: - self.layoutChanged.emit() + self.layoutChanged.emit() # type: ignore # Model interface ###################################################################### @@ -130,12 +131,12 @@ class DataModel(QAbstractTableModel): if not t.get("bfont"): return f = QFont() - f.setFamily(t.get("bfont", "arial")) - f.setPixelSize(t.get("bsize", 12)) + f.setFamily(cast(str, t.get("bfont", "arial"))) + f.setPixelSize(cast(int, t.get("bsize", 12))) return f elif role == Qt.TextAlignmentRole: - align = Qt.AlignVCenter + align: Union[Qt.AlignmentFlag, int] = Qt.AlignVCenter if self.activeCols[index.column()] not in ( "question", "answer", @@ -299,7 +300,7 @@ class DataModel(QAbstractTableModel): elif type == "template": t = c.template()["name"] if c.model()["type"] == MODEL_CLOZE: - t += " %d" % (c.ord + 1) + t = f"{t} {c.ord + 1}" return t elif type == "cardDue": # catch invalid dates @@ -308,7 +309,7 @@ class DataModel(QAbstractTableModel): except: t = "" if c.queue < 0: - t = "(" + t + ")" + t = f"({t})" return t elif type == "noteCrt": return time.strftime(self.time_format(), time.localtime(c.note().id / 1000)) @@ -582,8 +583,8 @@ class Browser(QMainWindow): self.mw = mw self.col = self.mw.col self.lastFilter = "" - self.focusTo = None - self._previewer = None + self.focusTo: Optional[int] = None + self._previewer: Optional[Previewer] = None self._closeEventHasCleanedUp = False self.form = aqt.forms.browser.Ui_Dialog() self.form.setupUi(self) @@ -2017,7 +2018,7 @@ update cards set usn=?, mod=?, did=? where id in """ nids = set() for s, nidlist in res: nids.update(nidlist) - self.col.tags.bulkAdd(nids, _("duplicate")) + self.col.tags.bulkAdd(list(nids), _("duplicate")) self.mw.progress.finish() self.model.endReset() self.mw.requireReset() @@ -2225,16 +2226,16 @@ class ChangeModel(QDialog): old = self.oldModel["tmpls"] combos = self.tcombos new = self.targetModel["tmpls"] - map = {} + template_map: Dict[int, Optional[int]] = {} for i, f in enumerate(old): idx = combos[i].currentIndex() if idx == len(new): # ignore - map[f["ord"]] = None + template_map[f["ord"]] = None else: f2 = new[idx] - map[f["ord"]] = f2["ord"] - return map + template_map[f["ord"]] = f2["ord"] + return template_map def getFieldMap(self): return self.getTemplateMap( diff --git a/qt/aqt/taglimit.py b/qt/aqt/taglimit.py index 0cb164683..971c41f49 100644 --- a/qt/aqt/taglimit.py +++ b/qt/aqt/taglimit.py @@ -1,5 +1,6 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/copyleft/agpl.html +from typing import List, Optional import aqt from aqt.qt import * @@ -9,8 +10,9 @@ from aqt.utils import restoreGeom, saveGeom class TagLimit(QDialog): def __init__(self, mw, parent): QDialog.__init__(self, parent, Qt.Window) + self.tags: Union[str, List] = "" self.mw = mw - self.parent = parent + self.parent: Optional[QWidget] = parent self.deck = self.parent.deck self.dialog = aqt.forms.taglimit.Ui_Dialog() self.dialog.setupUi(self) diff --git a/qt/aqt/update.py b/qt/aqt/update.py index 5d3bbda0b..8b179f65f 100644 --- a/qt/aqt/update.py +++ b/qt/aqt/update.py @@ -47,18 +47,18 @@ class LatestVersionFinder(QThread): print("update check failed") return if resp["msg"]: - self.newMsg.emit(resp) + self.newMsg.emit(resp) # type: ignore if resp["ver"]: - self.newVerAvail.emit(resp["ver"]) + self.newVerAvail.emit(resp["ver"]) # type: ignore diff = resp["time"] - time.time() if abs(diff) > 300: - self.clockIsOff.emit(diff) + self.clockIsOff.emit(diff) # type: ignore def askAndUpdate(mw, ver): baseStr = _("""