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

benedict.core.clean   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 21
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A clean() 0 5 3
A _clean_item() 0 8 2
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