| Conditions | 4 |
| Total Lines | 19 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 13 | def _flatten_item(d, base_dict, base_key, separator): |
||
| 14 | new_dict = base_dict |
||
| 15 | keys = list(d.keys()) |
||
| 16 | for key in keys: |
||
| 17 | new_key = _flatten_key(base_key, key, separator) |
||
| 18 | value = d.get(key, None) |
||
| 19 | if type_util.is_dict(value): |
||
| 20 | new_value = _flatten_item(value, |
||
| 21 | base_dict=new_dict, |
||
| 22 | base_key=new_key, |
||
| 23 | separator=separator) |
||
| 24 | new_dict.update(new_value) |
||
| 25 | continue |
||
| 26 | if new_key in new_dict: |
||
| 27 | raise KeyError( |
||
| 28 | 'Invalid key: "{}", key already in flatten dict.'.format( |
||
| 29 | new_key)) |
||
| 30 | new_dict[new_key] = value |
||
| 31 | return new_dict |
||
| 32 | |||
| 40 |