Enable strict_optional for aqt/studydeck, tts, mediasrv (#3542)

* Enable strict_optional for studydeck

* Fix mypy errors

* Enable strict_optional for tts

* Fix mypy errors in tts

* Enable strict_optional for mediasrv

* Fix mypy errors in mediasrv
This commit is contained in:
Ben Nguyen 2024-10-29 02:05:54 -07:00 committed by GitHub
parent 7f58ca213c
commit a25edecc88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 3 deletions

View file

@ -56,6 +56,12 @@ strict_optional = True
strict_optional = True strict_optional = True
[mypy-aqt.deckbrowser] [mypy-aqt.deckbrowser]
strict_optional = True strict_optional = True
[mypy-aqt.studydeck]
strict_optional = True
[mypy-aqt.tts]
strict_optional = True
[mypy-aqt.mediasrv]
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]

View file

@ -735,8 +735,12 @@ def _extract_page_context() -> PageContext:
return PageContext.NON_LEGACY_PAGE return PageContext.NON_LEGACY_PAGE
elif referer.path == "/_anki/legacyPageData": elif referer.path == "/_anki/legacyPageData":
query_params = parse_qs(referer.query) query_params = parse_qs(referer.query)
id = int(query_params.get("id", [None])[0]) query_id = query_params.get("id")
return aqt.mw.mediaServer.get_page_context(id) if not query_id:
return PageContext.UNKNOWN
id = int(query_id[0])
page_context = aqt.mw.mediaServer.get_page_context(id)
return page_context if page_context else PageContext.UNKNOWN
else: else:
return PageContext.UNKNOWN return PageContext.UNKNOWN

View file

@ -101,7 +101,7 @@ class StudyDeck(QDialog):
else: else:
self.exec() self.exec()
def eventFilter(self, obj: QObject, evt: QEvent) -> bool: def eventFilter(self, obj: QObject | None, evt: QEvent | None) -> bool:
if isinstance(evt, QKeyEvent) and evt.type() == QEvent.Type.KeyPress: if isinstance(evt, QKeyEvent) and evt.type() == QEvent.Type.KeyPress:
new_row = current_row = self.form.list.currentRow() new_row = current_row = self.form.list.currentRow()
rows_count = self.form.list.count() rows_count = self.form.list.count()
@ -178,6 +178,7 @@ class StudyDeck(QDialog):
def success(out: OpChangesWithId) -> None: def success(out: OpChangesWithId) -> None:
deck = self.mw.col.decks.get(DeckId(out.id)) deck = self.mw.col.decks.get(DeckId(out.id))
assert deck is not None
self.name = deck["name"] self.name = deck["name"]
self.accept_with_callback() self.accept_with_callback()

View file

@ -189,6 +189,7 @@ class MacTTSPlayer(TTSProcessPlayer):
stderr=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
) )
# write the input text to stdin # write the input text to stdin
assert self._process.stdin is not None
self._process.stdin.write(tag.field_text.encode("utf8")) self._process.stdin.write(tag.field_text.encode("utf8"))
self._process.stdin.close() self._process.stdin.close()
self._wait_for_termination(tag) self._wait_for_termination(tag)
@ -247,6 +248,7 @@ class MacTTSFilePlayer(MacTTSPlayer):
stderr=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
) )
# write the input text to stdin # write the input text to stdin
assert self._process.stdin is not None
self._process.stdin.write(tag.field_text.encode("utf8")) self._process.stdin.write(tag.field_text.encode("utf8"))
self._process.stdin.close() self._process.stdin.close()
self._wait_for_termination(tag) self._wait_for_termination(tag)