From 69aaf69d6f41aac5aadccdb4b1450c58da4d8a7d Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 30 Oct 2023 11:17:52 -0700 Subject: [PATCH] ruff: Fix B006 Do not use mutable data structures for argument defaults. Signed-off-by: Anders Kaseorg --- .../bots/game_handler_bot/test_game_handler_bot.py | 8 ++++---- .../zulip_bots/bots/salesforce/salesforce.py | 8 ++++---- zulip_bots/zulip_bots/game_handler.py | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py b/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py index de90052f..88b1726e 100644 --- a/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py +++ b/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List +from typing import Any, Dict, Sequence from unittest.mock import patch from typing_extensions import override @@ -78,7 +78,7 @@ class TestGameHandlerBot(BotTestCase, DefaultTests): self, id: str = "", bot: Any = None, - players: List[str] = ["foo", "baz"], + players: Sequence[str] = ["foo", "baz"], subject: str = "test game", stream: str = "test", ) -> Any: @@ -468,8 +468,8 @@ class TestGameHandlerBot(BotTestCase, DefaultTests): bot = self.add_user_to_cache("foo") self.add_user_to_cache("baz", bot) bot.invites = {"abcdefg": {"host": "foo@example.com", "baz@example.com": "a"}} - self.assertFalse(bot.is_user_not_player("foo@example.com")) - self.assertFalse(bot.is_user_not_player("baz@example.com")) + self.assertFalse(bot.is_user_not_player("foo@example.com", {})) + self.assertFalse(bot.is_user_not_player("baz@example.com", {})) def test_move_help_message(self) -> None: bot = self.setup_game() diff --git a/zulip_bots/zulip_bots/bots/salesforce/salesforce.py b/zulip_bots/zulip_bots/bots/salesforce/salesforce.py index c6e62bc8..224aee5f 100644 --- a/zulip_bots/zulip_bots/bots/salesforce/salesforce.py +++ b/zulip_bots/zulip_bots/bots/salesforce/salesforce.py @@ -2,7 +2,7 @@ import logging import re -from typing import Any, Dict, List +from typing import Any, Collection, Dict, List import simple_salesforce @@ -43,12 +43,12 @@ def get_help_text() -> str: def format_result( result: Dict[str, Any], - exclude_keys: List[str] = [], - force_keys: List[str] = [], + exclude_keys: Collection[str] = [], + force_keys: Collection[str] = [], rank_output: bool = False, show_all_keys: bool = False, ) -> str: - exclude_keys += ["Name", "attributes", "Id"] + exclude_keys = {*exclude_keys, "Name", "attributes", "Id"} output = "" if result["totalSize"] == 0: return "No records found." diff --git a/zulip_bots/zulip_bots/game_handler.py b/zulip_bots/zulip_bots/game_handler.py index 65db230b..51121751 100644 --- a/zulip_bots/zulip_bots/game_handler.py +++ b/zulip_bots/zulip_bots/game_handler.py @@ -3,7 +3,7 @@ import logging import random import re from copy import deepcopy -from typing import Any, Dict, List, Tuple +from typing import Any, Dict, Iterable, List, Sequence, Tuple from typing_extensions import override @@ -344,7 +344,7 @@ class GameAdapter: ) self.start_game_if_ready(game_id) - def create_game_lobby(self, message: Dict[str, Any], users: List[str] = []) -> None: + def create_game_lobby(self, message: Dict[str, Any], users: Sequence[str] = []) -> None: if self.is_game_in_subject(message["subject"], message["display_recipient"]): self.send_reply(message, "There is already a game in this stream.") return @@ -499,7 +499,7 @@ class GameAdapter: reverse=True, ) - def send_invite(self, game_id: str, user_email: str, message: Dict[str, Any] = {}) -> None: + def send_invite(self, game_id: str, user_email: str, message: Dict[str, Any]) -> None: self.invites[game_id].update({user_email.lower(): "p"}) self.send_message(user_email, self.alert_new_invitation(game_id), True) if message != {}: @@ -547,7 +547,7 @@ class GameAdapter: ) return object - def join_game(self, game_id: str, user_email: str, message: Dict[str, Any] = {}) -> None: + def join_game(self, game_id: str, user_email: str, message: Dict[str, Any]) -> None: if len(self.get_players(game_id)) >= self.max_players: if message != {}: self.send_reply(message, "This game is full.") @@ -638,7 +638,7 @@ To move subjects, send your message again, otherwise join the game using the lin self.instances[game_id].handle_message(message["content"], message["sender_email"]) def change_game_subject( - self, game_id: str, stream_name: str, subject_name: str, message: Dict[str, Any] = {} + self, game_id: str, stream_name: str, subject_name: str, message: Dict[str, Any] ) -> None: if self.get_game_instance_by_subject(stream_name, subject_name) is not None: if message != {}: @@ -689,7 +689,7 @@ To move subjects, send your message again, otherwise join the game using the lin self.user_cache = json.loads(user_cache_str) return self.user_cache - def verify_users(self, users: List[str], message: Dict[str, Any] = {}) -> List[str]: + def verify_users(self, users: Iterable[str], message: Dict[str, Any]) -> List[str]: verified_users = [] failed = False for u in users: @@ -741,7 +741,7 @@ To move subjects, send your message again, otherwise join the game using the lin or self.get_game_instance_by_subject(subject_name, stream_name) is not None ) - def is_user_not_player(self, user_email: str, message: Dict[str, Any] = {}) -> bool: + def is_user_not_player(self, user_email: str, message: Dict[str, Any]) -> bool: user = self.get_user_by_email(user_email) if user == {}: if message != {}: