Merge pull request #706 from mkrump/help-wanted-4-add-type-hints-4
Turn on check_untyped_defs for aqt.taglimit, aqt.update and aqt.browser
This commit is contained in:
commit
a239b9330d
@ -9,7 +9,7 @@ import time
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from operator import itemgetter
|
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 anki
|
||||||
import aqt
|
import aqt
|
||||||
@ -27,6 +27,7 @@ from aqt import AnkiQt, gui_hooks
|
|||||||
from aqt.editor import Editor
|
from aqt.editor import Editor
|
||||||
from aqt.exporting import ExportDialog
|
from aqt.exporting import ExportDialog
|
||||||
from aqt.previewer import BrowserPreviewer as PreviewDialog
|
from aqt.previewer import BrowserPreviewer as PreviewDialog
|
||||||
|
from aqt.previewer import Previewer
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.theme import theme_manager
|
from aqt.theme import theme_manager
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
@ -103,7 +104,7 @@ class DataModel(QAbstractTableModel):
|
|||||||
del self.cardObjs[c.id]
|
del self.cardObjs[c.id]
|
||||||
refresh = True
|
refresh = True
|
||||||
if refresh:
|
if refresh:
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit() # type: ignore
|
||||||
|
|
||||||
# Model interface
|
# Model interface
|
||||||
######################################################################
|
######################################################################
|
||||||
@ -130,12 +131,12 @@ class DataModel(QAbstractTableModel):
|
|||||||
if not t.get("bfont"):
|
if not t.get("bfont"):
|
||||||
return
|
return
|
||||||
f = QFont()
|
f = QFont()
|
||||||
f.setFamily(t.get("bfont", "arial"))
|
f.setFamily(cast(str, t.get("bfont", "arial")))
|
||||||
f.setPixelSize(t.get("bsize", 12))
|
f.setPixelSize(cast(int, t.get("bsize", 12)))
|
||||||
return f
|
return f
|
||||||
|
|
||||||
elif role == Qt.TextAlignmentRole:
|
elif role == Qt.TextAlignmentRole:
|
||||||
align = Qt.AlignVCenter
|
align: Union[Qt.AlignmentFlag, int] = Qt.AlignVCenter
|
||||||
if self.activeCols[index.column()] not in (
|
if self.activeCols[index.column()] not in (
|
||||||
"question",
|
"question",
|
||||||
"answer",
|
"answer",
|
||||||
@ -299,7 +300,7 @@ class DataModel(QAbstractTableModel):
|
|||||||
elif type == "template":
|
elif type == "template":
|
||||||
t = c.template()["name"]
|
t = c.template()["name"]
|
||||||
if c.model()["type"] == MODEL_CLOZE:
|
if c.model()["type"] == MODEL_CLOZE:
|
||||||
t += " %d" % (c.ord + 1)
|
t = f"{t} {c.ord + 1}"
|
||||||
return t
|
return t
|
||||||
elif type == "cardDue":
|
elif type == "cardDue":
|
||||||
# catch invalid dates
|
# catch invalid dates
|
||||||
@ -308,7 +309,7 @@ class DataModel(QAbstractTableModel):
|
|||||||
except:
|
except:
|
||||||
t = ""
|
t = ""
|
||||||
if c.queue < 0:
|
if c.queue < 0:
|
||||||
t = "(" + t + ")"
|
t = f"({t})"
|
||||||
return t
|
return t
|
||||||
elif type == "noteCrt":
|
elif type == "noteCrt":
|
||||||
return time.strftime(self.time_format(), time.localtime(c.note().id / 1000))
|
return time.strftime(self.time_format(), time.localtime(c.note().id / 1000))
|
||||||
@ -582,8 +583,8 @@ class Browser(QMainWindow):
|
|||||||
self.mw = mw
|
self.mw = mw
|
||||||
self.col = self.mw.col
|
self.col = self.mw.col
|
||||||
self.lastFilter = ""
|
self.lastFilter = ""
|
||||||
self.focusTo = None
|
self.focusTo: Optional[int] = None
|
||||||
self._previewer = None
|
self._previewer: Optional[Previewer] = None
|
||||||
self._closeEventHasCleanedUp = False
|
self._closeEventHasCleanedUp = False
|
||||||
self.form = aqt.forms.browser.Ui_Dialog()
|
self.form = aqt.forms.browser.Ui_Dialog()
|
||||||
self.form.setupUi(self)
|
self.form.setupUi(self)
|
||||||
@ -2017,7 +2018,7 @@ update cards set usn=?, mod=?, did=? where id in """
|
|||||||
nids = set()
|
nids = set()
|
||||||
for s, nidlist in res:
|
for s, nidlist in res:
|
||||||
nids.update(nidlist)
|
nids.update(nidlist)
|
||||||
self.col.tags.bulkAdd(nids, _("duplicate"))
|
self.col.tags.bulkAdd(list(nids), _("duplicate"))
|
||||||
self.mw.progress.finish()
|
self.mw.progress.finish()
|
||||||
self.model.endReset()
|
self.model.endReset()
|
||||||
self.mw.requireReset()
|
self.mw.requireReset()
|
||||||
@ -2225,16 +2226,16 @@ class ChangeModel(QDialog):
|
|||||||
old = self.oldModel["tmpls"]
|
old = self.oldModel["tmpls"]
|
||||||
combos = self.tcombos
|
combos = self.tcombos
|
||||||
new = self.targetModel["tmpls"]
|
new = self.targetModel["tmpls"]
|
||||||
map = {}
|
template_map: Dict[int, Optional[int]] = {}
|
||||||
for i, f in enumerate(old):
|
for i, f in enumerate(old):
|
||||||
idx = combos[i].currentIndex()
|
idx = combos[i].currentIndex()
|
||||||
if idx == len(new):
|
if idx == len(new):
|
||||||
# ignore
|
# ignore
|
||||||
map[f["ord"]] = None
|
template_map[f["ord"]] = None
|
||||||
else:
|
else:
|
||||||
f2 = new[idx]
|
f2 = new[idx]
|
||||||
map[f["ord"]] = f2["ord"]
|
template_map[f["ord"]] = f2["ord"]
|
||||||
return map
|
return template_map
|
||||||
|
|
||||||
def getFieldMap(self):
|
def getFieldMap(self):
|
||||||
return self.getTemplateMap(
|
return self.getTemplateMap(
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# Copyright: Ankitects Pty Ltd and contributors
|
# Copyright: Ankitects Pty Ltd and contributors
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/copyleft/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/copyleft/agpl.html
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
@ -9,8 +10,9 @@ from aqt.utils import restoreGeom, saveGeom
|
|||||||
class TagLimit(QDialog):
|
class TagLimit(QDialog):
|
||||||
def __init__(self, mw, parent):
|
def __init__(self, mw, parent):
|
||||||
QDialog.__init__(self, parent, Qt.Window)
|
QDialog.__init__(self, parent, Qt.Window)
|
||||||
|
self.tags: Union[str, List] = ""
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
self.parent = parent
|
self.parent: Optional[QWidget] = parent
|
||||||
self.deck = self.parent.deck
|
self.deck = self.parent.deck
|
||||||
self.dialog = aqt.forms.taglimit.Ui_Dialog()
|
self.dialog = aqt.forms.taglimit.Ui_Dialog()
|
||||||
self.dialog.setupUi(self)
|
self.dialog.setupUi(self)
|
||||||
|
@ -47,18 +47,18 @@ class LatestVersionFinder(QThread):
|
|||||||
print("update check failed")
|
print("update check failed")
|
||||||
return
|
return
|
||||||
if resp["msg"]:
|
if resp["msg"]:
|
||||||
self.newMsg.emit(resp)
|
self.newMsg.emit(resp) # type: ignore
|
||||||
if resp["ver"]:
|
if resp["ver"]:
|
||||||
self.newVerAvail.emit(resp["ver"])
|
self.newVerAvail.emit(resp["ver"]) # type: ignore
|
||||||
diff = resp["time"] - time.time()
|
diff = resp["time"] - time.time()
|
||||||
if abs(diff) > 300:
|
if abs(diff) > 300:
|
||||||
self.clockIsOff.emit(diff)
|
self.clockIsOff.emit(diff) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def askAndUpdate(mw, ver):
|
def askAndUpdate(mw, ver):
|
||||||
baseStr = _("""<h1>Anki Updated</h1>Anki %s has been released.<br><br>""") % ver
|
baseStr = _("""<h1>Anki Updated</h1>Anki %s has been released.<br><br>""") % ver
|
||||||
msg = QMessageBox(mw)
|
msg = QMessageBox(mw)
|
||||||
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No) # type: ignore
|
||||||
msg.setIcon(QMessageBox.Information)
|
msg.setIcon(QMessageBox.Information)
|
||||||
msg.setText(baseStr + _("Would you like to download it now?"))
|
msg.setText(baseStr + _("Would you like to download it now?"))
|
||||||
button = QPushButton(_("Ignore this update"))
|
button = QPushButton(_("Ignore this update"))
|
||||||
|
@ -76,3 +76,9 @@ check_untyped_defs=true
|
|||||||
check_untyped_defs=true
|
check_untyped_defs=true
|
||||||
[mypy-aqt.deckconf]
|
[mypy-aqt.deckconf]
|
||||||
check_untyped_defs=true
|
check_untyped_defs=true
|
||||||
|
[mypy-aqt.taglimit]
|
||||||
|
check_untyped_defs=true
|
||||||
|
[mypy-aqt.update]
|
||||||
|
check_untyped_defs=true
|
||||||
|
[mypy-aqt.browser]
|
||||||
|
check_untyped_defs=true
|
||||||
|
Loading…
Reference in New Issue
Block a user