Handle rest of lints

This commit is contained in:
Abdo 2025-06-23 12:17:56 +03:00
parent f20c698154
commit dbb74c371a
28 changed files with 49 additions and 53 deletions

View file

@ -25,6 +25,7 @@ lint.ignore = [
"FIX002", # Line contains TODO
# Pyflakes rules
"F402", # import-shadowed-by-loop-var
"F403", # undefined-local-with-import-star
"F405", # undefined-local-with-import-star-usage
"F841", # unused-variable
@ -45,6 +46,7 @@ lint.ignore = [
# Pylint rules
"PLW0603", # global-statement
"PLW2901", # redefined-loop-name
"PLC0415", # import-outside-top-level
"PLR2004", # magic-value-comparison

View file

@ -7,7 +7,7 @@ import pprint
import time
from typing import NewType
import anki # pylint: disable=unused-import
import anki
import anki.collection
import anki.decks
import anki.notes

View file

@ -10,7 +10,7 @@ import time
from collections.abc import Sequence
from typing import Any, NewType, Union
import anki # pylint: disable=unused-import
import anki
import anki.collection
import anki.notes
from anki import notetypes_pb2

View file

@ -7,7 +7,7 @@ import copy
from collections.abc import Sequence
from typing import NewType
import anki # pylint: disable=unused-import
import anki
import anki.cards
import anki.collection
import anki.decks

View file

@ -4,10 +4,8 @@
# 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
# future.
#
# pylint: disable=unused-import
# pylint: enable=invalid-name
# ruff: noqa: F401
from anki.decks import DeckTreeNode
from anki.errors import InvalidInput, NotFoundError
from anki.lang import TR

View file

@ -16,7 +16,7 @@ import re
from collections.abc import Collection, Sequence
from typing import Match
import anki # pylint: disable=unused-import
import anki
import anki.collection
from anki import tags_pb2
from anki._legacy import DeprecatedNamesMixin, deprecated

View file

@ -133,7 +133,7 @@ prefix = """\
# This file is automatically generated; edit tools/genhooks.py instead.
# Please import from anki.hooks instead of this file.
# pylint: disable=unused-import
# ruff: noqa: F401
from __future__ import annotations

View file

@ -3,6 +3,7 @@
from __future__ import annotations
# ruff: noqa: F401
import atexit
import logging
import os

View file

@ -6,8 +6,6 @@ from __future__ import annotations
import sys
if sys.platform == "darwin":
from anki_mac_helper import ( # pylint:disable=unused-import,import-error
macos_helper,
)
from anki_mac_helper import macos_helper
else:
macos_helper = None

View file

@ -927,7 +927,6 @@ class AddonsDialog(QDialog):
or self.mgr.configAction(addon.dir_name)
)
)
return
def _onAddonItemSelected(self, row_int: int) -> None:
try:

View file

@ -2,6 +2,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations
# ruff: noqa: F401
import sys
import aqt

View file

@ -1,5 +1,6 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# ruff: noqa: F401
from anki.utils import is_mac
from aqt.theme import theme_manager

View file

@ -2,6 +2,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations
# ruff: noqa: F401
import copy
import time
from collections.abc import Generator, Sequence

View file

@ -361,8 +361,7 @@ class Table:
for m in self.col.models.all():
for t in m["tmpls"]:
bsize = t.get("bsize", 0)
if bsize > curmax:
curmax = bsize
curmax = max(curmax, bsize)
assert self._view is not None
vh = self._view.verticalHeader()

View file

@ -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))
if m:
tag["src"] = m.group(1)
else:
# in external pastes, download remote media
if isinstance(src, str) and self.isURL(src):
fname = self._retrieveURL(src)
if fname:
tag["src"] = fname
elif isinstance(src, str) and src.startswith("data:image/"):
# and convert inlined data
tag["src"] = self.inlinedImageToFilename(str(src))
# in external pastes, download remote media
elif isinstance(src, str) and self.isURL(src):
fname = self._retrieveURL(src)
if fname:
tag["src"] = fname
elif isinstance(src, str) and src.startswith("data:image/"):
# and convert inlined data
tag["src"] = self.inlinedImageToFilename(str(src))
html = str(doc)
return html

View file

@ -212,11 +212,10 @@ class ExportDialog(QDialog):
if self.isVerbatim:
msg = tr.exporting_collection_exported()
self.mw.reopen()
elif self.isTextNote:
msg = tr.exporting_note_exported(count=self.exporter.count)
else:
if self.isTextNote:
msg = tr.exporting_note_exported(count=self.exporter.count)
else:
msg = tr.exporting_card_exported(count=self.exporter.count)
msg = tr.exporting_card_exported(count=self.exporter.count)
gui_hooks.legacy_exporter_did_export(self.exporter)
tooltip(msg, period=3000)
QDialog.reject(self)

View file

@ -1,3 +1,4 @@
# ruff: noqa: F401
from . import (
about,
addcards,

View file

@ -11,10 +11,10 @@ from collections.abc import Callable
from concurrent.futures import Future
from typing import Any
import anki.importing as importing
import aqt.deckchooser
import aqt.forms
import aqt.modelchooser
from anki import importing
from anki.importing.anki2 import MediaMapInvalid, V2ImportIntoV1
from anki.importing.apkg import AnkiPackageImporter
from aqt.import_export.importing import ColpkgImporter
@ -443,3 +443,4 @@ def setupApkgImport(mw: AnkiQt, importer: AnkiPackageImporter) -> bool:
return True
ColpkgImporter.do_import(mw, importer.file)
return False
return False

View file

@ -376,7 +376,6 @@ class AnkiQt(QMainWindow):
def openProfile(self) -> None:
name = self.pm.profiles()[self.profileForm.profiles.currentRow()]
self.pm.load(name)
return
def onOpenProfile(self, *, callback: Callable[[], None] | None = None) -> None:
def on_done() -> None:
@ -821,7 +820,7 @@ class AnkiQt(QMainWindow):
self.bottomWeb.hide_timer.start()
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.cleanup()
self.toolbarWeb.elevate()

View file

@ -113,7 +113,7 @@ class Overview:
self.mw.moveToState("deckBrowser")
elif url == "review":
openLink(f"{aqt.appShared}info/{self.sid}?v={self.sidVer}")
elif url == "studymore" or url == "customStudy":
elif url in {"studymore", "customStudy"}:
self.onStudyMore()
elif url == "unbury":
self.on_unbury()

View file

@ -11,7 +11,7 @@ from pathlib import Path
from anki.utils import is_mac
# pylint: disable=unused-import,import-error
# ruff: noqa: F401
def first_run_setup() -> None:
"""Code run the first time after install/upgrade.

View file

@ -128,7 +128,7 @@ class ProfileManager:
default_answer_keys = {ease_num: str(ease_num) for ease_num in range(1, 5)}
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"
## Settings which should be forgotten each Anki restart
self.session: dict[str, Any] = {}

View file

@ -119,13 +119,12 @@ class ProgressManager:
if not self._levels:
# no current progress; safe to fire
func()
elif repeat:
# skip this time; we'll fire again
pass
else:
if repeat:
# skip this time; we'll fire again
pass
else:
# retry in 100ms
self.single_shot(100, func, requires_collection)
# retry in 100ms
self.single_shot(100, func, requires_collection)
return handler

View file

@ -2,7 +2,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# make sure not to optimize imports on this file
# pylint: disable=unused-import
# ruff: noqa: F401
from __future__ import annotations
import os

View file

@ -2,8 +2,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# make sure not to optimize imports on this file
# pylint: disable=unused-import
# ruff: noqa: F401
"""
PyQt6 imports
"""

View file

@ -213,13 +213,12 @@ class ThemeManager:
return False
elif theme == Theme.DARK:
return True
elif is_win:
return get_windows_dark_mode()
elif is_mac:
return get_macos_dark_mode()
else:
if is_win:
return get_windows_dark_mode()
elif is_mac:
return get_macos_dark_mode()
else:
return get_linux_dark_mode()
return get_linux_dark_mode()
def apply_style(self) -> None:
"Apply currently configured style."

View file

@ -19,7 +19,7 @@ from send2trash import send2trash
import aqt
from anki._legacy import DeprecatedNamesMixinForModule
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 (
call,
invalid_filename,
@ -29,9 +29,9 @@ from anki.utils import (
version_with_build,
)
from aqt.qt import *
from aqt.qt import QT_VERSION_STR # noqa: F401
from aqt.qt import (
PYQT_VERSION_STR,
QT_VERSION_STR,
QAction,
QApplication,
QCheckBox,
@ -294,7 +294,7 @@ def showInfo(
icon = QMessageBox.Icon.Critical
else:
icon = QMessageBox.Icon.Information
mb = QMessageBox(parent_widget) #
mb = QMessageBox(parent_widget)
if textFormat == "plain":
mb.setTextFormat(Qt.TextFormat.PlainText)
elif textFormat == "rich":

View file

@ -43,11 +43,11 @@ except Exception as e:
print_error(
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:
print_error("Was unable to get active web views.")
exit(1)
sys.exit(1)
for tab_index, tab_data in enumerate(chrome.tabs):
print(f"Reloading page: {tab_data['title']}")