ruff: Fix TRY300 Consider moving this statement to an else
block.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
165581a644
commit
3e2f839946
4 changed files with 13 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -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!")
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -28,10 +28,10 @@ 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
|
||||
elif query.startswith("answer"):
|
||||
try:
|
||||
|
|
Loading…
Add table
Reference in a new issue