Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create a choice prompt for non string lists? #413

Open
1 task done
doronbehar opened this issue Dec 19, 2024 · 3 comments · May be fixed by #424
Open
1 task done

Can't create a choice prompt for non string lists? #413

doronbehar opened this issue Dec 19, 2024 · 3 comments · May be fixed by #424
Labels
Enhancement New feature or request

Comments

@doronbehar
Copy link

doronbehar commented Dec 19, 2024

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

  • I have checked that this issue occurs on the latest version of questionary.

Questionary version

2.0.1

Prompt Toolkit version

3.0.48

Operating System

Linux

@doronbehar doronbehar added the Bug Something isn't working label Dec 19, 2024
@doronbehar doronbehar changed the title Can't create a choice prompt for integers & booleans? Can't create a choice prompt for non string lists? Dec 19, 2024
@kiancross kiancross added Enhancement New feature or request and removed Bug Something isn't working labels Dec 29, 2024
@kiancross
Copy link
Collaborator

Thanks for reporting @doronbehar. I have marked this as a feature request.

@Celina1801 Celina1801 linked a pull request Jan 27, 2025 that will close this issue
2 tasks
@Celina1801
Copy link

Celina1801 commented Jan 27, 2025

Hello @doronbehar,
I just made a PR to resolve this Issue. Could you review it please ?
Thank you

@doronbehar
Copy link
Author

Thanks, but I switched to beaupy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants