From c4f9bf62fded2aff9c42a6b5a5b4465f81daf55e Mon Sep 17 00:00:00 2001 From: Fabian Wood Date: Thu, 30 Jul 2020 15:25:25 +1000 Subject: [PATCH] added typehints to modelchooser, updated mypy.ini --- qt/aqt/modelchooser.py | 24 ++++++++++++------------ qt/mypy.ini | 2 ++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/qt/aqt/modelchooser.py b/qt/aqt/modelchooser.py index fb50f3e02..6e67d93af 100644 --- a/qt/aqt/modelchooser.py +++ b/qt/aqt/modelchooser.py @@ -3,13 +3,13 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html from anki.lang import _ -from aqt import gui_hooks +from aqt import AnkiQt, gui_hooks from aqt.qt import * from aqt.utils import shortcut class ModelChooser(QHBoxLayout): - def __init__(self, mw, widget, label=True) -> None: + def __init__(self, mw: AnkiQt, widget: QWidget, label: bool = True) -> None: QHBoxLayout.__init__(self) self.widget = widget # type: ignore self.mw = mw @@ -19,9 +19,9 @@ class ModelChooser(QHBoxLayout): self.setSpacing(8) self.setupModels() gui_hooks.state_did_reset.append(self.onReset) - self.widget.setLayout(self) # type: ignore + self.widget.setLayout(self) - def setupModels(self): + def setupModels(self) -> None: if self.label: self.modelLabel = QLabel(_("Type")) self.addWidget(self.modelLabel) @@ -29,7 +29,7 @@ class ModelChooser(QHBoxLayout): self.models = QPushButton() # self.models.setStyleSheet("* { text-align: left; }") self.models.setToolTip(shortcut(_("Change Note Type (Ctrl+N)"))) - QShortcut(QKeySequence("Ctrl+N"), self.widget, activated=self.onModelChange) + QShortcut(QKeySequence("Ctrl+N"), self.widget, activated=self.onModelChange) # type: ignore self.models.setAutoDefault(False) self.addWidget(self.models) qconnect(self.models.clicked, self.onModelChange) @@ -41,16 +41,16 @@ class ModelChooser(QHBoxLayout): def cleanup(self) -> None: gui_hooks.state_did_reset.remove(self.onReset) - def onReset(self): + def onReset(self) -> None: self.updateModels() - def show(self): - self.widget.show() + def show(self) -> None: + self.widget.show() # type: ignore - def hide(self): - self.widget.hide() + def hide(self) -> None: + self.widget.hide() # type: ignore - def onEdit(self): + def onEdit(self) -> None: import aqt.models aqt.models.Models(self.mw, self.widget) @@ -87,5 +87,5 @@ class ModelChooser(QHBoxLayout): gui_hooks.current_note_type_did_change(current) self.mw.reset() - def updateModels(self): + def updateModels(self) -> None: self.models.setText(self.deck.models.current()["name"]) diff --git a/qt/mypy.ini b/qt/mypy.ini index d5edf0d1c..9adcb3d1b 100644 --- a/qt/mypy.ini +++ b/qt/mypy.ini @@ -86,3 +86,5 @@ check_untyped_defs=true check_untyped_defs=true [mypy-aqt.exporting] check_untyped_defs=true +[mypy-aqt.modelchooser] +check_untyped_defs=true