Repository navigation
Replies: 8 comments 1 reply
|
I think if this was configurable as an option, this would be great - on the other hand, we have a use-case where we have an Enum set up as which then means we can do Do you think there's some way to nicely make the behaviour configurable? |
|
One way to make this feature configurable as an option would be to create a dummy class NamedEnum(Enum):
passAnd to add the behaviour I described only to instances of |
|
+1 to this feature! I often have enums with numerical values, which are not convenient to use and see in the help message. I guess, this will also fix the problem when using |
|
The documentation for Enums - Choices is also slightly confusing in this aspect as the examples use the same words for both class NeuralNetwork(str, Enum):
simple = "simple"
conv = "conv"
lstm = "lstm" |
|
Ok I finally found a way to have this without changing typer: class MyEnum(Enum):
choice1 = {"k": "v"}
choice2 = 2
def __init__(self, val):
self.val = val
@property
def value(self):
return self.nameWith these re-definition of enum methods, one can use an Enum in typer, and obtained objects have the custom values in the @app.command()
def test(value: ME):
print("HELLO", value.val)Edit: not perfect though , as default values need to be passed as @app.command()
def test(value: ME = ME.choice1.name):
print("HELLO", value.val) |
|
@HaiyiMei's workaround from here seems to actually work quite well for this. This produces a nice help message too: |
Nicely done @multiplemonomials! Any ideas around how one could do something similar for multiple colors? Ie. a list of colors as input arguments? |
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem
I would like to be able to unleash the power of Enum ! The first case I stumbled onto is that of logging, e.g have the following Enum usable in typer:
Instead I have to use this one, and then convert the string to the right value
The solution you would like
I would like typer to interpret the
value.nameas arguments, and providevalue.valueto the called function, so that the following program would work as intended:All reactions