diff --git a/anki/decks.py b/anki/decks.py
index 7648d738e..b0e8234ba 100644
--- a/anki/decks.py
+++ b/anki/decks.py
@@ -128,8 +128,10 @@ class DeckManager:
# Deck save/load
#############################################################
- def id(self, name, create=True, type=defaultDeck):
+ def id(self, name, create=True, type=None):
"Add a deck with NAME. Reuse deck if already exists. Return id as int."
+ if type is None:
+ type = defaultDeck
name = name.replace('"', '')
name = unicodedata.normalize("NFC", name)
for id, g in list(self.decks.items()):
@@ -353,8 +355,10 @@ class DeckManager:
self.dconf[str(g['id'])] = g
self.save()
- def confId(self, name, cloneFrom=defaultConf):
+ def confId(self, name, cloneFrom=None):
"Create a new configuration and return id."
+ if cloneFrom is None:
+ type = defaultConf
c = copy.deepcopy(cloneFrom)
while 1:
id = intTime(1000)
diff --git a/anki/errors.py b/anki/errors.py
index 434e12bda..604e83ae2 100644
--- a/anki/errors.py
+++ b/anki/errors.py
@@ -4,6 +4,7 @@
class AnkiError(Exception):
def __init__(self, type, **data):
+ super().__init__()
self.type = type
self.data = data
def __str__(self):
@@ -14,6 +15,7 @@ class AnkiError(Exception):
class DeckRenameError(Exception):
def __init__(self, description):
+ super().__init__()
self.description = description
def __str__(self):
return "Couldn't rename deck: " + self.description
diff --git a/anki/exporting.py b/anki/exporting.py
index 6e5dfb74f..55526ab94 100644
--- a/anki/exporting.py
+++ b/anki/exporting.py
@@ -277,6 +277,7 @@ class AnkiPackageExporter(AnkiExporter):
raise Exception("Please switch to the normal scheduler before exporting a single deck with scheduling information.")
# prevent older clients from accessing
+ # pylint: disable=unreachable
self._addDummyCollection(z)
z.write(colfile, "collection.anki21")
diff --git a/anki/importing/mnemo.py b/anki/importing/mnemo.py
index f1be90e88..ec0bd1e24 100644
--- a/anki/importing/mnemo.py
+++ b/anki/importing/mnemo.py
@@ -173,6 +173,7 @@ acq_reps+ret_reps, lapses, card_type_id from cards"""):
fld = re.sub("\r?\n", "
", fld)
state = dict(n=1)
def repl(match):
+ # pylint: disable=cell-var-from-loop
# replace [...] with cloze refs
res = ("{{c%d::%s}}" % (state['n'], match.group(1)))
state['n'] += 1
diff --git a/anki/latex.py b/anki/latex.py
index bd2da3fcd..10d77d1e4 100644
--- a/anki/latex.py
+++ b/anki/latex.py
@@ -140,7 +140,6 @@ def _errMsg(type, texpath):
msg += "" + html.escape(log) + "
"
except:
msg += _("Have you installed latex and dvipng/dvisvgm?")
- pass
return msg
# setup q/a filter
diff --git a/anki/sched.py b/anki/sched.py
index e0792b338..dcce7963f 100644
--- a/anki/sched.py
+++ b/anki/sched.py
@@ -1390,6 +1390,7 @@ usn=:usn,mod=:mod,factor=:fact where id=:id""",
random.shuffle(nids)
for c, nid in enumerate(nids):
due[nid] = start+c*step
+ # pylint: disable=undefined-loop-variable
high = start+c*step
# shift?
if shift:
diff --git a/anki/schedv2.py b/anki/schedv2.py
index b3acd8de1..cdaa8b60c 100644
--- a/anki/schedv2.py
+++ b/anki/schedv2.py
@@ -1531,6 +1531,7 @@ usn=:usn,mod=:mod,factor=:fact where id=:id""",
random.shuffle(nids)
for c, nid in enumerate(nids):
due[nid] = start+c*step
+ # pylint: disable=undefined-loop-variable
high = start+c*step
# shift?
if shift:
diff --git a/anki/stats.py b/anki/stats.py
index d77ecb33c..d6aef9c88 100644
--- a/anki/stats.py
+++ b/anki/stats.py
@@ -21,6 +21,7 @@ class CardStats:
def report(self):
c = self.card
+ # pylint: disable=unnecessary-lambda
fmt = lambda x, **kwargs: fmtTimeSpan(x, short=True, **kwargs)
self.txt = "
"
self.addLine(_("Added"), self.date(c.id/1000))
@@ -809,8 +810,10 @@ from cards where did in %s""" % self._limit())
# Tools
######################################################################
- def _graph(self, id, data, conf={},
+ def _graph(self, id, data, conf=None,
type="bars", ylabel=_("Cards"), timeTicks=True, ylabel2=""):
+ if conf is None:
+ conf = {}
# display settings
if type == "pie":
conf['legend'] = {'container': "#%sLegend" % id, 'noColumns':2}
diff --git a/anki/sync.py b/anki/sync.py
index e7da9dc6d..f44814a6d 100644
--- a/anki/sync.py
+++ b/anki/sync.py
@@ -733,7 +733,8 @@ class MediaSyncer:
need.append(fname)
else:
self.col.log("have same already")
- ldirty and self.col.media.markClean([fname])
+ if ldirty:
+ self.col.media.markClean([fname])
elif lsum:
# deleted remotely
if not ldirty:
@@ -745,7 +746,8 @@ class MediaSyncer:
else:
# deleted both sides
self.col.log("both sides deleted")
- ldirty and self.col.media.markClean([fname])
+ if ldirty:
+ self.col.media.markClean([fname])
self._downloadFiles(need)
diff --git a/anki/tags.py b/anki/tags.py
index 0fc66b9a9..a8028d2c2 100644
--- a/anki/tags.py
+++ b/anki/tags.py
@@ -2,10 +2,6 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-from anki.utils import intTime, ids2str, json
-from anki.hooks import runHook
-import re
-
"""
Anki maintains a cache of used tags so it can quickly present a list of tags
for autocomplete and in the browser. For efficiency, deletions are not
@@ -14,6 +10,10 @@ tracked, so unused tags can only be removed from the list with a DB check.
This module manages the tag cache and tags for notes.
"""
+from anki.utils import intTime, ids2str, json
+from anki.hooks import runHook
+import re
+
class TagManager:
# Registry save/load
diff --git a/anki/utils.py b/anki/utils.py
index 728bb8c48..cd3a7e418 100644
--- a/anki/utils.py
+++ b/anki/utils.py
@@ -360,7 +360,7 @@ def call(argv, wait=True, **kwargs):
isMac = sys.platform.startswith("darwin")
isWin = sys.platform.startswith("win32")
isLin = not isMac and not isWin
-devMode = os.getenv("ANKIDEV", 0)
+devMode = os.getenv("ANKIDEV", "")
invalidFilenameChars = ":*?\"<>|"
diff --git a/aqt/browser.py b/aqt/browser.py
index 840aa7f6a..0ed9aa462 100644
--- a/aqt/browser.py
+++ b/aqt/browser.py
@@ -411,6 +411,7 @@ class Browser(QMainWindow):
self.show()
def setupMenus(self):
+ # pylint: disable=unnecessary-lambda
# actions
f = self.form
f.previewButton.clicked.connect(self.onTogglePreview)
@@ -808,8 +809,8 @@ by clicking on one on the left."""))
def __init__(self):
QTreeWidget.__init__(self)
self.itemClicked.connect(self.onTreeClick)
- self.itemExpanded.connect(lambda item: self.onTreeCollapse(item))
- self.itemCollapsed.connect(lambda item: self.onTreeCollapse(item))
+ self.itemExpanded.connect(self.onTreeCollapse)
+ self.itemCollapsed.connect(self.onTreeCollapse)
def keyPressEvent(self, evt):
if evt.key() in (Qt.Key_Return, Qt.Key_Enter):
diff --git a/aqt/editcurrent.py b/aqt/editcurrent.py
index c0418222a..f5da5c4e1 100644
--- a/aqt/editcurrent.py
+++ b/aqt/editcurrent.py
@@ -31,6 +31,7 @@ class EditCurrent(QDialog):
self.mw.requireReset()
self.show()
# reset focus after open, taking care not to retain webview
+ # pylint: disable=unnecessary-lambda
self.mw.progress.timer(100, lambda: self.editor.web.setFocus(), False)
def onReset(self):
diff --git a/aqt/editor.py b/aqt/editor.py
index 52b8ef297..3b5aa4633 100644
--- a/aqt/editor.py
+++ b/aqt/editor.py
@@ -3,7 +3,6 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import re
import os
-import urllib.request, urllib.error, urllib.parse
import ctypes
import urllib.request, urllib.parse, urllib.error
import warnings
@@ -126,7 +125,7 @@ class Editor:
mime, _ = mimetypes.guess_type(path)
with open(path, 'rb') as fp:
data = fp.read()
- data64 = b''.join(base64.encodestring(data).splitlines())
+ data64 = b''.join(base64.encodebytes(data).splitlines())
return 'data:%s;base64,%s' % (mime, data64.decode('ascii'))
diff --git a/aqt/main.py b/aqt/main.py
index 3580179ab..74d506259 100644
--- a/aqt/main.py
+++ b/aqt/main.py
@@ -23,7 +23,6 @@ import aqt.webview
import aqt.toolbar
import aqt.stats
import aqt.mediasrv
-from aqt.utils import showWarning
import anki.sound
import anki.mpv
from aqt.utils import saveGeom, restoreGeom, showInfo, showWarning, \
@@ -1229,6 +1228,7 @@ will be lost. Continue?"""))
pp = pprint.pprint
self._captureOutput(True)
try:
+ # pylint: disable=exec-used
exec(text)
except:
self._output += traceback.format_exc()
diff --git a/aqt/studydeck.py b/aqt/studydeck.py
index 489a38f46..50c713deb 100644
--- a/aqt/studydeck.py
+++ b/aqt/studydeck.py
@@ -11,8 +11,10 @@ from anki.lang import _
class StudyDeck(QDialog):
def __init__(self, mw, names=None, accept=None, title=None,
help="studydeck", current=None, cancel=True,
- parent=None, dyn=False, buttons=[], geomKey="default"):
+ parent=None, dyn=False, buttons=None, geomKey="default"):
QDialog.__init__(self, parent or mw)
+ if buttons is None:
+ buttons = []
self.mw = mw
self.form = aqt.forms.studydeck.Ui_Dialog()
self.form.setupUi(self)
diff --git a/aqt/webview.py b/aqt/webview.py
index 815ba5caa..ef255099b 100644
--- a/aqt/webview.py
+++ b/aqt/webview.py
@@ -223,7 +223,11 @@ class AnkiWebView(QWebEngineView):
return QColor("#ececec")
return self.style().standardPalette().color(QPalette.Window)
- def stdHtml(self, body, css=[], js=["jquery.js"], head=""):
+ def stdHtml(self, body, css=None, js=None, head=""):
+ if css is None:
+ css = []
+ if js is None:
+ js = ["jquery.js"]
if isWin:
widgetspec = "button { font-size: 12px; font-family:'Segoe UI'; }"
fontspec = 'font-size:12px;font-family:"Segoe UI";'