(self, read_context)
| 1200 | write_context.write_ref(item) |
| 1201 | |
| 1202 | def read(self, read_context): |
| 1203 | reduce_data_num_items = read_context.read_var_uint32() |
| 1204 | if reduce_data_num_items > 6: |
| 1205 | raise ValueError(f"Invalid reduce data length: {reduce_data_num_items}") |
| 1206 | reduce_data = [None] * 6 |
| 1207 | for i in range(reduce_data_num_items): |
| 1208 | reduce_data[i] = read_context.read_ref() |
| 1209 | |
| 1210 | if reduce_data[0] == 0: |
| 1211 | # Case 1: Global name |
| 1212 | return self._resolve_global_name(read_context, reduce_data[1]) |
| 1213 | elif reduce_data[0] == 1: |
| 1214 | # Case 2-5: Callable with args and optional state/items |
| 1215 | callable_obj = reduce_data[1] |
| 1216 | args = reduce_data[2] or () |
| 1217 | state = reduce_data[3] |
| 1218 | listitems = reduce_data[4] |
| 1219 | dictitems = reduce_data[5] if len(reduce_data) > 5 else None |
| 1220 | |
| 1221 | obj = read_context.policy.intercept_reduce_call(callable_obj, args) |
| 1222 | if obj is None: |
| 1223 | # Create the object using the callable and args |
| 1224 | if isinstance(callable_obj, type): |
| 1225 | read_context.policy.authorize_instantiation(callable_obj) |
| 1226 | obj = callable_obj(*args) |
| 1227 | |
| 1228 | # Restore state if present |
| 1229 | if state is not None: |
| 1230 | read_context.policy.intercept_setstate(obj, state) |
| 1231 | if hasattr(obj, "__setstate__"): |
| 1232 | obj.__setstate__(state) |
| 1233 | else: |
| 1234 | # Fallback: update __dict__ directly |
| 1235 | if hasattr(obj, "__dict__"): |
| 1236 | obj.__dict__.update(state) |
| 1237 | |
| 1238 | # Restore list items if present |
| 1239 | if listitems is not None: |
| 1240 | obj.extend(listitems) |
| 1241 | |
| 1242 | # Restore dict items if present |
| 1243 | if dictitems is not None: |
| 1244 | for key, value in dictitems: |
| 1245 | obj[key] = value |
| 1246 | |
| 1247 | result = read_context.policy.inspect_reduced_object(obj) |
| 1248 | if result is not None: |
| 1249 | obj = result |
| 1250 | return obj |
| 1251 | else: |
| 1252 | raise ValueError(f"Invalid reduce data format flag: {reduce_data[0]}") |
| 1253 | |
| 1254 | |
| 1255 | __skip_class_attr_names__ = ("__module__", "__qualname__", "__dict__", "__weakref__") |
nothing calls this directly
no test coverage detected