mirror of https://github.com/zulip/zulip.git
ruff: Fix UP032 Use f-string instead of `format` call.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
ff409342e1
commit
e932e2ce52
|
@ -36,7 +36,7 @@ current_version = version.ZULIP_VERSION
|
|||
if 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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -97,8 +97,8 @@ def assert_droplet_does_not_exist(my_token: str, droplet_name: str, recreate: bo
|
|||
if 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(
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -673,20 +673,16 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase):
|
|||
self._create_attachments()
|
||||
realm_id = get_realm("zulip").id
|
||||
host = 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),
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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```"
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue