Recursively update AttrDict d with AttrDict u
(d, u)
| 201 | |
| 202 | |
| 203 | def recursive_update(d, u): |
| 204 | """Recursively update AttrDict d with AttrDict u""" |
| 205 | for key, value in u.items(): |
| 206 | if isinstance(value, collections.abc.Mapping): |
| 207 | d.__dict__[key] = recursive_update(d.get(key, AttrDict({})), value) |
| 208 | elif isinstance(value, (list, tuple)): |
| 209 | if isinstance(value[0], dict): |
| 210 | d.__dict__[key] = [AttrDict(item) for item in value] |
| 211 | else: |
| 212 | d.__dict__[key] = value |
| 213 | else: |
| 214 | d.__dict__[key] = value |
| 215 | return d |