Skip to content

Commit d7dd800

Browse files
authored
Fix or suppress all Python type errors (#2307)
- Depends on #2306 - Supercedes #2267 This does add a lot of noise, and it can't be enforced in CI because Talon doesn't publish type stubs (that I know of), so I wonder whether it's worth it 🤔 ## Checklist - [x] I have run Talon spoken form tests - [-] 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
1 parent cb042d6 commit d7dd800

24 files changed

+116
-57
lines changed

cursorless-talon-dev/src/spoken_form_test.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,31 @@ def did_emit_pre_phrase_signal():
4242
return True
4343

4444
def private_cursorless_run_rpc_command_and_wait(
45-
command_id: str, arg1: Any, arg2: Any = None
45+
command_id: str, # pyright: ignore [reportGeneralTypeIssues]
46+
arg1: Any,
47+
arg2: Any = None,
4648
):
4749
commands_run.append(arg1)
4850

4951
def private_cursorless_run_rpc_command_no_wait(
50-
command_id: str, arg1: Any, arg2: Any = None
52+
command_id: str, # pyright: ignore [reportGeneralTypeIssues]
53+
arg1: Any,
54+
arg2: Any = None,
5155
):
5256
commands_run.append(arg1)
5357

5458
def private_cursorless_run_rpc_command_get(
55-
command_id: str, arg1: Any, arg2: Any = None
59+
command_id: str, # pyright: ignore [reportGeneralTypeIssues]
60+
arg1: Any,
61+
arg2: Any = None,
5662
) -> Any:
5763
commands_run.append(arg1)
5864
return mockedGetValue
5965

6066

6167
@mod.action_class
6268
class Actions:
63-
def private_cursorless_spoken_form_test_mode(enable: bool):
69+
def private_cursorless_spoken_form_test_mode(enable: bool): # pyright: ignore [reportGeneralTypeIssues]
6470
"""Enable/disable Cursorless spoken form test mode"""
6571
global saved_modes, saved_microphone
6672

@@ -84,7 +90,7 @@ def private_cursorless_spoken_form_test_mode(enable: bool):
8490
"Cursorless spoken form tests are done. Talon microphone is re-enabled."
8591
)
8692

87-
def private_cursorless_use_community_snippets(enable: bool):
93+
def private_cursorless_use_community_snippets(enable: bool): # pyright: ignore [reportGeneralTypeIssues]
8894
"""Enable/disable cursorless community snippets in test mode"""
8995
if enable:
9096
tags = set(ctx.tags)
@@ -99,7 +105,8 @@ def private_cursorless_use_community_snippets(enable: bool):
99105
print(f"Set community snippet enablement to {enable}")
100106

101107
def private_cursorless_spoken_form_test(
102-
phrase: str, mockedGetValue_: Optional[str]
108+
phrase: str, # pyright: ignore [reportGeneralTypeIssues]
109+
mockedGetValue_: Optional[str],
103110
):
104111
"""Run Cursorless spoken form test"""
105112
global commands_run, mockedGetValue

cursorless-talon/src/actions/actions.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from ..targets.target_types import (
66
CursorlessDestination,
7+
CursorlessExplicitTarget,
78
CursorlessTarget,
89
ImplicitDestination,
910
)
@@ -48,7 +49,7 @@
4849
"custom_action",
4950
]
5051

51-
callback_actions: dict[str, Callable[[CursorlessTarget], None]] = {
52+
callback_actions: dict[str, Callable[[CursorlessExplicitTarget], None]] = {
5253
"nextHomophone": cursorless_homophones_action,
5354
}
5455

@@ -88,7 +89,7 @@ def cursorless_action_or_ide_command(m) -> dict[str, str]:
8889

8990
@mod.action_class
9091
class Actions:
91-
def cursorless_command(action_name: str, target: CursorlessTarget):
92+
def cursorless_command(action_name: str, target: CursorlessExplicitTarget): # pyright: ignore [reportGeneralTypeIssues]
9293
"""Perform cursorless command on target"""
9394
if action_name in callback_actions:
9495
callback_actions[action_name](target)
@@ -107,28 +108,30 @@ def cursorless_command(action_name: str, target: CursorlessTarget):
107108
action = {"name": action_name, "target": target}
108109
actions.user.private_cursorless_command_and_wait(action)
109110

110-
def cursorless_vscode_command(command_id: str, target: CursorlessTarget):
111+
def cursorless_vscode_command(command_id: str, target: CursorlessTarget): # pyright: ignore [reportGeneralTypeIssues]
111112
"""
112113
Perform vscode command on cursorless target
113114
114115
Deprecated: prefer `cursorless_ide_command`
115116
"""
116117
return actions.user.cursorless_ide_command(command_id, target)
117118

118-
def cursorless_ide_command(command_id: str, target: CursorlessTarget):
119+
def cursorless_ide_command(command_id: str, target: CursorlessTarget): # pyright: ignore [reportGeneralTypeIssues]
119120
"""Perform ide command on cursorless target"""
120121
return cursorless_execute_command_action(command_id, target)
121122

122123
def cursorless_insert(
123-
destination: CursorlessDestination, text: Union[str, list[str]]
124+
destination: CursorlessDestination, # pyright: ignore [reportGeneralTypeIssues]
125+
text: Union[str, list[str]],
124126
):
125127
"""Perform text insertion on Cursorless destination"""
126128
if isinstance(text, str):
127129
text = [text]
128130
cursorless_replace_action(destination, text)
129131

130132
def private_cursorless_action_or_ide_command(
131-
instruction: dict[str, str], target: CursorlessTarget
133+
instruction: dict[str, str], # pyright: ignore [reportGeneralTypeIssues]
134+
target: CursorlessTarget,
132135
):
133136
"""Perform cursorless action or ide command on target (internal use only)"""
134137
type = instruction["type"]

cursorless-talon/src/actions/bring_move.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def cursorless_bring_move_targets(m) -> BringMoveTargets:
3535

3636
@mod.action_class
3737
class Actions:
38-
def private_cursorless_bring_move(action_name: str, targets: BringMoveTargets):
38+
def private_cursorless_bring_move(action_name: str, targets: BringMoveTargets): # pyright: ignore [reportGeneralTypeIssues]
3939
"""Execute Cursorless move/bring action"""
4040
actions.user.private_cursorless_command_and_wait(
4141
{

cursorless-talon/src/actions/call.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@mod.action_class
1010
class Actions:
1111
def private_cursorless_call(
12-
callee: CursorlessTarget,
12+
callee: CursorlessTarget, # pyright: ignore [reportGeneralTypeIssues]
1313
argument: CursorlessTarget = ImplicitTarget(),
1414
):
1515
"""Execute Cursorless call action"""

cursorless-talon/src/actions/get_text.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@mod.action_class
1111
class Actions:
1212
def cursorless_get_text(
13-
target: CursorlessTarget,
13+
target: CursorlessTarget, # pyright: ignore [reportGeneralTypeIssues]
1414
hide_decorations: bool = False,
1515
) -> str:
1616
"""Get target text. If hide_decorations is True, don't show decorations"""
@@ -21,7 +21,7 @@ def cursorless_get_text(
2121
)[0]
2222

2323
def cursorless_get_text_list(
24-
target: CursorlessTarget,
24+
target: CursorlessTarget, # pyright: ignore [reportGeneralTypeIssues]
2525
hide_decorations: bool = False,
2626
) -> list[str]:
2727
"""Get texts for multiple targets. If hide_decorations is True, don't show decorations"""

cursorless-talon/src/actions/homophones.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
from talon import actions, app
44

5-
from ..targets.target_types import CursorlessTarget, PrimitiveDestination
5+
from ..targets.target_types import (
6+
CursorlessExplicitTarget,
7+
PrimitiveDestination,
8+
)
69
from .get_text import cursorless_get_text_action
710
from .replace import cursorless_replace_action
811

912

10-
def cursorless_homophones_action(target: CursorlessTarget):
13+
def cursorless_homophones_action(target: CursorlessExplicitTarget):
1114
"""Replaced target with next homophone"""
1215
texts = cursorless_get_text_action(target, show_decorations=False)
1316
try:

cursorless-talon/src/actions/paste.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
@mod.action_class
1111
class Actions:
12-
def private_cursorless_paste(destination: CursorlessDestination):
12+
def private_cursorless_paste(
13+
destination: CursorlessDestination, # pyright: ignore [reportGeneralTypeIssues]
14+
):
1315
"""Execute Cursorless paste action"""
1416
actions.user.private_cursorless_command_and_wait(
1517
{

cursorless-talon/src/actions/reformat.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from talon import Module, actions
22

3-
from ..targets.target_types import CursorlessTarget, PrimitiveDestination
3+
from ..targets.target_types import (
4+
CursorlessExplicitTarget,
5+
PrimitiveDestination,
6+
)
47
from .get_text import cursorless_get_text_action
58
from .replace import cursorless_replace_action
69

@@ -11,7 +14,10 @@
1114

1215
@mod.action_class
1316
class Actions:
14-
def private_cursorless_reformat(target: CursorlessTarget, formatters: str):
17+
def private_cursorless_reformat(
18+
target: CursorlessExplicitTarget, # pyright: ignore [reportGeneralTypeIssues]
19+
formatters: str,
20+
):
1521
"""Execute Cursorless reformat action. Reformat target with formatter"""
1622
texts = cursorless_get_text_action(target, show_decorations=False)
1723
updated_texts = [actions.user.reformat_text(text, formatters) for text in texts]

cursorless-talon/src/actions/swap.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def cursorless_swap_targets(m) -> SwapTargets:
3636

3737
@mod.action_class
3838
class Actions:
39-
def private_cursorless_swap(targets: SwapTargets):
39+
def private_cursorless_swap(
40+
targets: SwapTargets, # pyright: ignore [reportGeneralTypeIssues]
41+
):
4042
"""Execute Cursorless swap action"""
4143
actions.user.private_cursorless_command_and_wait(
4244
{

cursorless-talon/src/actions/wrap.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
@mod.action_class
1111
class Actions:
1212
def private_cursorless_wrap_with_paired_delimiter(
13-
action_name: str, target: CursorlessTarget, paired_delimiter: list[str]
13+
action_name: str, # pyright: ignore [reportGeneralTypeIssues]
14+
target: CursorlessTarget,
15+
paired_delimiter: list[str],
1416
):
1517
"""Execute Cursorless wrap/rewrap with paired delimiter action"""
1618
if action_name == "rewrap":
@@ -26,7 +28,9 @@ def private_cursorless_wrap_with_paired_delimiter(
2628
)
2729

2830
def private_cursorless_wrap_with_snippet(
29-
action_name: str, target: CursorlessTarget, snippet_location: str
31+
action_name: str, # pyright: ignore [reportGeneralTypeIssues]
32+
target: CursorlessTarget,
33+
snippet_location: str,
3034
):
3135
"""Execute Cursorless wrap with snippet action"""
3236
if action_name == "wrapWithPairedDelimiter":

cursorless-talon/src/apps/vscode_settings.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
class Actions:
2929
def vscode_settings_path() -> Path:
3030
"""Get path of vscode settings json file"""
31+
...
3132

32-
def vscode_get_setting(key: str, default_value: Any = None):
33+
def vscode_get_setting(key: str, default_value: Any = None): # pyright: ignore [reportGeneralTypeIssues]
3334
"""Get the value of vscode setting at the given key"""
3435
path: Path = actions.user.vscode_settings_path()
3536
settings: dict = loads(path.read_text())
@@ -40,7 +41,7 @@ def vscode_get_setting(key: str, default_value: Any = None):
4041
return settings[key]
4142

4243
def vscode_get_setting_with_fallback(
43-
key: str,
44+
key: str, # pyright: ignore [reportGeneralTypeIssues]
4445
default_value: Any,
4546
fallback_value: Any,
4647
fallback_message: str,

cursorless-talon/src/cheatsheet/cheat_sheet.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def cheatsheet_dir_linux() -> Path:
7676
"""Get cheatsheet directory for Linux"""
7777
try:
7878
# 1. Get users actual document directory
79-
import platformdirs
79+
import platformdirs # pyright: ignore [reportMissingImports]
8080

8181
return Path(platformdirs.user_documents_dir())
8282
except Exception:

cursorless-talon/src/cheatsheet/get_list.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import typing
23
from collections.abc import Mapping, Sequence
34
from typing import Optional, TypedDict
45

@@ -37,7 +38,7 @@ def get_lists(
3738

3839
def get_raw_list(name: str) -> Mapping[str, str]:
3940
cursorless_list_name = get_cursorless_list_name(name)
40-
return registry.lists[cursorless_list_name][0].copy()
41+
return typing.cast(dict[str, str], registry.lists[cursorless_list_name][0]).copy()
4142

4243

4344
def get_spoken_form_from_list(list_name: str, value: str) -> str:

cursorless-talon/src/command.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CursorlessCommand:
1616

1717

1818
CURSORLESS_COMMAND_ID = "cursorless.command"
19-
last_phrase = None
19+
last_phrase: dict = {}
2020

2121
mod = Module()
2222

@@ -31,7 +31,7 @@ def on_phrase(d):
3131

3232
@mod.action_class
3333
class Actions:
34-
def private_cursorless_command_and_wait(action: dict):
34+
def private_cursorless_command_and_wait(action: dict): # pyright: ignore [reportGeneralTypeIssues]
3535
"""Execute cursorless command and wait for it to finish"""
3636
response = actions.user.private_cursorless_run_rpc_command_get(
3737
CURSORLESS_COMMAND_ID,
@@ -40,14 +40,14 @@ def private_cursorless_command_and_wait(action: dict):
4040
if "fallback" in response:
4141
perform_fallback(response["fallback"])
4242

43-
def private_cursorless_command_no_wait(action: dict):
43+
def private_cursorless_command_no_wait(action: dict): # pyright: ignore [reportGeneralTypeIssues]
4444
"""Execute cursorless command without waiting"""
4545
actions.user.private_cursorless_run_rpc_command_no_wait(
4646
CURSORLESS_COMMAND_ID,
4747
construct_cursorless_command(action),
4848
)
4949

50-
def private_cursorless_command_get(action: dict):
50+
def private_cursorless_command_get(action: dict): # pyright: ignore [reportGeneralTypeIssues]
5151
"""Execute cursorless command and return result"""
5252
response = actions.user.private_cursorless_run_rpc_command_get(
5353
CURSORLESS_COMMAND_ID,

cursorless-talon/src/csv_overrides.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import csv
2+
import typing
23
from collections import defaultdict
34
from collections.abc import Container
45
from dataclasses import dataclass
@@ -453,7 +454,9 @@ def get_full_path(filename: str):
453454
filename = f"{filename}.csv"
454455

455456
user_dir: Path = actions.path.talon_user()
456-
settings_directory = Path(settings.get("user.cursorless_settings_directory"))
457+
settings_directory = Path(
458+
typing.cast(str, settings.get("user.cursorless_settings_directory"))
459+
)
457460

458461
if not settings_directory.is_absolute():
459462
settings_directory = user_dir / settings_directory

cursorless-talon/src/cursorless_command_server.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
@mod.action_class
99
class Actions:
1010
def private_cursorless_run_rpc_command_and_wait(
11-
command_id: str, arg1: Any = None, arg2: Any = None
11+
command_id: str, # pyright: ignore [reportGeneralTypeIssues]
12+
arg1: Any = None,
13+
arg2: Any = None,
1214
):
1315
"""Execute command via rpc and wait for command to finish."""
1416
try:
@@ -17,7 +19,9 @@ def private_cursorless_run_rpc_command_and_wait(
1719
actions.user.vscode_with_plugin_and_wait(command_id, arg1, arg2)
1820

1921
def private_cursorless_run_rpc_command_no_wait(
20-
command_id: str, arg1: Any = None, arg2: Any = None
22+
command_id: str, # pyright: ignore [reportGeneralTypeIssues]
23+
arg1: Any = None,
24+
arg2: Any = None,
2125
):
2226
"""Execute command via rpc and DON'T wait."""
2327
try:
@@ -26,7 +30,9 @@ def private_cursorless_run_rpc_command_no_wait(
2630
actions.user.vscode_with_plugin(command_id, arg1, arg2)
2731

2832
def private_cursorless_run_rpc_command_get(
29-
command_id: str, arg1: Any = None, arg2: Any = None
33+
command_id: str, # pyright: ignore [reportGeneralTypeIssues]
34+
arg1: Any = None,
35+
arg2: Any = None,
3036
) -> Any:
3137
"""Execute command via rpc and return command output."""
3238
try:

cursorless-talon/src/modifiers/surrounding_pair.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"cursorless_delimiter_force_direction",
1212
desc="Can be used to force an ambiguous delimiter to extend in one direction",
1313
)
14-
ctx.lists["user.cursorless_delimiter_force_direction"] = [
14+
# FIXME: Remove type ignore once Talon supports list types
15+
# See https://github.com/talonvoice/talon/issues/654
16+
ctx.lists["user.cursorless_delimiter_force_direction"] = [ # pyright: ignore [reportArgumentType]
1517
"left",
1618
"right",
1719
]

cursorless-talon/src/number_small.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def private_cursorless_number_small(m) -> int:
3333
number_small_map = {n: i for i, n in enumerate(number_small_list)}
3434

3535
mod.list("private_cursorless_number_small", desc="List of small numbers")
36-
ctx.lists["self.private_cursorless_number_small"] = number_small_map.keys()
36+
# FIXME: Remove type ignore once Talon supports list types
37+
# See https://github.com/talonvoice/talon/issues/654
38+
ctx.lists["self.private_cursorless_number_small"] = number_small_map.keys() # pyright: ignore [reportArgumentType]
3739

3840

3941
@ctx.capture(

0 commit comments

Comments
 (0)