Skip to content

Commit 69aaf69

Browse files
committed
ruff: Fix B006 Do not use mutable data structures for argument defaults.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 32e0520 commit 69aaf69

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List
1+
from typing import Any, Dict, Sequence
22
from unittest.mock import patch
33

44
from typing_extensions import override
@@ -78,7 +78,7 @@ def setup_game(
7878
self,
7979
id: str = "",
8080
bot: Any = None,
81-
players: List[str] = ["foo", "baz"],
81+
players: Sequence[str] = ["foo", "baz"],
8282
subject: str = "test game",
8383
stream: str = "test",
8484
) -> Any:
@@ -468,8 +468,8 @@ def test_is_user_not_player(self) -> None:
468468
bot = self.add_user_to_cache("foo")
469469
self.add_user_to_cache("baz", bot)
470470
bot.invites = {"abcdefg": {"host": "[email protected]", "[email protected]": "a"}}
471-
self.assertFalse(bot.is_user_not_player("[email protected]"))
472-
self.assertFalse(bot.is_user_not_player("[email protected]"))
471+
self.assertFalse(bot.is_user_not_player("[email protected]", {}))
472+
self.assertFalse(bot.is_user_not_player("[email protected]", {}))
473473

474474
def test_move_help_message(self) -> None:
475475
bot = self.setup_game()

zulip_bots/zulip_bots/bots/salesforce/salesforce.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import logging
44
import re
5-
from typing import Any, Dict, List
5+
from typing import Any, Collection, Dict, List
66

77
import simple_salesforce
88

@@ -43,12 +43,12 @@ def get_help_text() -> str:
4343

4444
def format_result(
4545
result: Dict[str, Any],
46-
exclude_keys: List[str] = [],
47-
force_keys: List[str] = [],
46+
exclude_keys: Collection[str] = [],
47+
force_keys: Collection[str] = [],
4848
rank_output: bool = False,
4949
show_all_keys: bool = False,
5050
) -> str:
51-
exclude_keys += ["Name", "attributes", "Id"]
51+
exclude_keys = {*exclude_keys, "Name", "attributes", "Id"}
5252
output = ""
5353
if result["totalSize"] == 0:
5454
return "No records found."

zulip_bots/zulip_bots/game_handler.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import random
44
import re
55
from copy import deepcopy
6-
from typing import Any, Dict, List, Tuple
6+
from typing import Any, Dict, Iterable, List, Sequence, Tuple
77

88
from typing_extensions import override
99

@@ -344,7 +344,7 @@ def command_accept(self, message: Dict[str, Any], sender: str, content: str) ->
344344
)
345345
self.start_game_if_ready(game_id)
346346

347-
def create_game_lobby(self, message: Dict[str, Any], users: List[str] = []) -> None:
347+
def create_game_lobby(self, message: Dict[str, Any], users: Sequence[str] = []) -> None:
348348
if self.is_game_in_subject(message["subject"], message["display_recipient"]):
349349
self.send_reply(message, "There is already a game in this stream.")
350350
return
@@ -499,7 +499,7 @@ def get_sorted_player_statistics(self) -> List[Tuple[str, Dict[str, int]]]:
499499
reverse=True,
500500
)
501501

502-
def send_invite(self, game_id: str, user_email: str, message: Dict[str, Any] = {}) -> None:
502+
def send_invite(self, game_id: str, user_email: str, message: Dict[str, Any]) -> None:
503503
self.invites[game_id].update({user_email.lower(): "p"})
504504
self.send_message(user_email, self.alert_new_invitation(game_id), True)
505505
if message != {}:
@@ -547,7 +547,7 @@ def get_formatted_game_object(self, game_id: str) -> str:
547547
)
548548
return object
549549

550-
def join_game(self, game_id: str, user_email: str, message: Dict[str, Any] = {}) -> None:
550+
def join_game(self, game_id: str, user_email: str, message: Dict[str, Any]) -> None:
551551
if len(self.get_players(game_id)) >= self.max_players:
552552
if message != {}:
553553
self.send_reply(message, "This game is full.")
@@ -638,7 +638,7 @@ def parse_message(self, message: Dict[str, Any]) -> None:
638638
self.instances[game_id].handle_message(message["content"], message["sender_email"])
639639

640640
def change_game_subject(
641-
self, game_id: str, stream_name: str, subject_name: str, message: Dict[str, Any] = {}
641+
self, game_id: str, stream_name: str, subject_name: str, message: Dict[str, Any]
642642
) -> None:
643643
if self.get_game_instance_by_subject(stream_name, subject_name) is not None:
644644
if message != {}:
@@ -689,7 +689,7 @@ def get_user_cache(self) -> Dict[str, Any]:
689689
self.user_cache = json.loads(user_cache_str)
690690
return self.user_cache
691691

692-
def verify_users(self, users: List[str], message: Dict[str, Any] = {}) -> List[str]:
692+
def verify_users(self, users: Iterable[str], message: Dict[str, Any]) -> List[str]:
693693
verified_users = []
694694
failed = False
695695
for u in users:
@@ -741,7 +741,7 @@ def is_game_in_subject(self, subject_name: str, stream_name: str) -> bool:
741741
or self.get_game_instance_by_subject(subject_name, stream_name) is not None
742742
)
743743

744-
def is_user_not_player(self, user_email: str, message: Dict[str, Any] = {}) -> bool:
744+
def is_user_not_player(self, user_email: str, message: Dict[str, Any]) -> bool:
745745
user = self.get_user_by_email(user_email)
746746
if user == {}:
747747
if message != {}:

0 commit comments

Comments
 (0)