mirror of
https://github.com/ankitects/anki.git
synced 2026-01-13 22:13:58 -05:00
Run ruff-format
This commit is contained in:
parent
70e1302545
commit
aaad6ff2e0
21 changed files with 47 additions and 44 deletions
|
|
@ -164,7 +164,7 @@ class RustBackend(RustBackendGenerated):
|
|||
finally:
|
||||
elapsed = time.time() - start
|
||||
if current_thread() is main_thread() and elapsed > 0.2:
|
||||
print(f"blocked main thread for {int(elapsed*1000)}ms:")
|
||||
print(f"blocked main thread for {int(elapsed * 1000)}ms:")
|
||||
print("".join(traceback.format_stack()))
|
||||
|
||||
err = backend_pb2.BackendError()
|
||||
|
|
|
|||
|
|
@ -867,7 +867,9 @@ class Collection(DeprecatedNamesMixin):
|
|||
return column
|
||||
return None
|
||||
|
||||
def browser_row_for_id(self, id_: int) -> tuple[
|
||||
def browser_row_for_id(
|
||||
self, id_: int
|
||||
) -> tuple[
|
||||
Generator[tuple[str, bool, BrowserRow.Cell.TextElideMode.V], None, None],
|
||||
BrowserRow.Color.V,
|
||||
str,
|
||||
|
|
|
|||
|
|
@ -198,9 +198,7 @@ def get_def_lang(user_lang: str | None = None) -> tuple[int, str]:
|
|||
# getdefaultlocale() is deprecated since Python 3.11, but we need to keep using it as getlocale() behaves differently: https://bugs.python.org/issue38805
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", DeprecationWarning)
|
||||
(sys_lang, enc) = (
|
||||
locale.getdefaultlocale() # pylint: disable=deprecated-method
|
||||
)
|
||||
(sys_lang, enc) = locale.getdefaultlocale() # pylint: disable=deprecated-method
|
||||
except AttributeError:
|
||||
# this will return a different format on Windows (e.g. Italian_Italy), resulting in us falling back to en_US
|
||||
# further below
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ def _legacy_card_stats(
|
|||
col: anki.collection.Collection, card_id: anki.cards.CardId, include_revlog: bool
|
||||
) -> str:
|
||||
"A quick hack to preserve compatibility with the old HTML string API."
|
||||
random_id = f"cardinfo-{base62(random.randint(0, 2 ** 64 - 1))}"
|
||||
random_id = f"cardinfo-{base62(random.randint(0, 2**64 - 1))}"
|
||||
varName = random_id.replace("-", "")
|
||||
return f"""
|
||||
<div id="{random_id}"></div>
|
||||
|
|
|
|||
|
|
@ -169,8 +169,7 @@ def test_find_cards():
|
|||
# properties
|
||||
id = col.db.scalar("select id from cards limit 1")
|
||||
col.db.execute(
|
||||
"update cards set queue=2, ivl=10, reps=20, due=30, factor=2200 "
|
||||
"where id = ?",
|
||||
"update cards set queue=2, ivl=10, reps=20, due=30, factor=2200 where id = ?",
|
||||
id,
|
||||
)
|
||||
assert len(col.find_cards("prop:ivl>5")) == 1
|
||||
|
|
|
|||
|
|
@ -554,9 +554,7 @@ def test_bury():
|
|||
col.sched.bury_cards([c.id], manual=True) # pylint: disable=unexpected-keyword-arg
|
||||
c.load()
|
||||
assert c.queue == QUEUE_TYPE_MANUALLY_BURIED
|
||||
col.sched.bury_cards(
|
||||
[c2.id], manual=False
|
||||
) # pylint: disable=unexpected-keyword-arg
|
||||
col.sched.bury_cards([c2.id], manual=False) # pylint: disable=unexpected-keyword-arg
|
||||
c2.load()
|
||||
assert c2.queue == QUEUE_TYPE_SIBLING_BURIED
|
||||
|
||||
|
|
|
|||
|
|
@ -286,7 +286,6 @@ class NativeEventFilter(QAbstractNativeEventFilter):
|
|||
def nativeEventFilter(
|
||||
self, eventType: Any, message: Any
|
||||
) -> tuple[bool, Any | None]:
|
||||
|
||||
if eventType == "windows_generic_MSG":
|
||||
import ctypes.wintypes
|
||||
|
||||
|
|
|
|||
|
|
@ -1456,7 +1456,9 @@ class ChooseAddonsToUpdateDialog(QDialog):
|
|||
layout.addWidget(addons_list_widget)
|
||||
self.addons_list_widget = addons_list_widget
|
||||
|
||||
button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) # type: ignore
|
||||
button_box = QDialogButtonBox(
|
||||
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
|
||||
) # type: ignore
|
||||
qconnect(
|
||||
button_box.button(QDialogButtonBox.StandardButton.Ok).clicked, self.accept
|
||||
)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ def ankihub_login(
|
|||
username: str = "",
|
||||
password: str = "",
|
||||
) -> None:
|
||||
|
||||
def on_future_done(fut: Future[str], username: str, password: str) -> None:
|
||||
try:
|
||||
token = fut.result()
|
||||
|
|
@ -73,7 +72,6 @@ def ankihub_logout(
|
|||
on_success: Callable[[], None],
|
||||
token: str,
|
||||
) -> None:
|
||||
|
||||
def logout() -> None:
|
||||
mw.pm.set_ankihub_username(None)
|
||||
mw.pm.set_ankihub_token(None)
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ class CardLayout(QDialog):
|
|||
)
|
||||
for i in range(min(len(self.cloze_numbers), 9)):
|
||||
QShortcut( # type: ignore
|
||||
QKeySequence(f"Alt+{i+1}"),
|
||||
QKeySequence(f"Alt+{i + 1}"),
|
||||
self,
|
||||
activated=lambda n=i: self.pform.cloze_number_combo.setCurrentIndex(n),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -386,9 +386,7 @@ class DeckBrowser:
|
|||
if b[0]:
|
||||
b[0] = tr.actions_shortcut_key(val=shortcut(b[0]))
|
||||
buf += """
|
||||
<button title='%s' onclick='pycmd(\"%s\");'>%s</button>""" % tuple(
|
||||
b
|
||||
)
|
||||
<button title='%s' onclick='pycmd(\"%s\");'>%s</button>""" % tuple(b)
|
||||
self.bottom.draw(
|
||||
buf=buf,
|
||||
link_handler=self._linkHandler,
|
||||
|
|
|
|||
|
|
@ -450,7 +450,6 @@ class AnkiQt(QMainWindow):
|
|||
self.loadProfile()
|
||||
|
||||
def onOpenBackup(self) -> None:
|
||||
|
||||
def do_open(path: str) -> None:
|
||||
if not askUser(
|
||||
tr.qt_misc_replace_your_collection_with_an_earlier2(
|
||||
|
|
|
|||
|
|
@ -230,7 +230,11 @@ def _handle_local_file_request(request: LocalFileRequest) -> Response:
|
|||
else:
|
||||
max_age = 60 * 60
|
||||
return flask.send_file(
|
||||
fullpath, mimetype=mimetype, conditional=True, max_age=max_age, download_name="foo" # type: ignore[call-arg]
|
||||
fullpath,
|
||||
mimetype=mimetype,
|
||||
conditional=True,
|
||||
max_age=max_age,
|
||||
download_name="foo", # type: ignore[call-arg]
|
||||
)
|
||||
else:
|
||||
print(f"Not found: {path}")
|
||||
|
|
|
|||
|
|
@ -138,9 +138,9 @@ class MPVBase:
|
|||
extended_info = win32job.QueryInformationJobObject(
|
||||
self._job, win32job.JobObjectExtendedLimitInformation
|
||||
)
|
||||
extended_info["BasicLimitInformation"][
|
||||
"LimitFlags"
|
||||
] = win32job.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
|
||||
extended_info["BasicLimitInformation"]["LimitFlags"] = (
|
||||
win32job.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
|
||||
)
|
||||
win32job.SetInformationJobObject(
|
||||
self._job,
|
||||
win32job.JobObjectExtendedLimitInformation,
|
||||
|
|
@ -193,7 +193,10 @@ class MPVBase:
|
|||
None,
|
||||
)
|
||||
win32pipe.SetNamedPipeHandleState(
|
||||
self._sock, 1, None, None # PIPE_NOWAIT
|
||||
self._sock,
|
||||
1,
|
||||
None,
|
||||
None, # PIPE_NOWAIT
|
||||
)
|
||||
except pywintypes.error as err:
|
||||
if err.args[0] == winerror.ERROR_FILE_NOT_FOUND:
|
||||
|
|
|
|||
|
|
@ -307,9 +307,7 @@ class Overview:
|
|||
if b[0]:
|
||||
b[0] = tr.actions_shortcut_key(val=shortcut(b[0]))
|
||||
buf += """
|
||||
<button title="%s" onclick='pycmd("%s")'>%s</button>""" % tuple(
|
||||
b
|
||||
)
|
||||
<button title="%s" onclick='pycmd("%s")'>%s</button>""" % tuple(b)
|
||||
self.bottom.draw(
|
||||
buf=buf,
|
||||
link_handler=link_handler,
|
||||
|
|
|
|||
|
|
@ -483,7 +483,11 @@ create table if not exists profiles
|
|||
code = obj[1]
|
||||
name = obj[0]
|
||||
r = QMessageBox.question(
|
||||
None, "Anki", tr.profiles_confirm_lang_choice(lang=name), QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.No # type: ignore
|
||||
None,
|
||||
"Anki",
|
||||
tr.profiles_confirm_lang_choice(lang=name),
|
||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||
QMessageBox.StandardButton.No, # type: ignore
|
||||
)
|
||||
if r != QMessageBox.StandardButton.Yes:
|
||||
return self.setDefaultLang(f.lang.currentRow())
|
||||
|
|
|
|||
|
|
@ -597,10 +597,9 @@ class Reviewer:
|
|||
def _shortcutKeys(
|
||||
self,
|
||||
) -> Sequence[tuple[str, Callable] | tuple[Qt.Key, Callable]]:
|
||||
|
||||
def generate_default_answer_keys() -> (
|
||||
Generator[tuple[str, partial], None, None]
|
||||
):
|
||||
def generate_default_answer_keys() -> Generator[
|
||||
tuple[str, partial], None, None
|
||||
]:
|
||||
for ease in aqt.mw.pm.default_answer_keys:
|
||||
key = aqt.mw.pm.get_answer_key(ease)
|
||||
if not key:
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ class CustomStyles:
|
|||
button_pressed_gradient(
|
||||
tm.var(colors.BUTTON_GRADIENT_START),
|
||||
tm.var(colors.BUTTON_GRADIENT_END),
|
||||
tm.var(colors.SHADOW)
|
||||
tm.var(colors.SHADOW),
|
||||
)
|
||||
};
|
||||
}}
|
||||
|
|
@ -340,7 +340,7 @@ class CustomStyles:
|
|||
}}
|
||||
QTabBar::tab:selected:hover {{
|
||||
background: {
|
||||
button_gradient(
|
||||
button_gradient(
|
||||
tm.var(colors.BUTTON_PRIMARY_GRADIENT_START),
|
||||
tm.var(colors.BUTTON_PRIMARY_GRADIENT_END),
|
||||
)
|
||||
|
|
@ -391,7 +391,7 @@ class CustomStyles:
|
|||
button_pressed_gradient(
|
||||
tm.var(colors.BUTTON_GRADIENT_START),
|
||||
tm.var(colors.BUTTON_GRADIENT_END),
|
||||
tm.var(colors.SHADOW)
|
||||
tm.var(colors.SHADOW),
|
||||
)
|
||||
}
|
||||
}}
|
||||
|
|
@ -647,10 +647,12 @@ class CustomStyles:
|
|||
margin: -7px 0;
|
||||
}}
|
||||
QSlider::handle:hover {{
|
||||
background: {button_gradient(
|
||||
tm.var(colors.BUTTON_GRADIENT_START),
|
||||
tm.var(colors.BUTTON_GRADIENT_END),
|
||||
)}
|
||||
background: {
|
||||
button_gradient(
|
||||
tm.var(colors.BUTTON_GRADIENT_START),
|
||||
tm.var(colors.BUTTON_GRADIENT_END),
|
||||
)
|
||||
}
|
||||
}}
|
||||
"""
|
||||
|
||||
|
|
|
|||
|
|
@ -302,7 +302,6 @@ def sync_login(
|
|||
username: str = "",
|
||||
password: str = "",
|
||||
) -> None:
|
||||
|
||||
def on_future_done(fut: Future[SyncAuth], username: str, password: str) -> None:
|
||||
try:
|
||||
auth = fut.result()
|
||||
|
|
@ -374,7 +373,9 @@ def get_id_and_pass_from_user(
|
|||
g.addWidget(passwd, 1, 1)
|
||||
l2.setBuddy(passwd)
|
||||
vbox.addLayout(g)
|
||||
bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) # type: ignore
|
||||
bb = QDialogButtonBox(
|
||||
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
|
||||
) # type: ignore
|
||||
ok_button = bb.button(QDialogButtonBox.StandardButton.Ok)
|
||||
assert ok_button is not None
|
||||
ok_button.setAutoDefault(True)
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ class ThemeManager:
|
|||
self, card_ord: int, night_mode: bool | None = None
|
||||
) -> str:
|
||||
"Returns body classes used when showing a card."
|
||||
return f"card card{card_ord+1} {self.body_class(night_mode, reviewer=True)}"
|
||||
return f"card card{card_ord + 1} {self.body_class(night_mode, reviewer=True)}"
|
||||
|
||||
def var(self, vars: dict[str, str]) -> str:
|
||||
"""Given day/night colors/props, return the correct one for the current theme."""
|
||||
|
|
|
|||
|
|
@ -980,7 +980,6 @@ def _create_ankiwebview_subclass(
|
|||
/,
|
||||
**fixed_kwargs: Unpack[_AnkiWebViewKwargs],
|
||||
) -> Type[AnkiWebView]:
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: _AnkiWebViewKwargs) -> None:
|
||||
# user‑supplied kwargs override fixed kwargs
|
||||
merged = cast(_AnkiWebViewKwargs, {**fixed_kwargs, **kwargs})
|
||||
|
|
|
|||
Loading…
Reference in a new issue