From db7f128b832bc39be1f26bf6a5d40818c2c395cd Mon Sep 17 00:00:00 2001 From: Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com> Date: Tue, 12 Nov 2024 08:47:04 -0800 Subject: [PATCH] Enable strict_optional for aqt/mediacheck, theme, toolbar (#3569) * Enable strict_optional for mediacheck * Fix mypy errors * Enable strict_optional for theme * Fix mypy errors * Enable strict_optional for toolbar * Fix mypy errors --- .mypy.ini | 6 ++++++ qt/aqt/mediacheck.py | 3 +++ qt/aqt/theme.py | 4 +++- qt/aqt/toolbar.py | 6 ++++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.mypy.ini b/.mypy.ini index da2daea54..729186b0a 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -86,6 +86,12 @@ strict_optional = True strict_optional = True [mypy-aqt.flags] strict_optional = True +[mypy-aqt.mediacheck] +strict_optional = True +[mypy-aqt.theme] +strict_optional = True +[mypy-aqt.toolbar] +strict_optional = True [mypy-anki.scheduler.base] strict_optional = True [mypy-anki._backend.rsbridge] diff --git a/qt/aqt/mediacheck.py b/qt/aqt/mediacheck.py index ec47550d8..71ab5a07d 100644 --- a/qt/aqt/mediacheck.py +++ b/qt/aqt/mediacheck.py @@ -80,6 +80,7 @@ class MediaChecker: label = progress.media_check try: + assert self.progress_dialog is not None if self.progress_dialog.wantCancel: self.mw.col.set_wants_abort() except AttributeError: @@ -165,6 +166,7 @@ class MediaChecker: def _on_render_latex(self) -> None: self.progress_dialog = self.mw.progress.start() + assert self.progress_dialog is not None try: out = self.mw.col.media.render_all_latex(self._on_render_latex_progress) if self.progress_dialog.wantCancel: @@ -181,6 +183,7 @@ class MediaChecker: tooltip(tr.media_check_all_latex_rendered()) def _on_render_latex_progress(self, count: int) -> bool: + assert self.progress_dialog is not None if self.progress_dialog.wantCancel: return False diff --git a/qt/aqt/theme.py b/qt/aqt/theme.py index 735f720c4..c43cf8f86 100644 --- a/qt/aqt/theme.py +++ b/qt/aqt/theme.py @@ -231,7 +231,9 @@ class ThemeManager: self._current_widget_style = new_widget_style app = aqt.mw.app if not self._default_style: - self._default_style = app.style().objectName() + style = app.style() + assert style is not None + self._default_style = style.objectName() self._apply_palette(app) self._apply_style(app) gui_hooks.theme_did_change() diff --git a/qt/aqt/toolbar.py b/qt/aqt/toolbar.py index 7313f2a39..2ae8e6d72 100644 --- a/qt/aqt/toolbar.py +++ b/qt/aqt/toolbar.py @@ -37,7 +37,9 @@ class BottomToolbar: class ToolbarWebView(AnkiWebView): hide_condition: Callable[..., bool] - def __init__(self, mw: aqt.AnkiQt, kind: AnkiWebViewKind | None = None) -> None: + def __init__( + self, mw: aqt.AnkiQt, kind: AnkiWebViewKind = AnkiWebViewKind.DEFAULT + ) -> None: AnkiWebView.__init__(self, mw, kind=kind) self.mw = mw self.setFocusPolicy(Qt.FocusPolicy.WheelFocus) @@ -172,7 +174,7 @@ class TopWebView(ToolbarWebView): self.eval("""document.body.style.setProperty("min-height", "0px"); """) self.evalWithCallback("document.documentElement.offsetHeight", self._onHeight) - def resizeEvent(self, event: QResizeEvent) -> None: + def resizeEvent(self, event: QResizeEvent | None) -> None: super().resizeEvent(event) self.mw.web.evalWithCallback(