Swap the order of the prompt and value for selection items

Mostly I feel it makes sense to have the value first, and the actual prompt
second (based on no reason at all); but given that Select does it prompt
then value, this should conform to the same approach.
This commit is contained in:
Dave Pearson
2023-05-22 10:30:22 +01:00
parent 8339e8b513
commit a570b4403e

View File

@@ -22,16 +22,16 @@ class Selection(Generic[SelectionType], Option):
def __init__( def __init__(
self, self,
value: SelectionType,
prompt: TextType, prompt: TextType,
value: SelectionType,
id: str | None = None, id: str | None = None,
disabled: bool = False, disabled: bool = False,
): ):
"""Initialise the selection. """Initialise the selection.
Args: Args:
value: The value for the selection.
prompt: The prompt for the selection. prompt: The prompt for the selection.
value: The value for the selection.
selected: Is this particular selection selected? selected: Is this particular selection selected?
id: The optional ID for the selection. id: The optional ID for the selection.
disabled: The initial enabled/disabled state. Enabled by default. disabled: The initial enabled/disabled state. Enabled by default.
@@ -104,8 +104,8 @@ class SelectionList(Generic[SelectionType], OptionList):
def __init__( def __init__(
self, self,
*selections: tuple[SelectionType, TextType] *selections: tuple[TextType, SelectionType]
| tuple[SelectionType, TextType, bool], | tuple[TextType, SelectionType, bool],
name: str | None = None, name: str | None = None,
id: str | None = None, id: str | None = None,
classes: str | None = None, classes: str | None = None,
@@ -131,8 +131,8 @@ class SelectionList(Generic[SelectionType], OptionList):
def _make_selection( def _make_selection(
self, self,
selection: tuple[SelectionType, TextType] selection: tuple[TextType, SelectionType]
| tuple[SelectionType, TextType, bool], | tuple[TextType, SelectionType, bool],
) -> Selection[SelectionType]: ) -> Selection[SelectionType]:
"""Turn incoming selection data into a `Selection` instance. """Turn incoming selection data into a `Selection` instance.
@@ -143,15 +143,15 @@ class SelectionList(Generic[SelectionType], OptionList):
An instance of a `Selection`. An instance of a `Selection`.
""" """
if len(selection) == 3: if len(selection) == 3:
value, label, selected = selection label, value, selected = selection
elif len(selection) == 2: elif len(selection) == 2:
value, label, selected = (*selection, False) label, value, selected = (*selection, False)
else: else:
# TODO: Proper error. # TODO: Proper error.
raise TypeError("Wrong number of values for a selection.") raise TypeError("Wrong number of values for a selection.")
if selected: if selected:
self._selected[value] = None self._selected[value] = None
return Selection(value, label) return Selection(label, value)
def action_toggle(self) -> None: def action_toggle(self) -> None:
if self.highlighted is not None: if self.highlighted is not None: