ruff: Fix UP032 Use f-string instead of `format` call.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-03-20 19:43:05 -07:00 committed by Tim Abbott
parent f1b8e11e8b
commit a1a341f0ae
11 changed files with 35 additions and 68 deletions

View File

@ -2240,7 +2240,7 @@ class BillingSession(ABC):
# Should do this in JavaScript, using the user's time zone
if 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)

View File

@ -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)

View File

@ -45,9 +45,7 @@ with open("/proc/meminfo") as meminfo:
ram_gb = float(ram_size) / 1024.0 / 1024.0
if 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)

View File

@ -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:

View File

@ -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_difference
if 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:

View File

@ -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,

View File

@ -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"]:

View File

@ -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"]:

View File

@ -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} &gt; 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} &gt; 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} &gt; #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} &gt; #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:

View File

@ -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").id
host = 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").id
host = 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)

View File

@ -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(