ruff: Fix SIM118 Use key in dict
instead of key in dict.keys()
.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
6a37290cec
commit
93156d994a
6 changed files with 34 additions and 34 deletions
|
@ -317,8 +317,8 @@ def process_keys(content_list: List[str]) -> Tuple[Dict[str, int], Set[str], Set
|
|||
key_counts[key] = 0
|
||||
for key in content_keys:
|
||||
key_counts[key] += 1
|
||||
z_missing = {key for key in zhkeys.keys() if key_counts[key] == 0}
|
||||
h_missing = {key for key in hzkeys.keys() if key_counts[key] == 0}
|
||||
z_missing = {key for key in zhkeys if key_counts[key] == 0}
|
||||
h_missing = {key for key in hzkeys if key_counts[key] == 0}
|
||||
duplicates = any(val > 1 for val in key_counts.values())
|
||||
success = all(val == 1 for val in key_counts.values())
|
||||
return key_counts, z_missing, h_missing, duplicates, success
|
||||
|
|
|
@ -24,13 +24,13 @@ def get_bot_result(message_content: str, config: Dict[str, str], sender_id: str)
|
|||
response = request.getresponse()
|
||||
res_str = response.read().decode("utf8", "ignore")
|
||||
res_json = json.loads(res_str)
|
||||
if res_json["status"]["errorType"] != "success" and "result" not in res_json.keys():
|
||||
if res_json["status"]["errorType"] != "success" and "result" not in res_json:
|
||||
return "Error {}: {}.".format(
|
||||
res_json["status"]["code"], res_json["status"]["errorDetails"]
|
||||
)
|
||||
if res_json["result"]["fulfillment"]["speech"] == "":
|
||||
if (
|
||||
"alternateResult" in res_json.keys()
|
||||
"alternateResult" in res_json
|
||||
and res_json["alternateResult"]["fulfillment"]["speech"] != ""
|
||||
):
|
||||
return res_json["alternateResult"]["fulfillment"]["speech"]
|
||||
|
|
|
@ -74,7 +74,7 @@ def translate(text_to_translate, key, dest, src):
|
|||
|
||||
def get_code_for_language(language, all_languages):
|
||||
if language.lower() not in all_languages.values():
|
||||
if language.lower() not in all_languages.keys():
|
||||
if language.lower() not in all_languages:
|
||||
return ""
|
||||
language = all_languages[language.lower()]
|
||||
return language
|
||||
|
|
|
@ -99,7 +99,7 @@ def get_enabled_checkers(results: Dict) -> List:
|
|||
"""
|
||||
checkers = results["enabled_checkers"]
|
||||
enabled_checkers = []
|
||||
for checker in checkers.keys():
|
||||
for checker in checkers:
|
||||
if checkers[checker]: # == True/False
|
||||
enabled_checkers.append(checker)
|
||||
return enabled_checkers
|
||||
|
|
|
@ -31,7 +31,7 @@ login_url = "https://login.salesforce.com/"
|
|||
def get_help_text() -> str:
|
||||
command_text = ""
|
||||
for command in commands:
|
||||
if "template" in command.keys() and "description" in command.keys():
|
||||
if "template" in command and "description" in command:
|
||||
command_text += "**{}**: {}\n".format(
|
||||
"{} [arguments]".format(command["template"]), command["description"]
|
||||
)
|
||||
|
@ -90,23 +90,23 @@ def query_salesforce(
|
|||
limit_num = int(limit.group().rsplit(" ", 1)[1])
|
||||
logging.info("Searching with limit %d", limit_num)
|
||||
query = default_query
|
||||
if "query" in command.keys():
|
||||
if "query" in command:
|
||||
query = command["query"]
|
||||
object_type = object_types[command["object"]]
|
||||
res = salesforce.query(
|
||||
query.format(object_type["fields"], object_type["table"], qarg, limit_num)
|
||||
)
|
||||
exclude_keys: List[str] = []
|
||||
if "exclude_keys" in command.keys():
|
||||
if "exclude_keys" in command:
|
||||
exclude_keys = command["exclude_keys"]
|
||||
force_keys: List[str] = []
|
||||
if "force_keys" in command.keys():
|
||||
if "force_keys" in command:
|
||||
force_keys = command["force_keys"]
|
||||
rank_output = False
|
||||
if "rank_output" in command.keys():
|
||||
if "rank_output" in command:
|
||||
rank_output = command["rank_output"]
|
||||
show_all_keys = "show" in split_args
|
||||
if "show_all_keys" in command.keys():
|
||||
if "show_all_keys" in command:
|
||||
show_all_keys = command["show_all_keys"] or "show" in split_args
|
||||
return format_result(
|
||||
res,
|
||||
|
@ -153,7 +153,7 @@ class SalesforceHandler:
|
|||
if content.startswith(command_keyword):
|
||||
args = content.replace(command_keyword, "").strip()
|
||||
if args != "":
|
||||
if "callback" in command.keys():
|
||||
if "callback" in command:
|
||||
return command["callback"](args, self.sf, command)
|
||||
else:
|
||||
return query_salesforce(args, self.sf, command)
|
||||
|
|
|
@ -70,10 +70,10 @@ class GameAdapter:
|
|||
def add_user_statistics(self, user: str, values: Dict[str, int]) -> None:
|
||||
self.get_user_cache()
|
||||
current_values: Dict[str, int] = {}
|
||||
if "stats" in self.get_user_by_email(user).keys():
|
||||
if "stats" in self.get_user_by_email(user):
|
||||
current_values = self.user_cache[user]["stats"]
|
||||
for key, value in values.items():
|
||||
if key not in current_values.keys():
|
||||
if key not in current_values:
|
||||
current_values.update({key: 0})
|
||||
current_values[key] += value
|
||||
self.user_cache[user].update({"stats": current_values})
|
||||
|
@ -216,7 +216,7 @@ class GameAdapter:
|
|||
sender = message["sender_email"].lower()
|
||||
message["sender_email"] = message["sender_email"].lower()
|
||||
|
||||
if self.email not in self.user_cache.keys() and self.supports_computer:
|
||||
if self.email not in self.user_cache and self.supports_computer:
|
||||
self.add_user_to_cache(
|
||||
{"sender_email": self.email, "sender_full_name": self.full_name}
|
||||
)
|
||||
|
@ -224,7 +224,7 @@ class GameAdapter:
|
|||
if sender == self.email:
|
||||
return
|
||||
|
||||
if sender not in self.user_cache.keys():
|
||||
if sender not in self.user_cache:
|
||||
self.add_user_to_cache(message)
|
||||
logging.info("Added %s to user cache", sender)
|
||||
|
||||
|
@ -489,7 +489,7 @@ class GameAdapter:
|
|||
def get_sorted_player_statistics(self) -> List[Tuple[str, Dict[str, int]]]:
|
||||
players = []
|
||||
for user_name, u in self.user_cache.items():
|
||||
if "stats" in u.keys():
|
||||
if "stats" in u:
|
||||
players.append((user_name, u["stats"]))
|
||||
return sorted(
|
||||
players,
|
||||
|
@ -508,11 +508,11 @@ class GameAdapter:
|
|||
self.send_reply(message, self.confirm_new_invitation(user_email))
|
||||
|
||||
def cancel_game(self, game_id: str, reason: str = "") -> None:
|
||||
if game_id in self.invites.keys():
|
||||
if game_id in self.invites:
|
||||
self.broadcast(game_id, "Game cancelled.\n" + reason)
|
||||
del self.invites[game_id]
|
||||
return
|
||||
if game_id in self.instances.keys():
|
||||
if game_id in self.instances:
|
||||
self.instances[game_id].broadcast("Game ended.\n" + reason)
|
||||
del self.instances[game_id]
|
||||
return
|
||||
|
@ -541,7 +541,7 @@ class GameAdapter:
|
|||
object = f"""> **Game `{game_id}`**
|
||||
> {self.game_name}
|
||||
> {self.get_number_of_players(game_id)}/{self.max_players} players"""
|
||||
if game_id in self.instances.keys():
|
||||
if game_id in self.instances:
|
||||
instance = self.instances[game_id]
|
||||
if not self.is_single_player:
|
||||
object += "\n> **[Join Game](/#narrow/stream/{}/topic/{})**".format(
|
||||
|
@ -561,7 +561,7 @@ class GameAdapter:
|
|||
self.start_game_if_ready(game_id)
|
||||
|
||||
def get_players(self, game_id: str, parameter: str = "a") -> List[str]:
|
||||
if game_id in self.invites.keys():
|
||||
if game_id in self.invites:
|
||||
players: List[str] = []
|
||||
if (
|
||||
self.invites[game_id]["subject"] == "###private###" and "p" in parameter
|
||||
|
@ -573,14 +573,14 @@ class GameAdapter:
|
|||
if parameter in accepted:
|
||||
players.append(player)
|
||||
return players
|
||||
if game_id in self.instances.keys() and "p" not in parameter:
|
||||
if game_id in self.instances and "p" not in parameter:
|
||||
players = self.instances[game_id].players
|
||||
return players
|
||||
return []
|
||||
|
||||
def get_game_info(self, game_id: str) -> Dict[str, Any]:
|
||||
game_info: Dict[str, Any] = {}
|
||||
if game_id in self.instances.keys():
|
||||
if game_id in self.instances:
|
||||
instance = self.instances[game_id]
|
||||
game_info = {
|
||||
"game_id": game_id,
|
||||
|
@ -589,7 +589,7 @@ class GameAdapter:
|
|||
"subject": instance.subject,
|
||||
"players": self.get_players(game_id),
|
||||
}
|
||||
if game_id in self.invites.keys():
|
||||
if game_id in self.invites:
|
||||
invite = self.invites[game_id]
|
||||
game_info = {
|
||||
"game_id": game_id,
|
||||
|
@ -603,7 +603,7 @@ class GameAdapter:
|
|||
def get_user_by_name(self, name: str) -> Dict[str, Any]:
|
||||
name = name.strip()
|
||||
for user in self.user_cache.values():
|
||||
if "full_name" in user.keys() and user["full_name"].lower() == name.lower():
|
||||
if "full_name" in user and user["full_name"].lower() == name.lower():
|
||||
return user
|
||||
return {}
|
||||
|
||||
|
@ -646,9 +646,9 @@ To move subjects, send your message again, otherwise join the game using the lin
|
|||
if message != {}:
|
||||
self.send_reply(message, "There is already a game in this subject.")
|
||||
return
|
||||
if game_id in self.instances.keys():
|
||||
if game_id in self.instances:
|
||||
self.instances[game_id].change_subject(stream_name, subject_name)
|
||||
if game_id in self.invites.keys():
|
||||
if game_id in self.invites:
|
||||
invite = self.invites[game_id]
|
||||
invite["stream"] = stream_name
|
||||
invite["subject"] = stream_name
|
||||
|
@ -658,7 +658,7 @@ To move subjects, send your message again, otherwise join the game using the lin
|
|||
) -> str:
|
||||
user_email = user_email.lower()
|
||||
for game, users in self.invites.items():
|
||||
if user_email in users.keys():
|
||||
if user_email in users:
|
||||
if is_accepted:
|
||||
if message["type"] == "private":
|
||||
users[user_email] = "pa"
|
||||
|
@ -754,7 +754,7 @@ To move subjects, send your message again, otherwise join the game using the lin
|
|||
if user_email in instance.players:
|
||||
return False
|
||||
for invite in self.invites.values():
|
||||
for u in invite.keys():
|
||||
for u in invite:
|
||||
if u == "host" and user_email == invite["host"]:
|
||||
return False
|
||||
if u == user_email and "a" in invite[u]:
|
||||
|
@ -774,7 +774,7 @@ To move subjects, send your message again, otherwise join the game using the lin
|
|||
if private_recipients is not None:
|
||||
for user in private_recipients:
|
||||
self.send_message(user, content, True)
|
||||
if game_id in self.invites.keys() and self.invites[game_id]["subject"] != "###private###":
|
||||
if game_id in self.invites and self.invites[game_id]["subject"] != "###private###":
|
||||
self.send_message(
|
||||
self.invites[game_id]["stream"],
|
||||
content,
|
||||
|
@ -782,7 +782,7 @@ To move subjects, send your message again, otherwise join the game using the lin
|
|||
self.invites[game_id]["subject"],
|
||||
)
|
||||
return True
|
||||
if game_id in self.instances.keys():
|
||||
if game_id in self.instances:
|
||||
self.send_message(
|
||||
self.instances[game_id].stream, content, False, self.instances[game_id].subject
|
||||
)
|
||||
|
@ -801,7 +801,7 @@ To move subjects, send your message again, otherwise join the game using the lin
|
|||
for instance in self.instances.values():
|
||||
if user_email in instance.players:
|
||||
return instance.game_id
|
||||
for game_id in self.invites.keys():
|
||||
for game_id in self.invites:
|
||||
players = self.get_players(game_id)
|
||||
if user_email in players:
|
||||
return game_id
|
||||
|
@ -879,7 +879,7 @@ class GameInstance:
|
|||
self.end_game("except:" + player_email)
|
||||
return
|
||||
if content == "draw":
|
||||
if player_email in self.current_draw.keys():
|
||||
if player_email in self.current_draw:
|
||||
self.current_draw[player_email] = True
|
||||
else:
|
||||
self.current_draw = {p: False for p in self.players}
|
||||
|
|
Loading…
Add table
Reference in a new issue