ruff: Fix G001 Logging statement uses str.format.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-28 15:50:08 -07:00
parent 1ccb5db6ef
commit e537bbefdf
5 changed files with 20 additions and 26 deletions

View file

@ -262,9 +262,9 @@ def handle_event(event: Dict[str, Any]) -> None:
{"type": "stream", "to": stream, "subject": subject, "content": content}
)
if res["result"] == "success":
logging.info("Successfully sent Zulip with id: {}".format(res["id"]))
logging.info("Successfully sent Zulip with id: %s", res["id"])
else:
logging.warning("Failed to send Zulip: {} {}".format(res["result"], res["msg"]))
logging.warning("Failed to send Zulip: %s %s", res["result"], res["msg"])
# the main run loop for this mirror script

View file

@ -669,9 +669,9 @@ def zephyr_to_zulip(options: optparse.Values) -> None:
if "instance" in zeph:
zeph["subject"] = zeph["instance"]
logger.info(
"sending saved message to {} from {}...".format(
zeph.get("stream", zeph.get("recipient")), zeph["sender"]
)
"sending saved message to %s from %s...",
zeph.get("stream", zeph.get("recipient")),
zeph["sender"],
)
send_zulip(zulip_client, zeph)
except Exception:
@ -711,9 +711,7 @@ def send_zephyr(zwrite_args: List[str], content: str) -> Tuple[int, str]:
if stdout:
logger.info("stdout: " + stdout)
elif stderr:
logger.warning(
"zwrite command '{}' printed the following warning:".format(" ".join(zwrite_args))
)
logger.warning("zwrite command %r printed the following warning:", zwrite_args)
if stderr:
logger.warning("stderr: " + stderr)
return (p.returncode, stderr)
@ -929,7 +927,7 @@ def maybe_forward_to_zephyr(message: Dict[str, Any], zulip_client: zulip.Client)
timestamp_now = int(time.time())
if float(message["timestamp"]) < timestamp_now - 15:
logger.warning(
"Skipping out of order message: {} < {}".format(message["timestamp"], timestamp_now)
"Skipping out of order message: %s < %s", message["timestamp"], timestamp_now
)
return
try:
@ -1018,7 +1016,7 @@ def add_zulip_subscriptions(verbose: bool) -> None:
authorization_errors_fatal=False,
)
if res.get("result") != "success":
logger.error("Error subscribing to streams:\n{}".format(res["msg"]))
logger.error("Error subscribing to streams:\n%s", res["msg"])
return
already = res.get("already_subscribed")
@ -1026,13 +1024,9 @@ def add_zulip_subscriptions(verbose: bool) -> None:
unauthorized = res.get("unauthorized")
if verbose:
if already is not None and len(already) > 0:
logger.info(
"\nAlready subscribed to: {}".format(", ".join(list(already.values())[0]))
)
logger.info("\nAlready subscribed to: %s", ", ".join(list(already.values())[0]))
if new is not None and len(new) > 0:
logger.info(
"\nSuccessfully subscribed to: {}".format(", ".join(list(new.values())[0]))
)
logger.info("\nSuccessfully subscribed to: %s", ", ".join(list(new.values())[0]))
if unauthorized is not None and len(unauthorized) > 0:
logger.info(
"\n"

View file

@ -84,9 +84,9 @@ def send_message(recipients: List[str], stream: str, subject: str, message: str)
if message_data["type"] == "stream":
log.info(
'Sending message to stream "{}", subject "{}"... '.format(
message_data["to"], message_data["subject"]
)
"Sending message to stream %r, subject %r... ",
message_data["to"],
message_data["subject"],
)
else:
log.info("Sending message to %s... " % message_data["to"])

View file

@ -18,12 +18,12 @@ def do_send_message(client: zulip.Client, message_data: Dict[str, Any]) -> bool:
if message_data["type"] == "stream":
log.info(
'Sending message to stream "{}", subject "{}"... '.format(
message_data["to"], message_data["subject"]
)
"Sending message to stream %r, subject %r... ",
message_data["to"],
message_data["subject"],
)
else:
log.info("Sending message to {}... ".format(message_data["to"]))
log.info("Sending message to %s... ", message_data["to"])
response = client.send_message(message_data)
if response["result"] == "success":
log.info("Message sent.")

View file

@ -53,9 +53,9 @@ def read_config_from_env_vars(bot_name: Optional[str] = None) -> Dict[str, Dict[
first_bot_name = list(env_config.keys())[0]
bots_config[bot_name] = env_config[first_bot_name]
logging.warning(
"First bot name in the config list was changed from '{}' to '{}'".format(
first_bot_name, bot_name
)
"First bot name in the config list was changed from %r to %r",
first_bot_name,
bot_name,
)
else:
bots_config = dict(env_config)