✨ Add option to use Enum names instead of values on the commandline#224
✨ Add option to use Enum names instead of values on the commandline#224sirex wants to merge 64 commits into
Conversation
Fixes: fastapi#151 Added `names` parameter, in order to user Enum names instead of values. Also for IntEnum, names are used by default, even if names is False.
This comment was marked as outdated.
This comment was marked as outdated.
|
Thanks! This feature is so much missing when using enums with values of other types than strings. However I got an error with this code: transform: SymmetryTransformation = typer.Option(SymmetryTransformation.TRANSPOSE, names=True),I had to change the default to the value that should be provided on the CLI, not as received in the application: transform: SymmetryTransformation = typer.Option("TRANSPOSE", names=True), |
|
Is there some update on whether this can be merged? This would make the Choices feature much more pythonic. |
|
Bumping this for interest, surprised this isn't the default behavior but understandable if all of the exploration done around this feature was with string enums |
ryangalamb
left a comment
There was a problem hiding this comment.
This is a super useful feature, but I noticed some issues while reviewing this:
- The default values are broken. Should add a test case to cover that too. (Also pointed out by @Aerilius)
- The name
namesshould be changed to indicate that it's specific to enums. - The implicit behavior with
IntEnumwill likely cause confusion. I'd prefer consistency.
I'd also like to see a test case covering Argument. (I see that this is implemented for Argument, but a test case would help guard against accidentally breaking it.)
I know this has been open for a while, so no worries if you don't have the time/interest to keep working on this. Either way, thank you for getting this started!
|
Hi, thanks for the PR and apologies for the delay in reviewing this! I'll put this in draft and I'll update with the latest |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
This pull request has a merge conflict that needs to be resolved. |
|
Thanks for the work and interest on this! There are several refactors we needed to do, and some more we are still missing before tackling this. I didn't want to close PRs before providing an alternative solution, but I ended up leaving too many PRs open for too long, sorry for that. For now I'll close this one for cleanup, but we'll continue tracking this feature request in the discussion and internally. Thanks! ☕ |
Fixes: #151
Added
namesparameter, in order to user Enum names instead of values. Also for IntEnum, names are used by default, even if names is False.