From fe576a865dd896bed8a66fee7ab89d87cabc68f6 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 2 Oct 2021 23:37:12 +1000 Subject: [PATCH] convert some range(len()) calls for pylint --- pylib/anki/importing/noteimp.py | 8 ++++---- pylib/anki/scheduler/v1.py | 3 +-- pylib/anki/scheduler/v2.py | 5 ++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/pylib/anki/importing/noteimp.py b/pylib/anki/importing/noteimp.py index b89f9595a..eca2ed90d 100644 --- a/pylib/anki/importing/noteimp.py +++ b/pylib/anki/importing/noteimp.py @@ -143,12 +143,12 @@ class NoteImporter(Importer): dupeCount = 0 dupes: List[str] = [] for n in notes: - for c in range(len(n.fields)): + for c, field in enumerate(n.fields): if not self.allowHTML: - n.fields[c] = html.escape(n.fields[c], quote=False) - n.fields[c] = n.fields[c].strip() + n.fields[c] = html.escape(field, quote=False) + n.fields[c] = field.strip() if not self.allowHTML: - n.fields[c] = n.fields[c].replace("\n", "
") + n.fields[c] = field.replace("\n", "
") fld0 = unicodedata.normalize("NFC", n.fields[fld0idx]) # first field must exist if not fld0: diff --git a/pylib/anki/scheduler/v1.py b/pylib/anki/scheduler/v1.py index 1598a1505..adbd7a177 100644 --- a/pylib/anki/scheduler/v1.py +++ b/pylib/anki/scheduler/v1.py @@ -197,8 +197,7 @@ limit %d""" % (self._deckLimit(), self.reportLimit), self.dayCutoff, ) - for i in range(len(self._lrnQueue)): - self._lrnQueue[i] = (self._lrnQueue[i][0], self._lrnQueue[i][1]) + self._lrnQueue = [tuple(e) for e in self._lrnQueue] # as it arrives sorted by did first, we need to sort it self._lrnQueue.sort() return self._lrnQueue diff --git a/pylib/anki/scheduler/v2.py b/pylib/anki/scheduler/v2.py index 43500c4c1..1eddef19b 100644 --- a/pylib/anki/scheduler/v2.py +++ b/pylib/anki/scheduler/v2.py @@ -8,7 +8,7 @@ from __future__ import annotations import random import time from heapq import * -from typing import Any, Callable, Dict, List, Optional, Tuple, Union +from typing import Any, Callable, Dict, List, Optional, Tuple, Union, cast import anki # pylint: disable=unused-import from anki import hooks, scheduler_pb2 @@ -329,8 +329,7 @@ limit %d""" % (self._deckLimit(), self.reportLimit), cutoff, ) - for i in range(len(self._lrnQueue)): - self._lrnQueue[i] = (self._lrnQueue[i][0], self._lrnQueue[i][1]) + self._lrnQueue = [cast(Tuple[int, CardId], tuple(e)) for e in self._lrnQueue] # as it arrives sorted by did first, we need to sort it self._lrnQueue.sort() return self._lrnQueue