benedict.core.clean._clean_item()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 2
nop 4
1
from benedict.utils import type_util
2
3
4
def _clean_item(d, key, strings, collections):
5
    value = d.get(key, None)
6
    if not value:
7
        del_none = value is None
8
        del_string = strings and type_util.is_string(value)
9
        del_collection = collections and type_util.is_collection(value)
10
        return any([del_none, del_string, del_collection])
11
12
    return False
13
14
15
def clean(d, strings=True, collections=True):
16
    keys = list(d.keys())
17
    for key in keys:
18
        if _clean_item(d, key, strings, collections):
19
            del d[key]
20