Enable strict_optional for aqt/deckoptions, editcurrent, filtered_deck (#3556)

* Enable strict_optional for filtered_deck

* Fix mypy errors

* Enable strict_optional for editcurrent

* Fix mypy errors

* Enable strict_optional for deckoptions

* Fix mypy errors
This commit is contained in:
Ben Nguyen 2024-11-06 14:33:41 -08:00 committed by GitHub
parent 11d2b91268
commit ac731624e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 9 deletions

View file

@ -68,6 +68,12 @@ strict_optional = True
strict_optional = True
[mypy-aqt.fields]
strict_optional = True
[mypy-aqt.filtered_deck]
strict_optional = True
[mypy-aqt.editcurrent]
strict_optional = True
[mypy-aqt.deckoptions]
strict_optional = True
[mypy-anki.scheduler.base]
strict_optional = True
[mypy-anki._backend.rsbridge]

View file

@ -67,9 +67,10 @@ class DeckOptionsDialog(QDialog):
elif cmd == "_close":
self._close()
def closeEvent(self, evt: QCloseEvent) -> None:
def closeEvent(self, evt: QCloseEvent | None) -> None:
if self._close_event_has_cleaned_up:
return super().closeEvent(evt)
assert evt is not None
evt.ignore()
self.check_pending_changes()
@ -97,7 +98,7 @@ class DeckOptionsDialog(QDialog):
def reject(self) -> None:
self.mw.col.set_wants_abort()
self.web.cleanup()
self.web = None
self.web = None # type: ignore
saveGeom(self, self.TITLE)
QDialog.reject(self)
@ -112,10 +113,14 @@ def confirm_deck_then_display_options(active_card: Card | None = None) -> None:
decks = [aqt.mw.col.decks.current()]
if card := active_card:
if card.odid and card.odid != decks[0]["id"]:
decks.append(aqt.mw.col.decks.get(card.odid))
deck = aqt.mw.col.decks.get(card.odid)
assert deck is not None
decks.append(deck)
if not any(d["id"] == card.did for d in decks):
decks.append(aqt.mw.col.decks.get(card.did))
deck = aqt.mw.col.decks.get(card.did)
assert deck is not None
decks.append(deck)
if len(decks) == 1:
display_options_for_deck(decks[0])
@ -142,13 +147,16 @@ def _deck_prompt_dialog(decks: list[DeckDict]) -> None:
def display_options_for_deck_id(deck_id: DeckId) -> None:
display_options_for_deck(aqt.mw.col.decks.get(deck_id))
deck = aqt.mw.col.decks.get(deck_id)
assert deck is not None
display_options_for_deck(deck)
def display_options_for_deck(deck: DeckDict) -> None:
if not deck["dyn"]:
if KeyboardModifiersPressed().shift or not aqt.mw.col.v3_scheduler():
deck_legacy = aqt.mw.col.decks.get(DeckId(deck["id"]))
assert deck_legacy is not None
aqt.deckconf.DeckConf(aqt.mw, deck_legacy)
else:
DeckOptionsDialog(aqt.mw, deck)

View file

@ -28,10 +28,12 @@ class EditCurrent(QMainWindow):
self,
editor_mode=aqt.editor.EditorMode.EDIT_CURRENT,
)
assert self.mw.reviewer.card is not None
self.editor.card = self.mw.reviewer.card
self.editor.set_note(self.mw.reviewer.card.note(), focusTo=0)
restoreGeom(self, "editcurrent")
close_button = self.form.buttonBox.button(QDialogButtonBox.StandardButton.Close)
assert close_button is not None
close_button.setShortcut(QKeySequence("Ctrl+Return"))
# qt5.14+ doesn't handle numpad enter on Windows
self.compat_add_shorcut = QShortcut(QKeySequence("Ctrl+Enter"), self)
@ -46,6 +48,7 @@ class EditCurrent(QMainWindow):
# reload note
note = self.editor.note
try:
assert note is not None
note.load()
except NotFoundError:
# note's been deleted
@ -65,7 +68,7 @@ class EditCurrent(QMainWindow):
if card := self.mw.reviewer.card:
self.editor.set_note(card.note())
def closeEvent(self, evt: QCloseEvent) -> None:
def closeEvent(self, evt: QCloseEvent | None) -> None:
self.editor.call_after_note_saved(self.cleanup)
def _saveAndClose(self) -> None:

View file

@ -130,9 +130,10 @@ class FilteredDeckConfigDialog(QDialog):
build_label = tr.actions_rebuild()
else:
build_label = tr.decks_build()
self.form.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setText(
build_label
)
ok_button = self.form.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
assert ok_button is not None
ok_button.setText(build_label)
form.resched.setChecked(config.reschedule)
self._onReschedToggled(0)