Remove key pointed at by ``keypath`` from nested dict ``dict_``, if exists. .. versionadded:: 1.0
(dict_: Dict[str, Any], keypath: Tuple[str, ...])
| 1249 | |
| 1250 | |
| 1251 | def excise(dict_: Dict[str, Any], keypath: Tuple[str, ...]) -> None: |
| 1252 | """ |
| 1253 | Remove key pointed at by ``keypath`` from nested dict ``dict_``, if exists. |
| 1254 | |
| 1255 | .. versionadded:: 1.0 |
| 1256 | """ |
| 1257 | data = dict_ |
| 1258 | keypath_list = list(keypath) |
| 1259 | leaf_key = keypath_list.pop() |
| 1260 | while keypath_list: |
| 1261 | key = keypath_list.pop(0) |
| 1262 | if key not in data: |
| 1263 | # Not there, nothing to excise |
| 1264 | return |
| 1265 | data = data[key] |
| 1266 | if leaf_key in data: |
| 1267 | del data[leaf_key] |
| 1268 | |
| 1269 | |
| 1270 | def obliterate(base: Dict[str, Any], deletions: Dict[str, Any]) -> None: |