Skip to content

Enum Arguments/Options with custom click_type are always None #777

Discussion options

You must be logged in to vote

If you return value rather than OnlyOneCatEnum(value) from NoPluralCatsChoice.convert(), then animal and animal_option will correctly contain the enum instance OnlyOneCatEnum.CAT and ctx.params will contain the string cat, which is the intended behavior I believe.

The issue is that click.Choice is not expecting convert() to return an instance of an enum. When typer creates a click.Choice under the hood, it passes only with the values of the enum (and the enum is only dealt with in typer):

typer/typer/main.py

Lines 779 to 783 in 968d81d

elif lenient_issubclass(annotation, Enum):
return click.Choice(
[item.value for item in annotation],
case_sensitive=parameter_info.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AlessandroPomponio
Comment options

Answer selected by AlessandroPomponio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants