mirror of
https://github.com/ankitects/anki.git
synced 2026-01-13 14:03:55 -05:00
Handle rest of lints
This commit is contained in:
parent
f20c698154
commit
dbb74c371a
28 changed files with 49 additions and 53 deletions
|
|
@ -25,6 +25,7 @@ lint.ignore = [
|
||||||
"FIX002", # Line contains TODO
|
"FIX002", # Line contains TODO
|
||||||
|
|
||||||
# Pyflakes rules
|
# Pyflakes rules
|
||||||
|
"F402", # import-shadowed-by-loop-var
|
||||||
"F403", # undefined-local-with-import-star
|
"F403", # undefined-local-with-import-star
|
||||||
"F405", # undefined-local-with-import-star-usage
|
"F405", # undefined-local-with-import-star-usage
|
||||||
"F841", # unused-variable
|
"F841", # unused-variable
|
||||||
|
|
@ -45,6 +46,7 @@ lint.ignore = [
|
||||||
|
|
||||||
# Pylint rules
|
# Pylint rules
|
||||||
"PLW0603", # global-statement
|
"PLW0603", # global-statement
|
||||||
|
"PLW2901", # redefined-loop-name
|
||||||
"PLC0415", # import-outside-top-level
|
"PLC0415", # import-outside-top-level
|
||||||
"PLR2004", # magic-value-comparison
|
"PLR2004", # magic-value-comparison
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import pprint
|
||||||
import time
|
import time
|
||||||
from typing import NewType
|
from typing import NewType
|
||||||
|
|
||||||
import anki # pylint: disable=unused-import
|
import anki
|
||||||
import anki.collection
|
import anki.collection
|
||||||
import anki.decks
|
import anki.decks
|
||||||
import anki.notes
|
import anki.notes
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import time
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from typing import Any, NewType, Union
|
from typing import Any, NewType, Union
|
||||||
|
|
||||||
import anki # pylint: disable=unused-import
|
import anki
|
||||||
import anki.collection
|
import anki.collection
|
||||||
import anki.notes
|
import anki.notes
|
||||||
from anki import notetypes_pb2
|
from anki import notetypes_pb2
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import copy
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from typing import NewType
|
from typing import NewType
|
||||||
|
|
||||||
import anki # pylint: disable=unused-import
|
import anki
|
||||||
import anki.cards
|
import anki.cards
|
||||||
import anki.collection
|
import anki.collection
|
||||||
import anki.decks
|
import anki.decks
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,8 @@
|
||||||
# The backend code has moved into _backend; this file exists only to avoid breaking
|
# The backend code has moved into _backend; this file exists only to avoid breaking
|
||||||
# some add-ons. They should be updated to point to the correct location in the
|
# some add-ons. They should be updated to point to the correct location in the
|
||||||
# future.
|
# future.
|
||||||
#
|
|
||||||
# pylint: disable=unused-import
|
|
||||||
# pylint: enable=invalid-name
|
|
||||||
|
|
||||||
|
# ruff: noqa: F401
|
||||||
from anki.decks import DeckTreeNode
|
from anki.decks import DeckTreeNode
|
||||||
from anki.errors import InvalidInput, NotFoundError
|
from anki.errors import InvalidInput, NotFoundError
|
||||||
from anki.lang import TR
|
from anki.lang import TR
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import re
|
||||||
from collections.abc import Collection, Sequence
|
from collections.abc import Collection, Sequence
|
||||||
from typing import Match
|
from typing import Match
|
||||||
|
|
||||||
import anki # pylint: disable=unused-import
|
import anki
|
||||||
import anki.collection
|
import anki.collection
|
||||||
from anki import tags_pb2
|
from anki import tags_pb2
|
||||||
from anki._legacy import DeprecatedNamesMixin, deprecated
|
from anki._legacy import DeprecatedNamesMixin, deprecated
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ prefix = """\
|
||||||
# This file is automatically generated; edit tools/genhooks.py instead.
|
# This file is automatically generated; edit tools/genhooks.py instead.
|
||||||
# Please import from anki.hooks instead of this file.
|
# Please import from anki.hooks instead of this file.
|
||||||
|
|
||||||
# pylint: disable=unused-import
|
# ruff: noqa: F401
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
# ruff: noqa: F401
|
||||||
import atexit
|
import atexit
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ from __future__ import annotations
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
from anki_mac_helper import ( # pylint:disable=unused-import,import-error
|
from anki_mac_helper import macos_helper
|
||||||
macos_helper,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
macos_helper = None
|
macos_helper = None
|
||||||
|
|
|
||||||
|
|
@ -927,7 +927,6 @@ class AddonsDialog(QDialog):
|
||||||
or self.mgr.configAction(addon.dir_name)
|
or self.mgr.configAction(addon.dir_name)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
|
||||||
def _onAddonItemSelected(self, row_int: int) -> None:
|
def _onAddonItemSelected(self, row_int: int) -> None:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
# ruff: noqa: F401
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
# Copyright: Ankitects Pty Ltd and contributors
|
# Copyright: Ankitects Pty Ltd and contributors
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
# ruff: noqa: F401
|
||||||
from anki.utils import is_mac
|
from anki.utils import is_mac
|
||||||
from aqt.theme import theme_manager
|
from aqt.theme import theme_manager
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
# ruff: noqa: F401
|
||||||
import copy
|
import copy
|
||||||
import time
|
import time
|
||||||
from collections.abc import Generator, Sequence
|
from collections.abc import Generator, Sequence
|
||||||
|
|
|
||||||
|
|
@ -361,8 +361,7 @@ class Table:
|
||||||
for m in self.col.models.all():
|
for m in self.col.models.all():
|
||||||
for t in m["tmpls"]:
|
for t in m["tmpls"]:
|
||||||
bsize = t.get("bsize", 0)
|
bsize = t.get("bsize", 0)
|
||||||
if bsize > curmax:
|
curmax = max(curmax, bsize)
|
||||||
curmax = bsize
|
|
||||||
|
|
||||||
assert self._view is not None
|
assert self._view is not None
|
||||||
vh = self._view.verticalHeader()
|
vh = self._view.verticalHeader()
|
||||||
|
|
|
||||||
|
|
@ -1029,15 +1029,14 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
||||||
m = re.match(r"http://127.0.0.1:\d+/(.*)$", str(src))
|
m = re.match(r"http://127.0.0.1:\d+/(.*)$", str(src))
|
||||||
if m:
|
if m:
|
||||||
tag["src"] = m.group(1)
|
tag["src"] = m.group(1)
|
||||||
else:
|
# in external pastes, download remote media
|
||||||
# in external pastes, download remote media
|
elif isinstance(src, str) and self.isURL(src):
|
||||||
if isinstance(src, str) and self.isURL(src):
|
fname = self._retrieveURL(src)
|
||||||
fname = self._retrieveURL(src)
|
if fname:
|
||||||
if fname:
|
tag["src"] = fname
|
||||||
tag["src"] = fname
|
elif isinstance(src, str) and src.startswith("data:image/"):
|
||||||
elif isinstance(src, str) and src.startswith("data:image/"):
|
# and convert inlined data
|
||||||
# and convert inlined data
|
tag["src"] = self.inlinedImageToFilename(str(src))
|
||||||
tag["src"] = self.inlinedImageToFilename(str(src))
|
|
||||||
|
|
||||||
html = str(doc)
|
html = str(doc)
|
||||||
return html
|
return html
|
||||||
|
|
|
||||||
|
|
@ -212,11 +212,10 @@ class ExportDialog(QDialog):
|
||||||
if self.isVerbatim:
|
if self.isVerbatim:
|
||||||
msg = tr.exporting_collection_exported()
|
msg = tr.exporting_collection_exported()
|
||||||
self.mw.reopen()
|
self.mw.reopen()
|
||||||
|
elif self.isTextNote:
|
||||||
|
msg = tr.exporting_note_exported(count=self.exporter.count)
|
||||||
else:
|
else:
|
||||||
if self.isTextNote:
|
msg = tr.exporting_card_exported(count=self.exporter.count)
|
||||||
msg = tr.exporting_note_exported(count=self.exporter.count)
|
|
||||||
else:
|
|
||||||
msg = tr.exporting_card_exported(count=self.exporter.count)
|
|
||||||
gui_hooks.legacy_exporter_did_export(self.exporter)
|
gui_hooks.legacy_exporter_did_export(self.exporter)
|
||||||
tooltip(msg, period=3000)
|
tooltip(msg, period=3000)
|
||||||
QDialog.reject(self)
|
QDialog.reject(self)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# ruff: noqa: F401
|
||||||
from . import (
|
from . import (
|
||||||
about,
|
about,
|
||||||
addcards,
|
addcards,
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ from collections.abc import Callable
|
||||||
from concurrent.futures import Future
|
from concurrent.futures import Future
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import anki.importing as importing
|
|
||||||
import aqt.deckchooser
|
import aqt.deckchooser
|
||||||
import aqt.forms
|
import aqt.forms
|
||||||
import aqt.modelchooser
|
import aqt.modelchooser
|
||||||
|
from anki import importing
|
||||||
from anki.importing.anki2 import MediaMapInvalid, V2ImportIntoV1
|
from anki.importing.anki2 import MediaMapInvalid, V2ImportIntoV1
|
||||||
from anki.importing.apkg import AnkiPackageImporter
|
from anki.importing.apkg import AnkiPackageImporter
|
||||||
from aqt.import_export.importing import ColpkgImporter
|
from aqt.import_export.importing import ColpkgImporter
|
||||||
|
|
@ -443,3 +443,4 @@ def setupApkgImport(mw: AnkiQt, importer: AnkiPackageImporter) -> bool:
|
||||||
return True
|
return True
|
||||||
ColpkgImporter.do_import(mw, importer.file)
|
ColpkgImporter.do_import(mw, importer.file)
|
||||||
return False
|
return False
|
||||||
|
return False
|
||||||
|
|
|
||||||
|
|
@ -376,7 +376,6 @@ class AnkiQt(QMainWindow):
|
||||||
def openProfile(self) -> None:
|
def openProfile(self) -> None:
|
||||||
name = self.pm.profiles()[self.profileForm.profiles.currentRow()]
|
name = self.pm.profiles()[self.profileForm.profiles.currentRow()]
|
||||||
self.pm.load(name)
|
self.pm.load(name)
|
||||||
return
|
|
||||||
|
|
||||||
def onOpenProfile(self, *, callback: Callable[[], None] | None = None) -> None:
|
def onOpenProfile(self, *, callback: Callable[[], None] | None = None) -> None:
|
||||||
def on_done() -> None:
|
def on_done() -> None:
|
||||||
|
|
@ -821,7 +820,7 @@ class AnkiQt(QMainWindow):
|
||||||
self.bottomWeb.hide_timer.start()
|
self.bottomWeb.hide_timer.start()
|
||||||
|
|
||||||
def _reviewCleanup(self, newState: MainWindowState) -> None:
|
def _reviewCleanup(self, newState: MainWindowState) -> None:
|
||||||
if newState != "resetRequired" and newState != "review":
|
if newState not in {"resetRequired", "review"}:
|
||||||
self.reviewer.auto_advance_enabled = False
|
self.reviewer.auto_advance_enabled = False
|
||||||
self.reviewer.cleanup()
|
self.reviewer.cleanup()
|
||||||
self.toolbarWeb.elevate()
|
self.toolbarWeb.elevate()
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ class Overview:
|
||||||
self.mw.moveToState("deckBrowser")
|
self.mw.moveToState("deckBrowser")
|
||||||
elif url == "review":
|
elif url == "review":
|
||||||
openLink(f"{aqt.appShared}info/{self.sid}?v={self.sidVer}")
|
openLink(f"{aqt.appShared}info/{self.sid}?v={self.sidVer}")
|
||||||
elif url == "studymore" or url == "customStudy":
|
elif url in {"studymore", "customStudy"}:
|
||||||
self.onStudyMore()
|
self.onStudyMore()
|
||||||
elif url == "unbury":
|
elif url == "unbury":
|
||||||
self.on_unbury()
|
self.on_unbury()
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ from pathlib import Path
|
||||||
from anki.utils import is_mac
|
from anki.utils import is_mac
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-import,import-error
|
# ruff: noqa: F401
|
||||||
def first_run_setup() -> None:
|
def first_run_setup() -> None:
|
||||||
"""Code run the first time after install/upgrade.
|
"""Code run the first time after install/upgrade.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ class ProfileManager:
|
||||||
default_answer_keys = {ease_num: str(ease_num) for ease_num in range(1, 5)}
|
default_answer_keys = {ease_num: str(ease_num) for ease_num in range(1, 5)}
|
||||||
last_run_version: int = 0
|
last_run_version: int = 0
|
||||||
|
|
||||||
def __init__(self, base: Path) -> None: #
|
def __init__(self, base: Path) -> None:
|
||||||
"base should be retrieved via ProfileMangager.get_created_base_folder"
|
"base should be retrieved via ProfileMangager.get_created_base_folder"
|
||||||
## Settings which should be forgotten each Anki restart
|
## Settings which should be forgotten each Anki restart
|
||||||
self.session: dict[str, Any] = {}
|
self.session: dict[str, Any] = {}
|
||||||
|
|
|
||||||
|
|
@ -119,13 +119,12 @@ class ProgressManager:
|
||||||
if not self._levels:
|
if not self._levels:
|
||||||
# no current progress; safe to fire
|
# no current progress; safe to fire
|
||||||
func()
|
func()
|
||||||
|
elif repeat:
|
||||||
|
# skip this time; we'll fire again
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
if repeat:
|
# retry in 100ms
|
||||||
# skip this time; we'll fire again
|
self.single_shot(100, func, requires_collection)
|
||||||
pass
|
|
||||||
else:
|
|
||||||
# retry in 100ms
|
|
||||||
self.single_shot(100, func, requires_collection)
|
|
||||||
|
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
# make sure not to optimize imports on this file
|
# make sure not to optimize imports on this file
|
||||||
# pylint: disable=unused-import
|
# ruff: noqa: F401
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
# make sure not to optimize imports on this file
|
# make sure not to optimize imports on this file
|
||||||
# pylint: disable=unused-import
|
# ruff: noqa: F401
|
||||||
|
|
||||||
"""
|
"""
|
||||||
PyQt6 imports
|
PyQt6 imports
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -213,13 +213,12 @@ class ThemeManager:
|
||||||
return False
|
return False
|
||||||
elif theme == Theme.DARK:
|
elif theme == Theme.DARK:
|
||||||
return True
|
return True
|
||||||
|
elif is_win:
|
||||||
|
return get_windows_dark_mode()
|
||||||
|
elif is_mac:
|
||||||
|
return get_macos_dark_mode()
|
||||||
else:
|
else:
|
||||||
if is_win:
|
return get_linux_dark_mode()
|
||||||
return get_windows_dark_mode()
|
|
||||||
elif is_mac:
|
|
||||||
return get_macos_dark_mode()
|
|
||||||
else:
|
|
||||||
return get_linux_dark_mode()
|
|
||||||
|
|
||||||
def apply_style(self) -> None:
|
def apply_style(self) -> None:
|
||||||
"Apply currently configured style."
|
"Apply currently configured style."
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ from send2trash import send2trash
|
||||||
import aqt
|
import aqt
|
||||||
from anki._legacy import DeprecatedNamesMixinForModule
|
from anki._legacy import DeprecatedNamesMixinForModule
|
||||||
from anki.collection import Collection, HelpPage
|
from anki.collection import Collection, HelpPage
|
||||||
from anki.lang import TR, tr_legacyglobal # pylint: disable=unused-import
|
from anki.lang import TR, tr_legacyglobal # noqa: F401
|
||||||
from anki.utils import (
|
from anki.utils import (
|
||||||
call,
|
call,
|
||||||
invalid_filename,
|
invalid_filename,
|
||||||
|
|
@ -29,9 +29,9 @@ from anki.utils import (
|
||||||
version_with_build,
|
version_with_build,
|
||||||
)
|
)
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
|
from aqt.qt import QT_VERSION_STR # noqa: F401
|
||||||
from aqt.qt import (
|
from aqt.qt import (
|
||||||
PYQT_VERSION_STR,
|
PYQT_VERSION_STR,
|
||||||
QT_VERSION_STR,
|
|
||||||
QAction,
|
QAction,
|
||||||
QApplication,
|
QApplication,
|
||||||
QCheckBox,
|
QCheckBox,
|
||||||
|
|
@ -294,7 +294,7 @@ def showInfo(
|
||||||
icon = QMessageBox.Icon.Critical
|
icon = QMessageBox.Icon.Critical
|
||||||
else:
|
else:
|
||||||
icon = QMessageBox.Icon.Information
|
icon = QMessageBox.Icon.Information
|
||||||
mb = QMessageBox(parent_widget) #
|
mb = QMessageBox(parent_widget)
|
||||||
if textFormat == "plain":
|
if textFormat == "plain":
|
||||||
mb.setTextFormat(Qt.TextFormat.PlainText)
|
mb.setTextFormat(Qt.TextFormat.PlainText)
|
||||||
elif textFormat == "rich":
|
elif textFormat == "rich":
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,11 @@ except Exception as e:
|
||||||
print_error(
|
print_error(
|
||||||
f"Could not establish connection to Chromium remote debugger. Is Anki Open? Exception:\n{e}"
|
f"Could not establish connection to Chromium remote debugger. Is Anki Open? Exception:\n{e}"
|
||||||
)
|
)
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if chrome.tabs is None:
|
if chrome.tabs is None:
|
||||||
print_error("Was unable to get active web views.")
|
print_error("Was unable to get active web views.")
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
for tab_index, tab_data in enumerate(chrome.tabs):
|
for tab_index, tab_data in enumerate(chrome.tabs):
|
||||||
print(f"Reloading page: {tab_data['title']}")
|
print(f"Reloading page: {tab_data['title']}")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue