Merge pull request #400 from agentydragon/typing-sv2

Some type declarations for scheduler v2
This commit is contained in:
Damien Elmes 2019-12-28 07:12:02 +10:00 committed by GitHub
commit 0981523af0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,8 +44,8 @@ class Scheduler:
self._lrnCutoff = 0 self._lrnCutoff = 0
self._updateCutoff() self._updateCutoff()
def getCard(self) -> Any: def getCard(self) -> Optional[Card]:
"Pop the next card from the queue. None if finished." """Pop the next card from the queue. None if finished."""
self._checkDay() self._checkDay()
if not self._haveQueues: if not self._haveQueues:
self.reset() self.reset()
@ -57,6 +57,7 @@ class Scheduler:
self.reps += 1 self.reps += 1
card.startTimer() card.startTimer()
return card return card
return None
def reset(self) -> None: def reset(self) -> None:
self._updateCutoff() self._updateCutoff()
@ -316,8 +317,8 @@ order by due"""
# Getting the next card # Getting the next card
########################################################################## ##########################################################################
def _getCard(self) -> Any: def _getCard(self) -> Optional[Card]:
"Return the next due card id, or None." """Return the next due card, or None."""
# learning card due? # learning card due?
c = self._getLrnCard() c = self._getLrnCard()
if c: if c:
@ -402,10 +403,11 @@ did = ? and queue = 0 limit ?)""",
self._resetNew() self._resetNew()
return self._fillNew() return self._fillNew()
def _getNewCard(self) -> Any: def _getNewCard(self) -> Optional[Card]:
if self._fillNew(): if self._fillNew():
self.newCount -= 1 self.newCount -= 1
return self.col.getCard(self._newQueue.pop()) return self.col.getCard(self._newQueue.pop())
return None
def _updateNewCardRatio(self) -> None: def _updateNewCardRatio(self) -> None:
if self.col.conf["newSpread"] == NEW_CARDS_DISTRIBUTE: if self.col.conf["newSpread"] == NEW_CARDS_DISTRIBUTE:
@ -545,7 +547,7 @@ limit %d"""
self._lrnQueue.sort() self._lrnQueue.sort()
return self._lrnQueue return self._lrnQueue
def _getLrnCard(self, collapse: bool = False) -> Any: def _getLrnCard(self, collapse: bool = False) -> Optional[Card]:
self._maybeResetLrn(force=collapse and self.lrnCount == 0) self._maybeResetLrn(force=collapse and self.lrnCount == 0)
if self._fillLrn(): if self._fillLrn():
cutoff = time.time() cutoff = time.time()
@ -556,6 +558,7 @@ limit %d"""
card = self.col.getCard(id) card = self.col.getCard(id)
self.lrnCount -= 1 self.lrnCount -= 1
return card return card
return None
# daily learning # daily learning
def _fillLrnDay(self) -> Optional[bool]: def _fillLrnDay(self) -> Optional[bool]:
@ -588,10 +591,11 @@ did = ? and queue = 3 and due <= ? limit ?""",
# shouldn't reach here # shouldn't reach here
return False return False
def _getLrnDayCard(self) -> Any: def _getLrnDayCard(self) -> Optional[Card]:
if self._fillLrnDay(): if self._fillLrnDay():
self.lrnCount -= 1 self.lrnCount -= 1
return self.col.getCard(self._lrnDayQueue.pop()) return self.col.getCard(self._lrnDayQueue.pop())
return None
def _answerLrnCard(self, card: Card, ease: int) -> None: def _answerLrnCard(self, card: Card, ease: int) -> None:
conf = self._lrnConf(card) conf = self._lrnConf(card)
@ -920,12 +924,13 @@ limit ?"""
self._resetRev() self._resetRev()
return self._fillRev() return self._fillRev()
def _getRevCard(self) -> Any: def _getRevCard(self) -> Optional[Card]:
if self._fillRev(): if self._fillRev():
self.revCount -= 1 self.revCount -= 1
return self.col.getCard(self._revQueue.pop()) return self.col.getCard(self._revQueue.pop())
return None
def totalRevForCurrentDeck(self) -> Any: def totalRevForCurrentDeck(self) -> int:
return self.col.db.scalar( return self.col.db.scalar(
""" """
select count() from cards where id in ( select count() from cards where id in (
@ -1492,7 +1497,7 @@ To study outside of the normal schedule, click the Custom Study button below."""
# Next time reports # Next time reports
########################################################################## ##########################################################################
def nextIvlStr(self, card: Card, ease: int, short: bool = False) -> Any: def nextIvlStr(self, card: Card, ease: int, short: bool = False) -> str:
"Return the next interval for CARD as a string." "Return the next interval for CARD as a string."
ivl = self.nextIvl(card, ease) ivl = self.nextIvl(card, ease)
if not ivl: if not ivl: