Remove a couple of annoying type errors

The code worked and was fine, but pyright was getting upset at the typing.
This clears that up.
This commit is contained in:
Dave Pearson
2023-05-22 13:13:37 +01:00
parent 424c30fcf1
commit 127d93a260

View File

@@ -17,6 +17,7 @@ from ._toggle_button import ToggleButton
SelectionType = TypeVar("SelectionType")
"""The type for the value of a `Selection`"""
MessageSelectionType = TypeVar("MessageSelectionType")
"""The type for the value of a `SelectionList` message"""
@@ -201,9 +202,13 @@ class SelectionList(Generic[SelectionType], OptionList):
An instance of a `Selection`.
"""
if len(selection) == 3:
label, value, selected = selection
label, value, selected = cast(
tuple[TextType, SelectionType, bool], selection
)
elif len(selection) == 2:
label, value, selected = (*selection, False)
label, value, selected = cast(
tuple[TextType, SelectionType, bool], (*selection, False)
)
else:
# TODO: Proper error.
raise TypeError("Wrong number of values for a selection.")