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

Choice non string lists #424

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Celina1801
Copy link

@Celina1801 Celina1801 commented Jan 27, 2025

What is the problem that this PR addresses?

Closes #413
The issue addressed by this PR is the inability to handle non-string items in choice prompts. Previously, using lists or arrays containing integers, floats, booleans, or other non-string objects in the choices parameter caused runtime errors. This limitation impacted use cases requiring dynamic, type-diverse choices.

How did you solve it?

The solution involves enhancing the Choice.build method and related components in common.py to support non-string objects. Specifically:

The Choice.build method now converts non-string items into displayable strings for rendering while preserving their original type as the choice value.
Updated logic in InquirerControl to handle the mixed types seamlessly, ensuring compatibility with existing features such as shortcuts and separators.
Comprehensive unit tests were added to validate the behavior with non-string items, covering integers, floats, booleans, and mixed-type lists.

Checklist

  • I have read the Contributor's Guide.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@@ -116,6 +116,8 @@ def build(c: Union[str, "Choice", Dict[str, Any]]) -> "Choice":
return c
elif isinstance(c, str):
return Choice(c, c)
elif isinstance(c, (int, bool, float)): # Ajout pour les types primitifs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, do you mind changing the functions comment as well, stating that these types are allowed as well?

please remove frensh comments

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

Successfully merging this pull request may close these issues.

Can't create a choice prompt for non string lists?
2 participants