Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy: fix type checking error #3365

Merged
20 changes: 15 additions & 5 deletions qt/aqt/reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,20 @@ def korean_shortcuts(
def _shortcutKeys(
self,
) -> Sequence[tuple[str, Callable] | tuple[Qt.Key, Callable]]:

def generate_default_answer_keys():
for ease in aqt.mw.pm.default_answer_keys:
key = aqt.mw.pm.get_answer_key(ease)
if key:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Walrus operator would make this more concise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should key only be not None or does it also need to be different from the empty string?

In other words: I would like to change if key: to if key is not None:, provided this doesn't change its meaning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user can enter an empty string in the preferences, so we also need to guard against that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing the code. I wasn't sure about that.

if ease in (1, 2, 3, 4):
dae marked this conversation as resolved.
Show resolved Hide resolved
ease = cast(Literal[1, 2, 3, 4], ease)
answer_card_according_to_pressed_shortkey = functools.partial(
self._answerCard, ease
)
yield (key, answer_card_according_to_pressed_shortkey)
else:
raise ValueError("Invalid value")

return [
("e", self.mw.onEditCurrent),
(" ", self.onEnterKey),
Expand All @@ -617,11 +631,7 @@ def _shortcutKeys(
("o", self.onOptions),
("i", self.on_card_info),
("Ctrl+Alt+i", self.on_previous_card_info),
*(
(key, functools.partial(self._answerCard, ease))
for ease in aqt.mw.pm.default_answer_keys
if (key := aqt.mw.pm.get_answer_key(ease))
),
*generate_default_answer_keys(),
("u", self.mw.undo),
("5", self.on_pause_audio),
("6", self.on_seek_backward),
Expand Down