File: __init__.py

package info (click to toggle)
python-deepmerge 0.0.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 188 kB
  • sloc: python: 370; makefile: 195
file content (44 lines) | stat: -rw-r--r-- 970 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from .merger import Merger
from .strategy.core import STRATEGY_END

# some standard mergers available

# this merge will never raise an exception.
# in the case of type mismatches,
# the value from the second object
# will override the previous one.
always_merger = Merger(
    [
        (list, "append"),
        (dict, "merge")
    ],
    ["override"],
    ["override"]
)

# this merge strategies attempts
# to merge (append for list, unify for dicts)
# if possible, but raises an exception
# in the case of type conflicts.
merge_or_raise = Merger(
    [
        (list, "append"),
        (dict, "merge")
    ],
    [], []
)

# a conservative merge tactic:
# for data structures with a specific
# strategy, keep the existing value.
# similar to always_merger but instead
# keeps existing values when faced
# with a type conflict.
conservative_merger = Merger(
    [
        (list, "append"),
        (dict, "merge")
    ],
    ["use_existing"],
    ["use_existing"]
)