Skip to content

Commit 0b1e56b

Browse files
committed
fix regression in v2.2.2
when using tagged value pairs, the string representation behaved not as expected
1 parent 0b658ef commit 0b1e56b

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

examples/list_hints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import inquirer # noqa
44

55
choices_hints = {
6-
"Jumbo": "The biggest one we have",
7-
"Large": "If you need the extra kick",
86
"Standard": "For your every day use",
7+
"Large": "If you need the extra kick",
8+
"Jumbo": "The biggest one we have",
99
}
1010

1111
questions = [

src/inquirer/questions.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@
1212

1313

1414
class TaggedValue:
15-
def __init__(self, choice):
16-
self.label = choice[0]
17-
self.tag = choice[1]
18-
self._hash = hash(choice)
15+
def __init__(self, tag, value):
16+
self.tag = tag
17+
self.value = value
18+
self.tuple = (tag, value)
1919

2020
def __str__(self):
21-
return self.label
21+
return self.tag
2222

2323
def __repr__(self):
24-
return repr(self.tag)
24+
return repr(self.value)
2525

2626
def __eq__(self, other):
2727
if isinstance(other, TaggedValue):
28-
return other.tag == self.tag
28+
return other.value == self.value
2929
if isinstance(other, tuple):
30-
return other == (self.label, self.tag)
31-
return other == self.tag
30+
return other == self.tuple
31+
return other == self.value
3232

3333
def __ne__(self, other):
3434
return not self.__eq__(other)
3535

3636
def __hash__(self) -> int:
37-
return self._hash
37+
return hash(self.tuple)
3838

3939

4040
class Question:
@@ -93,7 +93,7 @@ def default(self):
9393
@property
9494
def choices_generator(self):
9595
for choice in self._solve(self._choices):
96-
yield (TaggedValue(choice) if isinstance(choice, tuple) and len(choice) == 2 else choice)
96+
yield (TaggedValue(*choice) if isinstance(choice, tuple) and len(choice) == 2 else choice)
9797

9898
@property
9999
def choices(self):

tests/unit/test_question.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,16 @@ def test_default_value_validation(self):
354354

355355
def test_tagged_value():
356356
LABEL = "label"
357-
TAG = "l"
358-
tp = (LABEL, TAG)
359-
tv = questions.TaggedValue(tp)
357+
VALUE = "l"
358+
tp = (LABEL, VALUE)
359+
tv = questions.TaggedValue(*tp)
360360

361361
assert (str(tv) == str(LABEL)) is True
362-
assert (repr(tv) == repr(TAG)) is True
362+
assert (repr(tv) == repr(VALUE)) is True
363363
assert (hash(tv) == hash(tp)) is True
364364

365365
assert (tv == tv) is True
366366
assert (tv != tv) is False
367367
assert (tv == tp) is True
368-
assert (tv == TAG) is True
368+
assert (tv == VALUE) is True
369369
assert (tv == "") is False

0 commit comments

Comments
 (0)