Skip to content

Commit

Permalink
smh it was only linting, tests were fine
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDyre committed Aug 9, 2024
1 parent 80a60b0 commit 174c4ec
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions spotipy/cache_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
from abc import ABC, abstractmethod
from json import JSONEncoder
from pathlib import Path
from typing import Dict, Optional, Type, Union

from redis import RedisError
Expand Down Expand Up @@ -75,10 +76,8 @@ def get_cached_token(self) -> Optional[TokenInfoType]:
token_info: Optional[TokenInfoType] = None

try:
f = open(self.cache_path)
token_info_string = f.read()
f.close()
token_info = json.loads(token_info_string)
with Path(self.cache_path).open("r") as f:
token_info = json.load(f)

except OSError as error:
if error.errno == errno.ENOENT:
Expand All @@ -91,9 +90,8 @@ def get_cached_token(self) -> Optional[TokenInfoType]:
def save_token_to_cache(self, token_info: TokenInfoType) -> None:
"""Save token cache to file."""
try:
f = open(self.cache_path, "w")
f.write(json.dumps(token_info, cls=self.encoder_cls))
f.close()
with Path(self.cache_path).open("w") as f:
json.dump(token_info, f, cls=self.encoder_cls)
except OSError:
logger.warning("Couldn't write token to cache at: %s", self.cache_path)

Expand Down

0 comments on commit 174c4ec

Please sign in to comment.