mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
mypy: fix type checking error (#3365)
* refactor: fix type checking error error: Argument 1 to "_answerCard" of "Reviewer" has incompatible type "int"; expected "Literal[1, 2, 3, 4]" [arg-type] * refactor: remove check that `ease` is correct number * refactor: rename variable * refactor: add type hint for generator function * refactor: revise import of `functools.partial` * refactor: invert logic of if-construct to avoid nesting. * refactor: properly check for `None` * Update qt/aqt/reviewer.py
This commit is contained in:
parent
83fe301c1c
commit
b35b69a2d3
1 changed files with 15 additions and 7 deletions
|
@ -3,13 +3,13 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import functools
|
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
from collections.abc import Callable, Sequence
|
from collections.abc import Callable, Generator, Sequence
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
|
from functools import partial
|
||||||
from typing import Any, Literal, Match, Union, cast
|
from typing import Any, Literal, Match, Union, cast
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
|
@ -591,6 +591,18 @@ class Reviewer:
|
||||||
def _shortcutKeys(
|
def _shortcutKeys(
|
||||||
self,
|
self,
|
||||||
) -> Sequence[tuple[str, Callable] | tuple[Qt.Key, Callable]]:
|
) -> Sequence[tuple[str, Callable] | tuple[Qt.Key, Callable]]:
|
||||||
|
|
||||||
|
def generate_default_answer_keys() -> (
|
||||||
|
Generator[tuple[str, partial], None, None]
|
||||||
|
):
|
||||||
|
for ease in aqt.mw.pm.default_answer_keys:
|
||||||
|
key = aqt.mw.pm.get_answer_key(ease)
|
||||||
|
if not key:
|
||||||
|
continue
|
||||||
|
ease = cast(Literal[1, 2, 3, 4], ease)
|
||||||
|
answer_card_according_to_pressed_key = partial(self._answerCard, ease)
|
||||||
|
yield (key, answer_card_according_to_pressed_key)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
("e", self.mw.onEditCurrent),
|
("e", self.mw.onEditCurrent),
|
||||||
(" ", self.onEnterKey),
|
(" ", self.onEnterKey),
|
||||||
|
@ -617,11 +629,7 @@ class Reviewer:
|
||||||
("o", self.onOptions),
|
("o", self.onOptions),
|
||||||
("i", self.on_card_info),
|
("i", self.on_card_info),
|
||||||
("Ctrl+Alt+i", self.on_previous_card_info),
|
("Ctrl+Alt+i", self.on_previous_card_info),
|
||||||
*(
|
*generate_default_answer_keys(),
|
||||||
(key, functools.partial(self._answerCard, ease))
|
|
||||||
for ease in aqt.mw.pm.default_answer_keys
|
|
||||||
if (key := aqt.mw.pm.get_answer_key(ease))
|
|
||||||
),
|
|
||||||
("u", self.mw.undo),
|
("u", self.mw.undo),
|
||||||
("5", self.on_pause_audio),
|
("5", self.on_pause_audio),
|
||||||
("6", self.on_seek_backward),
|
("6", self.on_seek_backward),
|
||||||
|
|
Loading…
Reference in a new issue