Determine if an object should be skipped based on backward compatibility. Args: type (str): The type of the object to check. arversion (str): The archive version of the object. current_ver (str): The current version of the decoder. Returns: bool: True i
(type, arversion, current_ver)
| 149 | |
| 150 | |
| 151 | def should_skip_object(type, arversion, current_ver): |
| 152 | """ |
| 153 | Determine if an object should be skipped based on backward compatibility. |
| 154 | |
| 155 | Args: |
| 156 | type (str): The type of the object to check. |
| 157 | arversion (str): The archive version of the object. |
| 158 | current_ver (str): The current version of the decoder. |
| 159 | |
| 160 | Returns: |
| 161 | bool: True if the object should be skipped, False otherwise. |
| 162 | """ |
| 163 | |
| 164 | # Validate global structures |
| 165 | if not isinstance(backward_compat, dict) or not isinstance(fast_shouldnt_skip, list): |
| 166 | raise ValueError("Global variables 'backward_compat' must be a dict and 'fast_shouldnt_skip' must be a list.") |
| 167 | |
| 168 | # Early return for cached types |
| 169 | if type in fast_shouldnt_skip: |
| 170 | debug_print(f"fast Type {type} is in the fast_shouldnt_skip list - don't skip.") |
| 171 | return False |
| 172 | |
| 173 | # If the type doesn't exist in any backward_compat entry |
| 174 | if all(type not in v for v in backward_compat.values()): |
| 175 | debug_print(f"fast Type {type} does not exist in the backward compatibility structure - don't skip.") |
| 176 | fast_shouldnt_skip.append(type) |
| 177 | return False |
| 178 | |
| 179 | # Parse current and archive versions |
| 180 | parsed_arversion = parse_version(arversion) |
| 181 | parsed_current_ver = parse_version(current_ver) |
| 182 | |
| 183 | # Find the lowest version where the type exists |
| 184 | compatible_versions = [ |
| 185 | parse_version(key) for key, types in backward_compat.items() if type in types |
| 186 | ] |
| 187 | if not compatible_versions: |
| 188 | debug_print(f"{type} has no compatible versions - don't skip.") |
| 189 | fast_shouldnt_skip.append(type) |
| 190 | return False |
| 191 | |
| 192 | lowest_version = min(compatible_versions) |
| 193 | debug_print(f"{type} lowest compatible version: {lowest_version}") |
| 194 | |
| 195 | # Check cascading compatibility |
| 196 | if parsed_current_ver < lowest_version: |
| 197 | # Current version is too old for this type |
| 198 | debug_print(f"{type} current version {parsed_current_ver} is less than {lowest_version} - skip.") |
| 199 | return True |
| 200 | |
| 201 | # Filter archive versions within compatibility range |
| 202 | versions = [ |
| 203 | key for key in backward_compat |
| 204 | if type in backward_compat[key] |
| 205 | and parse_version(key) >= parsed_arversion |
| 206 | and parse_version(key) <= parsed_current_ver |
| 207 | ] |
| 208 |
no test coverage detected