Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
python: Elide unnecessary list wrappers.
Anders Kaseorg2665a3ce2b44
diff --git a/analytics/lib/time_utils.py b/analytics/lib/time_utils.pyindex 888baf96d51..0afa73632e9 100644--- a/analytics/lib/time_utils.py+++ b/analytics/lib/time_utils.py@@ -30,4 +30,5 @@ def time_range(while current >= start:times.append(current)current -= step- return list(reversed(times))+ times.reverse()+ return timesdiff --git a/analytics/tests/test_counts.py b/analytics/tests/test_counts.pyindex 00a9af7fbdc..d182b714445 100644--- a/analytics/tests/test_counts.py+++ b/analytics/tests/test_counts.py@@ -1509,11 +1509,11 @@ class TestDeleteStats(AnalyticsTestCase):FillState.objects.create(property="test", end_time=self.TIME_ZERO, state=FillState.DONE)analytics = apps.get_app_config("analytics")- for table in list(analytics.models.values()):+ for table in analytics.models.values():self.assertTrue(table._default_manager.exists())do_drop_all_analytics_tables()- for table in list(analytics.models.values()):+ for table in analytics.models.values():self.assertFalse(table._default_manager.exists())def test_do_drop_single_stat(self) -> None:@@ -1533,11 +1533,11 @@ class TestDeleteStats(AnalyticsTestCase):FillState.objects.create(property="to_save", end_time=self.TIME_ZERO, state=FillState.DONE)analytics = apps.get_app_config("analytics")- for table in list(analytics.models.values()):+ for table in analytics.models.values():self.assertTrue(table._default_manager.exists())do_drop_single_stat("to_delete")- for table in list(analytics.models.values()):+ for table in analytics.models.values():self.assertFalse(table._default_manager.filter(property="to_delete").exists())self.assertTrue(table._default_manager.filter(property="to_save").exists())diff --git a/analytics/views/installation_activity.py b/analytics/views/installation_activity.pyindex 5588ddbf099..4d143160b38 100644--- a/analytics/views/installation_activity.py+++ b/analytics/views/installation_activity.py@@ -254,10 +254,7 @@ def realm_summary_table(realm_minutes: Dict[str, float]) -> str:row["string_id"] = realm_activity_link(row["string_id"])# Count active sites- def meets_goal(row: Dict[str, int]) -> bool:- return row["dau_count"] >= 5-- num_active_sites = len(list(filter(meets_goal, rows)))+ num_active_sites = sum(row["dau_count"] >= 5 for row in rows)# create totalstotal_dau_count = 0diff --git a/analytics/views/stats.py b/analytics/views/stats.pyindex 2b7e01ee38c..203a0dedb8a 100644--- a/analytics/views/stats.py+++ b/analytics/views/stats.py@@ -438,8 +438,7 @@ def get_chart_data(def sort_by_totals(value_arrays: Dict[str, List[int]]) -> List[str]:- totals = [(sum(values), label) for label, values in value_arrays.items()]- totals.sort(reverse=True)+ totals = sorted(((sum(values), label) for label, values in value_arrays.items()), reverse=True)return [label for total, label in totals]diff --git a/docs/tutorials/new-feature-tutorial.md b/docs/tutorials/new-feature-tutorial.mdindex 2d310e0b40c..e871f2a5526 100644--- a/docs/tutorials/new-feature-tutorial.md+++ b/docs/tutorials/new-feature-tutorial.md@@ -343,7 +343,7 @@ field and send an event. For example:def do_set_realm_authentication_methods(realm: Realm, authentication_methods: Dict[str, bool], *, acting_user: Optional[UserProfile]) -> None:- for key, value in list(authentication_methods.items()):+ for key, value in authentication_methods.items():index = getattr(realm.authentication_methods, key).numberrealm.authentication_methods.set_bit(index, int(value))realm.save(update_fields=['authentication_methods'])diff --git a/puppet/zulip/files/postgresql/wal-g-exporter b/puppet/zulip/files/postgresql/wal-g-exporterindex c0e7a9565cb..edb27907172 100755--- a/puppet/zulip/files/postgresql/wal-g-exporter+++ b/puppet/zulip/files/postgresql/wal-g-exporter@@ -36,7 +36,7 @@ class WalGPrometheusServer(BaseHTTPRequestHandler):def inner(value: float, labels: Optional[Mapping[str, str]] = None) -> None:label_str = ""if labels:- label_str = "{" + ",".join([f'{k}="{v}"' for k, v in labels.items()]) + "}"+ label_str = "{" + ",".join(f'{k}="{v}"' for k, v in labels.items()) + "}"self.metric_values[name][label_str] = f"{self.METRIC_PREFIX}{name}{label_str} {value}"if default_value is not None:diff --git a/scripts/log-search b/scripts/log-searchindex bb6a6f5b305..57e5b17c078 100755--- a/scripts/log-search+++ b/scripts/log-search@@ -472,7 +472,7 @@ def print_line(url,]- print(color + " ".join([p for p in parts if p is not None]) + (ENDC if use_color else ""))+ print(color + " ".join(p for p in parts if p is not None) + (ENDC if use_color else ""))if __name__ == "__main__":diff --git a/tools/droplets/create.py b/tools/droplets/create.pyindex 64aa03d347a..1516a61caee 100644--- a/tools/droplets/create.py+++ b/tools/droplets/create.py@@ -109,7 +109,7 @@ def assert_droplet_does_not_exist(my_token: str, droplet_name: str, recreate: bodef get_ssh_keys_string_from_github_ssh_key_dicts(userkey_dicts: List[Dict[str, Any]]) -> str:- return "\n".join([userkey_dict["key"] for userkey_dict in userkey_dicts])+ return "\n".join(userkey_dict["key"] for userkey_dict in userkey_dicts)def generate_dev_droplet_user_data(diff --git a/tools/setup/emoji/generate_emoji_names_table b/tools/setup/emoji/generate_emoji_names_tableindex 8be9fbce95f..ea9b109e615 100755--- a/tools/setup/emoji/generate_emoji_names_table+++ b/tools/setup/emoji/generate_emoji_names_table@@ -157,7 +157,7 @@ def generate_emoji_code_to_emoji_names_maps() -> None:def get_sorting_info(category: str, sort_order: int) -> str:- return " ".join([category, str(sort_order)])+ return f"{category} {sort_order}"def get_images_html(emoji_code: str) -> str:diff --git a/zerver/actions/invites.py b/zerver/actions/invites.pyindex b0fd6d29ae8..82fcc480b50 100644--- a/zerver/actions/invites.py+++ b/zerver/actions/invites.py@@ -422,12 +422,10 @@ def get_valid_invite_confirmations_generated_by_user(multiuse_invite_ids = MultiuseInvite.objects.filter(referred_by=user_profile).values_list("id", flat=True)- confirmations += list(- Confirmation.objects.filter(- type=Confirmation.MULTIUSE_INVITE,- object_id__in=multiuse_invite_ids,- ).filter(Q(expiry_date__gte=timezone_now()) | Q(expiry_date=None))- )+ confirmations += Confirmation.objects.filter(+ type=Confirmation.MULTIUSE_INVITE,+ object_id__in=multiuse_invite_ids,+ ).filter(Q(expiry_date__gte=timezone_now()) | Q(expiry_date=None))return confirmationsdiff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.pyindex ff64b1a9b26..c75298f087a 100644--- a/zerver/actions/message_edit.py+++ b/zerver/actions/message_edit.py@@ -774,7 +774,7 @@ def do_update_message()subscriber_ids = set(subscriptions.values_list("user_profile_id", flat=True))- users_to_be_notified += list(map(subscriber_info, sorted(subscriber_ids)))+ users_to_be_notified += map(subscriber_info, sorted(subscriber_ids))# UserTopic updates and the content of notifications depend on# whether we've moved the entire topic, or just part of it. Wediff --git a/zerver/actions/message_flags.py b/zerver/actions/message_flags.pyindex 1b4da063bff..4b3f9abe45f 100644--- a/zerver/actions/message_flags.py+++ b/zerver/actions/message_flags.py@@ -224,7 +224,7 @@ def do_clear_mobile_push_notifications_for_ids(assert len(user_profile_ids) == 1 or len(message_ids) == 1messages_by_user = defaultdict(list)- notifications_to_update = list(+ notifications_to_update = (UserMessage.objects.filter(message_id__in=message_ids,user_profile_id__in=user_profile_ids,diff --git a/zerver/actions/realm_settings.py b/zerver/actions/realm_settings.pyindex ec453339c60..e5c20c720ae 100644--- a/zerver/actions/realm_settings.py+++ b/zerver/actions/realm_settings.py@@ -169,7 +169,7 @@ def do_set_realm_authentication_methods() -> None:old_value = realm.authentication_methods_dict()with transaction.atomic():- for key, value in list(authentication_methods.items()):+ for key, value in authentication_methods.items():# This does queries in a loop, but this isn't a performance sensitive# path and is only run rarely.if value:@@ -409,15 +409,13 @@ def do_scrub_realm(realm: Realm, *, acting_user: Optional[UserProfile]) -> None:# more secure against bugs that may cause Message.realm to be incorrect for some# cross-realm messages to also determine the actual Recipients - to prevent# deletion of excessive messages.- all_recipient_ids_in_realm = (- list(Stream.objects.filter(realm=realm).values_list("recipient_id", flat=True))- + list(UserProfile.objects.filter(realm=realm).values_list("recipient_id", flat=True))- + list(- Subscription.objects.filter(- recipient__type=Recipient.HUDDLE, user_profile__realm=realm- ).values_list("recipient_id", flat=True)- )- )+ all_recipient_ids_in_realm = [+ *Stream.objects.filter(realm=realm).values_list("recipient_id", flat=True),+ *UserProfile.objects.filter(realm=realm).values_list("recipient_id", flat=True),+ *Subscription.objects.filter(+ recipient__type=Recipient.HUDDLE, user_profile__realm=realm+ ).values_list("recipient_id", flat=True),+ ]cross_realm_bot_message_ids = list(Message.objects.filter(# Filtering by both message.recipient and message.realm isdiff --git a/zerver/data_import/rocketchat.py b/zerver/data_import/rocketchat.pyindex 2ffbd73948a..7a88ad2d6ea 100644--- a/zerver/data_import/rocketchat.py+++ b/zerver/data_import/rocketchat.py@@ -284,7 +284,7 @@ def build_custom_emoji(# Build custom emojifor rc_emoji in custom_emoji_data["emoji"]:# Subject to change with changes in database- emoji_file_id = ".".join([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]@@ -849,9 +849,7 @@ def separate_channel_private_and_livechat_messages(private_messages: List[Dict[str, Any]],livechat_messages: List[Dict[str, Any]],) -> None:- private_channels_list = list(direct_id_to_direct_map.keys()) + list(- huddle_id_to_huddle_map.keys()- )+ private_channels_list = [*direct_id_to_direct_map, *huddle_id_to_huddle_map]for message in messages:if not message.get("rid"):# Message does not belong to any channel (might bediff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.pyindex e14fdec317d..4f1ae26b61b 100644--- a/zerver/data_import/slack.py+++ b/zerver/data_import/slack.py@@ -797,7 +797,7 @@ def get_messages_iterator(not read all the messages into memory at once, because forlarge imports that can OOM kill."""- dir_names = list(added_channels.keys()) + list(added_mpims.keys()) + list(dm_members.keys())+ dir_names = [*added_channels, *added_mpims, *dm_members]all_json_names: Dict[str, List[str]] = defaultdict(list)for dir_name in dir_names:dir_path = os.path.join(slack_data_dir, dir_name)diff --git a/zerver/lib/data_types.py b/zerver/lib/data_types.pyindex 20ee07ace75..1336fb1f33b 100644--- a/zerver/lib/data_types.py+++ b/zerver/lib/data_types.py@@ -67,7 +67,7 @@ class DictType:def schema(self, var_name: str) -> str:# Our current schema is lossy, since our OpenAPI configs# aren't rigorous about "required" fields yet.- keys = sorted(list(self.required_keys) + list(self.optional_keys))+ keys = sorted([*self.required_keys, *self.optional_keys])sub_schema = "\n".join(schema(name, data_type) for name, data_type in keys)return f"{var_name} (dict):\n{indent(sub_schema)}"diff --git a/zerver/lib/digest.py b/zerver/lib/digest.pyindex e184947df31..24b84fca294 100644--- a/zerver/lib/digest.py+++ b/zerver/lib/digest.py@@ -145,8 +145,7 @@ def _enqueue_emails_for_realm(realm: Realm, cutoff: datetime.datetime) -> None:.distinct())- user_ids = list(realm_user_ids - active_user_ids)- user_ids.sort()+ user_ids = sorted(realm_user_ids - active_user_ids)# We process batches of 30. We want a big enough batch# to amortize work, but not so big that a single itemdiff --git a/zerver/lib/events.py b/zerver/lib/events.pyindex 87f282bbece..7e5c2ff00f2 100644--- a/zerver/lib/events.py+++ b/zerver/lib/events.py@@ -1349,8 +1349,7 @@ def apply_event(for user_group in state["realm_user_groups"]:if user_group["id"] == event["group_id"]:members = set(user_group["members"])- user_group["members"] = list(members - set(event["user_ids"]))- user_group["members"].sort()+ user_group["members"] = sorted(members - set(event["user_ids"]))elif event["op"] == "add_subgroups":for user_group in state["realm_user_groups"]:if user_group["id"] == event["group_id"]:@@ -1360,10 +1359,9 @@ def apply_event(for user_group in state["realm_user_groups"]:if user_group["id"] == event["group_id"]:subgroups = set(user_group["direct_subgroup_ids"])- user_group["direct_subgroup_ids"] = list(+ user_group["direct_subgroup_ids"] = sorted(subgroups - set(event["direct_subgroup_ids"]))- user_group["direct_subgroup_ids"].sort()elif event["op"] == "remove":state["realm_user_groups"] = [ug for ug in state["realm_user_groups"] if ug["id"] != event["group_id"]@@ -1597,8 +1595,7 @@ def post_process_state(See the note above; the same technique applies below."""if "raw_users" in ret:- user_dicts = list(ret["raw_users"].values())- user_dicts = sorted(user_dicts, key=lambda x: x["user_id"])+ user_dicts = sorted(ret["raw_users"].values(), key=lambda x: x["user_id"])ret["realm_users"] = [d for d in user_dicts if d["is_active"]]ret["realm_non_active_users"] = [d for d in user_dicts if not d["is_active"]]diff --git a/zerver/lib/export.py b/zerver/lib/export.pyindex c1d44189f51..845deeaaaae 100644--- a/zerver/lib/export.py+++ b/zerver/lib/export.py@@ -308,16 +308,16 @@ DATE_FIELDS: Dict[TableName, List[Field]] = {def sanity_check_output(data: TableData) -> None:# First, we verify that the export tool has a declared# configuration for every table declared in the `models.py` files.- target_models = (- list(apps.get_app_config("analytics").get_models(include_auto_created=True))- + list(apps.get_app_config("django_otp").get_models(include_auto_created=True))- + list(apps.get_app_config("otp_static").get_models(include_auto_created=True))- + list(apps.get_app_config("otp_totp").get_models(include_auto_created=True))- + list(apps.get_app_config("phonenumber").get_models(include_auto_created=True))- + list(apps.get_app_config("social_django").get_models(include_auto_created=True))- + list(apps.get_app_config("two_factor").get_models(include_auto_created=True))- + list(apps.get_app_config("zerver").get_models(include_auto_created=True))- )+ target_models = [+ *apps.get_app_config("analytics").get_models(include_auto_created=True),+ *apps.get_app_config("django_otp").get_models(include_auto_created=True),+ *apps.get_app_config("otp_static").get_models(include_auto_created=True),+ *apps.get_app_config("otp_totp").get_models(include_auto_created=True),+ *apps.get_app_config("phonenumber").get_models(include_auto_created=True),+ *apps.get_app_config("social_django").get_models(include_auto_created=True),+ *apps.get_app_config("two_factor").get_models(include_auto_created=True),+ *apps.get_app_config("zerver").get_models(include_auto_created=True),+ ]all_tables_db = {model._meta.db_table for model in target_models}# These assertion statements will fire when we add a new databasediff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.pyindex 48085112225..01b1a24a114 100644--- a/zerver/lib/markdown/__init__.py+++ b/zerver/lib/markdown/__init__.py@@ -333,10 +333,7 @@ def image_preview_enabled(def list_of_tlds() -> List[str]:# Skip a few overly-common false-positives from file extensionscommon_false_positives = {"java", "md", "mov", "py", "zip"}- tlds = list(tld_set - common_false_positives)-- tlds.sort(key=len, reverse=True)- return tlds+ return sorted(tld_set - common_false_positives, key=len, reverse=True)def walk_tree(@@ -762,9 +759,7 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):if image_info is None:image_info = {}image_info["is_image"] = True- parsed_url_list = list(parsed_url)- parsed_url_list[4] = "raw=1" # Replaces query- image_info["image"] = urllib.parse.urlunparse(parsed_url_list)+ image_info["image"] = parsed_url._replace(query="raw=1").geturl()return image_inforeturn None@@ -992,8 +987,9 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):# Find the image size that is smaller than# TWITTER_MAX_IMAGE_HEIGHT px tall or the smallest- size_name_tuples = list(media_item["sizes"].items())- size_name_tuples.sort(reverse=True, key=lambda x: x[1]["h"])+ size_name_tuples = sorted(+ media_item["sizes"].items(), reverse=True, key=lambda x: x[1]["h"]+ )for size_name, size in size_name_tuples:if size["h"] < self.TWITTER_MAX_IMAGE_HEIGHT:breakdiff --git a/zerver/lib/markdown/nested_code_blocks.py b/zerver/lib/markdown/nested_code_blocks.pyindex 3be6cbf336a..56f81e7d71c 100644--- a/zerver/lib/markdown/nested_code_blocks.py+++ b/zerver/lib/markdown/nested_code_blocks.py@@ -46,8 +46,8 @@ class NestedCodeBlocksRendererTreeProcessor(markdown.treeprocessors.Treeprocessoparent.tag == "p"and grandparent.tag == "li"and parent.text is None- and len(list(parent)) == 1- and len(list(parent.itertext())) == 1+ and len(parent) == 1+ and sum(1 for text in parent.itertext()) == 1):# if the parent (<p>) has no text, and no children,# that means that the <code> element inside is itsdiff --git a/zerver/lib/message.py b/zerver/lib/message.pyindex 0d2286257af..d85f373ff68 100644--- a/zerver/lib/message.py+++ b/zerver/lib/message.py@@ -1401,9 +1401,11 @@ def format_unread_message_details(for message_id, huddle_message_details in raw_unread_data["huddle_dict"].items():# The client wants a list of user_ids in the conversation, excluding ourself,# that is sorted in numerical order.- user_ids = [int(s) for s in huddle_message_details["user_ids_string"].split(",")]- user_ids = [user_id for user_id in user_ids if user_id != my_user_id]- user_ids.sort()+ user_ids = sorted(+ user_id+ for s in huddle_message_details["user_ids_string"].split(",")+ if (user_id := int(s)) != my_user_id+ )message_details = MessageDetailsDict(type="private",user_ids=user_ids,diff --git a/zerver/lib/onboarding.py b/zerver/lib/onboarding.pyindex a438c98bf27..0efda0b0a64 100644--- a/zerver/lib/onboarding.py+++ b/zerver/lib/onboarding.py@@ -143,7 +143,7 @@ def bot_commands(no_help_command: bool = False) -> str:]if not no_help_command:commands.append("help")- return ", ".join(["`" + command + "`" for command in commands]) + "."+ return ", ".join("`" + command + "`" for command in commands) + "."def select_welcome_bot_response(human_response_lower: str) -> str:diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.pyindex 595c163a825..68853a0d004 100644--- a/zerver/lib/push_notifications.py+++ b/zerver/lib/push_notifications.py@@ -264,11 +264,9 @@ def send_apple_push_notification()for device in devices]- results = list(- await asyncio.gather(- *(apns_context.apns.send_notification(request) for request in requests),- return_exceptions=True,- )+ results = await asyncio.gather(+ *(apns_context.apns.send_notification(request) for request in requests),+ return_exceptions=True,)return zip(devices, results)@@ -724,7 +722,7 @@ def get_mobile_push_content(rendered_content: str) -> str:def render_olist(ol: lxml.html.HtmlElement) -> str:items = []counter = int(ol.get("start")) if ol.get("start") else 1- nested_levels = len(list(ol.iterancestors("ol")))+ nested_levels = sum(1 for ancestor in ol.iterancestors("ol"))indent = ("\n" + " " * nested_levels) if nested_levels else ""for li in ol:diff --git a/zerver/lib/request.py b/zerver/lib/request.pyindex c03acacf182..932597e0491 100644--- a/zerver/lib/request.py+++ b/zerver/lib/request.py@@ -470,9 +470,9 @@ def has_request_variables(# which could lead to inaccurate output.and 200 <= return_value.status_code < 300):- ignored_parameters = set(- list(request.POST.keys()) + list(request.GET.keys())- ).difference(request_notes.processed_parameters)+ ignored_parameters = {*request.POST, *request.GET}.difference(+ request_notes.processed_parameters+ )# This will be called each time a function decorated with# has_request_variables returns a MutableJsonResponse with adiff --git a/zerver/lib/stream_subscription.py b/zerver/lib/stream_subscription.pyindex 6f70a6718d7..5a64eaf695a 100644--- a/zerver/lib/stream_subscription.py+++ b/zerver/lib/stream_subscription.py@@ -94,7 +94,7 @@ def get_used_colors_for_user_ids(user_ids: List[int]) -> Dict[int, Set[str]]:result: Dict[int, Set[str]] = defaultdict(set)- for row in list(query):+ for row in query:assert row["color"] is not Noneresult[row["user_profile_id"]].add(row["color"])diff --git a/zerver/lib/streams.py b/zerver/lib/streams.pyindex 7908c3b180a..136bcee3a88 100644--- a/zerver/lib/streams.py+++ b/zerver/lib/streams.py@@ -964,8 +964,9 @@ def do_get_streams(stream_ids = {stream.id for stream in streams}recent_traffic = get_streams_traffic(stream_ids, user_profile.realm)- stream_dicts = [stream_to_dict(stream, recent_traffic) for stream in streams]- stream_dicts.sort(key=lambda elt: elt["name"])+ stream_dicts = sorted(+ (stream_to_dict(stream, recent_traffic) for stream in streams), key=lambda elt: elt["name"]+ )if include_default:default_stream_ids = get_default_stream_ids_for_realm(user_profile.realm_id)diff --git a/zerver/lib/string_validation.py b/zerver/lib/string_validation.pyindex 1536b0a80ff..09df29a8350 100644--- a/zerver/lib/string_validation.py+++ b/zerver/lib/string_validation.py@@ -10,9 +10,12 @@ from zerver.models import Stream# https://www.unicode.org/faq/private_use.html#nonchar4unicode_non_chars = {chr(x)- for x in list(range(0xFDD0, 0xFDF0)) # FDD0 through FDEF, inclusive- + list(range(0xFFFE, 0x110000, 0x10000)) # 0xFFFE, 0x1FFFE, ... 0x10FFFE inclusive- + list(range(0xFFFF, 0x110000, 0x10000)) # 0xFFFF, 0x1FFFF, ... 0x10FFFF inclusive+ for r in [+ range(0xFDD0, 0xFDF0), # FDD0 through FDEF, inclusive+ range(0xFFFE, 0x110000, 0x10000), # 0xFFFE, 0x1FFFE, ... 0x10FFFE inclusive+ range(0xFFFF, 0x110000, 0x10000), # 0xFFFF, 0x1FFFF, ... 0x10FFFF inclusive+ ]+ for x in r}diff --git a/zerver/lib/typed_endpoint.py b/zerver/lib/typed_endpoint.pyindex 29734f0b034..c44b4916288 100644--- a/zerver/lib/typed_endpoint.py+++ b/zerver/lib/typed_endpoint.py@@ -543,9 +543,9 @@ def typed_endpoint(# which could lead to inaccurate output.and 200 <= return_value.status_code < 300):- ignored_parameters = set(- list(request.POST.keys()) + list(request.GET.keys())- ).difference(request_notes.processed_parameters)+ ignored_parameters = {*request.POST, *request.GET}.difference(+ request_notes.processed_parameters+ )# This will be called each time a function decorated with @typed_endpoint# returns a MutableJsonResponse with a success status_code. Becausediff --git a/zerver/lib/user_counts.py b/zerver/lib/user_counts.pyindex a71781db169..9add4d77b81 100644--- a/zerver/lib/user_counts.py+++ b/zerver/lib/user_counts.py@@ -17,7 +17,7 @@ def realm_user_count_by_role(realm: Realm) -> Dict[str, Any]:str(UserProfile.ROLE_MEMBER): 0,str(UserProfile.ROLE_GUEST): 0,}- for value_dict in list(+ for value_dict in (UserProfile.objects.filter(realm=realm, is_bot=False, is_active=True).values("role").annotate(Count("role"))diff --git a/zerver/lib/user_topics.py b/zerver/lib/user_topics.pyindex dcc31712e29..e99f96e5da9 100644--- a/zerver/lib/user_topics.py+++ b/zerver/lib/user_topics.py@@ -229,7 +229,7 @@ def exclude_topic_mutes(topic_cond = topic_match_sa(topic_name)return and_(stream_cond, topic_cond)- condition = not_(or_(*list(map(mute_cond, rows))))+ condition = not_(or_(*map(mute_cond, rows)))return [*conditions, condition]diff --git a/zerver/lib/users.py b/zerver/lib/users.pyindex 8b8be7670f1..d62a25fe5e0 100644--- a/zerver/lib/users.py+++ b/zerver/lib/users.py@@ -182,10 +182,8 @@ def bulk_get_cross_realm_bots() -> Dict[str, UserProfile]:where_clause = ("upper(zerver_userprofile.email::text) IN (SELECT upper(email) FROM unnest(%s) AS email)")- users = list(- UserProfile.objects.filter(realm__string_id=settings.SYSTEM_BOT_REALM).extra(- where=[where_clause], params=(emails,)- )+ users = UserProfile.objects.filter(realm__string_id=settings.SYSTEM_BOT_REALM).extra(+ where=[where_clause], params=(emails,))return {user.email.lower(): user for user in users}diff --git a/zerver/lib/validator.py b/zerver/lib/validator.pyindex a1ece4dce6e..d46bfc2d1be 100644--- a/zerver/lib/validator.py+++ b/zerver/lib/validator.py@@ -316,7 +316,7 @@ def check_dict(delta_keys = set(val.keys()) - required_keys_set - optional_keys_setif len(delta_keys) != 0:raise ValidationError(- _("Unexpected arguments: {keys}").format(keys=", ".join(list(delta_keys)))+ _("Unexpected arguments: {keys}").format(keys=", ".join(delta_keys)))return cast(Dict[str, ResultT], val)diff --git a/zerver/management/commands/export_search.py b/zerver/management/commands/export_search.pyindex 43b22679bf6..0e792167628 100644--- a/zerver/management/commands/export_search.py+++ b/zerver/management/commands/export_search.py@@ -187,7 +187,7 @@ This is most often used for legal compliance..values_list("full_name", "delivery_email"))- return ", ".join([format_sender(e[0], e[1]) for e in users]), False+ return ", ".join(format_sender(e[0], e[1]) for e in users), Falsedef transform_message(message: Message) -> Dict[str, str]:row = {diff --git a/zerver/migrations/0284_convert_realm_admins_to_realm_owners.py b/zerver/migrations/0284_convert_realm_admins_to_realm_owners.pyindex 211fdf8c1ab..3e75ca94d09 100644--- a/zerver/migrations/0284_convert_realm_admins_to_realm_owners.py+++ b/zerver/migrations/0284_convert_realm_admins_to_realm_owners.py@@ -34,7 +34,7 @@ def set_realm_admins_as_realm_owners(str(UserProfile.ROLE_MEMBER): 0,str(UserProfile.ROLE_GUEST): 0,}- for value_dict in list(+ for value_dict in (UserProfile.objects.filter(realm=realm, is_bot=False, is_active=True).values("role").annotate(Count("role"))diff --git a/zerver/migrations/0371_invalid_characters_in_topics.py b/zerver/migrations/0371_invalid_characters_in_topics.pyindex 80a31650e91..90dbb5c8129 100644--- a/zerver/migrations/0371_invalid_characters_in_topics.py+++ b/zerver/migrations/0371_invalid_characters_in_topics.py@@ -8,9 +8,12 @@ from django.db.migrations.state import StateApps# https://www.unicode.org/faq/private_use.html#nonchar4unicode_non_chars = {chr(x)- for x in list(range(0xFDD0, 0xFDF0)) # FDD0 through FDEF, inclusive- + list(range(0xFFFE, 0x110000, 0x10000)) # 0xFFFE, 0x1FFFE, ... 0x10FFFE inclusive- + list(range(0xFFFF, 0x110000, 0x10000)) # 0xFFFF, 0x1FFFF, ... 0x10FFFF inclusive+ for r in [+ range(0xFDD0, 0xFDF0), # FDD0 through FDEF, inclusive+ range(0xFFFE, 0x110000, 0x10000), # 0xFFFE, 0x1FFFE, ... 0x10FFFE inclusive+ range(0xFFFF, 0x110000, 0x10000), # 0xFFFF, 0x1FFFF, ... 0x10FFFF inclusive+ ]+ for x in r}diff --git a/zerver/migrations/0375_invalid_characters_in_stream_names.py b/zerver/migrations/0375_invalid_characters_in_stream_names.pyindex 1b4c6541bed..ac497755a1b 100644--- a/zerver/migrations/0375_invalid_characters_in_stream_names.py+++ b/zerver/migrations/0375_invalid_characters_in_stream_names.py@@ -8,9 +8,12 @@ from django.db.migrations.state import StateApps# https://www.unicode.org/faq/private_use.html#nonchar4unicode_non_chars = {chr(x)- for x in list(range(0xFDD0, 0xFDF0)) # FDD0 through FDEF, inclusive- + list(range(0xFFFE, 0x110000, 0x10000)) # 0xFFFE, 0x1FFFE, ... 0x10FFFE inclusive- + list(range(0xFFFF, 0x110000, 0x10000)) # 0xFFFF, 0x1FFFF, ... 0x10FFFF inclusive+ for r in [+ range(0xFDD0, 0xFDF0), # FDD0 through FDEF, inclusive+ range(0xFFFE, 0x110000, 0x10000), # 0xFFFE, 0x1FFFE, ... 0x10FFFE inclusive+ range(0xFFFF, 0x110000, 0x10000), # 0xFFFF, 0x1FFFF, ... 0x10FFFF inclusive+ ]+ for x in r}diff --git a/zerver/migrations/0383_revoke_invitations_from_deactivated_users.py b/zerver/migrations/0383_revoke_invitations_from_deactivated_users.pyindex 671cb67fede..f2d9def5cc0 100644--- a/zerver/migrations/0383_revoke_invitations_from_deactivated_users.py+++ b/zerver/migrations/0383_revoke_invitations_from_deactivated_users.py@@ -36,13 +36,11 @@ def revoke_invitations(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor)multiuse_invite_ids = MultiuseInvite.objects.filter(referred_by_id__in=user_ids).values_list("id", flat=True)- confirmation_ids += list(- Confirmation.objects.filter(- type=Confirmation.MULTIUSE_INVITE,- expiry_date__gte=timezone_now(),- object_id__in=multiuse_invite_ids,- ).values_list("id", flat=True)- )+ confirmation_ids += Confirmation.objects.filter(+ type=Confirmation.MULTIUSE_INVITE,+ expiry_date__gte=timezone_now(),+ object_id__in=multiuse_invite_ids,+ ).values_list("id", flat=True)return confirmation_idsdiff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.pyindex c7011e2ce90..c218b641625 100644--- a/zerver/tests/test_auth_backends.py+++ b/zerver/tests/test_auth_backends.py@@ -5275,7 +5275,7 @@ class TestDevAuthBackend(ZulipTestCase):self.assertEqual(result.status_code, 302)self.assertEqual(result["Location"], "http://zulip.testserver/")self.assert_logged_in_user_id(user_profile.id)- self.assertIn("otp_device_id", list(self.client.session.keys()))+ self.assertIn("otp_device_id", self.client.session.keys())def test_redirect_to_next_url(self) -> None:def do_local_login(formaction: str) -> "TestHttpResponse":@@ -5937,7 +5937,7 @@ class TestLDAP(ZulipLDAPTestCase):for key, value in ldap_dir.items():self.assertTrue(regex.match(key))self.assertCountEqual(- list(value.keys()), [*common_attrs, "uid", "thumbnailPhoto", "userAccountControl"]+ value.keys(), [*common_attrs, "uid", "thumbnailPhoto", "userAccountControl"])ldap_dir = generate_dev_ldap_dir("b", 9)@@ -5945,14 +5945,14 @@ class TestLDAP(ZulipLDAPTestCase):regex = re.compile(r"(uid\=)+[a-zA-Z0-9_.+-]+(\,ou\=users\,dc\=zulip\,dc\=com)")for key, value in ldap_dir.items():self.assertTrue(regex.match(key))- self.assertCountEqual(list(value.keys()), [*common_attrs, "uid", "jpegPhoto"])+ self.assertCountEqual(value.keys(), [*common_attrs, "uid", "jpegPhoto"])ldap_dir = generate_dev_ldap_dir("c", 8)self.assert_length(ldap_dir, 8)regex = re.compile(r"(uid\=)+[a-zA-Z0-9_.+-]+(\,ou\=users\,dc\=zulip\,dc\=com)")for key, value in ldap_dir.items():self.assertTrue(regex.match(key))- self.assertCountEqual(list(value.keys()), [*common_attrs, "uid", "email"])+ self.assertCountEqual(value.keys(), [*common_attrs, "uid", "email"])@override_settings(AUTHENTICATION_BACKENDS=("zproject.backends.ZulipLDAPAuthBackend",))def test_dev_ldap_fail_login(self) -> None:diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.pyindex 78aac7dcdbb..72048e12ea1 100644--- a/zerver/tests/test_message_fetch.py+++ b/zerver/tests/test_message_fetch.py@@ -2498,7 +2498,7 @@ class GetOldMessagesTest(ZulipTestCase):params = {k: orjson.dumps(v).decode() for k, v in raw_params.items()}result = self.client_get("/json/messages/matches_narrow", params)messages = self.assert_json_success(result)["messages"]- self.assert_length(list(messages.keys()), 1)+ self.assert_length(messages, 1)message = messages[str(good_id)]self.assertEqual(message["match_content"],@@ -2514,7 +2514,7 @@ class GetOldMessagesTest(ZulipTestCase):params = {k: orjson.dumps(v).decode() for k, v in raw_params.items()}result = self.client_get("/json/messages/matches_narrow", params)messages = self.assert_json_success(result)["messages"]- self.assert_length(list(messages.keys()), 1)+ self.assert_length(messages, 1)message = messages[str(good_id)]self.assertEqual(message["match_content"],@@ -2973,7 +2973,7 @@ class GetOldMessagesTest(ZulipTestCase):params = {k: orjson.dumps(v).decode() for k, v in raw_params.items()}result = self.client_get("/json/messages/matches_narrow", params)messages = self.assert_json_success(result)["messages"]- self.assert_length(list(messages.keys()), 1)+ self.assert_length(messages, 1)message = messages[str(good_id)]self.assertIn("a href=", message["match_content"])self.assertIn("http://foo.com", message["match_content"])diff --git a/zerver/tests/test_user_groups.py b/zerver/tests/test_user_groups.pyindex a78d64cd789..4c45049ad15 100644--- a/zerver/tests/test_user_groups.py+++ b/zerver/tests/test_user_groups.py@@ -135,14 +135,14 @@ class UserGroupTestCase(ZulipTestCase):list(get_recursive_group_members(everyone_group)), [desdemona, iago, shiva])- self.assertIn(leadership_group, list(get_recursive_membership_groups(desdemona)))- self.assertIn(staff_group, list(get_recursive_membership_groups(desdemona)))- self.assertIn(everyone_group, list(get_recursive_membership_groups(desdemona)))+ self.assertIn(leadership_group, get_recursive_membership_groups(desdemona))+ self.assertIn(staff_group, get_recursive_membership_groups(desdemona))+ self.assertIn(everyone_group, get_recursive_membership_groups(desdemona))- self.assertIn(staff_group, list(get_recursive_membership_groups(iago)))- self.assertIn(everyone_group, list(get_recursive_membership_groups(iago)))+ self.assertIn(staff_group, get_recursive_membership_groups(iago))+ self.assertIn(everyone_group, get_recursive_membership_groups(iago))- self.assertIn(everyone_group, list(get_recursive_membership_groups(shiva)))+ self.assertIn(everyone_group, get_recursive_membership_groups(shiva))def test_subgroups_of_role_based_system_groups(self) -> None:realm = get_realm("zulip")diff --git a/zerver/views/development/dev_login.py b/zerver/views/development/dev_login.pyindex 38cfa318d86..acf0e14d656 100644--- a/zerver/views/development/dev_login.py+++ b/zerver/views/development/dev_login.py@@ -42,7 +42,7 @@ def get_dev_users(realm: Optional[Realm] = None, extra_users_count: int = 10) ->extra_users = users_query.filter(email__startswith="extrauser").order_by("email")# Limit the number of extra users we offer by defaultextra_users = extra_users[0:extra_users_count]- users = list(shakespearian_users) + list(extra_users)+ users = [*shakespearian_users, *extra_users]return usersdiff --git a/zerver/views/documentation.py b/zerver/views/documentation.pyindex 18e484b4238..95f7628f522 100644--- a/zerver/views/documentation.py+++ b/zerver/views/documentation.py@@ -281,7 +281,7 @@ class MarkdownDirectoryView(ApiURLView):def add_integrations_context(context: Dict[str, Any]) -> None:alphabetical_sorted_categories = OrderedDict(sorted(CATEGORIES.items()))alphabetical_sorted_integration = OrderedDict(sorted(INTEGRATIONS.items()))- enabled_integrations_count = len(list(filter(lambda v: v.is_enabled(), INTEGRATIONS.values())))+ enabled_integrations_count = sum(v.is_enabled() for v in INTEGRATIONS.values())# Subtract 1 so saying "Over X integrations" is correct. Then,# round down to the nearest multiple of 10.integrations_count_display = ((enabled_integrations_count - 1) // 10) * 10diff --git a/zerver/views/realm.py b/zerver/views/realm.pyindex 33b8dd7bdb3..c87747f3812 100644--- a/zerver/views/realm.py+++ b/zerver/views/realm.py@@ -166,7 +166,7 @@ def update_realm(if authentication_methods is not None:if not user_profile.is_realm_owner:raise OrganizationOwnerRequiredError- if True not in list(authentication_methods.values()):+ if True not in authentication_methods.values():raise JsonableError(_("At least one authentication method must be enabled."))if video_chat_provider is not None and video_chat_provider not in {p["id"] for p in Realm.VIDEO_CHAT_PROVIDERS.values()@@ -285,7 +285,7 @@ def update_realm(req_vars = {}req_group_setting_vars = {}- for k, v in list(locals().items()):+ for k, v in locals().items():if k in realm.property_types:req_vars[k] = v@@ -293,7 +293,7 @@ def update_realm(if k == permissions_configuration.id_field_name:req_group_setting_vars[k] = v- for k, v in list(req_vars.items()):+ for k, v in req_vars.items():if v is not None and getattr(realm, k) != v:do_set_realm_property(realm, k, v, acting_user=user_profile)if isinstance(v, str):@@ -535,10 +535,8 @@ def update_realm_user_settings_defaults(check_settings_values(notification_sound, email_notifications_batching_period_seconds)realm_user_default = RealmUserDefault.objects.get(realm=user_profile.realm)- request_settings = {- k: v for k, v in list(locals().items()) if (k in RealmUserDefault.property_types)- }- for k, v in list(request_settings.items()):+ request_settings = {k: v for k, v in locals().items() if (k in RealmUserDefault.property_types)}+ for k, v in request_settings.items():if v is not None and getattr(realm_user_default, k) != v:do_set_realm_user_default_setting(realm_user_default, k, v, acting_user=user_profile)diff --git a/zerver/views/user_settings.py b/zerver/views/user_settings.pyindex daf5db53aaa..248002bd0b5 100644--- a/zerver/views/user_settings.py+++ b/zerver/views/user_settings.py@@ -361,8 +361,8 @@ def json_change_settings(check_change_full_name(user_profile, full_name, user_profile)# Loop over user_profile.property_types- request_settings = {k: v for k, v in list(locals().items()) if k in user_profile.property_types}- for k, v in list(request_settings.items()):+ request_settings = {k: v for k, v in locals().items() if k in user_profile.property_types}+ for k, v in request_settings.items():if v is not None and getattr(user_profile, k) != v:do_change_user_setting(user_profile, k, v, acting_user=user_profile)diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.pyindex 7ced36228ac..53f30e5a44a 100644--- a/zerver/webhooks/github/view.py+++ b/zerver/webhooks/github/view.py@@ -892,7 +892,7 @@ def get_zulip_event_name(return "issue_milestoned_or_demilestoned"else:return "issues"- elif header_event in list(EVENT_FUNCTION_MAPPER.keys()):+ elif header_event in EVENT_FUNCTION_MAPPER:return header_eventelif header_event in IGNORED_EVENTS:return Nonediff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.pyindex 750fe99a0d4..184dcdd2ec4 100644--- a/zerver/webhooks/gitlab/view.py+++ b/zerver/webhooks/gitlab/view.py@@ -526,7 +526,7 @@ def get_event(request: HttpRequest, payload: WildValue, branches: Optional[str])if branches.find(branch) == -1:return None- if event in list(EVENT_FUNCTION_MAPPER.keys()):+ if event in EVENT_FUNCTION_MAPPER:return eventraise UnsupportedWebhookEventTypeError(event)diff --git a/zerver/webhooks/jotform/view.py b/zerver/webhooks/jotform/view.pyindex b0781b33cc2..2e86949978c 100644--- a/zerver/webhooks/jotform/view.py+++ b/zerver/webhooks/jotform/view.py@@ -20,10 +20,10 @@ def api_jotform_webhook() -> HttpResponse:topic = payload["formTitle"].tame(check_string)submission_id = payload["submissionID"].tame(check_string)- fields_dict = list(payload["pretty"].tame(check_string).split(", "))+ fields = payload["pretty"].tame(check_string).split(", ")form_response = f"A new submission (ID {submission_id}) was received:\n"- for field in fields_dict:+ for field in fields:form_response += f"* {field}\n"message = form_response.strip()diff --git a/zerver/webhooks/slack/view.py b/zerver/webhooks/slack/view.pyindex 6128af02b03..da39daed62a 100644--- a/zerver/webhooks/slack/view.py+++ b/zerver/webhooks/slack/view.py@@ -26,7 +26,7 @@ def api_slack_webhook(stream: str = "slack",channels_map_to_topics: str = "1",) -> HttpResponse:- if channels_map_to_topics not in list(VALID_OPTIONS.values()):+ if channels_map_to_topics not in VALID_OPTIONS.values():raise JsonableError(_("Error: channels_map_to_topics parameter other than 0 or 1"))if channels_map_to_topics == VALID_OPTIONS["SHOULD_BE_MAPPED"]: