深度更新合并字典
(
mapping: dict[K, Any], *updating_mappings: dict[K, Any]
)
| 124 | |
| 125 | |
| 126 | def deep_update( |
| 127 | mapping: dict[K, Any], *updating_mappings: dict[K, Any] |
| 128 | ) -> dict[K, Any]: |
| 129 | """深度更新合并字典""" |
| 130 | updated_mapping = mapping.copy() |
| 131 | for updating_mapping in updating_mappings: |
| 132 | for k, v in updating_mapping.items(): |
| 133 | if ( |
| 134 | k in updated_mapping |
| 135 | and isinstance(updated_mapping[k], dict) |
| 136 | and isinstance(v, dict) |
| 137 | ): |
| 138 | updated_mapping[k] = deep_update(updated_mapping[k], v) |
| 139 | else: |
| 140 | updated_mapping[k] = v |
| 141 | return updated_mapping |
| 142 | |
| 143 | |
| 144 | def lenient_issubclass( |
no test coverage detected