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 Kaseorga1a341f0ae61
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex 84addc5af5c..af87512ca0e 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -2240,7 +2240,7 @@ class BillingSession(ABC):# Should do this in JavaScript, using the user's time zoneif plan.is_free_trial() or downgrade_at_end_of_free_trial:assert plan.next_invoice_date is not None- renewal_date = "{dt:%B} {dt.day}, {dt.year}".format(dt=plan.next_invoice_date)+ renewal_date = f"{plan.next_invoice_date:%B} {plan.next_invoice_date.day}, {plan.next_invoice_date.year}"else:renewal_date = "{dt:%B} {dt.day}, {dt.year}".format(dt=start_of_next_billing_cycle(plan, now)diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.pyindex 1287fa354bc..fdfe5206ede 100755--- a/scripts/lib/zulip_tools.py+++ b/scripts/lib/zulip_tools.py@@ -563,10 +563,10 @@ def assert_not_running_as_root() -> None:if is_root():pwent = get_zulip_pwent()msg = (- "{shortname} should not be run as root. Use `su {user}` to switch to the 'zulip'\n"- "user before rerunning this, or use \n su {user} -c '{name} ...'\n"+ f"{os.path.basename(script_name)} should not be run as root. Use `su {pwent.pw_name}` to switch to the 'zulip'\n"+ f"user before rerunning this, or use \n su {pwent.pw_name} -c '{script_name} ...'\n""to switch users and run this as a single command."- ).format(name=script_name, shortname=os.path.basename(script_name), user=pwent.pw_name)+ )print(msg)sys.exit(1)diff --git a/tools/lib/provision.py b/tools/lib/provision.pyindex 82d898164d6..154958b97fc 100755--- a/tools/lib/provision.py+++ b/tools/lib/provision.py@@ -45,9 +45,7 @@ with open("/proc/meminfo") as meminfo:ram_gb = float(ram_size) / 1024.0 / 1024.0if ram_gb < 1.5:print(- "You have insufficient RAM ({} GB) to run the Zulip development environment.".format(- round(ram_gb, 2)- )+ f"You have insufficient RAM ({round(ram_gb, 2)} GB) to run the Zulip development environment.")print("We recommend at least 2 GB of RAM, and require at least 1.5 GB.")sys.exit(1)diff --git a/zerver/actions/create_realm.py b/zerver/actions/create_realm.pyindex 8e264c157f9..affb079190e 100644--- a/zerver/actions/create_realm.py+++ b/zerver/actions/create_realm.py@@ -325,13 +325,7 @@ def do_create_realm(support_url = get_realm_support_url(realm)organization_type = get_org_type_display_name(realm.org_type)- message = "[{name}]({support_link}) ([{subdomain}]({realm_link})). Organization type: {type}".format(- name=realm.name,- subdomain=realm.display_subdomain,- realm_link=realm.uri,- support_link=support_url,- type=organization_type,- )+ message = f"[{realm.name}]({support_url}) ([{realm.display_subdomain}]({realm.uri})). Organization type: {organization_type}"topic_name = "new organizations"try:diff --git a/zerver/lib/bot_storage.py b/zerver/lib/bot_storage.pyindex 7b3a9163da6..0dccb96a2b7 100644--- a/zerver/lib/bot_storage.py+++ b/zerver/lib/bot_storage.py@@ -45,9 +45,7 @@ def set_bot_storage(bot_profile: UserProfile, entries: List[Tuple[str, str]]) ->new_storage_size = get_bot_storage_size(bot_profile) + storage_size_differenceif new_storage_size > storage_size_limit:raise StateError(- "Request exceeds storage limit by {} characters. The limit is {} characters.".format(- new_storage_size - storage_size_limit, storage_size_limit- )+ f"Request exceeds storage limit by {new_storage_size - storage_size_limit} characters. The limit is {storage_size_limit} characters.")else:for key, value in entries:diff --git a/zerver/lib/email_mirror.py b/zerver/lib/email_mirror.pyindex d29a65943e8..dd06f16330b 100644--- a/zerver/lib/email_mirror.py+++ b/zerver/lib/email_mirror.py@@ -205,9 +205,7 @@ def send_mm_reply_to_stream(message_content=body,)except JsonableError as error:- error_message = "Error sending message to stream {stream} via message notification email reply:\n{error}".format(- stream=stream.name, error=error.msg- )+ error_message = f"Error sending message to stream {stream.name} via message notification email reply:\n{error.msg}"internal_send_private_message(get_system_bot(settings.NOTIFICATION_BOT, user_profile.realm_id),user_profile,diff --git a/zerver/management/commands/deactivate_user.py b/zerver/management/commands/deactivate_user.pyindex 6234daa54c1..63f0f42ee88 100644--- a/zerver/management/commands/deactivate_user.py+++ b/zerver/management/commands/deactivate_user.py@@ -37,10 +37,7 @@ class Command(ZulipBaseCommand):print(session.expire_date, session.get_decoded())print("")print(- "{} has {} active bots that will also be deactivated.".format(- user_profile.delivery_email,- get_active_bots_owned_by_user(user_profile).count(),- )+ f"{user_profile.delivery_email} has {get_active_bots_owned_by_user(user_profile).count()} active bots that will also be deactivated.")if not options["for_real"]:diff --git a/zerver/management/commands/delete_user.py b/zerver/management/commands/delete_user.pyindex 9e32ed31df1..dff58d38804 100644--- a/zerver/management/commands/delete_user.py+++ b/zerver/management/commands/delete_user.py@@ -57,10 +57,7 @@ This will:for user_profile in user_profiles:print(- "{} has {} active bots that will be deactivated as a result of the user's deletion.".format(- user_profile.delivery_email,- get_active_bots_owned_by_user(user_profile).count(),- )+ f"{user_profile.delivery_email} has {get_active_bots_owned_by_user(user_profile).count()} active bots that will be deactivated as a result of the user's deletion.")if not options["for_real"]:diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.pyindex 9610ee77883..b50a511f247 100644--- a/zerver/tests/test_markdown.py+++ b/zerver/tests/test_markdown.py@@ -2875,9 +2875,7 @@ class MarkdownTest(ZulipTestCase):content = "#**Denmark**"self.assertEqual(render_message_markdown(msg, content).rendered_content,- '<p><a class="stream" data-stream-id="{d.id}" href="/#narrow/stream/{d.id}-Denmark">#{d.name}</a></p>'.format(- d=denmark,- ),+ f'<p><a class="stream" data-stream-id="{denmark.id}" href="/#narrow/stream/{denmark.id}-Denmark">#{denmark.name}</a></p>',)def test_invalid_stream_followed_by_valid_mention(self) -> None:@@ -2891,9 +2889,7 @@ class MarkdownTest(ZulipTestCase):content = "#**Invalid** and #**Denmark**"self.assertEqual(render_message_markdown(msg, content).rendered_content,- '<p>#<strong>Invalid</strong> and <a class="stream" data-stream-id="{d.id}" href="/#narrow/stream/{d.id}-Denmark">#{d.name}</a></p>'.format(- d=denmark,- ),+ f'<p>#<strong>Invalid</strong> and <a class="stream" data-stream-id="{denmark.id}" href="/#narrow/stream/{denmark.id}-Denmark">#{denmark.name}</a></p>',)def test_stream_multiple(self) -> None:@@ -2927,9 +2923,7 @@ class MarkdownTest(ZulipTestCase):content = "#**CaseSens**"self.assertEqual(render_message_markdown(msg, content).rendered_content,- '<p><a class="stream" data-stream-id="{s.id}" href="/#narrow/stream/{s.id}-{s.name}">#{s.name}</a></p>'.format(- s=case_sens,- ),+ f'<p><a class="stream" data-stream-id="{case_sens.id}" href="/#narrow/stream/{case_sens.id}-{case_sens.name}">#{case_sens.name}</a></p>',)def test_stream_case_sensitivity_nonmatching(self) -> None:@@ -2957,9 +2951,7 @@ class MarkdownTest(ZulipTestCase):content = "#**Denmark>some topic**"self.assertEqual(render_message_markdown(msg, content).rendered_content,- '<p><a class="stream-topic" data-stream-id="{d.id}" href="/#narrow/stream/{d.id}-Denmark/topic/some.20topic">#{d.name} > some topic</a></p>'.format(- d=denmark,- ),+ f'<p><a class="stream-topic" data-stream-id="{denmark.id}" href="/#narrow/stream/{denmark.id}-Denmark/topic/some.20topic">#{denmark.name} > some topic</a></p>',)def test_topic_atomic_string(self) -> None:@@ -2981,9 +2973,7 @@ class MarkdownTest(ZulipTestCase):content = "#**Denmark>#1234**"self.assertEqual(render_message_markdown(msg, content).rendered_content,- '<p><a class="stream-topic" data-stream-id="{d.id}" href="/#narrow/stream/{d.id}-Denmark/topic/.231234">#{d.name} > #1234</a></p>'.format(- d=denmark,- ),+ f'<p><a class="stream-topic" data-stream-id="{denmark.id}" href="/#narrow/stream/{denmark.id}-Denmark/topic/.231234">#{denmark.name} > #1234</a></p>',)def test_topic_multiple(self) -> None:@@ -3052,10 +3042,7 @@ class MarkdownTest(ZulipTestCase):href = f"/#narrow/stream/{stream.id}-Stream-.231234"self.assertEqual(render_message_markdown(msg, content).rendered_content,- '<p><a class="stream" data-stream-id="{s.id}" href="{href}">#{s.name}</a></p>'.format(- s=stream,- href=href,- ),+ f'<p><a class="stream" data-stream-id="{stream.id}" href="{href}">#{stream.name}</a></p>',)def test_stream_invalid(self) -> None:diff --git a/zerver/tests/test_retention.py b/zerver/tests/test_retention.pyindex 86cc15f0c01..2cb90a95a33 100644--- a/zerver/tests/test_retention.py+++ b/zerver/tests/test_retention.py@@ -194,10 +194,10 @@ class ArchiveMessagesTestingBase(RetentionTestingBase):self.subscribe(user_profile, "Denmark")body = ("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)+ f" [zulip.txt](http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt)"+ f" http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py.... Some"+ f" more.... http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py"+ )expired_message_id = self.send_stream_message(user_profile, "Denmark", body)actual_message_id = self.send_stream_message(user_profile, "Denmark", body)@@ -754,13 +754,13 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase):self._create_attachments()realm_id = get_realm("zulip").idhost = get_realm("zulip").host- body = """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 ...- http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/new.py ....- http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/hello.txt ....- """.format(id=realm_id, host=host)+ body = 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 ...+ http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/new.py ....+ http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/hello.txt ....+ """msg_id = self.send_personal_message(self.sender, self.recipient, body)# Simulate a reply with the same contents.@@ -813,13 +813,13 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase):self._create_attachments()realm_id = get_realm("zulip").idhost = get_realm("zulip").host- body = """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 ...- http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/new.py ....- http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/hello.txt ....- """.format(id=realm_id, host=host)+ body = 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 ...+ http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/new.py ....+ http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/hello.txt ....+ """msg_id = self.send_personal_message(self.sender, self.recipient, body)diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex 4457db2d1e3..a57505cf06d 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -3274,9 +3274,7 @@ class DefaultStreamGroupTest(ZulipTestCase):)self.assert_json_error(result,- "Default stream group name too long (limit: {} characters)".format(- DefaultStreamGroup.MAX_NAME_LENGTH- ),+ f"Default stream group name too long (limit: {DefaultStreamGroup.MAX_NAME_LENGTH} characters)",)result = self.client_post(