Skip to content

Commit

Permalink
Enable strict_optional for aqt/mediasync, package, progress (#3577)
Browse files Browse the repository at this point in the history
* Enable strict_optional for mediasync

* Fix mypy errors

* Enable strict_optional for package

* Fix mypy errors

* Enable strict_optional for progress

* Fix mypy errors
  • Loading branch information
bpnguyen107 authored Nov 15, 2024
1 parent edf59c2 commit 29f714d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion qt/aqt/mediasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def show_diag_until_finished(self, on_finished: Callable[[], None]) -> None:
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():
Expand Down
2 changes: 1 addition & 1 deletion qt/aqt/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 10 additions & 3 deletions qt/aqt/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def update(
self._maybeShow()
if not self._shown:
return

assert self._win is not None
if label:
self._win.form.label.setText(label)

Expand Down Expand Up @@ -290,13 +292,15 @@ def _maybeShow(self) -> None:
self._showWin()

def _showWin(self) -> None:
assert self._win is not None
self._shown = time.monotonic()
self._win.show()

def _closeWin(self) -> None:
# 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
Expand All @@ -314,6 +318,7 @@ def busy(self) -> int:
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

Expand All @@ -334,7 +339,7 @@ def set_title(self, title: str) -> None:


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()
Expand All @@ -349,14 +354,16 @@ def cancel(self) -> None:
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
Expand Down

0 comments on commit 29f714d

Please sign in to comment.