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
This commit is contained in:
Ben Nguyen 2024-11-12 08:47:04 -08:00 committed by GitHub
parent 763712c696
commit db7f128b83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 3 deletions

View file

@ -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]

View file

@ -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

View file

@ -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()

View file

@ -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(