typer
typer copied to clipboard
Add option to use Enum names
Fixes: https://github.com/tiangolo/typer/issues/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.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 100.00%. Comparing base (
c3a4c72
) to head (b0f534e
). Report is 230 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #224 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 242 246 +4
Lines 4508 4559 +51
=========================================
+ Hits 4508 4559 +51
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
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),
Error: Invalid value for '--transform': invalid choice: SymmetryTransformation.TRANSPOSE. (choose from IDENTITY, ROT90, ROT180, ROT270, FLIP_X, FLIP_Y, TRANSPOSE, ANTITRANSPOSE)
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