-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
consider a choices parser #253
Comments
I rethought the API. I want it to support different sub-parsers. Given that, I thought it should mirror >>> from everett.manager import ChoiceOf, parse_data_size
>>> ChoiceOf(str, choices=["aws", "gcp"])("aws")
"aws"
>>> ChoiceOf(int, choices=["1", "2", "3"])("1")
1
>>> ChoiceOf(parse_data_size, choices=["1kb", "1mb", "1gb"])("1mb")
1000000 That gives a lot of flexibility. It forces values to be consistent in the places they show up that the user sees them (documentation, error messages, etc). It also allows the parsed value to be convenient for programming. |
willkg
added a commit
that referenced
this issue
Oct 29, 2024
willkg
added a commit
that referenced
this issue
Oct 30, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've had several situations where I want a parser that requires the value to be one of a list of possible values. I'd like to do something like:
and then have that work for "AWS" and "GCP" and raise a
ValueError
specifying one of the valid values for everything else.The text was updated successfully, but these errors were encountered: