Total Complexity | 5 |
Total Lines | 21 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |