> ## 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.

# Dict Assign-Update to Union

#### Sourcery refactoring id: `dict-assign-update-to-union`

#### Description

Changes dictionary assignments and updates to use the union operator.

#### Before

```python
def resolve_configs(
    default_config: Dict[str, Any],
    user_config: Dict[str, Any],
    project_config: Dict[str, Any],
):
    config = default_config.copy()
    config.update(user_config)
    config.update(project_config)
    return config
```

#### After

```python
def resolve_configs(
    default_config: Dict[str, Any],
    user_config: Dict[str, Any],
    project_config: Dict[str, Any],
):
    return default_config | user_config | project_config
```

#### Explanation

The union operator was implemented for dictionaries in Python 3.9 (see
[PEP 584](https://peps.python.org/pep-0584/)) and introduces a concise way to
merge dictionaries without resorting to copy/update statements.

See also: [`use-dictionary-union`](/reference/refactorings/python/use-dictionary-union/).
