Skip to content

Commit

Permalink
skip get_hint if no hints are defined
Browse files Browse the repository at this point in the history
this ensures the code is skipped when not needed.
Also helps with non-hashable stuff being passed in
  • Loading branch information
Cube707 committed Feb 3, 2024
1 parent 5af719b commit 58dde9f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/inquirer/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(
self._validate = validate
self.answers = {}
self.show_default = show_default
self.hints = hints or {}
self.hints = hints
self._other = other

if self._other:
Expand Down
4 changes: 3 additions & 1 deletion src/inquirer/render/console/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def _print_header(self, render):

def _print_hint(self, render):
msg_template = "{t.move_up}{t.clear_eol}{color}{msg}"
hint = render.get_hint()
hint = ""
if render.question.hints is not None:
hint = render.get_hint()
color = self._theme.Question.mark_color
if hint:
self.print_str(
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/console_render/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,19 @@ def test_second_hint_is_shown(self):
sut.render(question)

self.assertInStdout("Bar")

def test_taggedValue_with_dict(self):
stdin = helper.event_factory(key.DOWN, key.ENTER)
message = "Foo message"
variable = "Bar variable"
choices = [
("aa", {"a": 1}),
("bb", {"b": 2}),
]

question = questions.List(variable, message, choices=choices)

sut = ConsoleRender(event_generator=stdin)
sut.render(question)

self.assertInStdout("bb")

0 comments on commit 58dde9f

Please sign in to comment.