mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
NF: childMapNode
This commit is contained in:
parent
d079307536
commit
c3b2b8625e
4 changed files with 34 additions and 30 deletions
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue