def save(self, path: Union[str, IO]): state = self.__getstate__() with open_file(path, 'wb') as outfile: pickle.dump(state, outfile)