typer icon indicating copy to clipboard operation
typer copied to clipboard

Add option to use Enum names

Open sirex opened this issue 3 years ago • 4 comments

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.

sirex avatar Jan 21 '21 17:01 sirex

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.

codecov[bot] avatar Jan 21 '21 17:01 codecov[bot]

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),

Aerilius avatar Apr 15 '21 11:04 Aerilius

Is there some update on whether this can be merged? This would make the Choices feature much more pythonic.

mattchan-tencent avatar Mar 09 '22 21:03 mattchan-tencent

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

abondrnco avatar May 31 '22 20:05 abondrnco