Add some type declarations in tags.py

This commit is contained in:
Michal Pokorný (Rai) 2019-12-22 14:50:42 +01:00
parent af4d4af55d
commit 36bdb4ebe0

View file

@ -12,7 +12,7 @@ This module manages the tag cache and tags for notes.
import json import json
import re import re
from typing import Any, Callable, Dict, List, Tuple from typing import Callable, Dict, List, Tuple
from anki.hooks import runHook from anki.hooks import runHook
from anki.utils import ids2str, intTime from anki.utils import ids2str, intTime
@ -66,13 +66,13 @@ class TagManager:
self.register(set(self.split( self.register(set(self.split(
" ".join(self.col.db.list("select distinct tags from notes"+lim))))) " ".join(self.col.db.list("select distinct tags from notes"+lim)))))
def allItems(self) -> List[Tuple[Any, Any]]: def allItems(self) -> List[Tuple[str, int]]:
return list(self.tags.items()) return list(self.tags.items())
def save(self) -> None: def save(self) -> None:
self.changed = True self.changed = True
def byDeck(self, did, children=False) -> List: def byDeck(self, did, children=False) -> List[str]:
basequery = "select n.tags from cards c, notes n WHERE c.nid = n.id" basequery = "select n.tags from cards c, notes n WHERE c.nid = n.id"
if not children: if not children:
query = basequery + " AND c.did=?" query = basequery + " AND c.did=?"
@ -127,7 +127,7 @@ class TagManager:
# String-based utilities # String-based utilities
########################################################################## ##########################################################################
def split(self, tags) -> List: def split(self, tags) -> List[str]:
"Parse a string and return a list of tags." "Parse a string and return a list of tags."
return [t for t in tags.replace('\u3000', ' ').split(" ") if t] return [t for t in tags.replace('\u3000', ' ').split(" ") if t]
@ -165,7 +165,7 @@ class TagManager:
# List-based utilities # List-based utilities
########################################################################## ##########################################################################
def canonify(self, tagList) -> List: def canonify(self, tagList) -> List[str]:
"Strip duplicates, adjust case to match existing tags, and sort." "Strip duplicates, adjust case to match existing tags, and sort."
strippedTags = [] strippedTags = []
for t in tagList: for t in tagList: