From 11ea5c7b62a38f7479ff16d1ca92333ab8cf9a25 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 30 Oct 2023 10:46:17 -0700 Subject: [PATCH] ruff: Fix PLR5501 Use `elif` instead of `else` then `if`, to reduce indentation. Signed-off-by: Anders Kaseorg --- .../codebase/zulip_codebase_mirror | 5 ++-- .../bots/merels/libraries/mechanics.py | 11 ++++--- zulip_bots/zulip_bots/bots/trello/trello.py | 15 +++++----- .../bots/trivia_quiz/trivia_quiz.py | 7 ++--- zulip_bots/zulip_bots/game_handler.py | 29 +++++++++---------- zulip_bots/zulip_bots/run.py | 7 ++--- 6 files changed, 33 insertions(+), 41 deletions(-) diff --git a/zulip/integrations/codebase/zulip_codebase_mirror b/zulip/integrations/codebase/zulip_codebase_mirror index 6964df3c..20c0d44f 100755 --- a/zulip/integrations/codebase/zulip_codebase_mirror +++ b/zulip/integrations/codebase/zulip_codebase_mirror @@ -295,10 +295,9 @@ def run_mirror() -> None: if event_date > since: handle_event(event) since = event_date - else: + elif sleep_interval < 22: # back off a bit - if sleep_interval < 22: - sleep_interval += 4 + sleep_interval += 4 time.sleep(sleep_interval) except KeyboardInterrupt: diff --git a/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py b/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py index 076d3567..20ecb55c 100644 --- a/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py +++ b/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py @@ -258,13 +258,12 @@ def get_phase_number(grid, turn, x_pieces_possessed_not_on_grid, o_pieces_posses if x_pieces_possessed_not_on_grid != 0 or o_pieces_possessed_not_on_grid != 0: # Placing pieces return 1 + elif get_piece("X", grid) <= 3 or get_piece("O", grid) <= 3: + # Flying + return 3 else: - if get_piece("X", grid) <= 3 or get_piece("O", grid) <= 3: - # Flying - return 3 - else: - # Moving pieces - return 2 + # Moving pieces + return 2 def create_room(topic_name, merels_storage): diff --git a/zulip_bots/zulip_bots/bots/trello/trello.py b/zulip_bots/zulip_bots/bots/trello/trello.py index b8d7865a..41d9acd7 100644 --- a/zulip_bots/zulip_bots/bots/trello/trello.py +++ b/zulip_bots/zulip_bots/bots/trello/trello.py @@ -60,15 +60,14 @@ class TrelloHandler: bot_reply = self.get_all_supported_commands() elif content == ["get-all-boards"]: bot_reply = self.get_all_boards() + elif content[0] == "get-all-cards": + bot_reply = self.get_all_cards(content) + elif content[0] == "get-all-checklists": + bot_reply = self.get_all_checklists(content) + elif content[0] == "get-all-lists": + bot_reply = self.get_all_lists(content) else: - if content[0] == "get-all-cards": - bot_reply = self.get_all_cards(content) - elif content[0] == "get-all-checklists": - bot_reply = self.get_all_checklists(content) - elif content[0] == "get-all-lists": - bot_reply = self.get_all_lists(content) - else: - bot_reply = "Command not supported" + bot_reply = "Command not supported" bot_handler.send_reply(message, bot_reply) diff --git a/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py b/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py index 139f96c3..77c25934 100644 --- a/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py +++ b/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py @@ -207,11 +207,10 @@ def update_quiz(quiz: Dict[str, Any], quiz_id: str, bot_handler: BotHandler) -> def build_response(is_correct: bool, num_answers: int) -> str: if is_correct: response = ":tada: **{answer}** is correct, {sender_name}!" + elif num_answers >= 3: + response = ":disappointed: WRONG, {sender_name}! The correct answer is **{answer}**." else: - if num_answers >= 3: - response = ":disappointed: WRONG, {sender_name}! The correct answer is **{answer}**." - else: - response = ":disappointed: WRONG, {sender_name}! {option} is not correct." + response = ":disappointed: WRONG, {sender_name}! {option} is not correct." return response diff --git a/zulip_bots/zulip_bots/game_handler.py b/zulip_bots/zulip_bots/game_handler.py index 94b50173..76fe9f45 100644 --- a/zulip_bots/zulip_bots/game_handler.py +++ b/zulip_bots/zulip_bots/game_handler.py @@ -290,11 +290,10 @@ class GameAdapter: self.send_reply( message, "You are not in a game at the moment. Type `help` for help." ) + elif self.is_single_player: + self.send_reply(message, self.help_message_single_player()) else: - if self.is_single_player: - self.send_reply(message, self.help_message_single_player()) - else: - self.send_reply(message, self.help_message()) + self.send_reply(message, self.help_message()) except Exception as e: logging.exception("Error handling game message") self.bot_handler.send_reply(message, f"Error {e}.") @@ -893,16 +892,15 @@ class GameInstance: return if self.is_turn_of(player_email): self.handle_current_player_command(content) + elif self.game_adapter.is_single_player: + self.broadcast("It's your turn") else: - if self.game_adapter.is_single_player: - self.broadcast("It's your turn") - else: - self.broadcast( - "It's **{}**'s ({}) turn.".format( - self.game_adapter.get_username_by_email(self.players[self.turn]), - self.game_adapter.game_message_handler.get_player_color(self.turn), - ) + self.broadcast( + "It's **{}**'s ({}) turn.".format( + self.game_adapter.get_username_by_email(self.players[self.turn]), + self.game_adapter.game_message_handler.get_player_color(self.turn), ) + ) def broadcast(self, content: str) -> None: self.game_adapter.broadcast(self.game_id, content) @@ -1022,11 +1020,10 @@ class GameInstance: values.update({"games_drawn": 1}) else: values.update({"games_lost": 1}) + elif u == loser: + values.update({"games_lost": 1}) else: - if u == loser: - values.update({"games_lost": 1}) - else: - values.update({"games_won": 1}) + values.update({"games_won": 1}) self.game_adapter.add_user_statistics(u, values) if self.game_adapter.email in self.players: self.send_win_responses(winner) diff --git a/zulip_bots/zulip_bots/run.py b/zulip_bots/zulip_bots/run.py index b5a24db0..5ba101b9 100755 --- a/zulip_bots/zulip_bots/run.py +++ b/zulip_bots/zulip_bots/run.py @@ -72,11 +72,10 @@ def exit_gracefully_if_zulip_config_is_missing(config_file: Optional[str]) -> No else: error_msg = f"ERROR: {config_file} does not exist." + elif zulip_env_vars_are_present(): + return else: - if zulip_env_vars_are_present(): - return - else: - error_msg = "ERROR: You did not supply a Zulip config file." + error_msg = "ERROR: You did not supply a Zulip config file." if error_msg: print("\n")