|
1 | 1 | """ |
2 | | -Dictionary union operators (`|` and `|=`) provide clean, side-effect-free dictionary |
3 | | -merging, solving a fundamental software engineering challenge in state management. |
4 | | -
|
5 | | -In production engineering, managing application state and configuration pipelines |
6 | | -often requires combining multiple data sources (such as default settings, environment |
7 | | -variables, and user overrides). Prior to Python 3.9 (PEP 584), merging required |
8 | | -destructive in-place mutations via `dict.update()` or verbose `{**d1, **d2}` unpacking, |
9 | | -which often introduced subtle shared-state bugs across layers. |
10 | | -
|
11 | | -Key software engineering benefits: |
12 | | -- Immutability & Safety: `|` produces a new dictionary without mutating either operand, |
13 | | - preventing side-effects across components and concurrent execution paths. |
14 | | -- Deterministic Precedence: Subsequent dictionaries cleanly override earlier ones, |
15 | | - making layered configuration cascades explicit and predictable. |
16 | | -- Expressive In-Place Updates: `|=` clearly signals intentional local mutation |
17 | | - without sacrificing readability. |
| 2 | +Dictionary union operators (`|` and `|=`, introduced in Python 3.9 via PEP 584) |
| 3 | +provide clean syntax for merging dictionaries. |
| 4 | +
|
| 5 | +The binary operator `|` creates a new dictionary combining keys and values from |
| 6 | +both operands without mutating either one. The in-place operator `|=` updates the |
| 7 | +left-hand dictionary in place. When duplicate keys exist, the right-hand operand's |
| 8 | +value takes precedence. |
18 | 9 | """ |
19 | 10 |
|
20 | 11 | from typing import Any |
|
0 commit comments