| Conditions | 10 |
| Total Lines | 10 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Complex classes like benedict.utils.utility_util.clean() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # -*- coding: utf-8 -*- |
||
| 9 | def clean(d, strings=True, dicts=True, lists=True): |
||
| 10 | keys = list(d.keys()) |
||
| 11 | for key in keys: |
||
| 12 | value = d.get(key, None) |
||
| 13 | if not value: |
||
| 14 | if value is None or \ |
||
| 15 | strings and isinstance(value, string_types) or \ |
||
| 16 | dicts and isinstance(value, dict) or \ |
||
| 17 | lists and isinstance(value, (list, tuple, )): |
||
| 18 | del d[key] |
||
| 19 | |||
| 51 |