diff --git a/.ruff.toml b/.ruff.toml index 09f6a1b9c..cb1d651e4 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -28,7 +28,6 @@ lint.ignore = [ "F402", # import-shadowed-by-loop-var "F403", # undefined-local-with-import-star "F405", # undefined-local-with-import-star-usage - "F841", # unused-variable # Naming rules (invalid-name in pylint) "N801", # Class name should use CapWords convention diff --git a/build/ninja_gen/src/python.rs b/build/ninja_gen/src/python.rs index e1d8d9b46..93385e2cb 100644 --- a/build/ninja_gen/src/python.rs +++ b/build/ninja_gen/src/python.rs @@ -248,7 +248,14 @@ impl BuildAction for RuffCheck { build.add_inputs("", &self.deps); build.add_inputs("ruff", inputs![":pyenv:ruff"]); build.add_variable("folders", self.folders.join(" ")); - build.add_variable("mode", if self.check_only { "" } else { "--fix" }); + build.add_variable( + "mode", + if self.check_only { + "" + } else { + "--fix --unsafe-fixes" + }, + ); let hash = simple_hash(&self.deps); let kind = if self.check_only { "check" } else { "fix" }; diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index 172ec2a2c..e0864b301 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -29,7 +29,7 @@ if sys.version_info[0] < 3 or sys.version_info[1] < 9: # ensure unicode filenames are supported try: "ใƒ†ใ‚นใƒˆ".encode(sys.getfilesystemencoding()) -except UnicodeEncodeError as exc: +except UnicodeEncodeError: print("Anki requires a UTF-8 locale.") print("Please Google 'how to change locale on [your Linux distro]'") sys.exit(1) @@ -558,7 +558,7 @@ def run() -> None: print(f"Starting Anki {_version}...") try: _run() - except Exception as e: + except Exception: traceback.print_exc() QMessageBox.critical( None, diff --git a/qt/aqt/browser/sidebar/tree.py b/qt/aqt/browser/sidebar/tree.py index e28f166e9..22d7fa4a6 100644 --- a/qt/aqt/browser/sidebar/tree.py +++ b/qt/aqt/browser/sidebar/tree.py @@ -106,7 +106,7 @@ class SidebarTreeView(QTreeView): def _setup_style(self) -> None: # match window background color and tweak style bgcolor = QPalette().window().color().name() - border = theme_manager.var(colors.BORDER) + theme_manager.var(colors.BORDER) styles = [ "padding: 3px", "padding-right: 0px", @@ -711,7 +711,6 @@ class SidebarTreeView(QTreeView): def _flags_tree(self, root: SidebarItem) -> None: icon_off = "icons:flag-variant-off-outline.svg" - icon = "icons:flag-variant.svg" icon_outline = "icons:flag-variant-outline.svg" root = self._section_root( diff --git a/qt/aqt/browser/table/model.py b/qt/aqt/browser/table/model.py index e8d3bb7b6..732e8c99c 100644 --- a/qt/aqt/browser/table/model.py +++ b/qt/aqt/browser/table/model.py @@ -105,11 +105,11 @@ class DataModel(QAbstractTableModel): row = CellRow(*self.col.browser_row_for_id(item)) except BackendError as e: return CellRow.disabled(self.len_columns(), str(e)) - except Exception as e: + except Exception: return CellRow.disabled( self.len_columns(), tr.errors_please_check_database() ) - except BaseException as e: + except BaseException: # fatal error like a panic in the backend - dump it to the # console so it gets picked up by the error handler import traceback diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index bbad44bd6..f2f267097 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -796,7 +796,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too def accept(file: str) -> None: self.resolve_media(file) - file = getFile( + getFile( parent=self.widget, title=tr.editing_add_media(), cb=cast(Callable[[Any], None], accept), @@ -999,7 +999,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too if html.find(">") < 0: return html - with warnings.catch_warnings() as w: + with warnings.catch_warnings(): warnings.simplefilter("ignore", UserWarning) doc = BeautifulSoup(html, "html.parser") @@ -1101,7 +1101,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too ) filter = f"{tr.editing_media()} ({extension_filter})" - file = getFile( + getFile( parent=self.widget, title=tr.editing_add_media(), cb=cast(Callable[[Any], None], self.setup_mask_editor), diff --git a/qt/aqt/importing.py b/qt/aqt/importing.py index 282d15339..8701f9843 100644 --- a/qt/aqt/importing.py +++ b/qt/aqt/importing.py @@ -357,7 +357,7 @@ def importFile(mw: AnkiQt, file: str) -> None: try: importer.open() mw.progress.finish() - diag = ImportDialog(mw, importer) + ImportDialog(mw, importer) except UnicodeDecodeError: mw.progress.finish() showUnicodeWarning() diff --git a/qt/aqt/main.py b/qt/aqt/main.py index c141dc20c..e2e6f8534 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -675,7 +675,7 @@ class AnkiQt(QMainWindow): gui_hooks.collection_did_load(self.col) self.apply_collection_options() self.moveToState("deckBrowser") - except Exception as e: + except Exception: # dump error to stderr so it gets picked up by errors.py traceback.print_exc() diff --git a/qt/aqt/mpv.py b/qt/aqt/mpv.py index ac6a05b05..2586d024a 100644 --- a/qt/aqt/mpv.py +++ b/qt/aqt/mpv.py @@ -396,7 +396,7 @@ class MPVBase: return self._get_response(timeout) except MPVCommandError as e: raise MPVCommandError(f"{message['command']!r}: {e}") - except Exception as e: + except Exception: if _retry: print("mpv timed out, restarting") self._stop_process() diff --git a/qt/aqt/overview.py b/qt/aqt/overview.py index bbdbde3a6..b1fc9a119 100644 --- a/qt/aqt/overview.py +++ b/qt/aqt/overview.py @@ -180,7 +180,6 @@ class Overview: ############################################################ def _renderPage(self) -> None: - but = self.mw.button deck = self.mw.col.decks.current() self.sid = deck.get("sharedFrom") if self.sid: diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index 9ceeb713c..919be170c 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -153,7 +153,7 @@ class ProfileManager: else: try: self.load(profile) - except Exception as exc: + except Exception: self.invalid_profile_provided_on_commandline = True # Profile load/save diff --git a/qt/aqt/theme.py b/qt/aqt/theme.py index 6e91b2649..675eb9345 100644 --- a/qt/aqt/theme.py +++ b/qt/aqt/theme.py @@ -351,7 +351,7 @@ def get_windows_dark_mode() -> bool: r"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", ) return not QueryValueEx(key, "AppsUseLightTheme")[0] - except Exception as err: + except Exception: # key reportedly missing or set to wrong type on some systems return False @@ -415,12 +415,12 @@ def get_linux_dark_mode() -> bool: capture_output=True, encoding="utf8", ) - except FileNotFoundError as e: + except FileNotFoundError: # detection strategy failed, missing program # print(e) continue - except subprocess.CalledProcessError as e: + except subprocess.CalledProcessError: # detection strategy failed, command returned error # print(e) continue diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 9f48ea788..64d057082 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -1268,7 +1268,7 @@ def opengl_vendor() -> str | None: try: vf = ctx.versionFunctions(vp) # type: ignore - except ImportError as e: + except ImportError: return None if vf is None: diff --git a/qt/aqt/winpaths.py b/qt/aqt/winpaths.py index e53a47c06..8b2698739 100644 --- a/qt/aqt/winpaths.py +++ b/qt/aqt/winpaths.py @@ -100,7 +100,7 @@ _SHGetFolderPath.restype = _err_unless_zero def _get_path_buf(csidl): path_buf = ctypes.create_unicode_buffer(wintypes.MAX_PATH) - result = _SHGetFolderPath(0, csidl, 0, 0, path_buf) + _SHGetFolderPath(0, csidl, 0, 0, path_buf) return path_buf.value