Skip to content

Commit 7eded9a

Browse files
committed
refactor FilterList
1 parent 2818ec5 commit 7eded9a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

examples/filter_list.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
choices = [(k, str(choices_map[k])[:5]) for k in choices] if "tag" in args else choices
1919

2020

21-
def filter_func(text, collection):
22-
return filter(lambda x: text in str(x), collection)
21+
def filter_func(text, all_choices):
22+
# `all_choices` is the global `choices` in this example
23+
# in `tag` choices, tuples are cast to `str`. It's the user's responsibility to change this behaviour
24+
return filter(lambda x: text in str(x), all_choices)
2325

2426

2527
questions = [

src/inquirer/questions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ def __init__(
179179
other=False,
180180
autocomplete=None,
181181
filter_func=None,
182-
# choice_callback=None,
183182
):
184183
super().__init__(name, message, choices, default, ignore, validate, hints=hints, other=other)
185184
self.carousel = carousel
@@ -188,7 +187,7 @@ def __init__(
188187
self._all_choices = choices
189188

190189
def _filter_func(self, text, all_choices):
191-
# here we reset the 'self.choices' property, to use str() cast
190+
# reset 'self.choices' property to use str() cast, filter what user sees
192191
self._choices = all_choices
193192
return filter(lambda x: text in str(x), self.choices)
194193

0 commit comments

Comments
 (0)