Skip to content

Commit f26b861

Browse files
committed
ruff: Fix RUF012 Mutable class attributes should be annotated with typing.ClassVar.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent b37708b commit f26b861

File tree

25 files changed

+83
-76
lines changed

25 files changed

+83
-76
lines changed

zulip/integrations/bridge_with_matrix/matrix_bridge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from collections import OrderedDict
1313
from concurrent.futures import ThreadPoolExecutor
1414
from io import BytesIO
15-
from typing import Any, Dict, List, Match, Optional, Set, Tuple, Type, Union
15+
from typing import Any, ClassVar, Dict, List, Match, Optional, Set, Tuple, Type, Union
1616

1717
import nio
1818
from nio.responses import (
@@ -52,7 +52,7 @@ class MatrixToZulip:
5252
Matrix -> Zulip
5353
"""
5454

55-
non_formatted_messages: Dict[Type[nio.Event], str] = {
55+
non_formatted_messages: ClassVar[Dict[Type[nio.Event], str]] = {
5656
nio.StickerEvent: "sticker",
5757
}
5858

zulip/integrations/bridge_with_matrix/test_matrix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from contextlib import contextmanager
66
from subprocess import PIPE, Popen
77
from tempfile import mkdtemp
8-
from typing import Any, Awaitable, Callable, Iterator, List
8+
from typing import Any, Awaitable, Callable, Final, Iterator, List
99
from unittest import TestCase, mock
1010

1111
import nio
@@ -209,13 +209,13 @@ def __init__(self, sender: str = self.user_uid) -> None:
209209

210210
class MatrixBridgeZulipToMatrixTests(TestCase):
211211
room = mock.MagicMock()
212-
valid_zulip_config = dict(
212+
valid_zulip_config: Final = dict(
213213
stream="some stream",
214214
topic="some topic",
215215
email="some@email",
216216
bridges={("some stream", "some topic"): room},
217217
)
218-
valid_msg = dict(
218+
valid_msg: Final = dict(
219219
sender_email="[email protected]", # must not be equal to config:email
220220
sender_id=42,
221221
type="stream", # Can only mirror Zulip streams

zulip/integrations/zephyr/zephyr_ctypes.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232

3333

3434
class sockaddr(Structure):
35-
_fields_ = [
35+
_fields_ = (
3636
("sa_family", sa_family_t),
3737
("sa_data", c_char * 14),
38-
]
38+
)
3939

4040

4141
# --- glibc/inet/netinet/in.h ---
@@ -45,34 +45,30 @@ class sockaddr(Structure):
4545

4646

4747
class in_addr(Structure):
48-
_fields_ = [
49-
("s_addr", in_addr_t),
50-
]
48+
_fields_ = (("s_addr", in_addr_t),)
5149

5250

5351
class sockaddr_in(Structure):
54-
_fields_ = [
52+
_fields_ = (
5553
("sin_family", sa_family_t),
5654
("sin_port", in_port_t),
5755
("sin_addr", in_addr),
5856
("sin_zero", c_uint8 * 8),
59-
]
57+
)
6058

6159

6260
class in6_addr(Structure):
63-
_fields_ = [
64-
("s6_addr", c_uint8 * 16),
65-
]
61+
_fields_ = (("s6_addr", c_uint8 * 16),)
6662

6763

6864
class sockaddr_in6(Structure):
69-
_fields_ = [
65+
_fields_ = (
7066
("sin6_family", sa_family_t),
7167
("sin6_port", in_port_t),
7268
("sin6_flowinfo", c_uint32),
7369
("sin6_addr", in6_addr),
7470
("sin6_scope_id", c_uint32),
75-
]
71+
)
7672

7773

7874
# --- glibc/stdlib/stdlib.h ---
@@ -93,32 +89,32 @@ class sockaddr_in6(Structure):
9389

9490

9591
class _ZTimeval(Structure):
96-
_fields_ = [
92+
_fields_ = (
9793
("tv_sec", c_int),
9894
("tv_usec", c_int),
99-
]
95+
)
10096

10197

10298
class ZUnique_Id_t(Structure):
103-
_fields_ = [
99+
_fields_ = (
104100
("zuid_addr", in_addr),
105101
("tv", _ZTimeval),
106-
]
102+
)
107103

108104

109105
ZChecksum_t = c_uint
110106

111107

112108
class _ZSenderSockaddr(Union):
113-
_fields_ = [
109+
_fields_ = (
114110
("sa", sockaddr),
115111
("ip4", sockaddr_in),
116112
("ip6", sockaddr_in6),
117-
]
113+
)
118114

119115

120116
class ZNotice_t(Structure):
121-
_fields_ = [
117+
_fields_ = (
122118
("z_packet", c_char_p),
123119
("z_version", c_char_p),
124120
("z_kind", ZNotice_Kind_t),
@@ -147,15 +143,15 @@ class ZNotice_t(Structure):
147143
("z_message_len", c_int),
148144
("z_num_hdr_fields", c_uint),
149145
("z_hdr_fields", POINTER(c_char_p)),
150-
]
146+
)
151147

152148

153149
class ZSubscription_t(Structure):
154-
_fields_ = [
150+
_fields_ = (
155151
("zsub_recipient", c_char_p),
156152
("zsub_class", c_char_p),
157153
("zsub_classinst", c_char_p),
158-
]
154+
)
159155

160156

161157
Code_t = c_int

zulip/integrations/zephyr/zephyr_mirror_backend.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import textwrap
1515
import time
1616
from ctypes import POINTER, byref, c_char, c_int, c_ushort
17+
from enum import Enum, auto
1718
from pathlib import Path
1819
from queue import Queue
1920
from threading import Thread
@@ -29,8 +30,10 @@
2930
DEFAULT_SITE = "https://api.zulip.com"
3031

3132

32-
class States:
33-
Startup, ZulipToZephyr, ZephyrToZulip = list(range(3))
33+
class States(Enum):
34+
Startup = auto()
35+
ZulipToZephyr = auto()
36+
ZephyrToZulip = auto()
3437

3538

3639
CURRENT_STATE = States.Startup

zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Final
12
from unittest.mock import patch
23

34
from requests.exceptions import ConnectionError
@@ -8,7 +9,7 @@
89

910
class TestBeeminderBot(BotTestCase, DefaultTests):
1011
bot_name = "beeminder"
11-
normal_config = {"auth_token": "XXXXXX", "username": "aaron", "goalname": "goal"}
12+
normal_config: Final = {"auth_token": "XXXXXX", "username": "aaron", "goalname": "goal"}
1213

1314
help_message = """
1415
You can add datapoints towards your beeminder goals \

zulip_bots/zulip_bots/bots/connect_four/connect_four.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class ConnectFourMessageHandler:
8-
tokens = [":blue_circle:", ":red_circle:"]
8+
tokens = (":blue_circle:", ":red_circle:")
99

1010
def parse_board(self, board: Any) -> str:
1111
# Header for the top of the board

zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, List
1+
from typing import Dict, Final, List
22

33
from typing_extensions import override
44

@@ -99,7 +99,7 @@ def test_game_message_handler_responses(self) -> None:
9999
The first player to get 4 in a row wins!\n Good Luck!",
100100
)
101101

