From 5417937be90007cdd68360b863801ad72e8426f5 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Sun, 23 Feb 2025 14:07:27 +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/swmath2swh/collection_swhid_dir_ids.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/swmath2swh/collection_swhid_dir_ids.py b/src/swmath2swh/collection_swhid_dir_ids.py index 90892514..15b49ece 100644 --- a/src/swmath2swh/collection_swhid_dir_ids.py +++ b/src/swmath2swh/collection_swhid_dir_ids.py @@ -20,9 +20,8 @@ def get_swhid_dir(snaphot_url): object_id = match.group(1) print(f"Object ID: {object_id}") return "swh:1:dir:"+object_id.split("Object ID: ")[0] - else: - print("Object ID not found") - return 0 + print("Object ID not found") + return 0 list_swhid_dir=list() for snapshot in df.swhid: #print(snapshot)