Type annotations in notes.py

This commit is contained in:
Michal Pokorný (Rai) 2019-12-27 16:53:10 +01:00
parent 3357ecfed3
commit 5ee08b1b36

View File

@ -2,7 +2,7 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from typing import Any, List, Optional, Tuple
from typing import Any, Dict, List, Optional, Tuple
import anki # pylint: disable=unused-import
from anki.utils import (
@ -14,10 +14,22 @@ from anki.utils import (
stripHTMLMedia,
timestampID,
)
from anki.types import NoteType
class Note:
col: "anki.storage._Collection"
newlyAdded: bool
id: int
guid: str
_model: NoteType
mid: int
tags: List[str]
fields: List[str]
flags: int
data: str
_fmap: Dict[str, Tuple[Any, Any]]
scm: int
def __init__(
self,
@ -111,16 +123,16 @@ insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?)""",
)
]
def model(self) -> Any:
def model(self) -> Optional[NoteType]:
return self._model
# Dict interface
##################################################
def keys(self) -> List:
def keys(self) -> List[str]:
return list(self._fmap.keys())
def values(self) -> Any:
def values(self) -> List[str]:
return self.fields
def items(self) -> List[Tuple[Any, Any]]:
@ -132,14 +144,14 @@ insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?)""",
except:
raise KeyError(key)
def __getitem__(self, key: str) -> Any:
def __getitem__(self, key: str) -> str:
return self.fields[self._fieldOrd(key)]
def __setitem__(self, key: str, value: str) -> None:
self.fields[self._fieldOrd(key)] = value
def __contains__(self, key) -> bool:
return key in list(self._fmap.keys())
return key in self._fmap
# Tags
##################################################
@ -150,10 +162,10 @@ insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?)""",
def stringTags(self) -> Any:
return self.col.tags.join(self.col.tags.canonify(self.tags))
def setTagsFromStr(self, str) -> None:
self.tags = self.col.tags.split(str)
def setTagsFromStr(self, tags: str) -> None:
self.tags = self.col.tags.split(tags)
def delTag(self, tag) -> None:
def delTag(self, tag: str) -> None:
rem = []
for t in self.tags:
if t.lower() == tag.lower():