diff --git a/pottery/base.py b/pottery/base.py index a36807f4..153d65b7 100644 --- a/pottery/base.py +++ b/pottery/base.py @@ -56,9 +56,9 @@ def random_key(*, 'Find/return a random key that does not exist in the Redis instance.' if not isinstance(num_tries, int): raise TypeError('num_tries must be an int >= 0') - elif num_tries < 0: + if num_tries < 0: raise ValueError('num_tries must be an int >= 0') - elif num_tries <= 0: + if num_tries == 0: raise RandomKeyError(redis) all_chars = string.digits + string.ascii_letters diff --git a/pottery/cache.py b/pottery/cache.py index a048524b..d0efe697 100644 --- a/pottery/cache.py +++ b/pottery/cache.py @@ -303,8 +303,7 @@ def __retry(self, callable: Callable[[], Any], try_num: int = 0) -> Any: except WatchError: # pragma: no cover if try_num < self._num_tries - 1: return self.__retry(callable, try_num=try_num+1) - else: - raise + raise @_set_expiration def update(self, arg: InitArg = tuple(), **kwargs: JSONTypes) -> None: # type: ignore diff --git a/pottery/list.py b/pottery/list.py index 48175fb1..edf4c80e 100644 --- a/pottery/list.py +++ b/pottery/list.py @@ -267,10 +267,9 @@ def remove(self, value: JSONTypes) -> None: for index, element in enumerate(self): if element == value: self.__delete(pipeline, index) - break - else: - class_ = self.__class__.__name__ - raise ValueError(f'{class_}.remove(x): x not in {class_}') + return + class_name = self.__class__.__name__ + raise ValueError(f'{class_name}.remove(x): x not in {class_name}') def to_list(self) -> List[JSONTypes]: return list(self) diff --git a/pottery/redlock.py b/pottery/redlock.py index 28276be1..fad227f5 100644 --- a/pottery/redlock.py +++ b/pottery/redlock.py @@ -281,10 +281,10 @@ def __acquire_masters(self) -> bool: if quorum and max(validity_time, 0): return True - else: - with contextlib.suppress(ReleaseUnlockedLock): - self.__release() - return False + + with contextlib.suppress(ReleaseUnlockedLock): + self.__release() + return False def acquire(self, *, blocking: bool = True, timeout: int = -1) -> bool: '''Lock the lock. @@ -335,13 +335,13 @@ def acquire(self, *, blocking: bool = True, timeout: int = -1) -> bool: while timeout == -1 or timer.elapsed() / 1000 < timeout: if self.__acquire_masters(): return True - else: - time.sleep(random.uniform(0, self.RETRY_DELAY/1000)) + time.sleep(random.uniform(0, self.RETRY_DELAY/1000)) return False - elif timeout == -1: + + if timeout == -1: return self.__acquire_masters() - else: - raise ValueError("can't specify a timeout for a non-blocking call") + + raise ValueError("can't specify a timeout for a non-blocking call") __acquire = acquire @@ -396,8 +396,8 @@ def locked(self) -> int: validity_time = ttls[len(self.masters) // 2] validity_time -= round(timer.elapsed() + self.__drift()) return max(validity_time, 0) - else: - return 0 + + return 0 __locked = locked