Skip to content

Commit 11ea5c7

Browse files
committed
ruff: Fix PLR5501 Use elif instead of else then if, to reduce indentation.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 5c934e5 commit 11ea5c7

File tree

6 files changed

+33
-41
lines changed

6 files changed

+33
-41
lines changed

zulip/integrations/codebase/zulip_codebase_mirror

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,9 @@ def run_mirror() -> None:
295295
if event_date > since:
296296
handle_event(event)
297297
since = event_date
298-
else:
298+
elif sleep_interval < 22:
299299
# back off a bit
300-
if sleep_interval < 22:
301-
sleep_interval += 4
300+
sleep_interval += 4
302301
time.sleep(sleep_interval)
303302

304303
except KeyboardInterrupt:

zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,12 @@ def get_phase_number(grid, turn, x_pieces_possessed_not_on_grid, o_pieces_posses
258258
if x_pieces_possessed_not_on_grid != 0 or o_pieces_possessed_not_on_grid != 0:
259259
# Placing pieces
260260
return 1
261+
elif get_piece("X", grid) <= 3 or get_piece("O", grid) <= 3:
262+
# Flying
263+
return 3
261264
else:
262-
if get_piece("X", grid) <= 3 or get_piece("O", grid) <= 3:
263-
# Flying
264-
return 3
265-
else:
266-
# Moving pieces
267-
return 2
265+
# Moving pieces
266+
return 2
268267

269268

270269
def create_room(topic_name, merels_storage):

zulip_bots/zulip_bots/bots/trello/trello.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,14 @@ def handle_message(self, message: Dict[str, Any], bot_handler: BotHandler) -> No
6060
bot_reply = self.get_all_supported_commands()
6161
elif content == ["get-all-boards"]:
6262
bot_reply = self.get_all_boards()
63+
elif content[0] == "get-all-cards":
64+
bot_reply = self.get_all_cards(content)
65+
elif content[0] == "get-all-checklists":
66+
bot_reply = self.get_all_checklists(content)
67+
elif content[0] == "get-all-lists":
68+
bot_reply = self.get_all_lists(content)
6369
else:
64-
if content[0] == "get-all-cards":
65-
bot_reply = self.get_all_cards(content)
66-
elif content[0] == "get-all-checklists":
67-
bot_reply = self.get_all_checklists(content)
68-
elif content[0] == "get-all-lists":
69-
bot_reply = self.get_all_lists(content)
70-
else:
71-
bot_reply = "Command not supported"
70+
bot_reply = "Command not supported"
7271

7372
bot_handler.send_reply(message, bot_reply)
7473

zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,10 @@ def update_quiz(quiz: Dict[str, Any], quiz_id: str, bot_handler: BotHandler) ->
207207
def build_response(is_correct: bool, num_answers: int) -> str:
208208
if is_correct:
209209
response = ":tada: **{answer}** is correct, {sender_name}!"
210+
elif num_answers >= 3:
211+
response = ":disappointed: WRONG, {sender_name}! The correct answer is **{answer}**."
210212
else:
211-
if num_answers >= 3:
212-
response = ":disappointed: WRONG, {sender_name}! The correct answer is **{answer}**."
213-
else:
214-
response = ":disappointed: WRONG, {sender_name}! {option} is not correct."
213+
response = ":disappointed: WRONG, {sender_name}! {option} is not correct."
215214
return response
216215

217216

zulip_bots/zulip_bots/game_handler.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,10 @@ def handle_message(self, message: Dict[str, Any], bot_handler: BotHandler) -> No
290290
self.send_reply(
291291
message, "You are not in a game at the moment. Type `help` for help."
292292
)
293+
elif self.is_single_player:
294+
self.send_reply(message, self.help_message_single_player())
293295
else:
294-
if self.is_single_player:
295-
self.send_reply(message, self.help_message_single_player())
296-
else:
297-
self.send_reply(message, self.help_message())
296+
self.send_reply(message, self.help_message())
298297
except Exception as e:
299298
logging.exception("Error handling game message")
300299
self.bot_handler.send_reply(message, f"Error {e}.")
@@ -893,16 +892,15 @@ def handle_message(self, content: str, player_email: str) -> None:
893892
return
894893
if self.is_turn_of(player_email):
895894
self.handle_current_player_command(content)
895+
elif self.game_adapter.is_single_player:
896+
self.broadcast("It's your turn")
896897
else:
897-
if self.game_adapter.is_single_player:
898-
self.broadcast("It's your turn")
899-
else:
900-
self.broadcast(
901-
"It's **{}**'s ({}) turn.".format(
902-
self.game_adapter.get_username_by_email(self.players[self.turn]),
903-
self.game_adapter.game_message_handler.get_player_color(self.turn),
904-
)
898+
self.broadcast(
899+
"It's **{}**'s ({}) turn.".format(
900+
self.game_adapter.get_username_by_email(self.players[self.turn]),
901+
self.game_adapter.game_message_handler.get_player_color(self.turn),
905902
)
903+
)
906904

907905
def broadcast(self, content: str) -> None:
908906
self.game_adapter.broadcast(self.game_id, content)
@@ -1022,11 +1020,10 @@ def end_game(self, winner: str) -> None:
10221020
values.update({"games_drawn": 1})
10231021
else:
10241022
values.update({"games_lost": 1})
1023+
elif u == loser:
1024+
values.update({"games_lost": 1})
10251025
else:
1026-
if u == loser:
1027-
values.update({"games_lost": 1})
1028-
else:
1029-
values.update({"games_won": 1})
1026+
values.update({"games_won": 1})
10301027
self.game_adapter.add_user_statistics(u, values)
10311028
if self.game_adapter.email in self.players:
10321029
self.send_win_responses(winner)

zulip_bots/zulip_bots/run.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ def exit_gracefully_if_zulip_config_is_missing(config_file: Optional[str]) -> No
7272
else:
7373
error_msg = f"ERROR: {config_file} does not exist."
7474

75+
elif zulip_env_vars_are_present():
76+
return
7577
else:
76-
if zulip_env_vars_are_present():
77-
return
78-
else:
79-
error_msg = "ERROR: You did not supply a Zulip config file."
78+
error_msg = "ERROR: You did not supply a Zulip config file."
8079

8180
if error_msg:
8281
print("\n")

0 commit comments

Comments
 (0)