From cbeb47f8df5967481b4c78fd13ad0575c7b24542 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 25 Feb 2020 22:52:03 -0500 Subject: [PATCH 1/3] Improve mypy config - Make mypy stricter - Warn for unnecessary workarounds --- pylib/anki/collection.py | 2 +- pylib/anki/template.py | 2 +- pylib/mypy.ini | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index cfa2c3cdb..34946900b 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -183,7 +183,7 @@ class _Collection: select crt, mod, scm, dty, usn, ls, conf, models, decks, dconf, tags from col""" ) - self.conf = json.loads(conf) # type: ignore + self.conf = json.loads(conf) self.models.load(models) self.decks.load(decks, dconf) self.tags.load(tags) diff --git a/pylib/anki/template.py b/pylib/anki/template.py index 4687c2ed1..e122b5764 100644 --- a/pylib/anki/template.py +++ b/pylib/anki/template.py @@ -152,7 +152,7 @@ def fields_for_rendering(col: anki.storage._Collection, card: Card, note: Note): fields["Type"] = card.note_type()["name"] fields["Deck"] = col.decks.name(card.odid or card.did) fields["Subdeck"] = fields["Deck"].split("::")[-1] - fields["Card"] = card.template()["name"] # type: ignore + fields["Card"] = card.template()["name"] flag = card.userFlag() fields["CardFlag"] = flag and f"flag{flag}" or "" fields["c%d" % (card.ord + 1)] = "1" diff --git a/pylib/mypy.ini b/pylib/mypy.ini index 936704c56..4215061bb 100644 --- a/pylib/mypy.ini +++ b/pylib/mypy.ini @@ -4,6 +4,10 @@ pretty = false no_strict_optional = true show_error_codes = true check_untyped_defs = true +disallow_untyped_decorators = True +warn_redundant_casts = True +warn_unused_configs = True +warn_unused_ignores = True [mypy-win32file] ignore_missing_imports = True From 22ec886e07a71fc05310f4a73a48160a470cce86 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 25 Feb 2020 23:29:04 -0500 Subject: [PATCH 2/3] Add to contributors --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index e1a5518c4..ee5253fd3 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -26,6 +26,7 @@ Arthur Milchior Yngve Hoiseth Ijgnd Yoonchae Lee +Alan Du ******************** From a63c9e5a9a1fce5c404cd8b4851d1cba4f08728e Mon Sep 17 00:00:00 2001 From: Alan Du Date: Wed, 26 Feb 2020 22:27:58 -0500 Subject: [PATCH 3/3] Apply mypy improvements to aqt --- qt/aqt/addons.py | 2 +- qt/aqt/main.py | 2 +- qt/aqt/mediasync.py | 4 ++-- qt/aqt/profiles.py | 2 +- qt/aqt/taskman.py | 2 +- qt/i18n/po | 1 + qt/mypy.ini | 4 ++++ 7 files changed, 11 insertions(+), 6 deletions(-) create mode 160000 qt/i18n/po diff --git a/qt/aqt/addons.py b/qt/aqt/addons.py index 910d23cd0..08dbc673c 100644 --- a/qt/aqt/addons.py +++ b/qt/aqt/addons.py @@ -1031,7 +1031,7 @@ class DownloaderInstaller(QObject): self.client = client self.progressSignal.connect(self._progress_callback) # type: ignore - def bg_thread_progress(up, down): + def bg_thread_progress(up, down) -> None: self.progressSignal.emit(up, down) # type: ignore self.client.progress_hook = bg_thread_progress diff --git a/qt/aqt/main.py b/qt/aqt/main.py index 182c5de8a..bfd066216 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -1515,7 +1515,7 @@ Please ensure a profile is open and Anki is not busy, then try again.""" # ensure gc runs in main thread def setupDialogGC(self, obj: Any) -> None: - obj.finished.connect(lambda: self.gcWindow(obj)) # type: ignore + obj.finished.connect(lambda: self.gcWindow(obj)) def gcWindow(self, obj: Any) -> None: obj.deleteLater() diff --git a/qt/aqt/mediasync.py b/qt/aqt/mediasync.py index f0b46647a..116541972 100644 --- a/qt/aqt/mediasync.py +++ b/qt/aqt/mediasync.py @@ -115,8 +115,8 @@ class MediaSyncer: def is_syncing(self) -> bool: return self._syncing - def _on_start_stop(self, running: bool): - self.mw.toolbar.set_sync_active(running) # type: ignore + def _on_start_stop(self, running: bool) -> None: + self.mw.toolbar.set_sync_active(running) def show_sync_log(self): aqt.dialogs.open("sync_log", self.mw, self) diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index ba605f401..d6f63d425 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -137,7 +137,7 @@ class ProfileManager: def find_class(self, module, name): if module == "PyQt5.sip": try: - import PyQt5.sip # type: ignore # pylint: disable=unused-import + import PyQt5.sip # pylint: disable=unused-import except: # use old sip location module = "sip" diff --git a/qt/aqt/taskman.py b/qt/aqt/taskman.py index be305b7b5..d3cb257b4 100644 --- a/qt/aqt/taskman.py +++ b/qt/aqt/taskman.py @@ -18,7 +18,7 @@ Closure = Callable[[], None] class TaskManager(QObject): _closures_pending = pyqtSignal() - def __init__(self): + def __init__(self) -> None: QObject.__init__(self) self._executor = ThreadPoolExecutor() self._closures: List[Closure] = [] diff --git a/qt/i18n/po b/qt/i18n/po new file mode 160000 index 000000000..785000d3b --- /dev/null +++ b/qt/i18n/po @@ -0,0 +1 @@ +Subproject commit 785000d3bd0ee43f79c784b1ebf4dec725eb3cee diff --git a/qt/mypy.ini b/qt/mypy.ini index cfb88fea8..5d5a5ca40 100644 --- a/qt/mypy.ini +++ b/qt/mypy.ini @@ -3,6 +3,10 @@ python_version = 3.7 pretty = true no_strict_optional = true show_error_codes = true +disallow_untyped_decorators = True +warn_redundant_casts = True +warn_unused_configs = True +warn_unused_ignores = True [mypy-win32file] ignore_missing_imports = True