diff --git a/examples/list_hints.py b/examples/list_hints.py index b2877ea8..ce768013 100644 --- a/examples/list_hints.py +++ b/examples/list_hints.py @@ -3,9 +3,9 @@ import inquirer # noqa choices_hints = { - "Jumbo": "The biggest one we have", - "Large": "If you need the extra kick", "Standard": "For your every day use", + "Large": "If you need the extra kick", + "Jumbo": "The biggest one we have", } questions = [ diff --git a/examples/list_tagged.py b/examples/list_tagged.py index 9c565c53..0eb1d4db 100644 --- a/examples/list_tagged.py +++ b/examples/list_tagged.py @@ -1,11 +1,8 @@ -import os -import sys from pprint import pprint - -sys.path.append(os.path.realpath(".")) import inquirer # noqa +entries = [("one", 1), ("two", 2), ("three", 3)] questions = [ inquirer.List( @@ -20,8 +17,9 @@ ("Micro", "xs"), ], ), + inquirer.List("device", message="test", choices=entries), ] answers = inquirer.prompt(questions) -pprint(answers) +print(answers['size']) diff --git a/src/inquirer/questions.py b/src/inquirer/questions.py index 39d85813..741d7780 100644 --- a/src/inquirer/questions.py +++ b/src/inquirer/questions.py @@ -12,29 +12,29 @@ class TaggedValue: - def __init__(self, choice): - self.label = choice[0] - self.tag = choice[1] - self._hash = hash(choice) + def __init__(self, tag, value): + self.tag = tag + self.value = value + self.tuple = (tag, value) def __str__(self): - return self.label + return self.tag def __repr__(self): - return repr(self.tag) + return repr(self.value) def __eq__(self, other): if isinstance(other, TaggedValue): - return other.tag == self.tag + return other.value == self.value if isinstance(other, tuple): - return other == (self.label, self.tag) - return other == self.tag + return other == self.tuple + return other == self.value def __ne__(self, other): return not self.__eq__(other) def __hash__(self) -> int: - return self._hash + return hash(self.tuple) class Question: @@ -93,7 +93,7 @@ def default(self): @property def choices_generator(self): for choice in self._solve(self._choices): - yield (TaggedValue(choice) if isinstance(choice, tuple) and len(choice) == 2 else choice) + yield (TaggedValue(*choice) if isinstance(choice, tuple) and len(choice) == 2 else choice) @property def choices(self): diff --git a/tests/unit/test_question.py b/tests/unit/test_question.py index 9c9bdc8d..67e82ca4 100644 --- a/tests/unit/test_question.py +++ b/tests/unit/test_question.py @@ -354,16 +354,16 @@ def test_default_value_validation(self): def test_tagged_value(): LABEL = "label" - TAG = "l" - tp = (LABEL, TAG) - tv = questions.TaggedValue(tp) + VALUE = "l" + tp = (LABEL, VALUE) + tv = questions.TaggedValue(VALUE, LABEL) assert (str(tv) == str(LABEL)) is True - assert (repr(tv) == repr(TAG)) is True + assert (repr(tv) == repr(VALUE)) is True assert (hash(tv) == hash(tp)) is True assert (tv == tv) is True assert (tv != tv) is False assert (tv == tp) is True - assert (tv == TAG) is True + assert (tv == VALUE) is True assert (tv == "") is False