Skip to content

Commit

Permalink
Fix or suppress all Python type errors (#2307)
Browse files Browse the repository at this point in the history
- Depends on cursorless-dev/cursorless#2306
- Supercedes cursorless-dev/cursorless#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
  • Loading branch information
pokey authored and cursorless-bot committed Apr 28, 2024
1 parent 083bab7 commit a35a40b
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 51 deletions.
15 changes: 9 additions & 6 deletions src/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from ..targets.target_types import (
CursorlessDestination,
CursorlessExplicitTarget,
CursorlessTarget,
ImplicitDestination,
)
Expand Down Expand Up @@ -48,7 +49,7 @@
"custom_action",
]

callback_actions: dict[str, Callable[[CursorlessTarget], None]] = {
callback_actions: dict[str, Callable[[CursorlessExplicitTarget], None]] = {
"nextHomophone": cursorless_homophones_action,
}

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

@mod.action_class
class Actions:
def cursorless_command(action_name: str, target: CursorlessTarget):
def cursorless_command(action_name: str, target: CursorlessExplicitTarget): # pyright: ignore [reportGeneralTypeIssues]
"""Perform cursorless command on target"""
if action_name in callback_actions:
callback_actions[action_name](target)
Expand All @@ -107,28 +108,30 @@ def cursorless_command(action_name: str, target: CursorlessTarget):
action = {"name": action_name, "target": target}
actions.user.private_cursorless_command_and_wait(action)

def cursorless_vscode_command(command_id: str, target: CursorlessTarget):
def cursorless_vscode_command(command_id: str, target: CursorlessTarget): # pyright: ignore [reportGeneralTypeIssues]
"""
Perform vscode command on cursorless target
Deprecated: prefer `cursorless_ide_command`
"""
return actions.user.cursorless_ide_command(command_id, target)

def cursorless_ide_command(command_id: str, target: CursorlessTarget):
def cursorless_ide_command(command_id: str, target: CursorlessTarget): # pyright: ignore [reportGeneralTypeIssues]
"""Perform ide command on cursorless target"""
return cursorless_execute_command_action(command_id, target)

def cursorless_insert(
destination: CursorlessDestination, text: Union[str, list[str]]
destination: CursorlessDestination, # pyright: ignore [reportGeneralTypeIssues]
text: Union[str, list[str]],
):
"""Perform text insertion on Cursorless destination"""
if isinstance(text, str):
text = [text]
cursorless_replace_action(destination, text)

def private_cursorless_action_or_ide_command(
instruction: dict[str, str], target: CursorlessTarget
instruction: dict[str, str], # pyright: ignore [reportGeneralTypeIssues]
target: CursorlessTarget,
):
"""Perform cursorless action or ide command on target (internal use only)"""
type = instruction["type"]
Expand Down
2 changes: 1 addition & 1 deletion src/actions/bring_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def cursorless_bring_move_targets(m) -> BringMoveTargets:

@mod.action_class
class Actions:
def private_cursorless_bring_move(action_name: str, targets: BringMoveTargets):
def private_cursorless_bring_move(action_name: str, targets: BringMoveTargets): # pyright: ignore [reportGeneralTypeIssues]
"""Execute Cursorless move/bring action"""
actions.user.private_cursorless_command_and_wait(
{
Expand Down
2 changes: 1 addition & 1 deletion src/actions/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@mod.action_class
class Actions:
def private_cursorless_call(
callee: CursorlessTarget,
callee: CursorlessTarget, # pyright: ignore [reportGeneralTypeIssues]
argument: CursorlessTarget = ImplicitTarget(),
):
"""Execute Cursorless call action"""
Expand Down
4 changes: 2 additions & 2 deletions src/actions/get_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@mod.action_class
class Actions:
def cursorless_get_text(
target: CursorlessTarget,
target: CursorlessTarget, # pyright: ignore [reportGeneralTypeIssues]
hide_decorations: bool = False,
) -> str:
"""Get target text. If hide_decorations is True, don't show decorations"""
Expand All @@ -21,7 +21,7 @@ def cursorless_get_text(
)[0]

def cursorless_get_text_list(
target: CursorlessTarget,
target: CursorlessTarget, # pyright: ignore [reportGeneralTypeIssues]
hide_decorations: bool = False,
) -> list[str]:
"""Get texts for multiple targets. If hide_decorations is True, don't show decorations"""
Expand Down
7 changes: 5 additions & 2 deletions src/actions/homophones.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

from talon import actions, app

from ..targets.target_types import CursorlessTarget, PrimitiveDestination
from ..targets.target_types import (
CursorlessExplicitTarget,
PrimitiveDestination,
)
from .get_text import cursorless_get_text_action
from .replace import cursorless_replace_action


def cursorless_homophones_action(target: CursorlessTarget):
def cursorless_homophones_action(target: CursorlessExplicitTarget):
"""Replaced target with next homophone"""
texts = cursorless_get_text_action(target, show_decorations=False)
try:
Expand Down
4 changes: 3 additions & 1 deletion src/actions/paste.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

@mod.action_class
class Actions:
def private_cursorless_paste(destination: CursorlessDestination):
def private_cursorless_paste(
destination: CursorlessDestination, # pyright: ignore [reportGeneralTypeIssues]
):
"""Execute Cursorless paste action"""
actions.user.private_cursorless_command_and_wait(
{
Expand Down
10 changes: 8 additions & 2 deletions src/actions/reformat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from talon import Module, actions

from ..targets.target_types import CursorlessTarget, PrimitiveDestination
from ..targets.target_types import (
CursorlessExplicitTarget,
PrimitiveDestination,
)
from .get_text import cursorless_get_text_action
from .replace import cursorless_replace_action

Expand All @@ -11,7 +14,10 @@

@mod.action_class
class Actions:
def private_cursorless_reformat(target: CursorlessTarget, formatters: str):
def private_cursorless_reformat(
target: CursorlessExplicitTarget, # pyright: ignore [reportGeneralTypeIssues]
formatters: str,
):
"""Execute Cursorless reformat action. Reformat target with formatter"""
texts = cursorless_get_text_action(target, show_decorations=False)
updated_texts = [actions.user.reformat_text(text, formatters) for text in texts]
Expand Down
4 changes: 3 additions & 1 deletion src/actions/swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def cursorless_swap_targets(m) -> SwapTargets:

@mod.action_class
class Actions:
def private_cursorless_swap(targets: SwapTargets):
def private_cursorless_swap(
targets: SwapTargets, # pyright: ignore [reportGeneralTypeIssues]
):
"""Execute Cursorless swap action"""
actions.user.private_cursorless_command_and_wait(
{
Expand Down
8 changes: 6 additions & 2 deletions src/actions/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
@mod.action_class
class Actions:
def private_cursorless_wrap_with_paired_delimiter(
action_name: str, target: CursorlessTarget, paired_delimiter: list[str]
action_name: str, # pyright: ignore [reportGeneralTypeIssues]
target: CursorlessTarget,
paired_delimiter: list[str],
):
"""Execute Cursorless wrap/rewrap with paired delimiter action"""
if action_name == "rewrap":
Expand All @@ -26,7 +28,9 @@ def private_cursorless_wrap_with_paired_delimiter(
)

def private_cursorless_wrap_with_snippet(
action_name: str, target: CursorlessTarget, snippet_location: str
action_name: str, # pyright: ignore [reportGeneralTypeIssues]
target: CursorlessTarget,
snippet_location: str,
):
"""Execute Cursorless wrap with snippet action"""
if action_name == "wrapWithPairedDelimiter":
Expand Down
5 changes: 3 additions & 2 deletions src/apps/vscode_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
class Actions:
def vscode_settings_path() -> Path:
"""Get path of vscode settings json file"""
...

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

def vscode_get_setting_with_fallback(
key: str,
key: str, # pyright: ignore [reportGeneralTypeIssues]
default_value: Any,
fallback_value: Any,
fallback_message: str,
Expand Down
2 changes: 1 addition & 1 deletion src/cheatsheet/cheat_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def cheatsheet_dir_linux() -> Path:
"""Get cheatsheet directory for Linux"""
try:
# 1. Get users actual document directory
import platformdirs
import platformdirs # pyright: ignore [reportMissingImports]

return Path(platformdirs.user_documents_dir())
except Exception:
Expand Down
3 changes: 2 additions & 1 deletion src/cheatsheet/get_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import typing
from collections.abc import Mapping, Sequence
from typing import Optional, TypedDict

Expand Down Expand Up @@ -37,7 +38,7 @@ def get_lists(

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


def get_spoken_form_from_list(list_name: str, value: str) -> str:
Expand Down
8 changes: 4 additions & 4 deletions src/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CursorlessCommand:


CURSORLESS_COMMAND_ID = "cursorless.command"
last_phrase = None
last_phrase: dict = {}

mod = Module()

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

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

def private_cursorless_command_no_wait(action: dict):
def private_cursorless_command_no_wait(action: dict): # pyright: ignore [reportGeneralTypeIssues]
"""Execute cursorless command without waiting"""
actions.user.private_cursorless_run_rpc_command_no_wait(
CURSORLESS_COMMAND_ID,
construct_cursorless_command(action),
)

def private_cursorless_command_get(action: dict):
def private_cursorless_command_get(action: dict): # pyright: ignore [reportGeneralTypeIssues]
"""Execute cursorless command and return result"""
response = actions.user.private_cursorless_run_rpc_command_get(
CURSORLESS_COMMAND_ID,
Expand Down
5 changes: 4 additions & 1 deletion src/csv_overrides.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import csv
import typing
from collections import defaultdict
from collections.abc import Container
from dataclasses import dataclass
Expand Down Expand Up @@ -453,7 +454,9 @@ def get_full_path(filename: str):
filename = f"{filename}.csv"

user_dir: Path = actions.path.talon_user()
settings_directory = Path(settings.get("user.cursorless_settings_directory"))
settings_directory = Path(
typing.cast(str, settings.get("user.cursorless_settings_directory"))
)

if not settings_directory.is_absolute():
settings_directory = user_dir / settings_directory
Expand Down
12 changes: 9 additions & 3 deletions src/cursorless_command_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
@mod.action_class
class Actions:
def private_cursorless_run_rpc_command_and_wait(
command_id: str, arg1: Any = None, arg2: Any = None
command_id: str, # pyright: ignore [reportGeneralTypeIssues]
arg1: Any = None,
arg2: Any = None,
):
"""Execute command via rpc and wait for command to finish."""
try:
Expand All @@ -17,7 +19,9 @@ def private_cursorless_run_rpc_command_and_wait(
actions.user.vscode_with_plugin_and_wait(command_id, arg1, arg2)

def private_cursorless_run_rpc_command_no_wait(
command_id: str, arg1: Any = None, arg2: Any = None
command_id: str, # pyright: ignore [reportGeneralTypeIssues]
arg1: Any = None,
arg2: Any = None,
):
"""Execute command via rpc and DON'T wait."""
try:
Expand All @@ -26,7 +30,9 @@ def private_cursorless_run_rpc_command_no_wait(
actions.user.vscode_with_plugin(command_id, arg1, arg2)

def private_cursorless_run_rpc_command_get(
command_id: str, arg1: Any = None, arg2: Any = None
command_id: str, # pyright: ignore [reportGeneralTypeIssues]
arg1: Any = None,
arg2: Any = None,
) -> Any:
"""Execute command via rpc and return command output."""
try:
Expand Down
4 changes: 3 additions & 1 deletion src/modifiers/surrounding_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"cursorless_delimiter_force_direction",
desc="Can be used to force an ambiguous delimiter to extend in one direction",
)
ctx.lists["user.cursorless_delimiter_force_direction"] = [
# FIXME: Remove type ignore once Talon supports list types
# See https://github.com/talonvoice/talon/issues/654
ctx.lists["user.cursorless_delimiter_force_direction"] = [ # pyright: ignore [reportArgumentType]
"left",
"right",
]
Expand Down
4 changes: 3 additions & 1 deletion src/number_small.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def private_cursorless_number_small(m) -> int:
number_small_map = {n: i for i, n in enumerate(number_small_list)}

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


@ctx.capture(
Expand Down
10 changes: 6 additions & 4 deletions src/private_api/private_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ class TargetBuilderActions:
"""Cursorless private api low-level target builder actions"""

def cursorless_private_build_primitive_target(
modifiers: list[dict], mark: Optional[dict]
modifiers: list[dict], # pyright: ignore [reportGeneralTypeIssues]
mark: Optional[dict],
) -> PrimitiveTarget:
"""Cursorless private api low-level target builder: Create a primitive target"""
return PrimitiveTarget(mark, modifiers)

def cursorless_private_build_list_target(
elements: list[Union[PrimitiveTarget, RangeTarget]],
) -> Union[PrimitiveTarget, ListTarget]:
elements: list[Union[PrimitiveTarget, RangeTarget]], # pyright: ignore [reportGeneralTypeIssues]
) -> Union[PrimitiveTarget, RangeTarget, ListTarget]:
"""Cursorless private api low-level target builder: Create a list target"""
if len(elements) == 1:
return elements[0]
Expand All @@ -50,7 +51,8 @@ def cursorless_private_target_nothing() -> PrimitiveTarget:
@mod.action_class
class ActionActions:
def cursorless_private_action_highlight(
target: CursorlessTarget, highlightId: Optional[str] = None
target: CursorlessTarget, # pyright: ignore [reportGeneralTypeIssues]
highlightId: Optional[str] = None,
) -> None:
"""Cursorless private api: Highlights a target"""
payload = {
Expand Down
3 changes: 2 additions & 1 deletion src/scope_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
@mod.action_class
class Actions:
def private_cursorless_show_scope_visualizer(
scope_type: dict, visualization_type: str
scope_type: dict, # pyright: ignore [reportGeneralTypeIssues]
visualization_type: str,
):
"""Shows scope visualizer"""
actions.user.private_cursorless_run_rpc_command_no_wait(
Expand Down
Loading

0 comments on commit a35a40b

Please sign in to comment.