You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When default value for editor is a json, the question cannot be rendered. Here is an example reproducing the error
Python 3.10.8 (main, Oct 13 2022, 10:17:43) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> import inquirer
>>> questions=[inquirer.Editor("test", "This is a Question", default=json.dumps({"foo": "bar"}))]
>>> inquirer.prompt(questions)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/name/.local/share/virtualenvs/rihqt8cC/lib/python3.10/site-packages/inquirer/prompt.py", line 11, in prompt
answers[question.name] = render.render(question, answers)
File "/Users/name/.local/share/virtualenvs/rihqt8cC/lib/python3.10/site-packages/inquirer/render/console/__init__.py", line 38, in render
return self._event_loop(render)
File "/Users/name/.local/share/virtualenvs/rihqt8cC/lib/python3.10/site-packages/inquirer/render/console/__init__.py", line 48, in _event_loop
self._print_header(render)
File "/Users/name/.local/share/virtualenvs/rihqt8cC/lib/python3.10/site-packages/inquirer/render/console/__init__.py", line 76, in _print_header
default=render.question.default, color=self._theme.Question.default_color, normal=self.terminal.normal
File "/Users/name/.local/share/virtualenvs/rihqt8cC/lib/python3.10/site-packages/inquirer/questions.py", line 55, in default
return self.answers.get(self.name) or self._solve(self._default)
File "/Users/name/.local/share/virtualenvs/rihqt8cC/lib/python3.10/site-packages/inquirer/questions.py", line 80, in _solve
return prop.format(**self.answers)
KeyError: '"foo"'
>>>
The text was updated successfully, but these errors were encountered:
this stems from the fact that default will be stringifyed uppon Object-creation and than on rendering get a .format() applyed to it. This failes with json strings, as they contain curly brackets, which are interpreted for formating.
You might be able to escape the curly brackets by doubling them up as mentioned here. Alternatively, that response suggests using string.Template which might be a good alternative?
version:
2.10.0
When default value for editor is a json, the question cannot be rendered. Here is an example reproducing the error
The text was updated successfully, but these errors were encountered: