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):
https://github.com/tiangolo/typer/blob/968d81df54997fa0219ca2de2aeacbab54daa003/typer/main.py#L779-L783

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