def __getstate__(self): # BoundingRegions have slots, not a dict, so we have to # support pickle and deepcopy ourselves. state = {} for slot in get_occupied_slots(self): state[slot] = getattr(self, slot) return state