> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Collection to Bool

#### Sourcery refactoring id: `collection-to-bool`

#### Description:

Replace constant collection with boolean in boolean contexts

#### Before:

```python
if ("foo", "bar"):
    baz()
```

#### After:

```python
if True:
    baz()
```

#### Explanation:

In boolean contexts, dicts, lists, sets and tuples are true if they contain at
least one element, and false if they are empty. Because of this, constant
collections can be converted to bools based on their length. Some examples are:

- `[]`: empty list -> `False`
- `{}`: empty dictionary -> `False`
- `{0, 1, 2}`: non-empty set -> `True`
- `(a, b)`: non-empty tuple -> `True`
