✨ 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 54 commits intofastapi:masterfrom
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.
docs_src/multiple_values/options_with_multiple_values/tutorial002_py39.py
Outdated
Show resolved
Hide resolved
docs_src/multiple_values/arguments_with_multiple_values/tutorial003_py39.py
Outdated
Show resolved
Hide resolved
docs_src/multiple_values/options_with_multiple_values/tutorial003_py39.py
Outdated
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
svlandeg
left a comment
There was a problem hiding this comment.
I had another look at this PR, and brought it up-to-date with the latest docs formatting on master. I've also removed several unnecessary test files that weren't actually mentioned in the tutorial.
I think the PR is now again ready for review 🙏
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.