From 83ac5d9591bbb785b96e1b3bd3ca993d6539028b Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 26 Jan 2024 09:43:58 +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. --- model-gym-ros-env/car_node/car_node/wrapper.py | 3 +-- src/wrapper/wrapper.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/model-gym-ros-env/car_node/car_node/wrapper.py b/model-gym-ros-env/car_node/car_node/wrapper.py index befef1c7..c5b1f197 100644 --- a/model-gym-ros-env/car_node/car_node/wrapper.py +++ b/model-gym-ros-env/car_node/car_node/wrapper.py @@ -102,8 +102,7 @@ def start_position(self): x, y, t = map_utility.get_start_position(self.map_path) self.set_raceliens() return x, y, t - else: - raise Exception("Map path not set") + raise Exception("Map path not set") diff --git a/src/wrapper/wrapper.py b/src/wrapper/wrapper.py index 99f648b0..d8cae507 100644 --- a/src/wrapper/wrapper.py +++ b/src/wrapper/wrapper.py @@ -115,8 +115,7 @@ def start_position(self): x, y, t = map_utility.get_start_position(self.map_path) self.set_raceliens() return x, y, t - else: - raise Exception("Map path not set") + raise Exception("Map path not set")