From 446393b078b500f2736acf53b95bf8700d48353a Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Sun, 14 Jan 2024 14:18:05 +0000 Subject: [PATCH] refactor: refactor unnecessary `else` / `elif` when `if` block has a `return` statement The use of `else` or `elif` becomes redundant and can be dropped if the last statement under the leading `if` / `elif` block is a `return` statement. In the case of an `elif` after `return`, it can be written as a separate `if` block. For `else` blocks after `return`, the statements can be shifted out of `else`. Please refer to the examples below for reference. Refactoring the code this way can improve code-readability and make it easier to maintain. --- src/iSponsorBlockTV/conditional_ttl_cache.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/iSponsorBlockTV/conditional_ttl_cache.py b/src/iSponsorBlockTV/conditional_ttl_cache.py index 0c5892a..de5b852 100644 --- a/src/iSponsorBlockTV/conditional_ttl_cache.py +++ b/src/iSponsorBlockTV/conditional_ttl_cache.py @@ -41,13 +41,11 @@ class AsyncConditionalTTL: def __contains__(self, key): if key not in self.keys(): return False - else: - key_expiration = super().__getitem__(key)[1] - if key_expiration and key_expiration < datetime.datetime.now(): - del self[key] - return False - else: - return True + key_expiration = super().__getitem__(key)[1] + if key_expiration and key_expiration < datetime.datetime.now(): + del self[key] + return False + return True def __getitem__(self, key): value = super().__getitem__(key)[0]