Skip to content

Commit 374e4b0

Browse files
authored
Fix type hints (#822)
1 parent d7ada0c commit 374e4b0

File tree

13 files changed

+49
-34
lines changed

13 files changed

+49
-34
lines changed

cursorless-talon/src/actions/actions_callback.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from dataclasses import dataclass
2+
from typing import Any, Callable
23

34
from talon import Module
45

@@ -11,7 +12,7 @@
1112
class CallbackAction:
1213
term: str
1314
identifier: str
14-
callback: callable
15+
callback: Callable[[dict], Any]
1516

1617

1718
# NOTE: Please do not change these dicts. Use the CSVs for customization.

cursorless-talon/src/actions/actions_makeshift.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from dataclasses import dataclass
2+
from typing import Any, Optional
23

34
from talon import Module
45

@@ -8,9 +9,9 @@ class MakeshiftAction:
89
term: str
910
identifier: str
1011
vscode_command_id: str
11-
vscode_command_args: list = None
12+
vscode_command_args: Optional[list] = None
1213
restore_selection: bool = False
13-
post_command_sleep_ms: int = None
14+
post_command_sleep_ms: Optional[int] = None
1415
await_command: bool = True
1516

1617

@@ -56,13 +57,13 @@ class MakeshiftAction:
5657

5758
@dataclass
5859
class TalonOptions:
59-
post_command_sleep_ms: int = None
60+
post_command_sleep_ms: Optional[int] = None
6061
await_command: bool = True
6162

6263

6364
def get_parameters(action: MakeshiftAction):
6465
command = action.vscode_command_id
65-
command_options = {
66+
command_options: dict[str, Any] = {
6667
"restoreSelection": action.restore_selection,
6768
}
6869
if action.vscode_command_args:

cursorless-talon/src/actions/get_text.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
from typing import Optional
2+
13
from talon import actions
24

35

46
def get_text(
5-
target: dict, show_decorations: bool = None, ensure_single_target: bool = None
7+
target: dict,
8+
show_decorations: Optional[bool] = None,
9+
ensure_single_target: Optional[bool] = None,
610
):
711
"""Get target texts"""
812
return actions.user.cursorless_single_target_command_get(

cursorless-talon/src/actions/wrap.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def cursorless_wrapper(m) -> dict[str, Any]:
2929

3030

3131
# Maps from (action_type, wrapper_type) to action name
32-
action_map = {
32+
action_map: dict[tuple[str, str], str] = {
3333
("wrapWithPairedDelimiter", "pairedDelimiter"): "wrapWithPairedDelimiter",
3434
# This is awkward because we used an action name which was to verbose previously
3535
("wrapWithPairedDelimiter", "snippet"): "wrapWithSnippet",
@@ -41,7 +41,9 @@ def cursorless_wrapper(m) -> dict[str, Any]:
4141

4242
@mod.action_class
4343
class Actions:
44-
def cursorless_wrap(action_type: str, targets: dict, cursorless_wrapper: dict):
44+
def cursorless_wrap(
45+
action_type: str, targets: dict, cursorless_wrapper: dict[str, str]
46+
):
4547
"""Perform cursorless wrap action"""
4648
wrapper_type = cursorless_wrapper["type"]
4749
action = action_map[(action_type, wrapper_type)]

cursorless-talon/src/cheatsheet/cheat_sheet.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22
import webbrowser
3+
from typing import Optional
34

45
from talon import Module, actions, cron, skia, ui
56
from talon.canvas import Canvas
@@ -161,7 +162,7 @@ def draw_section(self, canvas, header_text, items):
161162
self.draw_items(canvas, items)
162163

163164
def draw_multicolumn_section(
164-
self, canvas, items, column_names: str, scopes_limit=25
165+
self, canvas, items, column_names: list[str], scopes_limit=25
165166
):
166167
items_0 = slice_dict(items, 0, scopes_limit)
167168
items_1 = slice_dict(items, scopes_limit)
@@ -338,6 +339,6 @@ def is_in_rect(canvas, mouse_pos, rect):
338339
)
339340

340341

341-
def slice_dict(dict: dict, start: int, end: int = None):
342+
def slice_dict(dict: dict, start: int, end: Optional[int] = None):
342343
keys = sorted(dict)[start:end]
343344
return {key: dict[key] for key in keys}

cursorless-talon/src/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def cursorless_multiple_target_command_no_wait(
122122

123123

124124
def construct_cursorless_command_argument(
125-
action: str, targets: list[dict], args: list[any]
125+
action: str, targets: list[dict], args: list[Any]
126126
):
127127
try:
128128
use_pre_phrase_snapshot = actions.user.did_emit_pre_phrase_signal()

cursorless-talon/src/compound_targets.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any
2+
13
from talon import Module
24

35
from .connective import default_range_connective
@@ -18,7 +20,7 @@
1820
@mod.capture(
1921
rule="[<user.cursorless_range_type>] {user.cursorless_range_connective} | <user.cursorless_range_type>"
2022
)
21-
def cursorless_range_connective_with_type(m) -> str:
23+
def cursorless_range_connective_with_type(m) -> dict[str, Any]:
2224
return {
2325
"connective": getattr(
2426
m, "cursorless_range_connective", default_range_connective
@@ -34,7 +36,7 @@ def cursorless_range_connective_with_type(m) -> str:
3436
"<user.cursorless_primitive_target> <user.cursorless_range_connective_with_type> <user.cursorless_primitive_target>"
3537
)
3638
)
37-
def cursorless_range(m) -> str:
39+
def cursorless_range(m) -> dict[str, Any]:
3840
primitive_targets = m.cursorless_primitive_target_list
3941
range_connective_with_type = getattr(
4042
m, "cursorless_range_connective_with_type", None

cursorless-talon/src/csv_overrides.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime
22
from pathlib import Path
3-
from typing import Optional
3+
from typing import Container, Optional
44

55
from talon import Context, Module, actions, app, fs
66

@@ -21,8 +21,8 @@
2121

2222
def init_csv_and_watch_changes(
2323
filename: str,
24-
default_values: dict[str, dict],
25-
extra_ignored_values: list[str] = None,
24+
default_values: dict[str, dict[str, str]],
25+
extra_ignored_values: Optional[list[str]] = None,
2626
allow_unknown_values: bool = False,
2727
default_list_name: Optional[str] = None,
2828
headers: list[str] = [SPOKEN_FORM_HEADER, CURSORLESS_IDENTIFIER_HEADER],
@@ -81,7 +81,7 @@ def on_watch(path, flags):
8181
ctx,
8282
)
8383

84-
fs.watch(file_path.parent, on_watch)
84+
fs.watch(str(file_path.parent), on_watch)
8585

8686
if file_path.is_file():
8787
current_values = update_file(
@@ -113,7 +113,7 @@ def on_watch(path, flags):
113113
)
114114

115115
def unsubscribe():
116-
fs.unwatch(file_path.parent, on_watch)
116+
fs.unwatch(str(file_path.parent), on_watch)
117117

118118
return unsubscribe
119119

@@ -177,7 +177,7 @@ def update_dicts(
177177
def update_file(
178178
path: Path,
179179
headers: list[str],
180-
default_values: dict,
180+
default_values: dict[str, str],
181181
extra_ignored_values: list[str],
182182
allow_unknown_values: bool,
183183
no_update_file: bool,
@@ -250,7 +250,7 @@ def csv_error(path: Path, index: int, message: str, value: str):
250250
def read_file(
251251
path: Path,
252252
headers: list[str],
253-
default_identifiers: list[str],
253+
default_identifiers: Container[str],
254254
extra_ignored_values: list[str],
255255
allow_unknown_values: bool,
256256
):
@@ -313,7 +313,7 @@ def get_full_path(filename: str):
313313
if not filename.endswith(".csv"):
314314
filename = f"{filename}.csv"
315315

316-
user_dir = actions.path.talon_user()
316+
user_dir: Path = actions.path.talon_user()
317317
settings_directory = Path(cursorless_settings_directory.get())
318318

319319
if not settings_directory.is_absolute():
@@ -322,8 +322,8 @@ def get_full_path(filename: str):
322322
return (settings_directory / filename).resolve()
323323

324324

325-
def get_super_values(values: dict[str, dict]):
326-
result = {}
327-
for dict in values.values():
328-
result.update(dict)
325+
def get_super_values(values: dict[str, dict[str, str]]):
326+
result: dict[str, str] = {}
327+
for value_dict in values.values():
328+
result.update(value_dict)
329329
return result

cursorless-talon/src/marks/mark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def on_watch(path, flags):
230230
fast_reload_job = cron.after("500ms", setup_hat_styles_csv)
231231
slow_reload_job = cron.after("10s", setup_hat_styles_csv)
232232

233-
fs.watch(vscode_settings_path, on_watch)
233+
fs.watch(str(vscode_settings_path), on_watch)
234234

235235

236236
app.register("ready", on_ready)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from typing import Any
2+
13
from talon import Module
24

35
mod = Module()
46

57

68
@mod.capture(rule="matching")
7-
def cursorless_matching_paired_delimiter(m) -> str:
9+
def cursorless_matching_paired_delimiter(m) -> dict[str, Any]:
810
return {"modifier": {"type": "matchingPairedDelimiter"}}

cursorless-talon/src/modifiers/position.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020

2121

22-
def construct_positional_modifier(position: str) -> dict:
22+
def construct_positional_modifier(position: str) -> dict[str, Any]:
2323
return {"type": "position", "position": position}
2424

2525

cursorless-talon/src/modifiers/sub_token.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
@mod.capture(rule="<user.ordinals_small> | last")
14-
def ordinal_or_last(m) -> str:
14+
def ordinal_or_last(m) -> int:
1515
"""An ordinal or the word 'last'"""
1616
if m[0] == "last":
1717
return -1
@@ -21,7 +21,7 @@ def ordinal_or_last(m) -> str:
2121
@mod.capture(
2222
rule="<user.ordinal_or_last> [{user.cursorless_range_connective} <user.ordinal_or_last>]"
2323
)
24-
def cursorless_ordinal_range(m) -> str:
24+
def cursorless_ordinal_range(m) -> dict[str, Any]:
2525
"""Ordinal range"""
2626
try:
2727
range_connective = m.cursorless_range_connective
@@ -40,7 +40,7 @@ def cursorless_ordinal_range(m) -> str:
4040

4141

4242
@mod.capture(rule="(first | last) <number_small>")
43-
def cursorless_first_last_range(m) -> str:
43+
def cursorless_first_last_range(m) -> dict[str, Any]:
4444
"""First/last range"""
4545
if m[0] == "first":
4646
return {"anchor": 0, "active": m.number_small - 1}

cursorless-talon/src/positional_target.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any
2+
13
from talon import Module
24

35
from .modifiers.position import construct_positional_modifier
@@ -11,16 +13,16 @@
1113
"<user.cursorless_target>"
1214
)
1315
)
14-
def cursorless_positional_target(m) -> list[dict]:
15-
target = m.cursorless_target
16+
def cursorless_positional_target(m) -> dict[str, Any]:
17+
target: dict[str, Any] = m.cursorless_target
1618
try:
1719
modifier = construct_positional_modifier(m.cursorless_position)
1820
return update_first_primitive_target(target, modifier)
1921
except AttributeError:
2022
return target
2123

2224

23-
def update_first_primitive_target(target: dict, modifier: dict):
25+
def update_first_primitive_target(target: dict[str, Any], modifier: dict[str, Any]):
2426
if target["type"] == "primitive":
2527
if "modifiers" not in target:
2628
target["modifiers"] = []

0 commit comments

Comments
 (0)