mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Enable strict_optional for aqt/clayout, changenotetype, fields (#3544)
* Enable strict_optional for clayout * Fix mypy errors * Enable strict_optional for changenotetype * Fix mypy errors * Enable strict_optional for fields * Fix mypy errors
This commit is contained in:
parent
a25edecc88
commit
8b84583433
4 changed files with 44 additions and 14 deletions
|
@ -62,6 +62,12 @@ strict_optional = True
|
||||||
strict_optional = True
|
strict_optional = True
|
||||||
[mypy-aqt.mediasrv]
|
[mypy-aqt.mediasrv]
|
||||||
strict_optional = True
|
strict_optional = True
|
||||||
|
[mypy-aqt.changenotetype]
|
||||||
|
strict_optional = True
|
||||||
|
[mypy-aqt.clayout]
|
||||||
|
strict_optional = True
|
||||||
|
[mypy-aqt.fields]
|
||||||
|
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]
|
||||||
|
|
|
@ -63,7 +63,7 @@ class ChangeNotetypeDialog(QDialog):
|
||||||
|
|
||||||
def reject(self) -> None:
|
def reject(self) -> None:
|
||||||
self.web.cleanup()
|
self.web.cleanup()
|
||||||
self.web = None
|
self.web = None # type: ignore
|
||||||
saveGeom(self, self.TITLE)
|
saveGeom(self, self.TITLE)
|
||||||
QDialog.reject(self)
|
QDialog.reject(self)
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,9 @@ class CardLayout(QDialog):
|
||||||
self.ord = ord
|
self.ord = ord
|
||||||
self.col = self.mw.col.weakref()
|
self.col = self.mw.col.weakref()
|
||||||
self.mm = self.mw.col.models
|
self.mm = self.mw.col.models
|
||||||
self.model = note.note_type()
|
note_type = note.note_type()
|
||||||
|
assert note_type is not None
|
||||||
|
self.model = note_type
|
||||||
self.templates = self.model["tmpls"]
|
self.templates = self.model["tmpls"]
|
||||||
self.fill_empty_action_toggled = fill_empty
|
self.fill_empty_action_toggled = fill_empty
|
||||||
self.night_mode_is_enabled = theme_manager.night_mode
|
self.night_mode_is_enabled = theme_manager.night_mode
|
||||||
|
@ -404,6 +406,7 @@ class CardLayout(QDialog):
|
||||||
m = QMenu(self)
|
m = QMenu(self)
|
||||||
|
|
||||||
a = m.addAction(tr.card_templates_fill_empty())
|
a = m.addAction(tr.card_templates_fill_empty())
|
||||||
|
assert a is not None
|
||||||
a.setCheckable(True)
|
a.setCheckable(True)
|
||||||
a.setChecked(self.fill_empty_action_toggled)
|
a.setChecked(self.fill_empty_action_toggled)
|
||||||
qconnect(a.triggered, self.on_fill_empty_action_toggled)
|
qconnect(a.triggered, self.on_fill_empty_action_toggled)
|
||||||
|
@ -411,11 +414,13 @@ class CardLayout(QDialog):
|
||||||
a.setVisible(False)
|
a.setVisible(False)
|
||||||
|
|
||||||
a = m.addAction(tr.card_templates_night_mode())
|
a = m.addAction(tr.card_templates_night_mode())
|
||||||
|
assert a is not None
|
||||||
a.setCheckable(True)
|
a.setCheckable(True)
|
||||||
a.setChecked(self.night_mode_is_enabled)
|
a.setChecked(self.night_mode_is_enabled)
|
||||||
qconnect(a.triggered, self.on_night_mode_action_toggled)
|
qconnect(a.triggered, self.on_night_mode_action_toggled)
|
||||||
|
|
||||||
a = m.addAction(tr.card_templates_add_mobile_class())
|
a = m.addAction(tr.card_templates_add_mobile_class())
|
||||||
|
assert a is not None
|
||||||
a.setCheckable(True)
|
a.setCheckable(True)
|
||||||
a.setChecked(self.mobile_emulation_enabled)
|
a.setChecked(self.mobile_emulation_enabled)
|
||||||
qconnect(a.toggled, self.on_mobile_class_action_toggled)
|
qconnect(a.toggled, self.on_mobile_class_action_toggled)
|
||||||
|
@ -754,6 +759,7 @@ class CardLayout(QDialog):
|
||||||
a = m.addAction(
|
a = m.addAction(
|
||||||
tr.actions_with_ellipsis(action=tr.card_templates_restore_to_default())
|
tr.actions_with_ellipsis(action=tr.card_templates_restore_to_default())
|
||||||
)
|
)
|
||||||
|
assert a is not None
|
||||||
qconnect(
|
qconnect(
|
||||||
a.triggered,
|
a.triggered,
|
||||||
lambda: self.on_restore_to_default(), # pylint: disable=unnecessary-lambda
|
lambda: self.on_restore_to_default(), # pylint: disable=unnecessary-lambda
|
||||||
|
@ -761,15 +767,19 @@ class CardLayout(QDialog):
|
||||||
|
|
||||||
if not self._isCloze():
|
if not self._isCloze():
|
||||||
a = m.addAction(tr.card_templates_add_card_type())
|
a = m.addAction(tr.card_templates_add_card_type())
|
||||||
|
assert a is not None
|
||||||
qconnect(a.triggered, self.onAddCard)
|
qconnect(a.triggered, self.onAddCard)
|
||||||
|
|
||||||
a = m.addAction(tr.card_templates_remove_card_type())
|
a = m.addAction(tr.card_templates_remove_card_type())
|
||||||
|
assert a is not None
|
||||||
qconnect(a.triggered, self.onRemove)
|
qconnect(a.triggered, self.onRemove)
|
||||||
|
|
||||||
a = m.addAction(tr.card_templates_rename_card_type())
|
a = m.addAction(tr.card_templates_rename_card_type())
|
||||||
|
assert a is not None
|
||||||
qconnect(a.triggered, self.onRename)
|
qconnect(a.triggered, self.onRename)
|
||||||
|
|
||||||
a = m.addAction(tr.card_templates_reposition_card_type())
|
a = m.addAction(tr.card_templates_reposition_card_type())
|
||||||
|
assert a is not None
|
||||||
qconnect(a.triggered, self.onReorder)
|
qconnect(a.triggered, self.onReorder)
|
||||||
|
|
||||||
m.addSeparator()
|
m.addSeparator()
|
||||||
|
@ -780,9 +790,11 @@ class CardLayout(QDialog):
|
||||||
else:
|
else:
|
||||||
s = tr.card_templates_off()
|
s = tr.card_templates_off()
|
||||||
a = m.addAction(tr.card_templates_deck_override() + s)
|
a = m.addAction(tr.card_templates_deck_override() + s)
|
||||||
|
assert a is not None
|
||||||
qconnect(a.triggered, self.onTargetDeck)
|
qconnect(a.triggered, self.onTargetDeck)
|
||||||
|
|
||||||
a = m.addAction(tr.card_templates_browser_appearance())
|
a = m.addAction(tr.card_templates_browser_appearance())
|
||||||
|
assert a is not None
|
||||||
qconnect(a.triggered, self.onBrowserDisplay)
|
qconnect(a.triggered, self.onBrowserDisplay)
|
||||||
|
|
||||||
m.popup(self.topAreaForm.templateOptions.mapToGlobal(QPoint(0, 0)))
|
m.popup(self.topAreaForm.templateOptions.mapToGlobal(QPoint(0, 0)))
|
||||||
|
@ -834,7 +846,9 @@ class CardLayout(QDialog):
|
||||||
te.setCol(self.col)
|
te.setCol(self.col)
|
||||||
l.addWidget(te)
|
l.addWidget(te)
|
||||||
if t["did"]:
|
if t["did"]:
|
||||||
te.setText(self.col.decks.get(t["did"])["name"])
|
deck = self.col.decks.get(t["did"])
|
||||||
|
assert deck is not None
|
||||||
|
te.setText(deck["name"])
|
||||||
te.selectAll()
|
te.selectAll()
|
||||||
bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
|
bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
|
||||||
qconnect(bb.rejected, d.close)
|
qconnect(bb.rejected, d.close)
|
||||||
|
@ -927,10 +941,10 @@ class CardLayout(QDialog):
|
||||||
saveGeom(self, "CardLayout")
|
saveGeom(self, "CardLayout")
|
||||||
saveSplitter(self.mainArea, "CardLayoutMainArea")
|
saveSplitter(self.mainArea, "CardLayoutMainArea")
|
||||||
self.preview_web.cleanup()
|
self.preview_web.cleanup()
|
||||||
self.preview_web = None
|
self.preview_web = None # type: ignore
|
||||||
self.model = None
|
self.model = None # type: ignore
|
||||||
self.rendered_card = None
|
self.rendered_card = None # type: ignore
|
||||||
self.mw = None
|
self.mw = None # type: ignore
|
||||||
|
|
||||||
def onHelp(self) -> None:
|
def onHelp(self) -> None:
|
||||||
openHelp(HelpPage.TEMPLATES)
|
openHelp(HelpPage.TEMPLATES)
|
||||||
|
|
|
@ -51,15 +51,20 @@ class FieldDialog(QDialog):
|
||||||
self.webview = None
|
self.webview = None
|
||||||
|
|
||||||
disable_help_button(self)
|
disable_help_button(self)
|
||||||
self.form.buttonBox.button(QDialogButtonBox.StandardButton.Help).setAutoDefault(
|
help_button = self.form.buttonBox.button(QDialogButtonBox.StandardButton.Help)
|
||||||
False
|
assert help_button is not None
|
||||||
)
|
help_button.setAutoDefault(False)
|
||||||
self.form.buttonBox.button(
|
|
||||||
|
cancel_button = self.form.buttonBox.button(
|
||||||
QDialogButtonBox.StandardButton.Cancel
|
QDialogButtonBox.StandardButton.Cancel
|
||||||
).setAutoDefault(False)
|
|
||||||
self.form.buttonBox.button(QDialogButtonBox.StandardButton.Save).setAutoDefault(
|
|
||||||
False
|
|
||||||
)
|
)
|
||||||
|
assert cancel_button is not None
|
||||||
|
cancel_button.setAutoDefault(False)
|
||||||
|
|
||||||
|
save_button = self.form.buttonBox.button(QDialogButtonBox.StandardButton.Save)
|
||||||
|
assert save_button is not None
|
||||||
|
save_button.setAutoDefault(False)
|
||||||
|
|
||||||
self.currentIdx: int | None = None
|
self.currentIdx: int | None = None
|
||||||
self.fillFields()
|
self.fillFields()
|
||||||
self.setupSignals()
|
self.setupSignals()
|
||||||
|
@ -112,6 +117,7 @@ class FieldDialog(QDialog):
|
||||||
# for pylint
|
# for pylint
|
||||||
return
|
return
|
||||||
# the item in idx is removed thus subtract 1.
|
# the item in idx is removed thus subtract 1.
|
||||||
|
assert idx is not None
|
||||||
if idx < dropPos:
|
if idx < dropPos:
|
||||||
movePos -= 1
|
movePos -= 1
|
||||||
self.moveField(movePos + 1) # convert to 1 based.
|
self.moveField(movePos + 1) # convert to 1 based.
|
||||||
|
@ -144,6 +150,9 @@ class FieldDialog(QDialog):
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
def onRename(self) -> None:
|
def onRename(self) -> None:
|
||||||
|
if self.currentIdx is None:
|
||||||
|
return
|
||||||
|
|
||||||
idx = self.currentIdx
|
idx = self.currentIdx
|
||||||
f = self.model["flds"][idx]
|
f = self.model["flds"][idx]
|
||||||
name = self._uniqueName(tr.actions_new_name(), self.currentIdx, f["name"])
|
name = self._uniqueName(tr.actions_new_name(), self.currentIdx, f["name"])
|
||||||
|
@ -195,6 +204,7 @@ class FieldDialog(QDialog):
|
||||||
|
|
||||||
def onPosition(self, delta: int = -1) -> None:
|
def onPosition(self, delta: int = -1) -> None:
|
||||||
idx = self.currentIdx
|
idx = self.currentIdx
|
||||||
|
assert idx is not None
|
||||||
l = len(self.model["flds"])
|
l = len(self.model["flds"])
|
||||||
txt = getOnlyText(tr.fields_new_position_1(val=l), default=str(idx + 1))
|
txt = getOnlyText(tr.fields_new_position_1(val=l), default=str(idx + 1))
|
||||||
if not txt:
|
if not txt:
|
||||||
|
|
Loading…
Reference in a new issue