ruff: Fix PLR1714 Consider merging multiple comparisons.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-30 10:40:48 -07:00
parent 192024ebc7
commit 93bb7eb61e
10 changed files with 16 additions and 16 deletions

View file

@ -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"):

View file

@ -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"

View file

@ -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)

View file

@ -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"

View file

@ -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:

View file

@ -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)

View file

@ -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"

View file

@ -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))

View file

@ -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)

View file

@ -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)