Skip to content
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

support removing empty values in ListOf #268

Closed
willkg opened this issue Oct 30, 2024 · 2 comments · Fixed by #269
Closed

support removing empty values in ListOf #268

willkg opened this issue Oct 30, 2024 · 2 comments · Fixed by #269

Comments

@willkg
Copy link
Owner

willkg commented Oct 30, 2024

ListOf takes a sub parser and an optional delimiter argument denoting what the delimiter for the items in the value should be.

That gives us things like this:

>>> from everett.manager import ListOf
>>> ListOf(str)("a, b,c")
['a', 'b', 'c']
>>> ListOf(str)("a, b,,,c")
['a', 'b', '', '', 'c']
>>> 

The problem is the empty strings which require the developer to add additional value validation/adjustments. Notably, if they don't want to support empty values (it's likely a typo), they have to do something like this:

>>> [item for item in ListOf(str)("a, b,,,c") if item]
['a', 'b', 'c']

I think we want to allow the developer to denote that empty strings are a configuration error.

@willkg
Copy link
Owner Author

willkg commented Oct 30, 2024

I think we have a couple of options. We could have ListOf be in charge of whether an empty string is a valid item before sending it to the sub-parser:

ListOf(str, allow_empty=False)

Or we could have the sub-parser be in charge of whether the item is valid:

ListOf(nonempty(str))

I think I may do the latter. That would be usable in other places, too.

@willkg
Copy link
Owner Author

willkg commented Oct 30, 2024

Scratch that. If we do the former, we can get a better error message because ListOf can say something like "yo, this configuration value 'a,,b' has empty strings in it" rather than "yo, this '' is an empty string".

willkg added a commit that referenced this issue Oct 30, 2024
This adds empty value validation to ListOf.
willkg added a commit that referenced this issue Oct 30, 2024
This adds empty value validation to ListOf.
willkg added a commit that referenced this issue Oct 30, 2024
This adds empty value validation to ListOf.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant