mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
ruff: Partially reformat Python with Ruff 0.9 (2025 style).
These are the changes that are backwards compatible with the 2024
style.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 653b0b0436)
This commit is contained in:
committed by
Tim Abbott
parent
680f318bc0
commit
cd485ef162
@@ -26,8 +26,7 @@ class Command(ZulipBaseCommand):
|
||||
parser.add_argument(
|
||||
"--time",
|
||||
"-t",
|
||||
help="Update stat tables from current state to "
|
||||
"--time. Defaults to the current time.",
|
||||
help="Update stat tables from current state to --time. Defaults to the current time.",
|
||||
default=timezone_now().isoformat(),
|
||||
)
|
||||
parser.add_argument("--utc", action="store_true", help="Interpret --time in UTC.")
|
||||
|
||||
@@ -349,7 +349,7 @@ def get_idempotency_key(ledger_entry: LicenseLedger) -> str | None:
|
||||
|
||||
|
||||
def cents_to_dollar_string(cents: int) -> str:
|
||||
return f"{cents / 100.:,.2f}"
|
||||
return f"{cents / 100.0:,.2f}"
|
||||
|
||||
|
||||
# Should only be called if the customer is being charged automatically
|
||||
|
||||
@@ -94,8 +94,7 @@ def parse_cache_script_args(description: str) -> argparse.Namespace:
|
||||
"--no-print-headings",
|
||||
dest="no_headings",
|
||||
action="store_true",
|
||||
help="If specified then script will not print headings for "
|
||||
"what will be deleted/kept back.",
|
||||
help="If specified then script will not print headings for what will be deleted/kept back.",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -46,8 +46,7 @@ def parse_args() -> argparse.Namespace:
|
||||
"--no-print-headings",
|
||||
dest="no_headings",
|
||||
action="store_true",
|
||||
help="If specified then script will not print headings for "
|
||||
"what will be deleted/kept back.",
|
||||
help="If specified then script will not print headings for what will be deleted/kept back.",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -105,8 +105,7 @@ def run() -> None:
|
||||
"openapi",
|
||||
["node", "tools/check-openapi"],
|
||||
["yaml"],
|
||||
description="Validates our OpenAPI/Swagger API documentation "
|
||||
"(zerver/openapi/zulip.yaml) ",
|
||||
description="Validates our OpenAPI/Swagger API documentation (zerver/openapi/zulip.yaml) ",
|
||||
fix_arg="--fix",
|
||||
)
|
||||
linter_config.external_linter(
|
||||
|
||||
@@ -86,7 +86,7 @@ class MessageThread(BaseModel):
|
||||
|
||||
|
||||
def create_user(full_name: str, avatar_filename: str | None) -> None:
|
||||
email = f'{full_name.replace(" ", "")}@zulip.com'
|
||||
email = f"{full_name.replace(' ', '')}@zulip.com"
|
||||
try:
|
||||
user = UserProfile.objects.get(realm=realm, full_name=full_name)
|
||||
except UserProfile.DoesNotExist:
|
||||
|
||||
@@ -336,7 +336,7 @@ def process_message_attachments(
|
||||
attachment_full_path = os.path.join(mattermost_data_dir, "data", attachment_path)
|
||||
|
||||
file_name = attachment_path.split("/")[-1]
|
||||
file_ext = f'.{file_name.split(".")[-1]}'
|
||||
file_ext = f".{file_name.split('.')[-1]}"
|
||||
|
||||
if file_ext.lower() in IMAGE_EXTENSIONS:
|
||||
has_image = True
|
||||
|
||||
@@ -147,7 +147,7 @@ def truncate_name(name: str, name_id: int, max_length: int = 60) -> str:
|
||||
|
||||
def get_stream_name(rc_channel: dict[str, Any]) -> str:
|
||||
if rc_channel.get("teamMain"):
|
||||
stream_name = f'[TEAM] {rc_channel["name"]}'
|
||||
stream_name = f"[TEAM] {rc_channel['name']}"
|
||||
else:
|
||||
stream_name = rc_channel["name"]
|
||||
|
||||
@@ -283,7 +283,7 @@ def build_custom_emoji(
|
||||
# Build custom emoji
|
||||
for rc_emoji in custom_emoji_data["emoji"]:
|
||||
# Subject to change with changes in database
|
||||
emoji_file_id = f'{rc_emoji["name"]}.{rc_emoji["extension"]}'
|
||||
emoji_file_id = f"{rc_emoji['name']}.{rc_emoji['extension']}"
|
||||
|
||||
emoji_file_info = emoji_file_data[emoji_file_id]
|
||||
|
||||
@@ -388,7 +388,7 @@ def process_message_attachment(
|
||||
|
||||
upload_file_data = upload_id_to_upload_data_map[upload["_id"]]
|
||||
file_name = upload["name"]
|
||||
file_ext = f'.{upload["type"].split("/")[-1]}'
|
||||
file_ext = f".{upload['type'].split('/')[-1]}"
|
||||
|
||||
has_image = False
|
||||
if file_ext.lower() in IMAGE_EXTENSIONS:
|
||||
@@ -420,7 +420,7 @@ def process_message_attachment(
|
||||
upload_file.write(b"".join(upload_file_data["chunk"]))
|
||||
|
||||
attachment_content = (
|
||||
f'{upload_file_data.get("description", "")}\n\n[{file_name}](/user_uploads/{s3_path})'
|
||||
f"{upload_file_data.get('description', '')}\n\n[{file_name}](/user_uploads/{s3_path})"
|
||||
)
|
||||
|
||||
fileinfo = {
|
||||
|
||||
@@ -456,7 +456,7 @@ def get_user_email(user: ZerverFieldsT, domain_name: str) -> str:
|
||||
if "email" in user["profile"]:
|
||||
return user["profile"]["email"]
|
||||
if user["is_mirror_dummy"]:
|
||||
return Address(username=user["name"], domain=f'{user["team_domain"]}.slack.com').addr_spec
|
||||
return Address(username=user["name"], domain=f"{user['team_domain']}.slack.com").addr_spec
|
||||
if "bot_id" in user["profile"]:
|
||||
return SlackBotEmail.get_email(user["profile"], domain_name)
|
||||
if get_user_full_name(user).lower() == "slackbot":
|
||||
|
||||
@@ -275,9 +275,7 @@ class HomepageForm(forms.Form):
|
||||
if not from_multiuse_invite and realm.invite_required:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Please request an invite for {email} "
|
||||
"from the organization "
|
||||
"administrator."
|
||||
"Please request an invite for {email} from the organization administrator."
|
||||
).format(email=email)
|
||||
)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class Command(ZulipBaseCommand):
|
||||
assert realm is not None # Should be ensured by parser
|
||||
if not realm.deactivated:
|
||||
raise CommandError(
|
||||
f'Realm {options["realm_id"]} is active. Please deactivate the realm the first.'
|
||||
f"Realm {options['realm_id']} is active. Please deactivate the realm the first."
|
||||
)
|
||||
print("Scrubbing", options["realm_id"])
|
||||
do_scrub_realm(realm, acting_user=None)
|
||||
|
||||
@@ -52,8 +52,7 @@ Example:
|
||||
parser.add_argument(
|
||||
"-s",
|
||||
"--stream",
|
||||
help="The name of the stream to which you'd like to send "
|
||||
"the message. Default: Denmark",
|
||||
help="The name of the stream to which you'd like to send the message. Default: Denmark",
|
||||
)
|
||||
|
||||
self.add_realm_args(parser, help="Specify which realm to connect to; default is zulip")
|
||||
|
||||
@@ -861,7 +861,7 @@ class MarkdownEmbedsTest(ZulipTestCase):
|
||||
self.assertEqual(converted.rendered_content, expected)
|
||||
|
||||
urls.append("https://www.google.com/images/srpr/logo4w.png")
|
||||
content = f"{urls[0]}\n\n" f">{urls[1]}\n\n" f"* {urls[2]}\n" f"* {urls[3]}"
|
||||
content = f"{urls[0]}\n\n>{urls[1]}\n\n* {urls[2]}\n* {urls[3]}"
|
||||
expected = (
|
||||
f'<div class="message_inline_image"><a href="{urls[0]}"><img src="{get_camo_url(urls[0])}"></a></div>'
|
||||
f'<blockquote>\n<p><a href="{urls[1]}">{urls[1]}</a></p>\n</blockquote>\n'
|
||||
@@ -2275,9 +2275,7 @@ class MarkdownMentionTest(ZulipTestCase):
|
||||
rendering_result = render_message_markdown(msg, content)
|
||||
self.assertEqual(
|
||||
rendering_result.rendered_content,
|
||||
'<p><span class="user-mention silent" '
|
||||
f'data-user-id="{user_id}">'
|
||||
"King Hamlet</span></p>",
|
||||
f'<p><span class="user-mention silent" data-user-id="{user_id}">King Hamlet</span></p>',
|
||||
)
|
||||
self.assertEqual(rendering_result.mentions_user_ids, set())
|
||||
|
||||
@@ -2296,9 +2294,7 @@ class MarkdownMentionTest(ZulipTestCase):
|
||||
rendering_result = render_message_markdown(msg, content)
|
||||
self.assertEqual(
|
||||
rendering_result.rendered_content,
|
||||
'<p><span class="user-mention silent" '
|
||||
f'data-user-id="{user_id}">'
|
||||
"King Hamlet</span></p>",
|
||||
f'<p><span class="user-mention silent" data-user-id="{user_id}">King Hamlet</span></p>',
|
||||
)
|
||||
self.assertEqual(rendering_result.mentions_user_ids, set())
|
||||
|
||||
@@ -2317,9 +2313,7 @@ class MarkdownMentionTest(ZulipTestCase):
|
||||
rendering_result = render_message_markdown(msg, content)
|
||||
self.assertEqual(
|
||||
rendering_result.rendered_content,
|
||||
'<p><span class="user-mention silent" '
|
||||
f'data-user-id="{user_id}">'
|
||||
"King Hamlet</span></p>",
|
||||
f'<p><span class="user-mention silent" data-user-id="{user_id}">King Hamlet</span></p>',
|
||||
)
|
||||
self.assertEqual(rendering_result.mentions_user_ids, set())
|
||||
|
||||
@@ -2676,9 +2670,7 @@ class MarkdownMentionTest(ZulipTestCase):
|
||||
rendering_result = render_message_markdown(msg, content)
|
||||
self.assertEqual(
|
||||
rendering_result.rendered_content,
|
||||
'<p><span class="user-mention" '
|
||||
f'data-user-id="{test_user.id}">'
|
||||
"@Atomic #123</span></p>",
|
||||
f'<p><span class="user-mention" data-user-id="{test_user.id}">@Atomic #123</span></p>',
|
||||
)
|
||||
self.assertEqual(rendering_result.mentions_user_ids, {test_user.id})
|
||||
content = "@_**Atomic #123**"
|
||||
|
||||
@@ -531,9 +531,7 @@ class EditMessageTest(ZulipTestCase):
|
||||
content="content before edit, line 1\n\ncontent before edit, line 3",
|
||||
)
|
||||
new_content_2 = (
|
||||
"content before edit, line 1\n"
|
||||
"content after edit, line 2\n"
|
||||
"content before edit, line 3"
|
||||
"content before edit, line 1\ncontent after edit, line 2\ncontent before edit, line 3"
|
||||
)
|
||||
result_2 = self.client_patch(
|
||||
f"/json/messages/{msg_id_2}",
|
||||
|
||||
@@ -448,7 +448,7 @@ do not match the types declared in the implementation of {function.__name__}.\n"
|
||||
self.assertIn(
|
||||
function_schema_type,
|
||||
(int, bool),
|
||||
f'\nUnexpected content type {actual_param_schema["contentMediaType"]} on function parameter {actual_param.param_name}, which does not match the OpenAPI definition.',
|
||||
f"\nUnexpected content type {actual_param_schema['contentMediaType']} on function parameter {actual_param.param_name}, which does not match the OpenAPI definition.",
|
||||
)
|
||||
function_params.add(
|
||||
(actual_param.request_var_name, schema_type(actual_param_schema, defs_mapping))
|
||||
|
||||
@@ -436,8 +436,7 @@ class AddNewUserHistoryTest(ZulipTestCase):
|
||||
with patch("zerver.models.Recipient.label", return_value="recip"):
|
||||
self.assertEqual(
|
||||
repr(message),
|
||||
"<Message: recip / / "
|
||||
f"<UserProfile: {user_profile.email} {user_profile.realm!r}>>",
|
||||
f"<Message: recip / / <UserProfile: {user_profile.email} {user_profile.realm!r}>>",
|
||||
)
|
||||
|
||||
user_message = most_recent_usermessage(user_profile)
|
||||
|
||||
@@ -1650,7 +1650,7 @@ class ActivateTest(ZulipTestCase):
|
||||
self.login("iago")
|
||||
|
||||
# Organization administrator cannot deactivate organization owner.
|
||||
result = self.client_delete(f'/json/users/{self.example_user("desdemona").id}')
|
||||
result = self.client_delete(f"/json/users/{self.example_user('desdemona').id}")
|
||||
self.assert_json_error(result, "Must be an organization owner")
|
||||
|
||||
iago = self.example_user("iago")
|
||||
|
||||
@@ -45,10 +45,7 @@ def remove_reaction(
|
||||
if emoji_code is None:
|
||||
if emoji_name is None:
|
||||
raise JsonableError(
|
||||
_(
|
||||
"At least one of the following arguments "
|
||||
"must be present: emoji_name, emoji_code"
|
||||
)
|
||||
_("At least one of the following arguments must be present: emoji_name, emoji_code")
|
||||
)
|
||||
# A correct full Zulip client implementation should always
|
||||
# pass an emoji_code, because of the corner cases discussed in
|
||||
|
||||
@@ -96,8 +96,7 @@ class FrontHookTests(WebhookTestCase):
|
||||
def test_mention_all(self) -> None:
|
||||
expected_topic_name = "cnv_keo696"
|
||||
expected_message = (
|
||||
"**Leela Turanga** left a comment:\n"
|
||||
"```quote\n@all Could someone else take this?\n```"
|
||||
"**Leela Turanga** left a comment:\n```quote\n@all Could someone else take this?\n```"
|
||||
)
|
||||
|
||||
self.check_webhook(
|
||||
@@ -177,8 +176,7 @@ class FrontHookTests(WebhookTestCase):
|
||||
def test_mention(self) -> None:
|
||||
expected_topic_name = "cnv_keocka"
|
||||
expected_message = (
|
||||
"**Leela Turanga** left a comment:\n"
|
||||
"```quote\n@bender Could you take it from here?\n```"
|
||||
"**Leela Turanga** left a comment:\n```quote\n@bender Could you take it from here?\n```"
|
||||
)
|
||||
|
||||
self.check_webhook(
|
||||
|
||||
@@ -298,8 +298,7 @@ class Command(ZulipBaseCommand):
|
||||
parser.add_argument(
|
||||
"--test-suite",
|
||||
action="store_true",
|
||||
help="Configures populate_db to create a deterministic "
|
||||
"data set for the backend tests.",
|
||||
help="Configures populate_db to create a deterministic data set for the backend tests.",
|
||||
)
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user