Analyze the differences between _import_structure objects and TYPE_CHECKING objects found in an init.
(import_dict_objects, type_hint_objects)
| 188 | |
| 189 | |
| 190 | def analyze_results(import_dict_objects, type_hint_objects): |
| 191 | """ |
| 192 | Analyze the differences between _import_structure objects and TYPE_CHECKING objects found in an init. |
| 193 | """ |
| 194 | |
| 195 | def find_duplicates(seq): |
| 196 | return [k for k, v in collections.Counter(seq).items() if v > 1] |
| 197 | |
| 198 | if list(import_dict_objects.keys()) != list(type_hint_objects.keys()): |
| 199 | return ["Both sides of the init do not have the same backends!"] |
| 200 | |
| 201 | errors = [] |
| 202 | for key in import_dict_objects.keys(): |
| 203 | duplicate_imports = find_duplicates(import_dict_objects[key]) |
| 204 | if duplicate_imports: |
| 205 | errors.append(f"Duplicate _import_structure definitions for: {duplicate_imports}") |
| 206 | duplicate_type_hints = find_duplicates(type_hint_objects[key]) |
| 207 | if duplicate_type_hints: |
| 208 | errors.append(f"Duplicate TYPE_CHECKING objects for: {duplicate_type_hints}") |
| 209 | |
| 210 | if sorted(set(import_dict_objects[key])) != sorted(set(type_hint_objects[key])): |
| 211 | name = "base imports" if key == "none" else f"{key} backend" |
| 212 | errors.append(f"Differences for {name}:") |
| 213 | for a in type_hint_objects[key]: |
| 214 | if a not in import_dict_objects[key]: |
| 215 | errors.append(f" {a} in TYPE_HINT but not in _import_structure.") |
| 216 | for a in import_dict_objects[key]: |
| 217 | if a not in type_hint_objects[key]: |
| 218 | errors.append(f" {a} in _import_structure but not in TYPE_HINT.") |
| 219 | return errors |
| 220 | |
| 221 | |
| 222 | def check_all_inits(): |
no test coverage detected