EDIT:
Now I noticed that this happens for any choices list of non-strings.. Maybe this should be labeled as a feature request.. Anyway, here's the original bug report:
Describe the bug
Can't use a Python pure list, nor a Numpy array of dtype integer, nor a Numpy array of booleans, nor a list of pure Python booleans. Example traceback for pure Python integers:
Traceback (most recent call last):
File "/home/doron/repos/lab-ion-trap-simulations/./t.py", line 7, in <module>
prompt([{
File "/nix/store/2ph1jmxhdj7cgkwxv9c4f3n4vndq50d1-python3-3.12.7-env/lib/python3.12/site-packages/questionary/prompt.py", line 78, in prompt
return unsafe_prompt(questions, answers, patch_stdout, true_color, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/2ph1jmxhdj7cgkwxv9c4f3n4vndq50d1-python3-3.12.7-env/lib/python3.12/site-packages/questionary/prompt.py", line 221, in unsafe_prompt
question = create_question_func(**_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/nix/store/2ph1jmxhdj7cgkwxv9c4f3n4vndq50d1-python3-3.12.7-env/lib/python3.12/site-packages/questionary/prompts/select.py", line 146, in select
ic = InquirerControl(
^^^^^^^^^^^^^^^^
File "/nix/store/2ph1jmxhdj7cgkwxv9c4f3n4vndq50d1-python3-3.12.7-env/lib/python3.12/site-packages/questionary/prompts/common.py", line 268, in __init__
self._init_choices(choices, pointed_at)
File "/nix/store/2ph1jmxhdj7cgkwxv9c4f3n4vndq50d1-python3-3.12.7-env/lib/python3.12/site-packages/questionary/prompts/common.py", line 324, in _init_choices
choice = Choice.build(c)
^^^^^^^^^^^^^^^
File "/nix/store/2ph1jmxhdj7cgkwxv9c4f3n4vndq50d1-python3-3.12.7-env/lib/python3.12/site-packages/questionary/prompts/common.py", line 122, in build
c.get("name"),
^^^^^
AttributeError: 'int' object has no attribute 'get'
Example
#!/usr/bin/env python
import sys
from questionary import prompt
answers = prompt([{
'name': 'integer',
'type': 'select',
'message': "Select favorite integer",
'choices': list(range(10)),
}])
Steps to reproduce
Simply run the provided MWE. Change that choices key to [True, False] or to np.array(list(range(10))) to view other variants of the bug.
Expected behaviour
Same behavior as this gives:
#!/usr/bin/env python
import sys
from questionary import prompt
answers = prompt([{
'name': 'integer',
'type': 'select',
'message': "Select favorite integer",
'choices': list(map(str, range(10))),
}])
answers['integer'] = int(answers['integer'])
print(answers)
Latest version
Questionary version
2.0.1
Prompt Toolkit version
3.0.48
Operating System
Linux
EDIT:
Now I noticed that this happens for any
choiceslist of non-strings.. Maybe this should be labeled as a feature request.. Anyway, here's the original bug report:Describe the bug
Can't use a Python pure
list, nor a Numpy array of dtype integer, nor a Numpy array of booleans, nor a list of pure Python booleans. Example traceback for pure Python integers:Example
Steps to reproduce
Simply run the provided MWE. Change that
choiceskey to[True, False]or tonp.array(list(range(10)))to view other variants of the bug.Expected behaviour
Same behavior as this gives:
Latest version
Questionary version
2.0.1
Prompt Toolkit version
3.0.48
Operating System
Linux