Skip to content

Commit

Permalink
Remove unused lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Vopaaz committed Nov 16, 2023
1 parent 08ffaf7 commit dc7ab96
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions checkpointing/util/pickle.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,11 @@
from io import IOBase
import pickle
from typing import Any
from checkpointing.config import defaults

try:
import pickle5
except ImportError:
pass


def get_pickle_module(protocol: int):
"""
Returns:
built-in pickle module if the given protocol is supported.
Otherwise check if the protocol = 5, if so, use pickle5.
"""

if protocol <= pickle.HIGHEST_PROTOCOL:
return pickle

elif protocol == 5:
return pickle5

else:
raise RuntimeError(f"pickle protocol {protocol} is not supported")


def dump(obj: Any, file: IOBase, protocol: int) -> None:
return get_pickle_module(protocol).dump(obj, file, protocol)
return pickle.dump(obj, file, protocol)


def load(file: IOBase, protocol: int) -> Any:
return get_pickle_module(protocol).load(file)
return pickle.load(file)

0 comments on commit dc7ab96

Please sign in to comment.