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

benedict.core.clean._clean_item()   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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