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")
|
credential_path = os.path.join(HOME_DIR, "google-credentials.json")
|
||||||
|
|
||||||
store = Storage(credential_path)
|
store = Storage(credential_path)
|
||||||
credentials = store.get()
|
return store.get()
|
||||||
|
|
||||||
return credentials
|
|
||||||
except client.Error:
|
except client.Error:
|
||||||
logging.exception("Error while trying to open the `google-credentials.json` file.")
|
logging.exception("Error while trying to open the `google-credentials.json` file.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -577,11 +577,12 @@ def zephyr_init_autoretry() -> None:
|
||||||
zephyr_port = c_ushort()
|
zephyr_port = c_ushort()
|
||||||
zephyr_ctypes.check(zephyr_ctypes.ZOpenPort(byref(zephyr_port)))
|
zephyr_ctypes.check(zephyr_ctypes.ZOpenPort(byref(zephyr_port)))
|
||||||
zephyr_ctypes.check(zephyr_ctypes.ZCancelSubscriptions(0))
|
zephyr_ctypes.check(zephyr_ctypes.ZCancelSubscriptions(0))
|
||||||
backoff.succeed()
|
|
||||||
return
|
|
||||||
except zephyr_ctypes.ZephyrError:
|
except zephyr_ctypes.ZephyrError:
|
||||||
logger.exception("Error initializing Zephyr library (retrying). Traceback:")
|
logger.exception("Error initializing Zephyr library (retrying). Traceback:")
|
||||||
backoff.fail()
|
backoff.fail()
|
||||||
|
else:
|
||||||
|
backoff.succeed()
|
||||||
|
return
|
||||||
|
|
||||||
quit_failed_initialization("Could not initialize Zephyr library, quitting!")
|
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()
|
session = f.read()
|
||||||
zephyr_ctypes.check(zephyr_ctypes.ZInitialize())
|
zephyr_ctypes.check(zephyr_ctypes.ZInitialize())
|
||||||
zephyr_ctypes.check(zephyr_ctypes.ZLoadSession(session, len(session)))
|
zephyr_ctypes.check(zephyr_ctypes.ZLoadSession(session, len(session)))
|
||||||
return
|
|
||||||
except zephyr_ctypes.ZephyrError:
|
except zephyr_ctypes.ZephyrError:
|
||||||
logger.exception("Error loading saved Zephyr session (retrying). Traceback:")
|
logger.exception("Error loading saved Zephyr session (retrying). Traceback:")
|
||||||
backoff.fail()
|
backoff.fail()
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
quit_failed_initialization("Could not load saved Zephyr session, quitting!")
|
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,
|
0,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
backoff.succeed()
|
|
||||||
return
|
|
||||||
except zephyr_ctypes.ZephyrError:
|
except zephyr_ctypes.ZephyrError:
|
||||||
# Probably a SERVNAK from the zephyr server, but log the
|
# Probably a SERVNAK from the zephyr server, but log the
|
||||||
# traceback just in case it's something else
|
# traceback just in case it's something else
|
||||||
logger.exception("Error subscribing to personals (retrying). Traceback:")
|
logger.exception("Error subscribing to personals (retrying). Traceback:")
|
||||||
backoff.fail()
|
backoff.fail()
|
||||||
|
else:
|
||||||
|
backoff.succeed()
|
||||||
|
return
|
||||||
|
|
||||||
quit_failed_initialization("Could not subscribe to personals, quitting!")
|
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:
|
def is_float(value: Any) -> bool:
|
||||||
try:
|
try:
|
||||||
float(value)
|
float(value)
|
||||||
return True
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
# Rounds the number 'x' to 'digits' significant digits.
|
# Rounds the number 'x' to 'digits' significant digits.
|
||||||
# A normal 'round()' would round the number to an absolute amount of
|
# A normal 'round()' would round the number to an absolute amount of
|
||||||
|
|
|
@ -28,10 +28,10 @@ class TriviaQuizHandler:
|
||||||
if query == "new":
|
if query == "new":
|
||||||
try:
|
try:
|
||||||
start_new_quiz(message, bot_handler)
|
start_new_quiz(message, bot_handler)
|
||||||
return
|
|
||||||
except NotAvailableError:
|
except NotAvailableError:
|
||||||
bot_response = "Uh-Oh! Trivia service is down."
|
bot_response = "Uh-Oh! Trivia service is down."
|
||||||
bot_handler.send_reply(message, bot_response)
|
bot_handler.send_reply(message, bot_response)
|
||||||
|
|
||||||
return
|
return
|
||||||
elif query.startswith("answer"):
|
elif query.startswith("answer"):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Reference in a new issue