From 29f714d9739d6d007b9ce2ba268bf64336550159 Mon Sep 17 00:00:00 2001 From: Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com> Date: Fri, 15 Nov 2024 05:24:50 -0800 Subject: [PATCH] Enable strict_optional for aqt/mediasync, package, progress (#3577) * Enable strict_optional for mediasync * Fix mypy errors * Enable strict_optional for package * Fix mypy errors * Enable strict_optional for progress * Fix mypy errors --- .mypy.ini | 6 ++++++ qt/aqt/mediasync.py | 2 +- qt/aqt/package.py | 2 +- qt/aqt/progress.py | 13 ++++++++++--- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.mypy.ini b/.mypy.ini index e34bccf45..da56d9d62 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -98,6 +98,12 @@ strict_optional = True strict_optional = True [mypy-aqt.webview] strict_optional = True +[mypy-aqt.mediasync] +strict_optional = True +[mypy-aqt.package] +strict_optional = True +[mypy-aqt.progress] +strict_optional = True [mypy-anki.scheduler.base] strict_optional = True [mypy-anki._backend.rsbridge] diff --git a/qt/aqt/mediasync.py b/qt/aqt/mediasync.py index 96054832c..7cfb6d4a7 100644 --- a/qt/aqt/mediasync.py +++ b/qt/aqt/mediasync.py @@ -119,7 +119,7 @@ class MediaSyncer: diag: MediaSyncDialog = aqt.dialogs.open("sync_log", self.mw, self, True) diag.show() - timer: QTimer | None = None + timer: QTimer def check_finished() -> None: if not self.is_syncing(): diff --git a/qt/aqt/package.py b/qt/aqt/package.py index 3f89366a2..f1ee8cd79 100644 --- a/qt/aqt/package.py +++ b/qt/aqt/package.py @@ -41,7 +41,7 @@ def _patch_pkgutil() -> None: def get_data_custom(package: str, resource: str) -> bytes | None: try: module = importlib.import_module(package) - reader = module.__loader__.get_resource_reader(package) # type: ignore[attr-defined] + reader = module.__loader__.get_resource_reader(package) # type: ignore with reader.open_resource(resource) as f: return f.read() except Exception: diff --git a/qt/aqt/progress.py b/qt/aqt/progress.py index 84d23a22e..4d23b33f4 100644 --- a/qt/aqt/progress.py +++ b/qt/aqt/progress.py @@ -216,6 +216,8 @@ class ProgressManager: self._maybeShow() if not self._shown: return + + assert self._win is not None if label: self._win.form.label.setText(label) @@ -290,6 +292,7 @@ class ProgressManager: self._showWin() def _showWin(self) -> None: + assert self._win is not None self._shown = time.monotonic() self._win.show() @@ -297,6 +300,7 @@ class ProgressManager: # if the parent window has been deleted, the progress dialog may have # already been dropped; delete it if it hasn't been if not sip.isdeleted(self._win): + assert self._win is not None self._win.cancel() self._win = None self._shown = 0 @@ -314,6 +318,7 @@ class ProgressManager: def _on_show_timer(self) -> None: if self.mw.app.focusWindow() is None: # if no window is focused (eg app is minimized), defer display + assert self._show_timer is not None self._show_timer.start(10) return @@ -334,7 +339,7 @@ class ProgressManager: class ProgressDialog(QDialog): - def __init__(self, parent: QWidget) -> None: + def __init__(self, parent: QWidget | None) -> None: QDialog.__init__(self, parent) disable_help_button(self) self.form = aqt.forms.progress.Ui_Dialog() @@ -349,14 +354,16 @@ class ProgressDialog(QDialog): self.hide() self.deleteLater() - def closeEvent(self, evt: QCloseEvent) -> None: + def closeEvent(self, evt: QCloseEvent | None) -> None: + assert evt is not None if self._closingDown: evt.accept() else: self.wantCancel = True evt.ignore() - def keyPressEvent(self, evt: QKeyEvent) -> None: + def keyPressEvent(self, evt: QKeyEvent | None) -> None: + assert evt is not None if evt.key() == Qt.Key.Key_Escape: evt.ignore() self.wantCancel = True