diff --git a/pylib/anki/decks.py b/pylib/anki/decks.py index 9c8fa0d3e..a566861d6 100644 --- a/pylib/anki/decks.py +++ b/pylib/anki/decks.py @@ -460,8 +460,11 @@ class DeckManager: out.extend(self.child_ids(parent_name)) return out - def childDids(self, did: int, childMap: Dict[int, Any]) -> List: - def gather(node, arr): + childMapNode = Dict[int, Any] + # Change to Dict[int, "DeckManager.childMapNode"] when MyPy allow recursive type + + def childDids(self, did: int, childMap: DeckManager.childMapNode) -> List: + def gather(node: DeckManager.childMapNode, arr): for did, child in node.items(): arr.append(did) gather(child, arr) @@ -470,9 +473,9 @@ class DeckManager: gather(childMap[did], arr) return arr - def childMap(self) -> Dict[Any, Dict[Any, dict]]: + def childMap(self) -> DeckManager.childMapNode: nameMap = self.nameMap() - childMap = {} + childMap: DeckManager.childMapNode = {} # go through all decks, sorted by name for deck in sorted(self.all(), key=self.key): diff --git a/pylib/anki/hooks.py b/pylib/anki/hooks.py index ba48e4afa..bfe5afad0 100644 --- a/pylib/anki/hooks.py +++ b/pylib/anki/hooks.py @@ -175,20 +175,20 @@ card_will_flush = _CardWillFlushHook() class _DeckAddedHook: """Obsolete, do not use.""" - _hooks: List[Callable[[Dict[str, Any]], None]] = [] + _hooks: List[Callable[[Deck], None]] = [] - def append(self, cb: Callable[[Dict[str, Any]], None]) -> None: - """(deck: Dict[str, Any])""" + def append(self, cb: Callable[[Deck], None]) -> None: + """(deck: Deck)""" self._hooks.append(cb) - def remove(self, cb: Callable[[Dict[str, Any]], None]) -> None: + def remove(self, cb: Callable[[Deck], None]) -> None: if cb in self._hooks: self._hooks.remove(cb) def count(self) -> int: return len(self._hooks) - def __call__(self, deck: Dict[str, Any]) -> None: + def __call__(self, deck: Deck) -> None: for hook in self._hooks: try: hook(deck) @@ -305,20 +305,20 @@ media_files_did_export = _MediaFilesDidExportHook() class _NoteTypeAddedHook: """Obsolete, do not use.""" - _hooks: List[Callable[[Dict[str, Any]], None]] = [] + _hooks: List[Callable[[NoteType], None]] = [] - def append(self, cb: Callable[[Dict[str, Any]], None]) -> None: - """(notetype: Dict[str, Any])""" + def append(self, cb: Callable[[NoteType], None]) -> None: + """(notetype: NoteType)""" self._hooks.append(cb) - def remove(self, cb: Callable[[Dict[str, Any]], None]) -> None: + def remove(self, cb: Callable[[NoteType], None]) -> None: if cb in self._hooks: self._hooks.remove(cb) def count(self) -> int: return len(self._hooks) - def __call__(self, notetype: Dict[str, Any]) -> None: + def __call__(self, notetype: NoteType) -> None: for hook in self._hooks: try: hook(notetype) @@ -397,20 +397,20 @@ class _SchedulerNewLimitForSingleDeckFilter: """Allows changing the number of new card for this deck (without considering descendants).""" - _hooks: List[Callable[[int, Dict[str, Any]], int]] = [] + _hooks: List[Callable[[int, Deck], int]] = [] - def append(self, cb: Callable[[int, Dict[str, Any]], int]) -> None: - """(count: int, deck: Dict[str, Any])""" + def append(self, cb: Callable[[int, Deck], int]) -> None: + """(count: int, deck: Deck)""" self._hooks.append(cb) - def remove(self, cb: Callable[[int, Dict[str, Any]], int]) -> None: + def remove(self, cb: Callable[[int, Deck], int]) -> None: if cb in self._hooks: self._hooks.remove(cb) def count(self) -> int: return len(self._hooks) - def __call__(self, count: int, deck: Dict[str, Any]) -> int: + def __call__(self, count: int, deck: Deck) -> int: for filter in self._hooks: try: count = filter(count, deck) @@ -428,20 +428,20 @@ class _SchedulerReviewLimitForSingleDeckFilter: """Allows changing the number of rev card for this deck (without considering descendants).""" - _hooks: List[Callable[[int, Dict[str, Any]], int]] = [] + _hooks: List[Callable[[int, Deck], int]] = [] - def append(self, cb: Callable[[int, Dict[str, Any]], int]) -> None: - """(count: int, deck: Dict[str, Any])""" + def append(self, cb: Callable[[int, Deck], int]) -> None: + """(count: int, deck: Deck)""" self._hooks.append(cb) - def remove(self, cb: Callable[[int, Dict[str, Any]], int]) -> None: + def remove(self, cb: Callable[[int, Deck], int]) -> None: if cb in self._hooks: self._hooks.remove(cb) def count(self) -> int: return len(self._hooks) - def __call__(self, count: int, deck: Dict[str, Any]) -> int: + def __call__(self, count: int, deck: Deck) -> int: for filter in self._hooks: try: count = filter(count, deck) diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index 8fc8f720e..66d8c2f99 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -13,6 +13,7 @@ import anki # pylint: disable=unused-import from anki import hooks from anki.cards import Card from anki.consts import * +from anki.decks import DeckManager from anki.lang import _ from anki.rsbackend import ( CountsForDeckToday, @@ -791,7 +792,7 @@ and due <= ? limit ?)""", lim = min(lim, self._deckRevLimitSingle(parent, parentLimit=lim)) return hooks.scheduler_review_limit_for_single_deck(lim, d) - def _revForDeck(self, did: int, lim: int, childMap: Dict[int, Any]) -> Any: + def _revForDeck(self, did: int, lim: int, childMap: DeckManager.childMapNode) -> Any: dids = [did] + self.col.decks.childDids(did, childMap) lim = min(lim, self.reportLimit) return self.col.db.scalar( diff --git a/qt/aqt/gui_hooks.py b/qt/aqt/gui_hooks.py index bd25a03b9..f5854c743 100644 --- a/qt/aqt/gui_hooks.py +++ b/qt/aqt/gui_hooks.py @@ -827,20 +827,20 @@ collection_did_load = _CollectionDidLoadHook() class _CurrentNoteTypeDidChangeHook: - _hooks: List[Callable[[Dict[str, Any]], None]] = [] + _hooks: List[Callable[[NoteType], None]] = [] - def append(self, cb: Callable[[Dict[str, Any]], None]) -> None: - """(notetype: Dict[str, Any])""" + def append(self, cb: Callable[[NoteType], None]) -> None: + """(notetype: NoteType)""" self._hooks.append(cb) - def remove(self, cb: Callable[[Dict[str, Any]], None]) -> None: + def remove(self, cb: Callable[[NoteType], None]) -> None: if cb in self._hooks: self._hooks.remove(cb) def count(self) -> int: return len(self._hooks) - def __call__(self, notetype: Dict[str, Any]) -> None: + def __call__(self, notetype: NoteType) -> None: for hook in self._hooks: try: hook(notetype)