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])
| 185 | |
| 186 | |
| 187 | def 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 |