Skip to content

Commit 5662788

Browse files
committed
Refactors typing
1 parent 685572a commit 5662788

4 files changed

Lines changed: 9 additions & 12 deletions

File tree

teletype/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "1.3.3"
1+
VERSION = "1.3.4"

teletype/components.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any, Dict, Generic, Iterable, List, Optional, Set, Tuple, Union
33

44
from teletype import codes, io
5-
from teletype.typing import TSTYLE, V
5+
from teletype.typedef import TSTYLE, V
66

77
__all__ = [
88
"SelectOne",
@@ -94,9 +94,6 @@ def mnemonic(self, m: Optional[str]):
9494
raise ValueError("mnemonic not present in value or label")
9595

9696

97-
ChoiceParam = Union[str, int, ChoiceHelper]
98-
99-
10097
class SelectOne:
10198
"""Allows the user to make a single selection
10299
@@ -107,27 +104,27 @@ class SelectOne:
107104

108105
_multiselect = False
109106

110-
def __init__(self, choices: Iterable[ChoiceParam], **chars: str):
107+
def __init__(self, choices: Iterable, **chars: str):
111108
self.chars = codes.CHARS_DEFAULT.copy()
112109
self.chars.update(chars)
113110
self._mnemonic_idx_map: Dict[str, int] = {}
114-
self._choices: List[ChoiceParam] = []
111+
self._choices: List[Any] = []
115112
for choice in choices:
116113
if choice in self._choices:
117114
continue
118115
self._choices.append(choice)
119116
if isinstance(choice, ChoiceHelper) and choice.mnemonic:
120117
self._mnemonic_idx_map[choice.mnemonic] = len(self._mnemonic_idx_map)
121118
self._line = 0
122-
self._selected_lines: Set[str] = set()
119+
self._selected_lines: Set[int] = set()
123120

124121
def __len__(self):
125122
return len(self.choices)
126123

127124
def __hash__(self):
128125
return self.choices.__hash__()
129126

130-
def _display_choice(self, idx: int, choice: ChoiceParam):
127+
def _display_choice(self, idx: int, choice: Any):
131128
print(" %s %s" % (self.chars["arrow"] if idx == 0 else " ", choice))
132129

133130
def _select_line(self):
@@ -185,15 +182,15 @@ def _process_keypress(self):
185182
raise KeyboardInterrupt("%s pressed" % key)
186183

187184
@staticmethod
188-
def _strip_choice(choice: ChoiceParam) -> Any:
185+
def _strip_choice(choice: Any) -> Any:
189186
if isinstance(choice, str):
190187
return io.strip_format(choice)
191188
if isinstance(choice, ChoiceHelper):
192189
return choice.value
193190
return choice
194191

195192
@property
196-
def choices(self) -> Tuple[ChoiceParam, ...]:
193+
def choices(self) -> Tuple:
197194
"""Returns read-only tuple of choices"""
198195
return tuple(self._choices)
199196

teletype/io/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any, Optional
44

55
from teletype import codes
6-
from teletype.typing import TSTYLE
6+
from teletype.typedef import TSTYLE
77

88
__all__ = [
99
"erase_lines",
File renamed without changes.

0 commit comments

Comments
 (0)