diff --git a/zulip/integrations/zephyr/zephyr_mirror_backend.py b/zulip/integrations/zephyr/zephyr_mirror_backend.py index e6efc0c6..62f6bde8 100755 --- a/zulip/integrations/zephyr/zephyr_mirror_backend.py +++ b/zulip/integrations/zephyr/zephyr_mirror_backend.py @@ -283,7 +283,7 @@ def maybe_restart_mirroring_script() -> None: if os.stat( os.path.join(options.stamp_path, "stamps", "restart_stamp") ).st_mtime > start_time or ( - (options.user == "tabbott" or options.user == "tabbott/extra") + options.user in ("tabbott", "tabbott/extra") and os.stat(os.path.join(options.stamp_path, "stamps", "tabbott_stamp")).st_mtime > start_time ): @@ -357,9 +357,9 @@ def process_loop(zulip_queue: "Queue[ZephyrDict]", log: Optional[IO[str]]) -> No def parse_zephyr_body(zephyr_data: str, notice_format: str) -> Tuple[str, str]: try: (zsig, body) = zephyr_data.split("\x00", 1) - if ( - notice_format == "New transaction [$1] entered in $2\nFrom: $3 ($5)\nSubject: $4" - or notice_format == "New transaction [$1] entered in $2\nFrom: $3\nSubject: $4" + if notice_format in ( + "New transaction [$1] entered in $2\nFrom: $3 ($5)\nSubject: $4", + "New transaction [$1] entered in $2\nFrom: $3\nSubject: $4", ): # Logic based off of owl_zephyr_get_message in barnowl fields = body.split("\x00") @@ -789,7 +789,7 @@ Feedback button or at support@zulip.com.""" # Forward messages sent to '(instance "WHITESPACE")' back to the # appropriate WHITESPACE instance for bidirectional mirroring instance = match_whitespace_instance.group(1) - elif instance == f"instance {zephyr_class}" or instance == f"test instance {zephyr_class}": + elif instance in (f"instance {zephyr_class}", f"test instance {zephyr_class}"): # Forward messages to e.g. -c -i white-magic back from the # place we forward them to if instance.startswith("test"): diff --git a/zulip_bots/zulip_bots/bots/beeminder/beeminder.py b/zulip_bots/zulip_bots/bots/beeminder/beeminder.py index 87657439..900706a2 100644 --- a/zulip_bots/zulip_bots/bots/beeminder/beeminder.py +++ b/zulip_bots/zulip_bots/bots/beeminder/beeminder.py @@ -23,7 +23,7 @@ def get_beeminder_response(message_content: str, config_info: Dict[str, str]) -> auth_token = config_info["auth_token"] message_content = message_content.strip() - if message_content == "" or message_content == "help": + if message_content in ("", "help"): return help_message url = f"https://www.beeminder.com/api/v1/users/{username}/goals/{goalname}/datapoints.json" diff --git a/zulip_bots/zulip_bots/bots/flock/flock.py b/zulip_bots/zulip_bots/bots/flock/flock.py index 8dbd15f8..0acb5f1a 100644 --- a/zulip_bots/zulip_bots/bots/flock/flock.py +++ b/zulip_bots/zulip_bots/bots/flock/flock.py @@ -84,7 +84,7 @@ def get_flock_response(content: str, config: Dict[str, str]) -> str: def get_flock_bot_response(content: str, config: Dict[str, str]) -> None: content = content.strip() - if content == "" or content == "help": + if content in ("", "help"): return help_message else: result = get_flock_response(content, config) diff --git a/zulip_bots/zulip_bots/bots/merels/libraries/interface.py b/zulip_bots/zulip_bots/bots/merels/libraries/interface.py index 842d8649..b44370d1 100644 --- a/zulip_bots/zulip_bots/bots/merels/libraries/interface.py +++ b/zulip_bots/zulip_bots/bots/merels/libraries/interface.py @@ -95,7 +95,7 @@ def construct_grid(board): grid = [[" " for _ in range(7)] for _ in range(7)] for k, cell in enumerate(board): - if cell == "O" or cell == "X": + if cell in ("O", "X"): grid[constants.ALLOWED_MOVES[k][0]][constants.ALLOWED_MOVES[k][1]] = cell return grid @@ -113,7 +113,7 @@ def construct_board(grid): for cell_location in constants.ALLOWED_MOVES: cell_content = grid[cell_location[0]][cell_location[1]] - if cell_content == "X" or cell_content == "O": + if cell_content in ("X", "O"): board += cell_content else: board += "N" diff --git a/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py b/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py index 343f5c0a..076d3567 100644 --- a/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py +++ b/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py @@ -56,11 +56,11 @@ def is_jump(vpos_before, hpos_before, vpos_after, hpos_after): # If the man is in outer square, the distance must be 3 or 1 if [vpos_before, hpos_before] in constants.OUTER_SQUARE: - return not (distance == 3 or distance == 1) + return distance not in (3, 1) # If the man is in middle square, the distance must be 2 or 1 if [vpos_before, hpos_before] in constants.MIDDLE_SQUARE: - return not (distance == 2 or distance == 1) + return distance not in (2, 1) # If the man is in inner square, the distance must be only 1 if [vpos_before, hpos_before] in constants.INNER_SQUARE: diff --git a/zulip_bots/zulip_bots/bots/salesforce/salesforce.py b/zulip_bots/zulip_bots/bots/salesforce/salesforce.py index 4a779a58..c6e62bc8 100644 --- a/zulip_bots/zulip_bots/bots/salesforce/salesforce.py +++ b/zulip_bots/zulip_bots/bots/salesforce/salesforce.py @@ -144,7 +144,7 @@ class SalesforceHandler: def get_salesforce_response(self, content: str) -> str: content = content.strip() - if content == "" or content == "help": + if content in ("", "help"): return get_help_text() if content.startswith("http") and "force" in content: return get_salesforce_link_details(content, self.sf) diff --git a/zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py b/zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py index 6315001b..5bad1fcd 100644 --- a/zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py +++ b/zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py @@ -44,7 +44,7 @@ class StackOverflowHandler: # Checking if the link exists. query = message["content"] - if query == "" or query == "help": + if query in ("", "help"): return help_text query_stack_url = "http://api.stackexchange.com/2.2/search/advanced" diff --git a/zulip_bots/zulip_bots/bots/susi/susi.py b/zulip_bots/zulip_bots/bots/susi/susi.py index ab36122c..b613a641 100644 --- a/zulip_bots/zulip_bots/bots/susi/susi.py +++ b/zulip_bots/zulip_bots/bots/susi/susi.py @@ -40,7 +40,7 @@ class SusiHandler: def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None: msg = message["content"] - if msg == "help" or msg == "": + if msg in ("help", ""): bot_handler.send_reply(message, self.usage()) return reply = requests.get("https://api.susi.ai/susi/chat.json", params=dict(q=msg)) diff --git a/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py b/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py index 5bf443fb..694bc538 100644 --- a/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py +++ b/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py @@ -198,7 +198,7 @@ def fs_mkdir(fs: Dict[str, Any], user: str, fn: str) -> Tuple[Dict[str, Any], An def fs_ls(fs: Dict[str, Any], user: str, fn: str) -> Tuple[Dict[str, Any], Any]: - if fn == "." or fn == "": + if fn in (".", ""): path = fs["user_paths"][user] else: path, msg = make_path(fs, user, fn) diff --git a/zulip_bots/zulip_bots/game_handler.py b/zulip_bots/zulip_bots/game_handler.py index d7a95601..94b50173 100644 --- a/zulip_bots/zulip_bots/game_handler.py +++ b/zulip_bots/zulip_bots/game_handler.py @@ -567,7 +567,7 @@ class GameAdapter: ) or "p" not in parameter: players = [self.invites[game_id]["host"]] for player, accepted in self.invites[game_id].items(): - if player == "host" or player == "subject" or player == "stream": + if player in ("host", "subject", "stream"): continue if parameter in accepted: players.append(player)