Skip to content

Commit ddccf0e

Browse files
committed
ruff: Fix UP032 Use f-string instead of format call.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent a49add3 commit ddccf0e

File tree

24 files changed

+88
-187
lines changed

24 files changed

+88
-187
lines changed

tools/deploy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ def pack(options: argparse.Namespace) -> None:
5555
zip_file.write(options.config, "zuliprc")
5656
# Pack the config file for the botfarm.
5757
bot_config = textwrap.dedent(
58-
"""\
58+
f"""\
5959
[deploy]
60-
bot={}
60+
bot={options.main}
6161
zuliprc=zuliprc
62-
""".format(options.main)
62+
"""
6363
)
6464
zip_file.writestr("config.ini", bot_config)
6565
zip_file.close()

tools/provision

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,10 @@ the Python version this command is executed with."""
5858
return_code = subprocess.call([options.python_interpreter, "-m", "venv", venv_dir])
5959
except OSError:
6060
print(
61-
"{red}Installation with venv failed. Probable errors are: "
61+
f"{red}Installation with venv failed. Probable errors are: "
6262
"You are on Ubuntu and you haven't installed python3-venv,"
6363
"or you are running an unsupported python version"
64-
"or python is not installed properly{end_format}".format(
65-
red=red, end_format=end_format
66-
)
64+
f"or python is not installed properly{end_format}"
6765
)
6866
sys.exit(1)
6967
raise

zulip/integrations/bridge_with_irc/irc-mirror.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
traceback.print_exc()
4848
print(
4949
"You have unsatisfied dependencies. Install all missing dependencies with "
50-
"{} --provision".format(sys.argv[0])
50+
f"{sys.argv[0]} --provision"
5151
)
5252
sys.exit(1)
5353

zulip/integrations/bridge_with_matrix/test_matrix.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,7 @@ def test_write_sample_config_from_zuliprc(self) -> None:
118118
)
119119
self.assertEqual(
120120
output_lines,
121-
[
122-
"Wrote sample configuration to '{}' using zuliprc file '{}'".format(
123-
path, zuliprc_path
124-
)
125-
],
121+
[f"Wrote sample configuration to '{path}' using zuliprc file '{zuliprc_path}'"],
126122
)
127123

128124
with open(path) as sample_file:
@@ -143,11 +139,7 @@ def test_detect_zuliprc_does_not_exist(self) -> None:
143139
)
144140
self.assertEqual(
145141
output_lines,
146-
[
147-
"Could not write sample config: Zuliprc file '{}' does not exist.".format(
148-
zuliprc_path
149-
)
150-
],
142+
[f"Could not write sample config: Zuliprc file '{zuliprc_path}' does not exist."],
151143
)
152144

153145
def test_parse_multiple_bridges(self) -> None:

zulip/integrations/codebase/zulip_codebase_mirror

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ def handle_event(event: Dict[str, Any]) -> None:
173173

174174
if "status_id" in changes:
175175
status_change = changes.get("status_id")
176-
content += "Status changed from **{}** to **{}**\n\n".format(
177-
status_change[0],
178-
status_change[1],
179-
)
176+
content += f"Status changed from **{status_change[0]}** to **{status_change[1]}**\n\n"
180177
elif event_type == "ticketing_milestone":
181178
stream = config.ZULIP_TICKETS_STREAM_NAME
182179

@@ -199,12 +196,7 @@ def handle_event(event: Dict[str, Any]) -> None:
199196
url = make_url(f"projects/{project_link}/repositories/{repo_link}/commit/{commit}")
200197

201198
subject = f"{actor_name} commented on {commit}"
202-
content = "{} commented on [{}]({}):\n\n~~~ quote\n{}".format(
203-
actor_name,
204-
commit,
205-
url,
206-
comment,
207-
)
199+
content = f"{actor_name} commented on [{commit}]({url}):\n\n~~~ quote\n{comment}"
208200
else:
209201
# Otherwise, this is a Discussion item, and handle it
210202
subj = raw_props.get("subject")

zulip/integrations/hg/zulip_changegroup.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,12 @@ def format_summary_line(
3030

3131
if web_url:
3232
shortlog_base_url = web_url.rstrip("/") + "/shortlog/"
33-
summary_url = "{shortlog}{tip}?revcount={revcount}".format(
34-
shortlog=shortlog_base_url, tip=tip - 1, revcount=revcount
35-
)
36-
formatted_commit_count = "[{revcount} commit{s}]({url})".format(
37-
revcount=revcount, s=plural, url=summary_url
38-
)
33+
summary_url = f"{shortlog_base_url}{tip - 1}?revcount={revcount}"
34+
formatted_commit_count = f"[{revcount} commit{plural}]({summary_url})"
3935
else:
4036
formatted_commit_count = f"{revcount} commit{plural}"
4137

42-
return "**{user}** pushed {commits} to **{branch}** (`{tip}:{node}`):\n\n".format(
43-
user=user, commits=formatted_commit_count, branch=branch, tip=tip, node=node[:12]
44-
)
38+
return f"**{user}** pushed {formatted_commit_count} to **{branch}** (`{tip}:{node[:12]}`):\n\n"
4539

4640

4741
def format_commit_lines(web_url: str, repo: repo, base: int, tip: int) -> str:

zulip/integrations/perforce/zulip_change-commit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777

7878
if p4web is not None:
7979
# linkify the change number
80-
change = "[{change}]({p4web}/{change}?ac=10)".format(p4web=p4web, change=change)
80+
change = f"[{change}]({p4web}/{change}?ac=10)"
8181

8282
message = """**{user}** committed revision @{change} to `{path}`.
8383

zulip/integrations/rss/rss-bot

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,7 @@ def send_zulip(entry: Any, feed_name: str) -> Dict[str, Any]:
177177
if opts.unwrap:
178178
body = unwrap_text(body)
179179

180-
content = "**[{}]({})**\n{}\n{}".format(
181-
entry.title,
182-
entry.link,
183-
strip_tags(body),
184-
entry.link,
185-
)
180+
content = f"**[{entry.title}]({entry.link})**\n{strip_tags(body)}\n{entry.link}"
186181

187182
if opts.math:
188183
content = content.replace("$", "$$")

zulip/integrations/zephyr/zephyr_mirror_backend.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,7 @@ def forward_to_zephyr(message: Dict[str, Any], zulip_client: zulip.Client) -> No
793793
# Forward messages sent to '(instance "WHITESPACE")' back to the
794794
# appropriate WHITESPACE instance for bidirectional mirroring
795795
instance = match_whitespace_instance.group(1)
796-
elif instance == f"instance {zephyr_class}" or instance == "test instance {}".format(
797-
zephyr_class,
798-
):
796+
elif instance == f"instance {zephyr_class}" or instance == f"test instance {zephyr_class}":
799797
# Forward messages to e.g. -c -i white-magic back from the
800798
# place we forward them to
801799
if instance.startswith("test"):

zulip/tests/test_default_arguments.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ def test_config_path_with_tilde(self, mock_os_path_exists: bool) -> None:
4141
expanded_test_path = os.path.abspath(os.path.expanduser(test_path))
4242
self.assertEqual(
4343
str(cm.exception),
44-
"api_key or email not specified and " "file {} does not exist".format(
45-
expanded_test_path
46-
),
44+
"api_key or email not specified and " f"file {expanded_test_path} does not exist",
4745
)
4846

4947

0 commit comments

Comments
 (0)