You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could you make it so that options for enums appear in the help-message?
here is a code example
fromenumimportEnumfromtypingimportLiteralfromtapimportTapclassMyEnum(str, Enum):
A="aaa"B="bbb"C="ccc"def__str__(self):
# it would be nice if this overwrite wouldn't be neededreturnself.valueclassMyArgs(Tap):
myEnum1: MyEnum=MyEnum.A# here options are not listedmyEnum2: Literal[MyEnum.A, MyEnum.B, MyEnum.C] =MyEnum.A# workaround, that repeats all optionsdefconfigure(self):
# this works fine, but it would be neat if it wasn't neededself.add_argument('--myEnum3', type=MyEnum, choices=list(MyEnum))
print(MyArgs().parse_args())
help-message:
$ python main2.py -h
usage: main2.py [--myEnum1 MYENUM1] [--myEnum2 {aaa,bbb,ccc}] [-h] --myEnum3 {aaa,bbb,ccc}
optional arguments:
--myEnum1 MYENUM1 (<enum 'MyEnum'>, default=aaa) here options are not listed
--myEnum2 {aaa,bbb,ccc}
(Literal[<MyEnum.A: 'aaa'>, <MyEnum.B: 'bbb'>, <MyEnum.C: 'ccc'>], default=aaa) workaround, that repeats all options
-h, --help show this help message and exit
--myEnum3 {aaa,bbb,ccc}
(required)
the actual parsed values are as expected the same in all 3 cases:
Additional note: i have considered literals, but they are weird when used together with enums. I want enums because later if use the old "if elif elif" to handle the selected option, When I use string-literals there, typos will become an issue. Also with enums I can "jump to source" in my IDE. It would be neat if I could convert an enum to a literal (or vice verse) without repeating all options, but I have not found a way to do this.
The text was updated successfully, but these errors were encountered:
hello,
Could you make it so that options for enums appear in the help-message?
here is a code example
help-message:
the actual parsed values are as expected the same in all 3 cases:
Additional note: i have considered literals, but they are weird when used together with enums. I want enums because later if use the old "if elif elif" to handle the selected option, When I use string-literals there, typos will become an issue. Also with enums I can "jump to source" in my IDE. It would be neat if I could convert an enum to a literal (or vice verse) without repeating all options, but I have not found a way to do this.
The text was updated successfully, but these errors were encountered: