Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR ports the changes from #52499 to master.
What does this PR do?
This adds a function
filter_falsey
tosalt.utils.data
. The function can be used to filter values from a list or dict that evaluate to false (but are notbool(False)
). Optionally, a level of recursion can be set to process nested dicts/lists. Also optionally, a list of types to not filter can be passed inignore_types
.What issues does this PR fix or reference?
None that I know of.
Previous Behavior
The functionality does not exist.
New Behavior
We are now able to filter falsey values from dicts or lists.
This is especially handy when having to process a lot of kwargs that are explicitly specified in the function argument list, which default to
None
, but need not be passed on if they are None.For example:
will become
Which is a typical use-case for most Boto calls.
Tests written?
Yes
Commits signed with GPG?
Yes