Dict Assign-Update to Union
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.
Sourcery refactoring id: dict-assign-update-to-union
Section titled “Sourcery refactoring id: dict-assign-update-to-union”Description
Section titled “Description”Changes dictionary assignments and updates to use the union operator.
Before
Section titled “Before”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 configdef resolve_configs( default_config: Dict[str, Any], user_config: Dict[str, Any], project_config: Dict[str, Any],): return default_config | user_config | project_configExplanation
Section titled “Explanation”The union operator was implemented for dictionaries in Python 3.9 (see PEP 584) and introduces a concise way to merge dictionaries without resorting to copy/update statements.
See also: use-dictionary-union.