8000 A few typing related fixes. · cool-RR/python-prompt-toolkit@8333011 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8333011

Browse files
A few typing related fixes.
1 parent a883d0f commit 8333011

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

prompt_toolkit/widgets/base.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@
1313
`prompt_toolkit.shortcuts.dialogs` on the other hand is considered stable.
1414
"""
1515
from functools import partial
16-
from typing import Callable, Generic, List, Optional, Tuple, TypeVar, Union
16+
from typing import (
17+
Callable,
18+
Generic,
19+
List,
20+
Optional,
21+
Sequence,
22+
Tuple,
23+
TypeVar,
24+
Union,
25+
)
1726

1827
from prompt_toolkit.application.current import get_app
1928
from prompt_toolkit.auto_suggest import AutoSuggest, DynamicAutoSuggest
@@ -583,17 +592,7 @@ class _DialogList(Generic[_T]):
583592
checked_style: str = ""
584593
multiple_selection: bool = False
585594

586-
def _handle_enter(self) -> None:
587-
if self.multiple_selection:
588-
val = self.values[self._selected_index][0]
589-
if val in self.current_values:
590-
self.current_values.remove(val)
591-
else:
592-
self.current_values.append(val)
593-
else:
594-
self.current_value = self.values[self._selected_index][0]
595-
596-
def __init__(self, values: List[Tuple[_T, AnyFormattedText]]) -> None:
595+
def __init__(self, values: Sequence[Tuple[_T, AnyFormattedText]]) -> None:
597596
assert len(values) > 0
598597

599598
self.values = values
@@ -658,6 +657,16 @@ def _(event: E) -> None:
658657
],
659658
dont_extend_height=True)
660659

660+
def _handle_enter(self) -> None:
661+
if self.multiple_selection:
662+
val = self.values[self._selected_index][0]
663+
if val in self.current_values:
664+
self.current_values.remove(val)
665+
else:
666+
self.current_values.append(val)
667+
else:
668+
self.current_value = self.values[self._selected_index][0]
669+
661670
def _get_text_fragments(self) -> StyleAndTextTuples:
662671
def mouse_handler(mouse_event: MouseEvent) -> None:
663672
"""
@@ -708,7 +717,7 @@ def __pt_container__(self) -> Container:
708717
return self.window
709718

710719

711-
class RadioList(_DialogList):
720+
class RadioList(_DialogList[_T]):
712721
"""
713722
List of radio buttons. Only one can be checked at the same time.
714723
@@ -723,7 +732,7 @@ class RadioList(_DialogList):
723732
multiple_selection = False
724733

725734

726-
class CheckboxList(_DialogList):
735+
class CheckboxList(_DialogList[_T]):
727736
"""
728737
List of checkbox buttons. Several can be checked at the same time.
729738
@@ -738,7 +747,7 @@ class CheckboxList(_DialogList):
738747
multiple_selection = True
739748

740749

741-
class Checkbox(CheckboxList):
750+
class Checkbox(CheckboxList[str]):
742751
"""Backward compatibility util: creates a 1-sized CheckboxList
743752
744753
:param text: the text

0 commit comments

Comments
 (0)
0