Show possible values of a list field, if the amount of values is finite
See original GitHub issueIs your feature request related to a problem? Please describe.
I’d like to be able to pass a list of flags to my program. The flags are all listed in an enum and the variable in the dataclass is defined as flags: List[MyEnum] = ...
Argument parsing works, but no proper help text is generated.
Describe the solution you’d like If the argument of the List annotation has a finite amount of possible values (e.g. enum values), it would be nice to list those. This is already done, when a field is directly annotated as an enum.
Possible output:
--my_config [MyEnum [MyEnum ...]]
Configure some values here
(default: [SomeValue, OneMore])
(possible: {SomeValue, AnotherValue, YetAnotherValue, OneMore})
Although I’m not sure, where/how the values should be listed
Describe alternatives you’ve considered I could manually update the help text when the enum values change, but that violates the DRY principle.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to show the only absolute value on a finite field is the ...
The textbook I'm currently reading (Gouvêa - P-adic Numbers An Introduction) asked me to show that for a finite field K the only...
Read more >Add a lookup or values list field to an Access web app
Use a lookup field to find ("look up") values in one table that you can use in another table. A lookup field can...
Read more >isFinite() - JavaScript - MDN Web Docs - Mozilla
The global isFinite() function determines whether the passed value is a finite number. If needed, the parameter is first converted to a number....
Read more >Finite field - Wikipedia
In mathematics, a finite field or Galois field (so-named in honor of Évariste Galois) is a field that contains a finite number of...
Read more >4.2 Types of variables - Statistique Canada
A variable is a characteristic that can be measured and that can assume different values. Height, age, income, province or country of birth, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @lebrice, thanks for your fast feedback and effort. The amount of flags is around 20 to 30. I think your solution with manually specifying the help string is ok, since it can be automatically generated. I only have to work out how to deal with the line breaks, to avoid a single long line. I’ll close this issue and might reopen it, if I stumble into any further problems 😄
Hey @Wooza, out of curiosity, in your context is the number of flags used completely arbitrary? Could you give me a bit more detail about some scenarios where you think this could be useful?
For instance this is what is currently supported:
Executing this with the “–help flag”:
As you can see, the help string defaults for enums are quite ugly. I was able to achieve the kind of formatting I think you’re describing with this:
which gives:
However this doesn’t currently work (apart from the “–help” option), as its impossible to parse the values:
Also, for the help string formatting, you could also easily do this, which would totally work! (you’d lose the auto-generated help strings and would have to add it manually to the
help
argument though):Which would get you what you want, in the end:
This sounds like the best option, in my opinion. Let me know what you think.