Passed
Push — master ( 969640...b3caf6 )
by Fabio
01:22
created

benedict.core.merge   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 16
dl 0
loc 24
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A _merge_dict() 0 3 2
A _merge_item() 0 6 3
A merge() 0 5 2
1
# -*- coding: utf-8 -*-
2
3
from benedict.utils import type_util
4
5
6
def _merge_dict(d, other):
7
    for key, value in other.items():
8
        _merge_item(d, key, value)
9
10
11
def _merge_item(d, key, value):
12
    item = d.get(key, None)
13
    if type_util.is_dict(item) and type_util.is_dict(value):
14
        _merge_dict(item, value)
15
    else:
16
        d[key] = value
17
18
19
def merge(d, other, *args):
20
    others = [other] + list(args)
21
    for other in others:
22
        _merge_dict(d, other)
23
    return d
24