From beb971083ba13c4a6e03cfd259db89c09703e1be Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Tue, 14 Dec 2021 21:36:49 +0000 Subject: [PATCH] Refactor unnecessary `else` / `elif` when `if` block has a `return` statement --- minesweeper/GameElements.py | 15 +++++---------- minesweeper/GameLogic.py | 12 +++++------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/minesweeper/GameElements.py b/minesweeper/GameElements.py index 6eae45a..e27573d 100644 --- a/minesweeper/GameElements.py +++ b/minesweeper/GameElements.py @@ -23,8 +23,7 @@ def __str__(self): """ if self.isFlagged: return "F" # this element was flagged - else: - return "*" # this element has neither been flagged nor revealed + return "*" # this element has neither been flagged nor revealed @abstractmethod def flag(self): @@ -52,8 +51,7 @@ class Mine(GameElement): def __str__(self): if self.isRevealed: return "X" # the bomb explodes - else: - return super().__str__() + return super().__str__() def flag(self): """ @@ -64,8 +62,7 @@ def flag(self): super().flag() if self.isFlagged: return 1 - else: - return -1 + return -1 def reveal(self): """ @@ -87,8 +84,7 @@ def __init__(self, counter): def __str__(self): if self.isRevealed: return str(self.counter) # show the bomb counter - else: - return super().__str__() + return super().__str__() def flag(self): """ @@ -109,5 +105,4 @@ def reveal(self): super().reveal() if self.counter == 0: return True - else: - return False + return False diff --git a/minesweeper/GameLogic.py b/minesweeper/GameLogic.py index 968b76f..849c711 100644 --- a/minesweeper/GameLogic.py +++ b/minesweeper/GameLogic.py @@ -139,8 +139,7 @@ def flag(self, x, y): self.ended = True self.won = True return self.__str__ - else: - return "You have to reveal at least one field before you can use flag." + return "You have to reveal at least one field before you can use flag." def reveal(self, x, y, nop=False): """ @@ -170,8 +169,7 @@ def reveal(self, x, y, nop=False): self.won = True if nop: return "" - else: - return self.__str__ + return self.__str__ def reveal_adjacent_counters(self, x, y): """ @@ -277,13 +275,13 @@ def parse_input(self, message: str) -> str: if message[4:8] == "easy": self.game_round = GameRound(8, 8, 10) return self.game_round.print_empty() - elif message[4:8] == "hard": + if message[4:8] == "hard": self.game_round = GameRound(30, 16, 99) return self.game_round.print_empty() - elif message[4:10] == "medium": + if message[4:10] == "medium": self.game_round = GameRound(16, 16, 40) return self.game_round.print_empty() - elif message[4:10] == "custom": + if message[4:10] == "custom": index_x = message.find("x", 11) index = message.find(",", 11) try: