From 3e2f839946f86a3314a3fbef8c5732c625d161d5 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 1 Nov 2023 20:00:47 -0700 Subject: [PATCH] ruff: Fix TRY300 Consider moving this statement to an `else` block. Signed-off-by: Anders Kaseorg --- zulip/integrations/google/google-calendar | 4 +--- zulip/integrations/zephyr/zephyr_mirror_backend.py | 13 ++++++++----- zulip_bots/zulip_bots/bots/converter/converter.py | 3 ++- .../zulip_bots/bots/trivia_quiz/trivia_quiz.py | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/zulip/integrations/google/google-calendar b/zulip/integrations/google/google-calendar index 37879f77..87299b7f 100755 --- a/zulip/integrations/google/google-calendar +++ b/zulip/integrations/google/google-calendar @@ -102,9 +102,7 @@ def get_credentials() -> client.Credentials: credential_path = os.path.join(HOME_DIR, "google-credentials.json") store = Storage(credential_path) - credentials = store.get() - - return credentials + return store.get() except client.Error: logging.exception("Error while trying to open the `google-credentials.json` file.") sys.exit(1) diff --git a/zulip/integrations/zephyr/zephyr_mirror_backend.py b/zulip/integrations/zephyr/zephyr_mirror_backend.py index 608c7db7..5a96f0da 100755 --- a/zulip/integrations/zephyr/zephyr_mirror_backend.py +++ b/zulip/integrations/zephyr/zephyr_mirror_backend.py @@ -577,11 +577,12 @@ def zephyr_init_autoretry() -> None: zephyr_port = c_ushort() zephyr_ctypes.check(zephyr_ctypes.ZOpenPort(byref(zephyr_port))) zephyr_ctypes.check(zephyr_ctypes.ZCancelSubscriptions(0)) - backoff.succeed() - return except zephyr_ctypes.ZephyrError: logger.exception("Error initializing Zephyr library (retrying). Traceback:") backoff.fail() + else: + backoff.succeed() + return quit_failed_initialization("Could not initialize Zephyr library, quitting!") @@ -594,10 +595,11 @@ def zephyr_load_session_autoretry(session_path: str) -> None: session = f.read() zephyr_ctypes.check(zephyr_ctypes.ZInitialize()) zephyr_ctypes.check(zephyr_ctypes.ZLoadSession(session, len(session))) - return except zephyr_ctypes.ZephyrError: logger.exception("Error loading saved Zephyr session (retrying). Traceback:") backoff.fail() + else: + return quit_failed_initialization("Could not load saved Zephyr session, quitting!") @@ -620,13 +622,14 @@ def zephyr_subscribe_autoretry(sub: Tuple[str, str, str]) -> None: 0, ) ) - backoff.succeed() - return except zephyr_ctypes.ZephyrError: # Probably a SERVNAK from the zephyr server, but log the # traceback just in case it's something else logger.exception("Error subscribing to personals (retrying). Traceback:") backoff.fail() + else: + backoff.succeed() + return quit_failed_initialization("Could not subscribe to personals, quitting!") diff --git a/zulip_bots/zulip_bots/bots/converter/converter.py b/zulip_bots/zulip_bots/bots/converter/converter.py index de415076..c23a6b9d 100644 --- a/zulip_bots/zulip_bots/bots/converter/converter.py +++ b/zulip_bots/zulip_bots/bots/converter/converter.py @@ -11,10 +11,11 @@ from zulip_bots.lib import BotHandler def is_float(value: Any) -> bool: try: float(value) - return True except ValueError: return False + return True + # Rounds the number 'x' to 'digits' significant digits. # A normal 'round()' would round the number to an absolute amount of diff --git a/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py b/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py index 332a51c1..2f134909 100644 --- a/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py +++ b/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py @@ -28,11 +28,11 @@ class TriviaQuizHandler: if query == "new": try: start_new_quiz(message, bot_handler) - return except NotAvailableError: bot_response = "Uh-Oh! Trivia service is down." bot_handler.send_reply(message, bot_response) - return + + return elif query.startswith("answer"): try: (quiz_id, answer) = parse_answer(query)