Skip to content

Commit 2c4e706

Browse files
committed
ruff: Fix N801 Class name should use CapWords convention.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 272c63b commit 2c4e706

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

zulip/integrations/bridge_with_matrix/matrix_bridge.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535
MATRIX_MESSAGE_TEMPLATE: str = "<{username} ({uid})> {message}"
3636

3737

38-
class Bridge_ConfigException(Exception):
38+
class BridgeConfigException(Exception):
3939
pass
4040

4141

42-
class Bridge_FatalMatrixException(Exception):
42+
class BridgeFatalMatrixException(Exception):
4343
pass
4444

4545

46-
class Bridge_FatalZulipException(Exception):
46+
class BridgeFatalZulipException(Exception):
4747
pass
4848

4949

@@ -86,7 +86,7 @@ async def create(
8686
# the new messages and not with all the old ones.
8787
sync_response: Union[SyncResponse, SyncError] = await matrix_client.sync()
8888
if isinstance(sync_response, nio.SyncError):
89-
raise Bridge_FatalMatrixException(sync_response.message)
89+
raise BridgeFatalMatrixException(sync_response.message)
9090

9191
return matrix_to_zulip
9292

@@ -117,10 +117,10 @@ async def _matrix_to_zulip(self, room: nio.MatrixRoom, event: nio.Event) -> None
117117
)
118118
except Exception as exception:
119119
# Generally raised when user is forbidden
120-
raise Bridge_FatalZulipException(exception)
120+
raise BridgeFatalZulipException(exception)
121121
if result["result"] != "success":
122122
# Generally raised when API key is invalid
123-
raise Bridge_FatalZulipException(result["msg"])
123+
raise BridgeFatalZulipException(result["msg"])
124124

125125
# Update the bot's read marker in order to show the other users which
126126
# messages are already processed by the bot.
@@ -194,14 +194,14 @@ async def matrix_join_rooms(self) -> None:
194194
for room_id in self.matrix_config["bridges"]:
195195
result: Union[JoinResponse, JoinError] = await self.matrix_client.join(room_id)
196196
if isinstance(result, nio.JoinError):
197-
raise Bridge_FatalMatrixException(str(result))
197+
raise BridgeFatalMatrixException(str(result))
198198

199199
async def matrix_login(self) -> None:
200200
result: Union[LoginResponse, LoginError] = await self.matrix_client.login(
201201
self.matrix_config["password"]
202202
)
203203
if isinstance(result, nio.LoginError):
204-
raise Bridge_FatalMatrixException(str(result))
204+
raise BridgeFatalMatrixException(str(result))
205205

206206
async def run(self) -> None:
207207
print("Starting message handler on Matrix client")
@@ -230,7 +230,7 @@ def __init__(
230230
# Precompute the url of the Zulip server, needed later.
231231
result: Dict[str, Any] = self.zulip_client.get_server_settings()
232232
if result["result"] != "success":
233-
raise Bridge_FatalZulipException("cannot get server settings")
233+
raise BridgeFatalZulipException("cannot get server settings")
234234
self.server_url: str = result["realm_uri"]
235235

236236
@classmethod
@@ -250,7 +250,7 @@ def _matrix_send(self, **kwargs: Any) -> None:
250250
self.matrix_client.room_send(**kwargs), self.loop
251251
).result()
252252
if isinstance(result, nio.RoomSendError):
253-
raise Bridge_FatalMatrixException(str(result))
253+
raise BridgeFatalMatrixException(str(result))
254254

255255
def _zulip_to_matrix(self, msg: Dict[str, Any]) -> None:
256256
logging.debug("_zulip_to_matrix; msg: %s", msg)
@@ -303,12 +303,12 @@ def ensure_stream_membership(self) -> None:
303303
for stream, _ in self.zulip_config["bridges"]:
304304
result: Dict[str, Any] = self.zulip_client.get_stream_id(stream)
305305
if result["result"] == "error":
306-
raise Bridge_FatalZulipException(f"cannot access stream '{stream}': {result}")
306+
raise BridgeFatalZulipException(f"cannot access stream '{stream}': {result}")
307307
if result["result"] != "success":
308-
raise Bridge_FatalZulipException(f"cannot checkout stream id for stream '{stream}'")
308+
raise BridgeFatalZulipException(f"cannot checkout stream id for stream '{stream}'")
309309
result = self.zulip_client.add_subscriptions(streams=[{"name": stream}])
310310
if result["result"] != "success":
311-
raise Bridge_FatalZulipException(f"cannot subscribe to stream '{stream}': {result}")
311+
raise BridgeFatalZulipException(f"cannot subscribe to stream '{stream}': {result}")
312312

