From 87992b8b290a2cd3f779012b046921127947531d Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 29 Feb 2024 18:02:52 -0800 Subject: [PATCH] ruff: Fix PERF403 Use a dictionary comprehension instead of a for-loop. This is a preview rule, not yet enabled by default. Signed-off-by: Anders Kaseorg --- analytics/views/stats.py | 4 +--- zerver/lib/user_groups.py | 18 +++--------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/analytics/views/stats.py b/analytics/views/stats.py index dad1a67b9c..868619b1a9 100644 --- a/analytics/views/stats.py +++ b/analytics/views/stats.py @@ -485,9 +485,7 @@ def sort_by_totals(value_arrays: Dict[str, List[int]]) -> List[str]: def sort_client_labels(data: Dict[str, Dict[str, List[int]]]) -> List[str]: realm_order = sort_by_totals(data["everyone"]) user_order = sort_by_totals(data["user"]) - label_sort_values: Dict[str, float] = {} - for i, label in enumerate(realm_order): - label_sort_values[label] = i + label_sort_values: Dict[str, float] = {label: i for i, label in enumerate(realm_order)} for i, label in enumerate(user_order): label_sort_values[label] = min(i - 0.1, label_sort_values.get(label, i)) return [label for label, sort_value in sorted(label_sort_values.items(), key=lambda x: x[1])] diff --git a/zerver/lib/user_groups.py b/zerver/lib/user_groups.py index b27f0194ad..281cf7662e 100644 --- a/zerver/lib/user_groups.py +++ b/zerver/lib/user_groups.py @@ -554,20 +554,8 @@ def get_system_user_group_for_user(user_profile: UserProfile) -> UserGroup: def get_server_supported_permission_settings() -> ServerSupportedPermissionSettings: - realm_permission_group_settings: Dict[str, GroupPermissionSetting] = {} - for permission_name, permission_config in Realm.REALM_PERMISSION_GROUP_SETTINGS.items(): - realm_permission_group_settings[permission_name] = permission_config - - stream_permission_group_settings: Dict[str, GroupPermissionSetting] = {} - for permission_name, permission_config in Stream.stream_permission_group_settings.items(): - stream_permission_group_settings[permission_name] = permission_config - - group_permission_settings: Dict[str, GroupPermissionSetting] = {} - for permission_name, permission_config in UserGroup.GROUP_PERMISSION_SETTINGS.items(): - group_permission_settings[permission_name] = permission_config - return ServerSupportedPermissionSettings( - realm=realm_permission_group_settings, - stream=stream_permission_group_settings, - group=group_permission_settings, + realm=Realm.REALM_PERMISSION_GROUP_SETTINGS, + stream=Stream.stream_permission_group_settings, + group=UserGroup.GROUP_PERMISSION_SETTINGS, )