From 5f8d150652dbbf4f3dd4636bc5655824d16430fa Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 24 Jan 2022 17:34:20 +0200 Subject: [PATCH] Remove redundant _get_cache_backend and add some typing --- src/pylast/__init__.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/pylast/__init__.py b/src/pylast/__init__.py index 3065e7d..2077e0e 100644 --- a/src/pylast/__init__.py +++ b/src/pylast/__init__.py @@ -409,44 +409,37 @@ class _Network: """Returns True if web proxy is enabled.""" return self.proxy is not None - def enable_rate_limit(self): + def enable_rate_limit(self) -> None: """Enables rate limiting for this network""" self.limit_rate = True - def disable_rate_limit(self): + def disable_rate_limit(self) -> None: """Disables rate limiting for this network""" self.limit_rate = False - def is_rate_limited(self): + def is_rate_limited(self) -> bool: """Return True if web service calls are rate limited""" return self.limit_rate - def enable_caching(self, file_path=None): + def enable_caching(self, file_path=None) -> None: """Enables caching request-wide for all cacheable calls. * file_path: A file path for the backend storage file. If None set, a temp file would probably be created, according the backend. """ - if not file_path: self.cache_backend = _ShelfCacheBackend.create_shelf() return self.cache_backend = _ShelfCacheBackend(file_path) - def disable_caching(self): + def disable_caching(self) -> None: """Disables all caching features.""" - self.cache_backend = None - def is_caching_enabled(self): + def is_caching_enabled(self) -> bool: """Returns True if caching is enabled.""" - - return not (self.cache_backend is None) - - def _get_cache_backend(self): - - return self.cache_backend + return self.cache_backend is not None def search_for_album(self, album_name): """Searches for an album by its name. Returns a AlbumSearch object. @@ -839,7 +832,7 @@ class _Request: self.params["method"] = method_name if network.is_caching_enabled(): - self.cache = network._get_cache_backend() + self.cache = network.cache_backend if self.session_key: self.params["sk"] = self.session_key