Skip to content

Commit 9a1bd93

Browse files
authored
Type hint Talon cheatsheet get_list (#1850)
## 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
1 parent 81a757c commit 9a1bd93

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

cursorless-talon/src/cheatsheet/get_list.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
11
import re
2+
from collections.abc import Mapping, Sequence
3+
from typing import Optional, TypedDict
24

35
from talon import registry
46

57
from ..conventions import get_cursorless_list_name
68

79

8-
def get_list(name, type, descriptions=None):
10+
class Variation(TypedDict):
11+
spokenForm: str
12+
description: str
13+
14+
15+
class ListItemDescriptor(TypedDict):
16+
id: str
17+
type: str
18+
variations: list[Variation]
19+
20+
21+
def get_list(
22+
name: str, type: str, descriptions: Optional[Mapping[str, str]] = None
23+
) -> list[ListItemDescriptor]:
924
if descriptions is None:
1025
descriptions = {}
1126

1227
items = get_raw_list(name)
13-
item_dict = items if isinstance(items, dict) else {item: item for item in items}
1428

15-
return make_dict_readable(type, item_dict, descriptions)
29+
return make_dict_readable(type, items, descriptions)
1630

1731

18-
def get_lists(names: list[str], type: str, descriptions=None):
32+
def get_lists(
33+
names: Sequence[str], type: str, descriptions: Optional[Mapping[str, str]] = None
34+
) -> list[ListItemDescriptor]:
1935
return [item for name in names for item in get_list(name, type, descriptions)]
2036

2137

22-
def get_raw_list(name):
38+
def get_raw_list(name: str) -> Mapping[str, str]:
2339
cursorless_list_name = get_cursorless_list_name(name)
2440
return registry.lists[cursorless_list_name][0].copy()
2541

2642

27-
def make_dict_readable(type: str, dict, descriptions=None):
28-
if descriptions is None:
29-
descriptions = {}
30-
43+
def make_dict_readable(
44+
type: str, dict: Mapping[str, str], descriptions: Mapping[str, str]
45+
) -> list[ListItemDescriptor]:
3146
return [
3247
{
3348
"id": value,
@@ -43,7 +58,7 @@ def make_dict_readable(type: str, dict, descriptions=None):
4358
]
4459

4560

46-
def make_readable(text):
61+
def make_readable(text: str) -> str:
4762
text = text.replace(".", " ")
4863
return de_camel(text).lower().capitalize()
4964

0 commit comments

Comments
 (0)