Skip to content

Commit

Permalink
Fix or suppress all Python type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey committed Apr 25, 2024
1 parent 93c0dcd commit 0df0b7e
Show file tree
Hide file tree
Showing 24 changed files with 116 additions and 57 deletions.
19 changes: 13 additions & 6 deletions cursorless-talon-dev/src/spoken_form_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,31 @@ def did_emit_pre_phrase_signal():
return True

def private_cursorless_run_rpc_command_and_wait(
command_id: str, arg1: Any, arg2: Any = None
command_id: str, # pyright: ignore [reportGeneralTypeIssues]
arg1: Any,
arg2: Any = None,
):
commands_run.append(arg1)

def private_cursorless_run_rpc_command_no_wait(
command_id: str, arg1: Any, arg2: Any = None
command_id: str, # pyright: ignore [reportGeneralTypeIssues]
arg1: Any,
arg2: Any = None,
):
commands_run.append(arg1)

def private_cursorless_run_rpc_command_get(
command_id: str, arg1: Any, arg2: Any = None
command_id: str, # pyright: ignore [reportGeneralTypeIssues]
arg1: Any,
arg2: Any = None,
) -> Any:
commands_run.append(arg1)
return mockedGetValue


@mod.action_class
class Actions:
def private_cursorless_spoken_form_test_mode(enable: bool):
def private_cursorless_spoken_form_test_mode(enable: bool): # pyright: ignore [reportGeneralTypeIssues]
"""Enable/disable Cursorless spoken form test mode"""
global saved_modes, saved_microphone

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

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

def private_cursorless_spoken_form_test(
phrase: str, mockedGetValue_: Optional[str]
phrase: str, # pyright: ignore [reportGeneralTypeIssues]
mockedGetValue_: Optional[str],
):
"""Run Cursorless spoken form test"""
global commands_run, mockedGetValue
Expand Down
15 changes: 9 additions & 6 deletions cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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 cursorless-talon/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
Loading

0 comments on commit 0df0b7e

Please sign in to comment.