11import re
2+ from collections .abc import Mapping , Sequence
3+ from typing import Optional , TypedDict
24
35from talon import registry
46
57from ..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