Fixing type hints

Matched all type hints, changed the original Sequence[] type hint for _answerButtonList() in reviewer.py on mypy's recommendation.
This commit is contained in:
Thomas B 2020-08-19 16:15:49 -04:00
parent 649142e5b3
commit 897ec72608
3 changed files with 14 additions and 11 deletions

View file

@ -7,7 +7,7 @@ See pylib/anki/hooks.py
from __future__ import annotations
from typing import Any, Callable, List, Optional, Tuple
from typing import Any, Callable, List, Optional, Tuple, Sequence
import anki
import aqt
@ -2177,6 +2177,7 @@ class _ReviewerWillInitAnswerButtonsFilter:
_hooks: List[
Callable[
["Optional[Tuple[Tuple[int, str], ...]]", "aqt.reviewer.Reviewer", Card],
["Tuple[Tuple[int, str], ...]", "aqt.reviewer.Reviewer", Card],
Tuple[Tuple[int, str], ...],
]
] = []
@ -2184,17 +2185,17 @@ class _ReviewerWillInitAnswerButtonsFilter:
def append(
self,
cb: Callable[
["Optional[Tuple[Tuple[int, str], ...]]", "aqt.reviewer.Reviewer", Card],
["Tuple[Tuple[int, str], ...]", "aqt.reviewer.Reviewer", Card],
Tuple[Tuple[int, str], ...],
],
) -> None:
"""(buttons_tuple: Optional[Tuple[Tuple[int, str], ...]], reviewer: aqt.reviewer.Reviewer, card: Card)"""
"""(buttons_tuple: Tuple[Tuple[int, str], ...], reviewer: aqt.reviewer.Reviewer, card: Card)"""
self._hooks.append(cb)
def remove(
self,
cb: Callable[
["Optional[Tuple[Tuple[int, str], ...]]", "aqt.reviewer.Reviewer", Card],
["Tuple[Tuple[int, str], ...]", "aqt.reviewer.Reviewer", Card],
Tuple[Tuple[int, str], ...],
],
) -> None:
@ -2206,7 +2207,7 @@ class _ReviewerWillInitAnswerButtonsFilter:
def __call__(
self,
buttons_tuple: Optional[Tuple[Tuple[int, str], ...]],
buttons_tuple: Tuple[Tuple[int, str], ...],
reviewer: aqt.reviewer.Reviewer,
card: Card,
) -> Tuple[Tuple[int, str], ...]:

View file

@ -621,10 +621,10 @@ time = %(time)d;
else:
return 2
def _answerButtonList(self) -> Sequence[Tuple[int, str], ...]:
def _answerButtonList(self) -> Tuple[Tuple[int, str], ...]:
button_count = self.mw.col.sched.answerButtons(self.card)
if button_count == 2:
buttons_tuple = ((1, _("Again")), (2, _("Good")),)
buttons_tuple: Tuple[Tuple[int, str], ...] = ((1, _("Again")), (2, _("Good")),)
elif button_count == 3:
buttons_tuple = ((1, _("Again")), (2, _("Good")), (3, _("Easy")))
else:

View file

@ -61,19 +61,21 @@ hooks = [
Hook(
name="reviewer_will_init_answer_buttons",
args=[
"buttons_tuple: Optional[Tuple[Tuple[int, str], ...]]",
"buttons_tuple: Tuple[Tuple[int, str], ...]",
"reviewer: aqt.reviewer.Reviewer",
"card: Card",
],
return_type="Tuple[Tuple[int, str], ...]",
doc="""Used to modify list of answer buttons
buttons_tuple is a tuple of buttons, with each button represented by a tuple
containing an int for the button's number and a string for the button's label.
buttons_tuple is a sequence of buttons, with each button represented
by a tuple containing an int for the button's number and a string for
the button's label.
Return a tuple of the form ((1, "Label1"), (2, "Label2"), ...)
Note: import _ from anki.lang to support automatic translation, using, e.g.,
Note: import _ from anki.lang to support automatic translation, using,
e.g.,
((1, _("Label1")), ...)
""",
),