Enable unsafe fixes in fix:ruff, and enable unused var warning

This commit is contained in:
Damien Elmes 2025-06-29 14:20:12 +07:00
parent 72f879cada
commit f057478c1a
14 changed files with 25 additions and 21 deletions

View file

@ -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

View file

@ -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" };

View file

@ -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,

View file

@ -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(

View file

@ -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

View file

@ -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),

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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:

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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