313313
def get_matrix_room_for_zulip_message(self, msg: Dict[str, Any]) -> Optional[str]:
314314
"""Check whether we want to process the given message.
@@ -459,10 +459,10 @@ def read_configuration(config_file: str) -> Dict[str, Dict[str, Any]]:
459459
try:
460460
config.read(config_file)
461461
except configparser.Error as exception:
462-
raise Bridge_ConfigException(str(exception))
462+
raise BridgeConfigException(str(exception))
463463

464464
if set(config.sections()) < {"matrix", "zulip"}:
465-
raise Bridge_ConfigException("Please ensure the configuration has zulip & matrix sections.")
465+
raise BridgeConfigException("Please ensure the configuration has zulip & matrix sections.")
466466

467467
result: Dict[str, Dict[str, Any]] = {"matrix": {}, "zulip": {}}
468468
# For Matrix: create a mapping with the Matrix room_ids as keys and
@@ -484,7 +484,7 @@ def read_configuration(config_file: str) -> Dict[str, Dict[str, Any]]:
484484

485485
if section.startswith("additional_bridge"):
486486
if section_keys != bridge_key_set:
487-
raise Bridge_ConfigException(
487+
raise BridgeConfigException(
488488
f"Please ensure the bridge configuration section {section} contain the following keys: {bridge_key_set}."
489489
)
490490

@@ -493,7 +493,7 @@ def read_configuration(config_file: str) -> Dict[str, Dict[str, Any]]:
493493
result["matrix"]["bridges"][section_config["room_id"]] = zulip_target
494494
elif section == "matrix":
495495
if section_keys != matrix_full_key_set:
496-
raise Bridge_ConfigException(
496+
raise BridgeConfigException(
497497
"Please ensure the matrix configuration section contains the following keys: %s."
498498
% str(matrix_full_key_set)
499499
)
@@ -505,10 +505,10 @@ def read_configuration(config_file: str) -> Dict[str, Dict[str, Any]]:
505505

506506
# Verify the format of the Matrix user ID.
507507
if re.fullmatch(r"@[^:]+:.+", result["matrix"]["mxid"]) is None:
508-
raise Bridge_ConfigException("Malformatted mxid.")
508+
raise BridgeConfigException("Malformatted mxid.")
509509
elif section == "zulip":
510510
if section_keys != zulip_full_key_set:
511-
raise Bridge_ConfigException(
511+
raise BridgeConfigException(
512512
"Please ensure the zulip configuration section contains the following keys: %s."
513513
% str(zulip_full_key_set)
514514
)
@@ -555,9 +555,9 @@ async def run(zulip_config: Dict[str, Any], matrix_config: Dict[str, Any], no_no
555555

556556
await asyncio.gather(matrix_to_zulip.run(), zulip_to_matrix.run())
557557

558-
except Bridge_FatalMatrixException as exception:
558+
except BridgeFatalMatrixException as exception:
559559
sys.exit(f"Matrix bridge error: {exception}")
560-
except Bridge_FatalZulipException as exception:
560+
except BridgeFatalZulipException as exception:
561561
sys.exit(f"Zulip bridge error: {exception}")
562562
except zulip.ZulipError as exception:
563563
sys.exit(f"Zulip error: {exception}")
@@ -571,7 +571,7 @@ async def run(zulip_config: Dict[str, Any], matrix_config: Dict[str, Any], no_no
571571

572572
def write_sample_config(target_path: str, zuliprc: Optional[str]) -> None:
573573
if os.path.exists(target_path):
574-
raise Bridge_ConfigException(f"Path '{target_path}' exists; not overwriting existing file.")
574+
raise BridgeConfigException(f"Path '{target_path}' exists; not overwriting existing file.")
575575

576576
sample_dict: OrderedDict[str, OrderedDict[str, str]] = OrderedDict(
577577
(
@@ -613,20 +613,20 @@ def write_sample_config(target_path: str, zuliprc: Optional[str]) -> None:
613613

614614
if zuliprc is not None:
615615
if not os.path.exists(zuliprc):
616-
raise Bridge_ConfigException(f"Zuliprc file '{zuliprc}' does not exist.")
616+
raise BridgeConfigException(f"Zuliprc file '{zuliprc}' does not exist.")
617617

618618
zuliprc_config: configparser.ConfigParser = configparser.ConfigParser()
619619
try:
620620
zuliprc_config.read(zuliprc)
621621
except configparser.Error as exception:
622-
raise Bridge_ConfigException(str(exception))
622+
raise BridgeConfigException(str(exception))
623623

624624
try:
625625
sample_dict["zulip"]["email"] = zuliprc_config["api"]["email"]
626626
sample_dict["zulip"]["site"] = zuliprc_config["api"]["site"]
627627
sample_dict["zulip"]["api_key"] = zuliprc_config["api"]["key"]
628628
except KeyError as exception:
629-
raise Bridge_ConfigException("You provided an invalid zuliprc file: " + str(exception))
629+
raise BridgeConfigException("You provided an invalid zuliprc file: " + str(exception))
630630

631631
sample: configparser.ConfigParser = configparser.ConfigParser()
632632
sample.read_dict(sample_dict)
@@ -648,7 +648,7 @@ def main() -> None:
648648
if options.sample_config:
649649
try:
650650
write_sample_config(options.sample_config, options.zuliprc)
651-
except Bridge_ConfigException as exception:
651+
except BridgeConfigException as exception:
652652
print(f"Could not write sample config: {exception}")
653653
sys.exit(1)
654654
if options.zuliprc is None:
@@ -667,7 +667,7 @@ def main() -> None:
667667

668668
try:
669669
config: Dict[str, Dict[str, Any]] = read_configuration(options.config)
670-
except Bridge_ConfigException as exception:
670+
except BridgeConfigException as exception:
671671
print(f"Could not parse config file: {exception}")
672672
sys.exit(1)
673673

zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def game_start_message(self) -> str:
256256
return "Welcome to tic-tac-toe!To make a move, type @-mention `move <number>` or `<number>`"
257257

258258

259-
class ticTacToeHandler(GameAdapter):
259+
class TicTacToeHandler(GameAdapter):
260260
"""
261261
You can play tic-tac-toe! Make sure your message starts with
262262
"@mention-bot".
@@ -304,4 +304,4 @@ def coords_from_command(cmd: str) -> str:
304304
return cmd
305305

306306

307-
handler_class = ticTacToeHandler
307+
handler_class = TicTacToeHandler

0 commit comments

Comments
 (0)