From 127d93a2605e8d697b87732ed4a23b300c1a0825 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 22 May 2023 13:13:37 +0100 Subject: [PATCH] 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. --- src/textual/widgets/_selection_list.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/textual/widgets/_selection_list.py b/src/textual/widgets/_selection_list.py index 02ec4839f..29ede5dbe 100644 --- a/src/textual/widgets/_selection_list.py +++ b/src/textual/widgets/_selection_list.py @@ -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.")