Check the safety of updating one dictionary with another. Raises ValueError if dictionaries have non-compatible values for any key, where compatibility is determined by identity (they are the same item) or the `compat` function. Parameters ---------- first_dict, second_dict
(
first_dict: Mapping[K, V],
second_dict: Mapping[K, V],
compat: Callable[[V, V], bool] = equivalent,
)
| 289 | |
| 290 | |
| 291 | def update_safety_check( |
| 292 | first_dict: Mapping[K, V], |
| 293 | second_dict: Mapping[K, V], |
| 294 | compat: Callable[[V, V], bool] = equivalent, |
| 295 | ) -> None: |
| 296 | """Check the safety of updating one dictionary with another. |
| 297 | |
| 298 | Raises ValueError if dictionaries have non-compatible values for any key, |
| 299 | where compatibility is determined by identity (they are the same item) or |
| 300 | the `compat` function. |
| 301 | |
| 302 | Parameters |
| 303 | ---------- |
| 304 | first_dict, second_dict : dict-like |
| 305 | All items in the second dictionary are checked against for conflicts |
| 306 | against items in the first dictionary. |
| 307 | compat : function, optional |
| 308 | Binary operator to determine if two values are compatible. By default, |
| 309 | checks for equivalence. |
| 310 | """ |
| 311 | for k, v in second_dict.items(): |
| 312 | if k in first_dict and not compat(v, first_dict[k]): |
| 313 | raise ValueError( |
| 314 | "unsafe to merge dictionaries without " |
| 315 | f"overriding values; conflicting key {k!r}" |
| 316 | ) |
| 317 | |
| 318 | |
| 319 | def remove_incompatible_items( |
no test coverage detected
searching dependent graphs…