Like update, but merges sub-dicts instead of clobbering at the top level. Updates d1 in-place
(d1, d2)
| 17 | |
| 18 | |
| 19 | def _merge(d1, d2): |
| 20 | """Like update, but merges sub-dicts instead of clobbering at the top level. |
| 21 | |
| 22 | Updates d1 in-place |
| 23 | """ |
| 24 | |
| 25 | if not isinstance(d2, dict) or not isinstance(d1, dict): |
| 26 | return d2 |
| 27 | for key, value in d2.items(): |
| 28 | d1[key] = _merge(d1.get(key), value) |
| 29 | return d1 |
| 30 | |
| 31 | |
| 32 | #----------------------------------------------------------------------------- |