From 1da52f89fea4e44c05d77819cc1113fb796af4d3 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 16 Dec 2019 17:47:07 +1000 Subject: [PATCH] be explicit in our not-None assumptions to appease type checker --- anki/collection.py | 3 +++ anki/importing/mnemo.py | 2 ++ anki/importing/pauker.py | 1 + anki/stats.py | 7 ++++--- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/anki/collection.py b/anki/collection.py index 6321e9f1e..370391980 100644 --- a/anki/collection.py +++ b/anki/collection.py @@ -393,6 +393,7 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""", for nid, mid, flds in self.db.execute( "select id, mid, flds from notes where id in "+snids): model = self.models.get(mid) + assert(model) avail = self.models.availOrds(model, flds) did = dids.get(nid) or model['did'] due = dues.get(nid) @@ -456,6 +457,7 @@ insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,0,"")""", card.did = note.model()['did'] # if invalid did, use default instead deck = self.decks.get(card.did) + assert(deck) if deck['dyn']: # must not be a filtered deck card.did = 1 @@ -567,6 +569,7 @@ where c.nid = n.id and c.id in %s group by nid""" % ids2str(cids)): flist = splitFields(data[6]) fields = {} model = self.models.get(data[2]) + assert(model) for (name, (idx, conf)) in list(self.models.fieldMap(model).items()): fields[name] = flist[idx] fields['Tags'] = data[5].strip() diff --git a/anki/importing/mnemo.py b/anki/importing/mnemo.py index 0cfaf195e..294253882 100644 --- a/anki/importing/mnemo.py +++ b/anki/importing/mnemo.py @@ -33,6 +33,7 @@ f._id=d._fact_id"""): notes[note['_id']] = note note = {'_id': _id} curid = id + assert(note) note[k] = v if note: notes[note['_id']] = note @@ -82,6 +83,7 @@ acq_reps+ret_reps, lapses, card_type_id from cards"""): c.due = self.col.sched.today+rem # get ord m = re.search(r".(\d+)$", row[1]) + assert(m) ord = int(m.group(1))-1 if 'cards' not in note: note['cards'] = {} diff --git a/anki/importing/pauker.py b/anki/importing/pauker.py index 95a1d12d5..055c1bfe7 100644 --- a/anki/importing/pauker.py +++ b/anki/importing/pauker.py @@ -50,6 +50,7 @@ class PaukerImporter(NoteImporter): front = card.findtext('./FrontSide/Text') back = card.findtext('./ReverseSide/Text') note = ForeignNote() + assert(front and back) note.fields = [html.escape(x.strip()).replace('\n','
').replace(' ','  ') for x in [front,back]] notes.append(note) diff --git a/anki/stats.py b/anki/stats.py index 615b5b145..409cbdb68 100644 --- a/anki/stats.py +++ b/anki/stats.py @@ -363,8 +363,7 @@ group by day order by day""" % (self._limit(), lim), return self._section(txt1) + self._section(txt2) def _ansInfo(self, totd, studied, first, unit, convHours=False, total=None): - if not totd: - return + assert(totd) tot = totd[-1][1] period = self._periodDays() if not period: @@ -504,12 +503,14 @@ group by day order by day""" % lim, lim = "where " + " and ".join(lims) else: lim = "" - return self.col.db.first(""" + ret = self.col.db.first(""" select count(), abs(min(day)) from (select (cast((id/1000 - :cut) / 86400.0 as int)+1) as day from revlog %s group by day order by day)""" % lim, cut=self.col.sched.dayCutoff) + assert(ret) + return ret # Intervals ######################################################################