From b3b4d23f9d8942c883081bb9fdd16cf3a00aaebc Mon Sep 17 00:00:00 2001 From: Matt Krump <1036969+mkrump@users.noreply.github.com> Date: Thu, 23 Jul 2020 20:32:57 -0600 Subject: [PATCH 1/6] Add type hints for apt.deckconf * Add type hints for apt.deckconf * Turn on check_untyped_defs for apt.deckconf --- qt/aqt/deckconf.py | 12 +++++++----- qt/mypy.ini | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/qt/aqt/deckconf.py b/qt/aqt/deckconf.py index cb8c37a4f..cd62042af 100644 --- a/qt/aqt/deckconf.py +++ b/qt/aqt/deckconf.py @@ -3,7 +3,9 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html from operator import itemgetter -from typing import Dict, Union +from typing import Any, Dict + +from PyQt5.QtWidgets import QLineEdit import aqt from anki.consts import NEW_CARDS_RANDOM @@ -257,14 +259,14 @@ class DeckConf(QDialog): # Saving ################################################## - def updateList(self, conf, key, w, minSize=1): + def updateList(self, conf: Any, key: str, w: QLineEdit, minSize: int = 1) -> None: items = str(w.text()).split(" ") ret = [] - for i in items: - if not i: + for item in items: + if not item: continue try: - i = float(i) + i = float(item) assert i > 0 if i == int(i): i = int(i) diff --git a/qt/mypy.ini b/qt/mypy.ini index 063e7abc8..4a13f5e7d 100644 --- a/qt/mypy.ini +++ b/qt/mypy.ini @@ -68,3 +68,5 @@ check_untyped_defs=true check_untyped_defs=true [mypy-aqt.dyndeckconf] check_untyped_defs=true +[mypy-aqt.deckconf] +check_untyped_defs=true From 0c640d13ba96e7f063252671b6ead66cc10d3981 Mon Sep 17 00:00:00 2001 From: Matt Krump <1036969+mkrump@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:35:49 -0600 Subject: [PATCH 2/6] Move name in Contributors so contrib.sh recognizes change of email --- CONTRIBUTORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 2d3d27f4f..b22118f34 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -42,8 +42,8 @@ kenden Nickolay Yudin neitrinoweb Andreas Reis -Alexander Presnyakov Matt Krump +Alexander Presnyakov ******************** The text of the 3 clause BSD license follows: From b0dd85f87e81e40714800de2c05de39b11440f18 Mon Sep 17 00:00:00 2001 From: Matt Krump <1036969+mkrump@users.noreply.github.com> Date: Fri, 24 Jul 2020 10:59:45 -0600 Subject: [PATCH 3/6] Add type hints to aqt.models * Add type hints to aqt.models * Turn on type checking for aqt.models --- qt/aqt/models.py | 6 +++--- qt/mypy.ini | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/qt/aqt/models.py b/qt/aqt/models.py index f7b5afcb4..170a2e2ed 100644 --- a/qt/aqt/models.py +++ b/qt/aqt/models.py @@ -6,6 +6,7 @@ from typing import List, Optional import aqt.clayout from anki import stdmodels +from anki.backend_pb2 import NoteTypeNameIDUseCount from anki.lang import _, ngettext from anki.models import NoteType from anki.notes import Note @@ -88,7 +89,7 @@ class Models(QDialog): self.mw.taskman.with_progress(save, on_done, self) - def updateModelsList(self, notetypes): + def updateModelsList(self, notetypes: List[NoteTypeNameIDUseCount]) -> None: row = self.form.modelsList.currentRow() if row == -1: row = 0 @@ -96,8 +97,7 @@ class Models(QDialog): self.models = notetypes for m in self.models: - mUse = m.use_count - mUse = ngettext("%d note", "%d notes", mUse) % mUse + mUse = ngettext("%d note", "%d notes", m.use_count) % m.use_count item = QListWidgetItem("%s [%s]" % (m.name, mUse)) self.form.modelsList.addItem(item) self.form.modelsList.setCurrentRow(row) diff --git a/qt/mypy.ini b/qt/mypy.ini index 063e7abc8..a39a1de9c 100644 --- a/qt/mypy.ini +++ b/qt/mypy.ini @@ -68,3 +68,5 @@ check_untyped_defs=true check_untyped_defs=true [mypy-aqt.dyndeckconf] check_untyped_defs=true +[mypy-aqt.models] +check_untyped_defs=true From 186f1c77208f1e585e1c698a949aaaa1ee828fb8 Mon Sep 17 00:00:00 2001 From: Matt Krump <1036969+mkrump@users.noreply.github.com> Date: Fri, 24 Jul 2020 11:19:40 -0600 Subject: [PATCH 4/6] Add type hints to errors * Add type hints to errors * Turn on type checking for aqt.errors --- qt/aqt/errors.py | 2 +- qt/mypy.ini | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/qt/aqt/errors.py b/qt/aqt/errors.py index de73435d4..b6cbc2eb6 100644 --- a/qt/aqt/errors.py +++ b/qt/aqt/errors.py @@ -54,7 +54,7 @@ class ErrorHandler(QObject): def setTimer(self): # we can't create a timer from a different thread, so we post a # message to the object on the main thread - self.errorTimer.emit() + self.errorTimer.emit() # type: ignore def _setTimer(self): if not self.timer: diff --git a/qt/mypy.ini b/qt/mypy.ini index a39a1de9c..b6203b753 100644 --- a/qt/mypy.ini +++ b/qt/mypy.ini @@ -70,3 +70,5 @@ check_untyped_defs=true check_untyped_defs=true [mypy-aqt.models] check_untyped_defs=true +[mypy-aqt.errors] +check_untyped_defs=true From a844a8b0c505079dcff62b0785a449378b5078e8 Mon Sep 17 00:00:00 2001 From: Matt Krump <1036969+mkrump@users.noreply.github.com> Date: Fri, 24 Jul 2020 12:38:34 -0600 Subject: [PATCH 5/6] Add type hints to importing * Add type hints to importing * Turn on type checking for aqt.importing --- qt/aqt/importing.py | 7 +++++-- qt/mypy.ini | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/qt/aqt/importing.py b/qt/aqt/importing.py index ce217287a..257fd4bfe 100644 --- a/qt/aqt/importing.py +++ b/qt/aqt/importing.py @@ -10,6 +10,7 @@ import traceback import unicodedata import zipfile from concurrent.futures import Future +from typing import Optional import anki.importing as importing import aqt.deckchooser @@ -55,7 +56,7 @@ class ChangeMap(QDialog): self.frm.fields.setCurrentRow(n) else: self.frm.fields.setCurrentRow(n + 1) - self.field = None + self.field: Optional[str] = None def getField(self): self.exec_() @@ -488,7 +489,9 @@ def _replaceWithApkg(mw, filename, backup): colname = "collection.anki2" with z.open(colname) as source, open(mw.pm.collectionPath(), "wb") as target: - shutil.copyfileobj(source, target) + # ignore appears related to https://github.com/python/typeshed/issues/4349 + # see if can turn off once issue fix is merged in + shutil.copyfileobj(source, target) # type: ignore d = os.path.join(mw.pm.profileFolder(), "collection.media") for n, (cStr, file) in enumerate( diff --git a/qt/mypy.ini b/qt/mypy.ini index b6203b753..44468f7aa 100644 --- a/qt/mypy.ini +++ b/qt/mypy.ini @@ -72,3 +72,5 @@ check_untyped_defs=true check_untyped_defs=true [mypy-aqt.errors] check_untyped_defs=true +[mypy-aqt.importing] +check_untyped_defs=true From 0bd793b30a16456797873c17ec51fde6717d9283 Mon Sep 17 00:00:00 2001 From: Matt Krump <1036969+mkrump@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:35:49 -0600 Subject: [PATCH 6/6] Move name in Contributors so contrib.sh recognizes change of email --- CONTRIBUTORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 2d3d27f4f..b22118f34 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -42,8 +42,8 @@ kenden Nickolay Yudin neitrinoweb Andreas Reis -Alexander Presnyakov Matt Krump +Alexander Presnyakov ******************** The text of the 3 clause BSD license follows: