Skip to content

Commit fcd4fe3

Browse files
committed
ruff: Fix UP031 Use format specifiers instead of percent format.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent ddccf0e commit fcd4fe3

File tree

11 files changed

+37
-50
lines changed

11 files changed

+37
-50
lines changed

zulip/integrations/bridge_with_irc/irc_mirror_backend.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ def check_subscription_or_die(self) -> None:
5151
subs = [s["name"] for s in resp["subscriptions"]]
5252
if self.stream not in subs:
5353
print(
54-
"The bot is not yet subscribed to stream '%s'. Please subscribe the bot to the stream first."
55-
% (self.stream,)
54+
f"The bot is not yet subscribed to stream '{self.stream}'. Please subscribe the bot to the stream first."
5655
)
5756
exit(1)
5857

zulip/integrations/bridge_with_matrix/matrix_bridge.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async def create(
9191
return matrix_to_zulip
9292

9393
async def _matrix_to_zulip(self, room: nio.MatrixRoom, event: nio.Event) -> None:
94-
logging.debug("_matrix_to_zulip; room %s, event: %s" % (str(room.room_id), str(event)))
94+
logging.debug(f"_matrix_to_zulip; room {str(room.room_id)}, event: {str(event)}")
9595

9696
# We do this to identify the messages generated from Zulip -> Matrix
9797
# and we make sure we don't forward it again to the Zulip stream.
@@ -253,7 +253,7 @@ def _matrix_send(self, **kwargs: Any) -> None:
253253
raise Bridge_FatalMatrixException(str(result))
254254

255255
def _zulip_to_matrix(self, msg: Dict[str, Any]) -> None:
256-
logging.debug("_zulip_to_matrix; msg: %s" % (str(msg),))
256+
logging.debug(f"_zulip_to_matrix; msg: {str(msg)}")
257257

258258
room_id: Optional[str] = self.get_matrix_room_for_zulip_message(msg)
259259
if room_id is None:
@@ -485,8 +485,7 @@ def read_configuration(config_file: str) -> Dict[str, Dict[str, Any]]:
485485
if section.startswith("additional_bridge"):
486486
if section_keys != bridge_key_set:
487487
raise Bridge_ConfigException(
488-
"Please ensure the bridge configuration section %s contain the following keys: %s."
489-
% (section, str(bridge_key_set))
488+
f"Please ensure the bridge configuration section {section} contain the following keys: {str(bridge_key_set)}."
490489
)
491490

492491
zulip_target = (section_config["stream"], section_config["topic"])
@@ -519,7 +518,7 @@ def read_configuration(config_file: str) -> Dict[str, Dict[str, Any]]:
519518
for key in zulip_bridge_key_set:
520519
first_bridge[key] = section_config[key]
521520
else:
522-
logging.warning("Unknown section %s" % (section,))
521+
logging.warning(f"Unknown section {section}")
523522

524523
# Add the "first_bridge" to the bridges.
525524
zulip_target = (first_bridge["stream"], first_bridge["topic"])

zulip/integrations/codebase/zulip_codebase_mirror

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ def handle_event(event: Dict[str, Any]) -> None:
147147
if assignee is None:
148148
assignee = "no one"
149149
subject = f"#{num}: {name}"
150-
content = (
151-
"""%s created a new ticket [#%s](%s) priority **%s** assigned to %s:\n\n~~~ quote\n %s"""
152-
% (actor_name, num, url, priority, assignee, name)
153-
)
150+
content = f"""{actor_name} created a new ticket [#{num}]({url}) priority **{priority}** assigned to {assignee}:\n\n~~~ quote\n {name}"""
154151
elif event_type == "ticketing_note":
155152
stream = config.ZULIP_TICKETS_STREAM_NAME
156153

@@ -225,8 +222,7 @@ def handle_event(event: Dict[str, Any]) -> None:
225222
)
226223
end_ref_url = make_url(f"projects/{project_link}/repositories/{repo_link}/commit/{end_ref}")
227224
between_url = make_url(
228-
"projects/%s/repositories/%s/compare/%s...%s"
229-
% (project_link, repo_link, start_ref, end_ref)
225+
f"projects/{project_link}/repositories/{repo_link}/compare/{start_ref}...{end_ref}"
230226
)
231227

232228
subject = f"Deployment to {environment}"

zulip/integrations/zephyr/check-mirroring

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ for key, (stream, test) in zhkeys.items():
250250
server_failure_again = send_zephyr(zwrite_args, str(new_key))
251251
if server_failure_again:
252252
logging.error(
253-
"Zephyr server failure twice in a row on keys %s and %s! Aborting."
254-
% (key, new_key)
253+
f"Zephyr server failure twice in a row on keys {key} and {new_key}! Aborting."
255254
)
256255
print_status_and_exit(1)
257256
else:

zulip/integrations/zephyr/zephyr_mirror_backend.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,9 @@ def zephyr_to_zulip(options: optparse.Values) -> None:
669669
if "instance" in zeph:
670670
zeph["subject"] = zeph["instance"]
671671
logger.info(
672-
"sending saved message to %s from %s..."
673-
% (zeph.get("stream", zeph.get("recipient")), zeph["sender"])
672+
"sending saved message to {} from {}...".format(
673+
zeph.get("stream", zeph.get("recipient")), zeph["sender"]
674+
)
674675
)
675676
send_zulip(zulip_client, zeph)
676677
except Exception:
@@ -831,16 +832,15 @@ def forward_to_zephyr(message: Dict[str, Any], zulip_client: zulip.Client) -> No
831832
if result is None:
832833
send_error_zulip(
833834
zulip_client,
834-
"""%s
835+
f"""{support_heading}
835836
836837
Your Zulip-Zephyr mirror bot was unable to forward that last message \
837838
from Zulip to Zephyr because you were sending to a zcrypted Zephyr \
838839
class and your mirroring bot does not have access to the relevant \
839840
key (perhaps because your AFS tokens expired). That means that while \
840841
Zulip users (like you) received it, Zephyr users did not.
841842
842-
%s"""
843-
% (support_heading, support_closing),
843+
{support_closing}""",
844844
)
845845
return
846846

@@ -858,15 +858,14 @@ class and your mirroring bot does not have access to the relevant \
858858
elif code == 0:
859859
send_error_zulip(
860860
zulip_client,
861-
"""%s
861+
f"""{support_heading}
862862
863863
Your last message was successfully mirrored to zephyr, but zwrite \
864864
returned the following warning:
865865
866-
%s
866+
{stderr}
867867
868-
%s"""
869-
% (support_heading, stderr, support_closing),
868+
{support_closing}""",
870869
)
871870
return
872871
elif code != 0 and (
@@ -881,16 +880,15 @@ class and your mirroring bot does not have access to the relevant \
881880
return
882881
send_error_zulip(
883882
zulip_client,
884-
"""%s
883+
f"""{support_heading}
885884
886885
Your last message was forwarded from Zulip to Zephyr unauthenticated, \
887886
because your Kerberos tickets have expired. It was sent successfully, \
888887
but please renew your Kerberos tickets in the screen session where you \
889888
are running the Zulip-Zephyr mirroring bot, so we can send \
890889
authenticated Zephyr messages for you again.
891890
892-
%s"""
893-
% (support_heading, support_closing),
891+
{support_closing}""",
894892
)
895893
return
896894

@@ -899,16 +897,15 @@ class and your mirroring bot does not have access to the relevant \
899897
# but regardless, we should just notify the user.
900898
send_error_zulip(
901899
zulip_client,
902-
"""%s
900+
f"""{support_heading}
903901
904902
Your Zulip-Zephyr mirror bot was unable to forward that last message \
905903
from Zulip to Zephyr. That means that while Zulip users (like you) \
906904
received it, Zephyr users did not. The error message from zwrite was:
907905
908-
%s
906+
{stderr}
909907
910-
%s"""
911-
% (support_heading, stderr, support_closing),
908+
{support_closing}""",
912909
)
913910
return
914911

@@ -1279,11 +1276,10 @@ def die_gracefully(signal: int, frame: Optional[FrameType]) -> None:
12791276
"\n"
12801277
+ "\n".join(
12811278
textwrap.wrap(
1282-
"""\
1279+
f"""\
12831280
Could not find API key file.
1284-
You need to either place your api key file at %s,
1281+
You need to either place your api key file at {options.api_key_file},
12851282
or specify the --api-key-file option."""
1286-
% (options.api_key_file,)
12871283
)
12881284
)
12891285
)

zulip/zulip/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,7 @@ def __init__(
496496
if client_cert is None:
497497
if client_cert_key is not None:
498498
raise ConfigNotFoundError(
499-
"client cert key '%s' specified, but no client cert public part provided"
500-
% (client_cert_key,)
499+
f"client cert key '{client_cert_key}' specified, but no client cert public part provided"
501500
)
502501
else: # we have a client cert
503502
if not os.path.isfile(client_cert):
@@ -609,8 +608,7 @@ def error_retry(error_string: str) -> bool:
609608
if self.verbose:
610609
if not query_state["had_error_retry"]:
611610
sys.stdout.write(
612-
"zulip API(%s): connection error%s -- retrying."
613-
% (
611+
"zulip API({}): connection error{} -- retrying.".format(
614612
url.split(API_VERSTRING, 2)[0],
615613
error_string,
616614
)

zulip/zulip/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ def send_message(recipients: List[str], stream: str, subject: str, message: str)
8484

8585
if message_data["type"] == "stream":
8686
log.info(
87-
'Sending message to stream "%s", subject "%s"... '
88-
% (message_data["to"], message_data["subject"])
87+
'Sending message to stream "{}", subject "{}"... '.format(
88+
message_data["to"], message_data["subject"]
89+
)
8990
)
9091
else:
9192
log.info("Sending message to %s... " % message_data["to"])

zulip/zulip/send.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ def do_send_message(client: zulip.Client, message_data: Dict[str, Any]) -> bool:
1818

1919
if message_data["type"] == "stream":
2020
log.info(
21-
'Sending message to stream "%s", subject "%s"... '
22-
% (message_data["to"], message_data["subject"])
21+
'Sending message to stream "{}", subject "{}"... '.format(
22+
message_data["to"], message_data["subject"]
23+
)
2324
)
2425
else:
2526
log.info("Sending message to {}... ".format(message_data["to"]))

zulip_bots/zulip_bots/bots/giphy/giphy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ def get_bot_giphy_response(
9696
"let's try again later! :grin:"
9797
)
9898
except GiphyNoResultException:
99-
return 'Sorry, I don\'t have a GIF for "%s"! ' ":astonished:" % (keyword,)
99+
return f'Sorry, I don\'t have a GIF for "{keyword}"! ' ":astonished:"
100100
return (
101-
"[Click to enlarge](%s)"
102-
"[](/static/images/interactive-bot/giphy/powered-by-giphy.png)" % (gif_url,)
101+
f"[Click to enlarge]({gif_url})"
102+
"[](/static/images/interactive-bot/giphy/powered-by-giphy.png)"
103103
)
104104

105105

zulip_bots/zulip_bots/bots/youtube/youtube.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ def get_bot_response(
123123
elif len(video_list) == 1:
124124
return (
125125
reply
126-
+ "\n%s - [Watch now](https://www.youtube.com/watch?v=%s)"
127-
% (video_list[0][0], video_list[0][1])
126+
+ f"\n{video_list[0][0]} - [Watch now](https://www.youtube.com/watch?v={video_list[0][1]})"
128127
).strip()
129128

130129
for title, id in video_list:

0 commit comments

Comments
 (0)