Skip to content

Commit 3b38e7b

Browse files
auscompgeekpokey
andauthored
Tighten and fix Talon actions type hints (#1849)
This fixes an incorrect type hint, removes a few implicit `Any`s, and tightens up how `cursorless_get_text_action` can be used. ## Checklist - [ ] ~I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/)~ - [ ] ~I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet)~ - [x] I have not broken the cheatsheet Co-authored-by: Pokey Rule <[email protected]>
1 parent adb0918 commit 3b38e7b

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

cursorless-talon/src/actions/actions.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Union
1+
from typing import Callable, Union
22

33
from talon import Module, actions
44

@@ -15,7 +15,6 @@
1515

1616
mod = Module()
1717

18-
1918
mod.list(
2019
"cursorless_simple_action",
2120
desc="Cursorless internal: simple actions",
@@ -48,7 +47,7 @@
4847
"experimental_action",
4948
]
5049

51-
callback_actions = {
50+
callback_actions: dict[str, Callable[[CursorlessTarget], None]] = {
5251
"callAsFunction": cursorless_call_action,
5352
"findInDocument": actions.user.private_cursorless_find,
5453
"nextHomophone": cursorless_homophones_action,
@@ -74,7 +73,7 @@
7473
"{user.cursorless_custom_action}"
7574
)
7675
)
77-
def cursorless_action_or_ide_command(m) -> dict:
76+
def cursorless_action_or_ide_command(m) -> dict[str, str]:
7877
try:
7978
value = m.cursorless_custom_action
8079
type = "ide_command"
@@ -127,7 +126,7 @@ def cursorless_insert(
127126
cursorless_replace_action(destination, text)
128127

129128
def private_cursorless_action_or_ide_command(
130-
instruction: dict, target: CursorlessTarget
129+
instruction: dict[str, str], target: CursorlessTarget
131130
):
132131
"""Perform cursorless action or ide command on target (internal use only)"""
133132
type = instruction["type"]

cursorless-talon/src/actions/get_text.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
def cursorless_get_text_action(
99
target: CursorlessTarget,
10+
*,
1011
show_decorations: Optional[bool] = None,
1112
ensure_single_target: Optional[bool] = None,
1213
) -> list[str]:
1314
"""Get target texts"""
14-
options = {}
15+
options: dict[str, bool] = {}
1516

1617
if show_decorations is not None:
1718
options["showDecorations"] = show_decorations

cursorless-talon/src/actions/homophones.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
from typing import Optional
2+
13
from talon import actions, app
24

3-
from ..targets.target_types import PrimitiveDestination
5+
from ..targets.target_types import CursorlessTarget, PrimitiveDestination
46
from .get_text import cursorless_get_text_action
57
from .replace import cursorless_replace_action
68

79

8-
def cursorless_homophones_action(target: dict):
10+
def cursorless_homophones_action(target: CursorlessTarget):
911
"""Replaced target with next homophone"""
1012
texts = cursorless_get_text_action(target, show_decorations=False)
1113
try:
@@ -17,16 +19,16 @@ def cursorless_homophones_action(target: dict):
1719
cursorless_replace_action(destination, updated_texts)
1820

1921

20-
def get_next_homophone(word: str):
21-
homophones = actions.user.homophones_get(word)
22+
def get_next_homophone(word: str) -> str:
23+
homophones: Optional[list[str]] = actions.user.homophones_get(word)
2224
if not homophones:
2325
raise LookupError(f"Found no homophones for '{word}'")
2426
index = (homophones.index(word.lower()) + 1) % len(homophones)
2527
homophone = homophones[index]
2628
return format_homophone(word, homophone)
2729

2830

29-
def format_homophone(word: str, homophone: str):
31+
def format_homophone(word: str, homophone: str) -> str:
3032
if word.isupper():
3133
return homophone.upper()
3234
if word == word.capitalize():

0 commit comments

Comments
 (0)