mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 08:22:24 -04:00
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
This commit is contained in:
parent
edf59c2bb2
commit
29f714d973
4 changed files with 18 additions and 5 deletions
|
@ -98,6 +98,12 @@ strict_optional = True
|
||||||
strict_optional = True
|
strict_optional = True
|
||||||
[mypy-aqt.webview]
|
[mypy-aqt.webview]
|
||||||
strict_optional = True
|
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]
|
[mypy-anki.scheduler.base]
|
||||||
strict_optional = True
|
strict_optional = True
|
||||||
[mypy-anki._backend.rsbridge]
|
[mypy-anki._backend.rsbridge]
|
||||||
|
|
|
@ -119,7 +119,7 @@ class MediaSyncer:
|
||||||
diag: MediaSyncDialog = aqt.dialogs.open("sync_log", self.mw, self, True)
|
diag: MediaSyncDialog = aqt.dialogs.open("sync_log", self.mw, self, True)
|
||||||
diag.show()
|
diag.show()
|
||||||
|
|
||||||
timer: QTimer | None = None
|
timer: QTimer
|
||||||
|
|
||||||
def check_finished() -> None:
|
def check_finished() -> None:
|
||||||
if not self.is_syncing():
|
if not self.is_syncing():
|
||||||
|
|
|
@ -41,7 +41,7 @@ def _patch_pkgutil() -> None:
|
||||||
def get_data_custom(package: str, resource: str) -> bytes | None:
|
def get_data_custom(package: str, resource: str) -> bytes | None:
|
||||||
try:
|
try:
|
||||||
module = importlib.import_module(package)
|
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:
|
with reader.open_resource(resource) as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
@ -216,6 +216,8 @@ class ProgressManager:
|
||||||
self._maybeShow()
|
self._maybeShow()
|
||||||
if not self._shown:
|
if not self._shown:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
assert self._win is not None
|
||||||
if label:
|
if label:
|
||||||
self._win.form.label.setText(label)
|
self._win.form.label.setText(label)
|
||||||
|
|
||||||
|
@ -290,6 +292,7 @@ class ProgressManager:
|
||||||
self._showWin()
|
self._showWin()
|
||||||
|
|
||||||
def _showWin(self) -> None:
|
def _showWin(self) -> None:
|
||||||
|
assert self._win is not None
|
||||||
self._shown = time.monotonic()
|
self._shown = time.monotonic()
|
||||||
self._win.show()
|
self._win.show()
|
||||||
|
|
||||||
|
@ -297,6 +300,7 @@ class ProgressManager:
|
||||||
# if the parent window has been deleted, the progress dialog may have
|
# if the parent window has been deleted, the progress dialog may have
|
||||||
# already been dropped; delete it if it hasn't been
|
# already been dropped; delete it if it hasn't been
|
||||||
if not sip.isdeleted(self._win):
|
if not sip.isdeleted(self._win):
|
||||||
|
assert self._win is not None
|
||||||
self._win.cancel()
|
self._win.cancel()
|
||||||
self._win = None
|
self._win = None
|
||||||
self._shown = 0
|
self._shown = 0
|
||||||
|
@ -314,6 +318,7 @@ class ProgressManager:
|
||||||
def _on_show_timer(self) -> None:
|
def _on_show_timer(self) -> None:
|
||||||
if self.mw.app.focusWindow() is None:
|
if self.mw.app.focusWindow() is None:
|
||||||
# if no window is focused (eg app is minimized), defer display
|
# if no window is focused (eg app is minimized), defer display
|
||||||
|
assert self._show_timer is not None
|
||||||
self._show_timer.start(10)
|
self._show_timer.start(10)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -334,7 +339,7 @@ class ProgressManager:
|
||||||
|
|
||||||
|
|
||||||
class ProgressDialog(QDialog):
|
class ProgressDialog(QDialog):
|
||||||
def __init__(self, parent: QWidget) -> None:
|
def __init__(self, parent: QWidget | None) -> None:
|
||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self, parent)
|
||||||
disable_help_button(self)
|
disable_help_button(self)
|
||||||
self.form = aqt.forms.progress.Ui_Dialog()
|
self.form = aqt.forms.progress.Ui_Dialog()
|
||||||
|
@ -349,14 +354,16 @@ class ProgressDialog(QDialog):
|
||||||
self.hide()
|
self.hide()
|
||||||
self.deleteLater()
|
self.deleteLater()
|
||||||
|
|
||||||
def closeEvent(self, evt: QCloseEvent) -> None:
|
def closeEvent(self, evt: QCloseEvent | None) -> None:
|
||||||
|
assert evt is not None
|
||||||
if self._closingDown:
|
if self._closingDown:
|
||||||
evt.accept()
|
evt.accept()
|
||||||
else:
|
else:
|
||||||
self.wantCancel = True
|
self.wantCancel = True
|
||||||
evt.ignore()
|
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:
|
if evt.key() == Qt.Key.Key_Escape:
|
||||||
evt.ignore()
|
evt.ignore()
|
||||||
self.wantCancel = True
|
self.wantCancel = True
|
||||||
|
|
Loading…
Reference in a new issue