11
11
12
12
13
13
class TaggedValue :
14
- def __init__ (self , label , value ):
15
- self .label = label
16
- self .value = value
14
+ def __init__ (self , choice ):
15
+ self .label = choice [0 ]
16
+ self .tag = choice [1 ]
17
+ self ._hash = hash (choice )
17
18
18
19
def __str__ (self ):
19
20
return self .label
20
21
21
22
def __repr__ (self ):
22
- return self .value
23
+ return repr ( self .tag )
23
24
24
25
def __eq__ (self , other ):
25
26
if isinstance (other , TaggedValue ):
26
- return self .value == other .value
27
- return self .value == other
27
+ return other .tag == self .tag
28
+ if isinstance (other , tuple ):
29
+ return other == (self .label , self .tag )
30
+ return other == self .tag
28
31
29
32
def __ne__ (self , other ):
30
33
return not self .__eq__ (other )
31
34
35
+ def __hash__ (self ) -> int :
36
+ return self ._hash
37
+
32
38
33
39
class Question :
34
40
kind = "base question"
@@ -42,6 +48,7 @@ def __init__(
42
48
ignore = False ,
43
49
validate = True ,
44
50
show_default = False ,
51
+ hints = None ,
45
52
other = False ,
46
53
):
47
54
self .name = name
@@ -52,6 +59,7 @@ def __init__(
52
59
self ._validate = validate
53
60
self .answers = {}
54
61
self .show_default = show_default
62
+ self .hints = hints or {}
55
63
self ._other = other
56
64
57
65
if self ._other :
@@ -84,7 +92,7 @@ def default(self):
84
92
@property
85
93
def choices_generator (self ):
86
94
for choice in self ._solve (self ._choices ):
87
- yield (TaggedValue (* choice ) if isinstance (choice , tuple ) and len (choice ) == 2 else choice )
95
+ yield (TaggedValue (choice ) if isinstance (choice , tuple ) and len (choice ) == 2 else choice )
88
96
89
97
@property
90
98
def choices (self ):
@@ -143,14 +151,15 @@ def __init__(
143
151
name ,
144
152
message = "" ,
145
153
choices = None ,
154
+ hints = None ,
146
155
default = None ,
147
156
ignore = False ,
148
157
validate = True ,
149
158
carousel = False ,
150
159
other = False ,
151
160
autocomplete = None ,
152
161
):
153
- super ().__init__ (name , message , choices , default , ignore , validate , other = other )
162
+ super ().__init__ (name , message , choices , default , ignore , validate , hints = hints , other = other )
154
163
self .carousel = carousel
155
164
self .autocomplete = autocomplete
156
165
@@ -163,6 +172,7 @@ def __init__(
163
172
name ,
164
173
message = "" ,
165
174
choices = None ,
175
+ hints = None ,
166
176
locked = None ,
167
177
default = None ,
168
178
ignore = False ,
@@ -171,7 +181,7 @@ def __init__(
171
181
other = False ,
172
182
autocomplete = None ,
173
183
):
174
- super ().__init__ (name , message , choices , default , ignore , validate , other = other )
184
+ super ().__init__ (name , message , choices , default , ignore , validate , hints = hints , other = other )
175
185
self .locked = locked
176
186
self .carousel = carousel
177
187
self .autocomplete = autocomplete
0 commit comments