dnf-json: CacheState factory as classmethod

In this case it might be functionally equivalent, but it's generally
nicer to have factory methods as class methods.
This commit is contained in:
Achilleas Koutsou 2022-03-04 13:00:28 +01:00 committed by Christian Kellner
parent 3268c1f28f
commit 447df031dd

View file

@ -76,13 +76,13 @@ class CacheState():
del self.folder_dict[folder]
shutil.rmtree(folder)
@staticmethod
def load(cache_dir):
@classmethod
def load(cls, cache_dir):
try:
with open(os.path.join(cache_dir,"cache_state.pkl"), "rb") as inp:
return pickle.load(inp)
except FileNotFoundError:
return CacheState(cache_dir, timedelta(hours=24))
return cls(cache_dir, timedelta(hours=24))
def store(self):
with open(os.path.join(self.cache_dir, "cache_state.pkl"), "wb") as outp: