MCPcopy
hub / github.com/redis/redis-py / at_most_one_value_set

Function at_most_one_value_set

redis/commands/helpers.py:187–203  ·  view source on GitHub ↗

Checks that at most one of the values in the iterable is truthy. Args: iterable: An iterable of values to check. Returns: True if at most one value is truthy, False otherwise. Raises: Might raise an error if the values in iterable are not boolean-compatibl

(iterable: Iterable[Any])

Source from the content-addressed store, hash-verified

185
186
187def at_most_one_value_set(iterable: Iterable[Any]):
188 """
189 Checks that at most one of the values in the iterable is truthy.
190
191 Args:
192 iterable: An iterable of values to check.
193
194 Returns:
195 True if at most one value is truthy, False otherwise.
196
197 Raises:
198 Might raise an error if the values in iterable are not boolean-compatible.
199 For example if the type of the values implement
200 __len__ or __bool__ methods and they raise an error.
201 """
202 values = (bool(x) for x in iterable)
203 return sum(values) <= 1

Callers 6

getexMethod · 0.85
increxMethod · 0.85
msetexMethod · 0.85
setMethod · 0.85
hgetexMethod · 0.85
hsetexMethod · 0.85

Calls 1

sumClass · 0.85

Tested by

no test coverage detected