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
I used the GitHub search to find a similar issue and didn't find it.
I searched the Typer documentation, with the integrated search.
I already searched in Google "How to X in Typer" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to Typer but to Click.
Commit to Help
I commit to help with one of those options 👆
Example Code
importtyperfromenumimportEnumclassChoiceEnum(Enum):
option_one="opt1"option_two="opt2"option_three="opt3"app=typer.Typer()
@app.command()defsubcommand(argument_option: ChoiceEnum=typer.Option(ChoiceEnum.option_two.value,
prompt="argument option",
show_choices=True)):
prompt_option: ChoiceEnum=typer.prompt("prompt option",
ChoiceEnum.option_three.value,
show_choices=True)
print(f"Argument choice: {argument_option}")
print(f"Prompt choice: {prompt_option}")
if__name__=="__main__":
app()
# The result of running the above script results in the following output:## > argument option (opt1, opt2, opt3) [opt2]: # > prompt option [opt3]: # > Argument choice: ChoiceEnum.option_two# > Prompt choice: opt3
Description
Using the typer.prompt function isn't displaying the choices of an enum the same way that an Option does.
Am I doing something wrong here? Is there some other way I should be doing the prompt in order for it to display the choices as is done with the argument choices?
Also, why are the return values different (the prompt gives me the string "opt3", while the argument returns the enum value itself).
Operating System
macOS
Operating System Details
No response
Typer Version
0.6.1
Python Version
Python 3.10.8
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Managed to figure out that I needed to add type=ChoiceEnum to the prompt call to get the return value to be of the same type as the argument. Still doesn't fix showing the choices.
Still think that the typer behavior needs to be looked at to make the behavior a bit more predictable. Would think that label should be updated to bug.
First Check
Commit to Help
Example Code
Description
Using the
typer.prompt
function isn't displaying the choices of an enum the same way that an Option does.Am I doing something wrong here? Is there some other way I should be doing the prompt in order for it to display the choices as is done with the argument choices?
Also, why are the return values different (the prompt gives me the string "opt3", while the argument returns the enum value itself).
Operating System
macOS
Operating System Details
No response
Typer Version
0.6.1
Python Version
Python 3.10.8
Additional Context
No response
The text was updated successfully, but these errors were encountered: