Recursively update one dictionary using another. None values will delete their keys.
(target: dict[Any, Any], new: dict[Any, Any])
| 14 | |
| 15 | |
| 16 | def recursive_update(target: dict[Any, Any], new: dict[Any, Any]) -> None: |
| 17 | """Recursively update one dictionary using another. |
| 18 | |
| 19 | None values will delete their keys. |
| 20 | """ |
| 21 | for k, v in new.items(): |
| 22 | if isinstance(v, dict): |
| 23 | if k not in target: |
| 24 | target[k] = {} |
| 25 | recursive_update(target[k], v) |
| 26 | if not target[k]: |
| 27 | # Prune empty subdicts |
| 28 | del target[k] |
| 29 | |
| 30 | elif v is None: |
| 31 | target.pop(k, None) |
| 32 | |
| 33 | else: |
| 34 | target[k] = v |
| 35 | |
| 36 | |
| 37 | class BaseJSONConfigManager(LoggingConfigurable): |
no outgoing calls
no test coverage detected
searching dependent graphs…