102-
blank_board = [
102+
blank_board: Final = [
103103
[0, 0, 0, 0, 0, 0, 0],
104104
[0, 0, 0, 0, 0, 0, 0],
105105
[0, 0, 0, 0, 0, 0, 0],
@@ -108,7 +108,7 @@ def test_game_message_handler_responses(self) -> None:
108108
[0, 0, 0, 0, 0, 0, 0],
109109
]
110110

111-
almost_win_board = [
111+
almost_win_board: Final = [
112112
[0, 0, 0, 0, 0, 0, 0],
113113
[0, 0, 0, 0, 0, 0, 0],
114114
[0, 0, 0, 0, 0, 0, 0],
@@ -117,7 +117,7 @@ def test_game_message_handler_responses(self) -> None:
117117
[1, -1, 0, 0, 0, 0, 0],
118118
]
119119

120-
almost_draw_board = [
120+
almost_draw_board: Final = [
121121
[1, -1, 1, -1, 1, -1, 0],
122122
[0, 0, 0, 0, 0, 0, 1],
123123
[0, 0, 0, 0, 0, 0, -1],

zulip_bots/zulip_bots/bots/dropbox_share/test_dropbox_share.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Final
12
from unittest.mock import patch
23

34
from zulip_bots.bots.dropbox_share.test_util import (
@@ -75,7 +76,7 @@ def get_help() -> str:
7576

7677
class TestDropboxBot(BotTestCase, DefaultTests):
7778
bot_name = "dropbox_share"
78-
config_info = {"access_token": "1234567890"}
79+
config_info: Final = {"access_token": "1234567890"}
7980

8081
def test_bot_responds_to_empty_message(self):
8182
with self.mock_config_info(self.config_info):

zulip_bots/zulip_bots/bots/flock/test_flock.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Final
12
from unittest.mock import patch
23

34
from requests.exceptions import ConnectionError
@@ -7,9 +8,9 @@
78

89
class TestFlockBot(BotTestCase, DefaultTests):
910
bot_name = "flock"
10-
normal_config = {"token": "12345"}
11+
normal_config: Final = {"token": "12345"}
1112

12-
message_config = {"token": "12345", "text": "Ricky: test message", "to": "u:somekey"}
13+
message_config: Final = {"token": "12345", "text": "Ricky: test message", "to": "u:somekey"}
1314

1415
help_message = """
1516
You can send messages to any Flock user associated with your account from Zulip.

zulip_bots/zulip_bots/bots/front/front.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
class FrontHandler:
1010
FRONT_API = "https://api2.frontapp.com/conversations/{}"
11-
COMMANDS = [
11+
COMMANDS = (
1212
("archive", "Archive a conversation."),
1313
("delete", "Delete a conversation."),
1414
("spam", "Mark a conversation as spam."),
1515
("open", "Restore a conversation."),
1616
("comment <text>", "Leave a comment."),
17-
]
17+
)
1818
CNV_ID_REGEXP = "cnv_(?P<id>[0-9a-z]+)"
1919
COMMENT_PREFIX = "comment "
2020

0 commit comments

Comments
 (0)