Add py3.9 to hooks (#1542)

* Add py3.9 to hooks

This follows examples from efb1ce46d4 I assume the
hooks were missed because those were not considered types but strings.

I did not even try to run pyupgrade and did the change manually, then used bazel format

* remove wildcard import in find.py, and change Any to object (dae)
This commit is contained in:
Arthur Milchior 2021-12-09 00:11:22 +01:00 committed by GitHub
parent 8306bc1e25
commit 69469c6428
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 34 deletions

View file

@ -5,9 +5,8 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING, Any
from anki.hooks import *
from anki.notes import NoteId from anki.notes import NoteId
if TYPE_CHECKING: if TYPE_CHECKING:
@ -32,7 +31,7 @@ class Finder:
def findReplace( def findReplace(
col: Collection, col: Collection,
nids: List[NoteId], nids: list[NoteId],
src: str, src: str,
dst: str, dst: str,
regex: bool = False, regex: bool = False,
@ -51,7 +50,7 @@ def findReplace(
).count ).count
def fieldNamesForNotes(col: Collection, nids: List[NoteId]) -> List[str]: def fieldNamesForNotes(col: Collection, nids: list[NoteId]) -> list[str]:
return list(col.field_names_for_note_ids(nids)) return list(col.field_names_for_note_ids(nids))
@ -59,7 +58,7 @@ def fieldNamesForNotes(col: Collection, nids: List[NoteId]) -> List[str]:
########################################################################## ##########################################################################
def fieldNames(col: Collection, downcase: bool = True) -> List: def fieldNames(col: Collection, downcase: bool = True) -> list[str]:
fields: set[str] = set() fields: set[str] = set()
for m in col.models.all(): for m in col.models.all():
for f in m["flds"]: for f in m["flds"]:

View file

@ -34,7 +34,7 @@ hooks = [
Hook(name="media_files_did_export", args=["count: int"]), Hook(name="media_files_did_export", args=["count: int"]),
Hook( Hook(
name="exporters_list_created", name="exporters_list_created",
args=["exporters: List[Tuple[str, Any]]"], args=["exporters: list[tuple[str, Any]]"],
legacy_hook="exportersList", legacy_hook="exportersList",
), ),
Hook( Hook(
@ -127,7 +127,7 @@ prefix = """\
from __future__ import annotations from __future__ import annotations
from typing import Any, Callable, List, Sequence, Tuple from typing import Any, Callable, Sequence
import anki import anki
import anki.hooks import anki.hooks
from anki.cards import Card from anki.cards import Card

View file

@ -19,8 +19,7 @@ prefix = """\
from __future__ import annotations from __future__ import annotations
from typing import Any, Callable, Dict, List, Sequence, Tuple, Optional, \ from typing import Any, Callable, Sequence, Literal
Union, Literal
import anki import anki
import aqt import aqt
@ -81,11 +80,11 @@ hooks = [
Hook( Hook(
name="reviewer_will_init_answer_buttons", name="reviewer_will_init_answer_buttons",
args=[ args=[
"buttons_tuple: Tuple[Tuple[int, str], ...]", "buttons_tuple: tuple[tuple[int, str], ...]",
"reviewer: aqt.reviewer.Reviewer", "reviewer: aqt.reviewer.Reviewer",
"card: Card", "card: Card",
], ],
return_type="Tuple[Tuple[int, str], ...]", return_type="tuple[tuple[int, str], ...]",
doc="""Used to modify list of answer buttons doc="""Used to modify list of answer buttons
buttons_tuple is a tuple of buttons, with each button represented by a buttons_tuple is a tuple of buttons, with each button represented by a
@ -102,11 +101,11 @@ hooks = [
Hook( Hook(
name="reviewer_will_answer_card", name="reviewer_will_answer_card",
args=[ args=[
"ease_tuple: Tuple[bool, Literal[1, 2, 3, 4]]", "ease_tuple: tuple[bool, Literal[1, 2, 3, 4]]",
"reviewer: aqt.reviewer.Reviewer", "reviewer: aqt.reviewer.Reviewer",
"card: Card", "card: Card",
], ],
return_type="Tuple[bool, Literal[1, 2, 3, 4]]", return_type="tuple[bool, Literal[1, 2, 3, 4]]",
doc="""Used to modify the ease at which a card is rated or to bypass doc="""Used to modify the ease at which a card is rated or to bypass
rating the card completely. rating the card completely.
@ -137,7 +136,7 @@ hooks = [
), ),
Hook( Hook(
name="reviewer_will_play_question_sounds", name="reviewer_will_play_question_sounds",
args=["card: Card", "tags: List[anki.sound.AVTag]"], args=["card: Card", "tags: list[anki.sound.AVTag]"],
doc="""Called before showing the question/front side. doc="""Called before showing the question/front side.
`tags` can be used to inspect and manipulate the sounds `tags` can be used to inspect and manipulate the sounds
@ -152,7 +151,7 @@ hooks = [
), ),
Hook( Hook(
name="reviewer_will_play_answer_sounds", name="reviewer_will_play_answer_sounds",
args=["card: Card", "tags: List[anki.sound.AVTag]"], args=["card: Card", "tags: list[anki.sound.AVTag]"],
doc="""Called before showing the answer/back side. doc="""Called before showing the answer/back side.
`tags` can be used to inspect and manipulate the sounds `tags` can be used to inspect and manipulate the sounds
@ -457,7 +456,7 @@ hooks = [
), ),
Hook( Hook(
name="browser_did_fetch_columns", name="browser_did_fetch_columns",
args=["columns: Dict[str, aqt.browser.Column]"], args=["columns: dict[str, aqt.browser.Column]"],
doc="""Allows you to add custom columns to the browser. doc="""Allows you to add custom columns to the browser.
columns is a dictionary of data obejcts. You can add an entry with a custom columns is a dictionary of data obejcts. You can add an entry with a custom
@ -483,7 +482,7 @@ hooks = [
# different sig to original # different sig to original
Hook( Hook(
name="state_shortcuts_will_change", name="state_shortcuts_will_change",
args=["state: str", "shortcuts: List[Tuple[str, Callable]]"], args=["state: str", "shortcuts: list[tuple[str, Callable]]"],
), ),
# UI state/refreshing # UI state/refreshing
################### ###################
@ -508,7 +507,7 @@ hooks = [
), ),
Hook( Hook(
name="operation_did_execute", name="operation_did_execute",
args=["changes: anki.collection.OpChanges", "handler: Optional[object]"], args=["changes: anki.collection.OpChanges", "handler: object | None"],
doc="""Called after an operation completes. doc="""Called after an operation completes.
Changes can be inspected to determine whether the UI needs updating. Changes can be inspected to determine whether the UI needs updating.
@ -518,8 +517,8 @@ hooks = [
Hook( Hook(
name="focus_did_change", name="focus_did_change",
args=[ args=[
"new: Optional[QWidget]", "new: QWidget | None",
"old: Optional[QWidget]", "old: QWidget | None",
], ],
doc="""Called each time the focus changes. Can be used to defer updates from doc="""Called each time the focus changes. Can be used to defer updates from
`operation_did_execute` until a window is brought to the front.""", `operation_did_execute` until a window is brought to the front.""",
@ -548,8 +547,8 @@ hooks = [
################### ###################
Hook( Hook(
name="webview_did_receive_js_message", name="webview_did_receive_js_message",
args=["handled: Tuple[bool, Any]", "message: str", "context: Any"], args=["handled: tuple[bool, Any]", "message: str", "context: Any"],
return_type="Tuple[bool, Any]", return_type="tuple[bool, Any]",
doc="""Used to handle pycmd() messages sent from Javascript. doc="""Used to handle pycmd() messages sent from Javascript.
Message is the string passed to pycmd(). Message is the string passed to pycmd().
@ -585,7 +584,7 @@ hooks = [
name="webview_will_set_content", name="webview_will_set_content",
args=[ args=[
"web_content: aqt.webview.WebContent", "web_content: aqt.webview.WebContent",
"context: Optional[Any]", "context: object | None",
], ],
doc="""Used to modify web content before it is rendered. doc="""Used to modify web content before it is rendered.
@ -663,8 +662,8 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
name="main_window_should_require_reset", name="main_window_should_require_reset",
args=[ args=[
"will_reset: bool", "will_reset: bool",
"reason: Union[aqt.main.ResetReason, str]", "reason: aqt.main.ResetReason | str",
"context: Optional[Any]", "context: object | None",
], ],
return_type="bool", return_type="bool",
doc="""Executed before the main window will require a reset doc="""Executed before the main window will require a reset
@ -704,7 +703,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
), ),
Hook( Hook(
name="top_toolbar_did_init_links", name="top_toolbar_did_init_links",
args=["links: List[str]", "top_toolbar: aqt.toolbar.Toolbar"], args=["links: list[str]", "top_toolbar: aqt.toolbar.Toolbar"],
doc="""Used to modify or add links in the top toolbar of Anki's main window doc="""Used to modify or add links in the top toolbar of Anki's main window
'links' is a list of HTML link elements. Add-ons can generate their own links 'links' is a list of HTML link elements. Add-ons can generate their own links
@ -769,8 +768,8 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
), ),
Hook( Hook(
name="add_cards_will_add_note", name="add_cards_will_add_note",
args=["problem: Optional[str]", "note: anki.notes.Note"], args=["problem: str | None", "note: anki.notes.Note"],
return_type="Optional[str]", return_type="str | None",
doc="""Decides whether the note should be added to the collection or doc="""Decides whether the note should be added to the collection or
not. It is assumed to come from the addCards window. not. It is assumed to come from the addCards window.
@ -801,15 +800,15 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
################### ###################
Hook( Hook(
name="editor_did_init_left_buttons", name="editor_did_init_left_buttons",
args=["buttons: List[str]", "editor: aqt.editor.Editor"], args=["buttons: list[str]", "editor: aqt.editor.Editor"],
), ),
Hook( Hook(
name="editor_did_init_buttons", name="editor_did_init_buttons",
args=["buttons: List[str]", "editor: aqt.editor.Editor"], args=["buttons: list[str]", "editor: aqt.editor.Editor"],
), ),
Hook( Hook(
name="editor_did_init_shortcuts", name="editor_did_init_shortcuts",
args=["shortcuts: List[Tuple]", "editor: aqt.editor.Editor"], args=["shortcuts: list[tuple]", "editor: aqt.editor.Editor"],
legacy_hook="setupEditorShortcuts", legacy_hook="setupEditorShortcuts",
), ),
Hook( Hook(
@ -949,7 +948,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
), ),
Hook( Hook(
name="addons_dialog_will_delete_addons", name="addons_dialog_will_delete_addons",
args=["dialog: aqt.addons.AddonsDialog", "ids: List[str]"], args=["dialog: aqt.addons.AddonsDialog", "ids: list[str]"],
doc="""Allows doing an action before an add-on is deleted.""", doc="""Allows doing an action before an add-on is deleted.""",
), ),
# Model # Model
@ -961,10 +960,10 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
Hook( Hook(
name="models_did_init_buttons", name="models_did_init_buttons",
args=[ args=[
"buttons: List[Tuple[str, Callable[[], None]]]", "buttons: list[tuple[str, Callable[[], None]]]",
"models: aqt.models.Models", "models: aqt.models.Models",
], ],
return_type="List[Tuple[str, Callable[[], None]]]", return_type="list[tuple[str, Callable[[], None]]]",
doc="""Allows adding buttons to the Model dialog""", doc="""Allows adding buttons to the Model dialog""",
), ),
# Fields # Fields