Skip to content

Commit 93156d9

Browse files
committed
ruff: Fix SIM118 Use key in dict instead of key in dict.keys().
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 6a37290 commit 93156d9

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

zulip/integrations/zephyr/check-mirroring

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ def process_keys(content_list: List[str]) -> Tuple[Dict[str, int], Set[str], Set
317317
key_counts[key] = 0
318318
for key in content_keys:
319319
key_counts[key] += 1
320-
z_missing = {key for key in zhkeys.keys() if key_counts[key] == 0}
321-
h_missing = {key for key in hzkeys.keys() if key_counts[key] == 0}
320+
z_missing = {key for key in zhkeys if key_counts[key] == 0}
321+
h_missing = {key for key in hzkeys if key_counts[key] == 0}
322322
duplicates = any(val > 1 for val in key_counts.values())
323323
success = all(val == 1 for val in key_counts.values())
324324
return key_counts, z_missing, h_missing, duplicates, success

zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ def get_bot_result(message_content: str, config: Dict[str, str], sender_id: str)
2424
response = request.getresponse()
2525
res_str = response.read().decode("utf8", "ignore")
2626
res_json = json.loads(res_str)
27-
if res_json["status"]["errorType"] != "success" and "result" not in res_json.keys():
27+
if res_json["status"]["errorType"] != "success" and "result" not in res_json:
2828
return "Error {}: {}.".format(
2929
res_json["status"]["code"], res_json["status"]["errorDetails"]
3030
)
3131
if res_json["result"]["fulfillment"]["speech"] == "":
3232
if (
33-
"alternateResult" in res_json.keys()
33+
"alternateResult" in res_json
3434
and res_json["alternateResult"]["fulfillment"]["speech"] != ""
3535
):
3636
return res_json["alternateResult"]["fulfillment"]["speech"]

zulip_bots/zulip_bots/bots/google_translate/google_translate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def translate(text_to_translate, key, dest, src):
7474

7575
def get_code_for_language(language, all_languages):
7676
if language.lower() not in all_languages.values():
77-
if language.lower() not in all_languages.keys():
77+
if language.lower() not in all_languages:
7878
return ""
7979
language = all_languages[language.lower()]
8080
return language

zulip_bots/zulip_bots/bots/monkeytestit/lib/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def get_enabled_checkers(results: Dict) -> List:
9999
"""
100100
checkers = results["enabled_checkers"]
101101
enabled_checkers = []
102-
for checker in checkers.keys():
102+
for checker in checkers:
103103
if checkers[checker]: # == True/False
104104
enabled_checkers.append(checker)
105105
return enabled_checkers

zulip_bots/zulip_bots/bots/salesforce/salesforce.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
def get_help_text() -> str:
3232
command_text = ""
3333
for command in commands:
34-
if "template" in command.keys() and "description" in command.keys():
34+
if "template" in command and "description" in command:
3535
command_text += "**{}**: {}\n".format(
3636
"{} [arguments]".format(command["template"]), command["description"]
3737
)
@@ -90,23 +90,23 @@ def query_salesforce(
9090
limit_num = int(limit.group().rsplit(" ", 1)[1])
9191
logging.info("Searching with limit %d", limit_num)
9292
query = default_query
93-
if "query" in command.keys():
93+
if "query" in command:
9494
query = command["query"]
9595
object_type = object_types[command["object"]]
9696
res = salesforce.query(
9797
query.format(object_type["fields"], object_type["table"], qarg, limit_num)
9898
)
9999
exclude_keys: List[str] = []
100-
if "exclude_keys" in command.keys():
100+
if "exclude_keys" in command:
101101
exclude_keys = command["exclude_keys"]
102102
force_keys: List[str] = []
103-
if "force_keys" in command.keys():
103+
if "force_keys" in command:
104104
force_keys = command["force_keys"]
105105
rank_output = False
106-
if "rank_output" in command.keys():
106+
if "rank_output" in command:
107107
rank_output = command["rank_output"]
108108
show_all_keys = "show" in split_args
109-
if "show_all_keys" in command.keys():
109+
if "show_all_keys" in command:
110110
show_all_keys = command["show_all_keys"] or "show" in split_args
111111
return format_result(
112112
res,
@@ -153,7 +153,7 @@ def get_salesforce_response(self, content: str) -> str:
153153
if content.startswith(command_keyword):
154154
args = content.replace(command_keyword, "").strip()
155155
if args != "":
156-
if "callback" in command.keys():
156+
if "callback" in command:
157157
return command["callback"](args, self.sf, command)
158158
else:
159159
return query_salesforce(args, self.sf, command)

zulip_bots/zulip_bots/game_handler.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ def __init__(
7070
def add_user_statistics(self, user: str, values: Dict[str, int]) -> None:
7171
self.get_user_cache()
7272
current_values: Dict[str, int] = {}
73-
if "stats" in self.get_user_by_email(user).keys():
73+
if "stats" in self.get_user_by_email(user):
7474
current_values = self.user_cache[user]["stats"]
7575
for key, value in values.items():
76-
if key not in current_values.keys():
76+
if key not in current_values:
7777
current_values.update({key: 0})
7878
current_values[key] += value
7979
self.user_cache[user].update({"stats": current_values})
@@ -216,15 +216,15 @@ def handle_message(self, message: Dict[str, Any], bot_handler: BotHandler) -> No
216216
sender = message["sender_email"].lower()
217217
message["sender_email"] = message["sender_email"].lower()
218218

219-
if self.email not in self.user_cache.keys() and self.supports_computer:
219+
if self.email not in self.user_cache and self.supports_computer:
220220
self.add_user_to_cache(
221221
{"sender_email": self.email, "sender_full_name": self.full_name}
222222
)
223223

224224
if sender == self.email:
225225
return
226226

227-
if sender not in self.user_cache.keys():
227+
if sender not in self.user_cache:
228228
self.add_user_to_cache(message)
229229
logging.info("Added %s to user cache", sender)
230230

@@ -489,7 +489,7 @@ def command_leaderboard(self, message: Dict[str, Any], sender: str, content: str
489489
def get_sorted_player_statistics(self) -> List[Tuple[str, Dict[str, int]]]:
490490
players = []
491491
for user_name, u in self.user_cache.items():
492-
if "stats" in u.keys():
492+
if "stats" in u:
493493
players.append((user_name, u["stats"]))
494494
return sorted(
495495
players,
@@ -508,11 +508,11 @@ def send_invite(self, game_id: str, user_email: str, message: Dict[str, Any] = {
508508
self.send_reply(message, self.confirm_new_invitation(user_email))
509509

510510
def cancel_game(self, game_id: str, reason: str = "") -> None:
511-
if game_id in self.invites.keys():
511+
if game_id in self.invites:
512512
self.broadcast(game_id, "Game cancelled.\n" + reason)
513513
del self.invites[game_id]
514514
return
515-
if game_id in self.instances.keys():
515+
if game_id in self.instances:
516516
self.instances[game_id].broadcast("Game ended.\n" + reason)
517517
del self.instances[game_id]
518518
return
@@ -541,7 +541,7 @@ def get_formatted_game_object(self, game_id: str) -> str:
541541
object = f"""> **Game `{game_id}`**
542542
> {self.game_name}
543543
> {self.get_number_of_players(game_id)}/{self.max_players} players"""
544-
if game_id in self.instances.keys():
544+
if game_id in self.instances:
545545
instance = self.instances[game_id]
546546
if not self.is_single_player:
547547
object += "\n> **[Join Game](/#narrow/stream/{}/topic/{})**".format(
@@ -561,7 +561,7 @@ def join_game(self, game_id: str, user_email: str, message: Dict[str, Any] = {})
561561
self.start_game_if_ready(game_id)
562562

563563
def get_players(self, game_id: str, parameter: str = "a") -> List[str]:
564-
if game_id in self.invites.keys():
564+
if game_id in self.invites:
565565
players: List[str] = []
566566
if (
567567
self.invites[game_id]["subject"] == "###private###" and "p" in parameter
@@ -573,14 +573,14 @@ def get_players(self, game_id: str, parameter: str = "a") -> List[str]:
573573
if parameter in accepted:
574574
players.append(player)
575575
return players
576-
if game_id in self.instances.keys() and "p" not in parameter:
576+
if game_id in self.instances and "p" not in parameter:
577577
players = self.instances[game_id].players
578578
return players
579579
return []
580580

581581
def get_game_info(self, game_id: str) -> Dict[str, Any]:
582582
game_info: Dict[str, Any] = {}
583-
if game_id in self.instances.keys():
583+
if game_id in self.instances:
584584
instance = self.instances[game_id]
585585
game_info = {
586586
"game_id": game_id,
@@ -589,7 +589,7 @@ def get_game_info(self, game_id: str) -> Dict[str, Any]:
589589
"subject": instance.subject,
590590
"players": self.get_players(game_id),
591591
}
592-
if game_id in self.invites.keys():
592+
if game_id in self.invites:
593593
invite = self.invites[game_id]
594594
game_info = {
595595
"game_id": game_id,
@@ -603,7 +603,7 @@ def get_game_info(self, game_id: str) -> Dict[str, Any]:
603603
def get_user_by_name(self, name: str) -> Dict[str, Any]:
604604
name = name.strip()
605605
for user in self.user_cache.values():
606-
if "full_name" in user.keys() and user["full_name"].lower() == name.lower():
606+
if "full_name" in user and user["full_name"].lower() == name.lower():
607607
return user
608608
return {}
609609

@@ -646,9 +646,9 @@ def change_game_subject(
646646
if message != {}:
647647
self.send_reply(message, "There is already a game in this subject.")
648648
return
649-
if game_id in self.instances.keys():
649+
if game_id in self.instances:
650650
self.instances[game_id].change_subject(stream_name, subject_name)
651-
if game_id in self.invites.keys():
651+
if game_id in self.invites:
652652
invite = self.invites[game_id]
653653
invite["stream"] = stream_name
654654
invite["subject"] = stream_name
@@ -658,7 +658,7 @@ def set_invite_by_user(
658658
) -> str:
659659
user_email = user_email.lower()
660660
for game, users in self.invites.items():
661-
if user_email in users.keys():
661+
if user_email in users:
662662
if is_accepted:
663663
if message["type"] == "private":
664664
users[user_email] = "pa"
@@ -754,7 +754,7 @@ def is_user_not_player(self, user_email: str, message: Dict[str, Any] = {}) -> b
754754
if user_email in instance.players:
755755
return False
756756
for invite in self.invites.values():
757-
for u in invite.keys():
757+
for u in invite:
758758
if u == "host" and user_email == invite["host"]:
759759
return False
760760
if u == user_email and "a" in invite[u]:
@@ -774,15 +774,15 @@ def broadcast(self, game_id: str, content: str, include_private: bool = True) ->
774774
if private_recipients is not None:
775775
for user in private_recipients:
776776
self.send_message(user, content, True)
777-
if game_id in self.invites.keys() and self.invites[game_id]["subject"] != "###private###":
777+
if game_id in self.invites and self.invites[game_id]["subject"] != "###private###":
778778
self.send_message(
779779
self.invites[game_id]["stream"],
780780
content,
781781
False,
782782
self.invites[game_id]["subject"],
783783
)
784784
return True
785-
if game_id in self.instances.keys():
785+
if game_id in self.instances:
786786
self.send_message(
787787
self.instances[game_id].stream, content, False, self.instances[game_id].subject
788788
)
@@ -801,7 +801,7 @@ def get_game_id_by_email(self, user_email: str) -> str:
801801
for instance in self.instances.values():
802802
if user_email in instance.players:
803803
return instance.game_id
804-
for game_id in self.invites.keys():
804+
for game_id in self.invites:
805805
players = self.get_players(game_id)
806806
if user_email in players:
807807
return game_id
@@ -879,7 +879,7 @@ def handle_message(self, content: str, player_email: str) -> None:
879879
self.end_game("except:" + player_email)
880880
return
881881
if content == "draw":
882-
if player_email in self.current_draw.keys():
882+
if player_email in self.current_draw:
883883
self.current_draw[player_email] = True
884884
else:
885885
self.current_draw = {p: False for p in self.players}

0 commit comments

Comments
 (0)