Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
ruff: Fix UP032 Use f-string instead of `format` call.
Anders Kaseorge932e2ce52a4
diff --git a/scripts/lib/unpack-zulip b/scripts/lib/unpack-zulipindex b9d458817a1..1102e3fd1bd 100755--- a/scripts/lib/unpack-zulip+++ b/scripts/lib/unpack-zulip@@ -36,7 +36,7 @@ current_version = version.ZULIP_VERSIONif is_invalid_upgrade(current_version, new_version):print(FAIL + "Your current version is very old. Please first upgrade to version "- "1.4.3 and then upgrade to {}.".format(new_version) + ENDC+ f"1.4.3 and then upgrade to {new_version}." + ENDC)shutil.rmtree(extract_path)sys.exit(1)diff --git a/tools/droplets/add_mentor.py b/tools/droplets/add_mentor.pyindex e11986e01ed..6f113ec79ad 100644--- a/tools/droplets/add_mentor.py+++ b/tools/droplets/add_mentor.py@@ -52,7 +52,7 @@ if __name__ == "__main__":if args.remove:remove_re = re.compile(- "#<{0}>{{{{.+}}}}<{0}>(\n)?".format(args.username), re.DOTALL | re.MULTILINE+ rf"#<{args.username}>{{{{.+}}}}<{args.username}>(\n)?", re.DOTALL | re.MULTILINE)with open(authorized_keys, "r+") as f:diff --git a/tools/droplets/create.py b/tools/droplets/create.pyindex c9e0427ca4c..64aa03d347a 100644--- a/tools/droplets/create.py+++ b/tools/droplets/create.py@@ -97,8 +97,8 @@ def assert_droplet_does_not_exist(my_token: str, droplet_name: str, recreate: boif droplet.name.lower() == droplet_name:if not recreate:print(- "Droplet {} already exists. Pass --recreate if you "- "need to recreate the droplet.".format(droplet_name)+ f"Droplet {droplet_name} already exists. Pass --recreate if you "+ "need to recreate the droplet.")sys.exit(1)else:@@ -251,8 +251,8 @@ def create_dns_record(my_token: str, record_name: str, ipv4: str, ipv6: str) ->def print_dev_droplet_instructions(username: str, droplet_domain_name: str) -> None:print(- """-COMPLETE! Droplet for GitHub user {0} is available at {1}.+ f"""+COMPLETE! Droplet for GitHub user {username} is available at {droplet_domain_name}.Instructions for use are below. (copy and paste to the user)@@ -260,16 +260,14 @@ Instructions for use are below. (copy and paste to the user)Your remote Zulip dev server has been created!- Connect to your server by running- `ssh zulipdev@{1}` on the command line+ `ssh zulipdev@{droplet_domain_name}` on the command line(Terminal for macOS and Linux, Bash for Git on Windows).- There is no password; your account is configured to use your SSH keys.- Once you log in, you should see `(zulip-py3-venv) ~$`.- To start the dev server, `cd zulip` and then run `./tools/run-dev`.- While the dev server is running, you can see the Zulip server in your browser at- http://{1}:9991.-""".format(- username, droplet_domain_name- )+ http://{droplet_domain_name}:9991.+""")print(diff --git a/tools/generate-integration-docs-screenshot b/tools/generate-integration-docs-screenshotindex 9acc395fd34..52e761fd7e6 100755--- a/tools/generate-integration-docs-screenshot+++ b/tools/generate-integration-docs-screenshot@@ -130,8 +130,8 @@ def custom_headers(headers_json: str) -> Dict[str, str]:return orjson.loads(headers_json)except orjson.JSONDecodeError as ve:raise argparse.ArgumentTypeError(- "Encountered an error while attempting to parse custom headers: {}\n"- "Note: all strings must be enclosed within \"\" instead of ''".format(ve)+ f"Encountered an error while attempting to parse custom headers: {ve}\n"+ "Note: all strings must be enclosed within \"\" instead of ''")@@ -156,10 +156,8 @@ def send_bot_mock_message(client.send_message(request)except KeyError:print(- "{} contains invalid configuration. "- 'Fields "subject" and "body" are required for non-webhook integrations.'.format(- fixture_path- )+ f"{fixture_path} contains invalid configuration. "+ 'Fields "subject" and "body" are required for non-webhook integrations.')sys.exit(1)diff --git a/zerver/lib/bot_config.py b/zerver/lib/bot_config.pyindex d1097e05e65..aa3a0e97089 100644--- a/zerver/lib/bot_config.py+++ b/zerver/lib/bot_config.py@@ -55,10 +55,8 @@ def set_bot_config(bot_profile: UserProfile, key: str, value: str) -> None:new_config_size = old_config_size + (new_entry_size - old_entry_size)if new_config_size > config_size_limit:raise ConfigError(- "Cannot store configuration. Request would require {} characters. "- "The current configuration size limit is {} characters.".format(- new_config_size, config_size_limit- )+ f"Cannot store configuration. Request would require {new_config_size} characters. "+ f"The current configuration size limit is {config_size_limit} characters.")obj, created = BotConfigData.objects.get_or_create(bot_profile=bot_profile, key=key, defaults={"value": value}diff --git a/zerver/lib/zcommand.py b/zerver/lib/zcommand.pyindex e29335499b6..a92b40a301f 100644--- a/zerver/lib/zcommand.py+++ b/zerver/lib/zcommand.py@@ -11,13 +11,7 @@ def process_zcommands(content: str, user_profile: UserProfile) -> Dict[str, Any]def change_mode_setting(setting_name: str, switch_command: str, setting: str, setting_value: int) -> str:- msg = (- "Changed to {setting_name}! To revert "- "{setting_name}, type `/{switch_command}`.".format(- setting_name=setting_name,- switch_command=switch_command,- )- )+ msg = f"Changed to {setting_name}! To revert {setting_name}, type `/{switch_command}`."do_change_user_setting(user_profile=user_profile,setting_name=setting,diff --git a/zerver/management/commands/send_webhook_fixture_message.py b/zerver/management/commands/send_webhook_fixture_message.pyindex 609b6483731..5f8524dce77 100644--- a/zerver/management/commands/send_webhook_fixture_message.py+++ b/zerver/management/commands/send_webhook_fixture_message.py@@ -56,8 +56,8 @@ approach shown above.custom_headers_dict = orjson.loads(custom_headers)except orjson.JSONDecodeError as ve:raise CommandError(- "Encountered an error while attempting to parse custom headers: {}\n"- "Note: all strings must be enclosed within \"\" instead of ''".format(ve)+ f"Encountered an error while attempting to parse custom headers: {ve}\n"+ "Note: all strings must be enclosed within \"\" instead of ''")return standardize_headers(custom_headers_dict)diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.pyindex c6c37a2d5f6..73a4298f11b 100644--- a/zerver/tests/test_auth_backends.py+++ b/zerver/tests/test_auth_backends.py@@ -1719,9 +1719,9 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase, ABC):self.assertEqual(result.status_code, 200)self.assert_in_response('action="/register/"', result)self.assert_in_response(- "Your email address, {}, is not "+ f"Your email address, {email}, is not ""in one of the domains that are allowed to register "- "for accounts in this organization.".format(email),+ "for accounts in this organization.",result,)diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.pyindex 1459e378763..1d06850df3e 100644--- a/zerver/tests/test_markdown.py+++ b/zerver/tests/test_markdown.py@@ -2543,12 +2543,12 @@ class MarkdownTest(ZulipTestCase):render_markdown(msg, content).rendered_content,"<p>Look to "'<a class="stream" '- 'data-stream-id="{denmark.id}" '- 'href="/#narrow/stream/{denmark.id}-Denmark">#{denmark.name}</a> and '+ f'data-stream-id="{denmark.id}" '+ f'href="/#narrow/stream/{denmark.id}-Denmark">#{denmark.name}</a> and ''<a class="stream" '- 'data-stream-id="{scotland.id}" '- 'href="/#narrow/stream/{scotland.id}-Scotland">#{scotland.name}</a>, '- "there something</p>".format(denmark=denmark, scotland=scotland),+ f'data-stream-id="{scotland.id}" '+ f'href="/#narrow/stream/{scotland.id}-Scotland">#{scotland.name}</a>, '+ "there something</p>",)def test_stream_case_sensitivity(self) -> None:@@ -2622,14 +2622,14 @@ class MarkdownTest(ZulipTestCase):self.assertEqual(render_markdown(msg, content).rendered_content,"<p>This has two links: "- '<a class="stream-topic" data-stream-id="{denmark.id}" '- 'href="/#narrow/stream/{denmark.id}-{denmark.name}/topic/some.20topic">'- "#{denmark.name} > some topic</a>"+ f'<a class="stream-topic" data-stream-id="{denmark.id}" '+ f'href="/#narrow/stream/{denmark.id}-{denmark.name}/topic/some.20topic">'+ f"#{denmark.name} > some topic</a>"" and "- '<a class="stream-topic" data-stream-id="{scotland.id}" '- 'href="/#narrow/stream/{scotland.id}-{scotland.name}/topic/other.20topic">'- "#{scotland.name} > other topic</a>"- ".</p>".format(denmark=denmark, scotland=scotland),+ f'<a class="stream-topic" data-stream-id="{scotland.id}" '+ f'href="/#narrow/stream/{scotland.id}-{scotland.name}/topic/other.20topic">'+ f"#{scotland.name} > other topic</a>"+ ".</p>",)def test_possible_stream_names(self) -> None:@@ -2652,10 +2652,7 @@ class MarkdownTest(ZulipTestCase):href = f"/#narrow/stream/{uni.id}-{quoted_name}"self.assertEqual(render_markdown(msg, content).rendered_content,- '<p><a class="stream" data-stream-id="{s.id}" href="{href}">#{s.name}</a></p>'.format(- s=uni,- href=href,- ),+ f'<p><a class="stream" data-stream-id="{uni.id}" href="{href}">#{uni.name}</a></p>',)def test_stream_atomic_string(self) -> None:diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.pyindex d4ffd76c788..ac2d92c3e54 100644--- a/zerver/tests/test_message_send.py+++ b/zerver/tests/test_message_send.py@@ -1501,8 +1501,7 @@ class StreamMessagesTest(ZulipTestCase):message = most_recent_message(receiving_user_profile)self.assertEqual(repr(message),- "<Message: Denmark / my topic / "- "<UserProfile: {} {!r}>>".format(sender.email, sender.realm),+ f"<Message: Denmark / my topic / <UserProfile: {sender.email} {sender.realm!r}>>",)def test_message_mentions(self) -> None:diff --git a/zerver/tests/test_retention.py b/zerver/tests/test_retention.pyindex c2ebea6dddc..51fbd04894e 100644--- a/zerver/tests/test_retention.py+++ b/zerver/tests/test_retention.py@@ -673,20 +673,16 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase):self._create_attachments()realm_id = get_realm("zulip").idhost = get_realm("zulip").host- body1 = """Some files here ...[zulip.txt](- http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt)- http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py ....- Some more.... http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py- """.format(- id=realm_id, host=host- )- body2 = """Some files here- http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt ...- http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/hello.txt ....- http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/new.py ....- """.format(- id=realm_id, host=host- )+ body1 = f"""Some files here ...[zulip.txt](+ http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt)+ http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py ....+ Some more.... http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py+ """+ body2 = f"""Some files here+ http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt ...+ http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/hello.txt ....+ http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/new.py ....+ """msg_ids = [self.send_personal_message(self.sender, self.recipient, body1),diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 48ab3e0bd5a..8b74f228887 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -342,7 +342,7 @@ class AddNewUserHistoryTest(ZulipTestCase):self.assertEqual(repr(message),"<Message: recip / / "- "<UserProfile: {} {!r}>>".format(user_profile.email, user_profile.realm),+ f"<UserProfile: {user_profile.email} {user_profile.realm!r}>>",)user_message = most_recent_usermessage(user_profile)diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.pyindex 29c51b8a7ed..8083240d814 100644--- a/zerver/tests/test_upload.py+++ b/zerver/tests/test_upload.py@@ -598,7 +598,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):self.subscribe(hamlet, "test")body = (f"[f1.txt](http://{host}/user_uploads/" + f1_path_id + ") "- "[f2.txt](http://{}/user_uploads/".format(host) + f2_path_id + ")"+ f"[f2.txt](http://{host}/user_uploads/" + f2_path_id + ")")msg_id = self.send_stream_message(hamlet, "test", body, "test")@@ -608,7 +608,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):new_body = (f"[f3.txt](http://{host}/user_uploads/" + f3_path_id + ") "- "[f2.txt](http://{}/user_uploads/".format(host) + f2_path_id + ")"+ f"[f2.txt](http://{host}/user_uploads/" + f2_path_id + ")")result = self.client_patch("/json/messages/" + str(msg_id),diff --git a/zerver/webhooks/front/view.py b/zerver/webhooks/front/view.pyindex 9384afc7de0..ba74429fa5c 100644--- a/zerver/webhooks/front/view.py+++ b/zerver/webhooks/front/view.py@@ -41,20 +41,16 @@ def get_target_name(payload: WildValue) -> str:def get_inbound_message_body(payload: WildValue) -> str:link, outbox, inbox, subject = get_message_data(payload)return (- "[Inbound message]({link}) from **{outbox}** to **{inbox}**:\n"- "```quote\n*Subject*: {subject}\n```".format(- link=link, outbox=outbox, inbox=inbox, subject=subject- )+ f"[Inbound message]({link}) from **{outbox}** to **{inbox}**:\n"+ f"```quote\n*Subject*: {subject}\n```")def get_outbound_message_body(payload: WildValue) -> str:link, outbox, inbox, subject = get_message_data(payload)return (- "[Outbound message]({link}) from **{inbox}** to **{outbox}**:\n"- "```quote\n*Subject*: {subject}\n```".format(- link=link, inbox=inbox, outbox=outbox, subject=subject- )+ f"[Outbound message]({link}) from **{inbox}** to **{outbox}**:\n"+ f"```quote\n*Subject*: {subject}\n```")