1
1
import re
2
+ from collections .abc import Mapping , Sequence
3
+ from typing import Optional , TypedDict
2
4
3
5
from talon import registry
4
6
5
7
from ..conventions import get_cursorless_list_name
6
8
7
9
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 ]:
9
24
if descriptions is None :
10
25
descriptions = {}
11
26
12
27
items = get_raw_list (name )
13
- item_dict = items if isinstance (items , dict ) else {item : item for item in items }
14
28
15
- return make_dict_readable (type , item_dict , descriptions )
29
+ return make_dict_readable (type , items , descriptions )
16
30
17
31
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 ]:
19
35
return [item for name in names for item in get_list (name , type , descriptions )]
20
36
21
37
22
- def get_raw_list (name ) :
38
+ def get_raw_list (name : str ) -> Mapping [ str , str ] :
23
39
cursorless_list_name = get_cursorless_list_name (name )
24
40
return registry .lists [cursorless_list_name ][0 ].copy ()
25
41
26
42
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 ]:
31
46
return [
32
47
{
33
48
"id" : value ,
@@ -43,7 +58,7 @@ def make_dict_readable(type: str, dict, descriptions=None):
43
58
]
44
59
45
60
46
- def make_readable (text ) :
61
+ def make_readable (text : str ) -> str :
47
62
text = text .replace ("." , " " )
48
63
return de_camel (text ).lower ().capitalize ()
49
64
0 commit comments