Skip to content

Commit

Permalink
refactor: refactor unnecessary else / elif when if block has a …
Browse files Browse the repository at this point in the history
…`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.
  • Loading branch information
deepsource-autofix[bot] authored Jan 26, 2024
1 parent d6296ee commit 83ac5d9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions model-gym-ros-env/car_node/car_node/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")



Expand Down
3 changes: 1 addition & 2 deletions src/wrapper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")



Expand Down

0 comments on commit 83ac5d9

Please sign in to comment.