Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

ruff: Fix PERF102 Using only the keys/values of a dict.

Anders Kaseorgc4748298bb74
diff --git a/tools/setup/emoji/emoji_setup_utils.py b/tools/setup/emoji/emoji_setup_utils.py
index 628e57c5108..cbb06d2adea 100644
--- a/tools/setup/emoji/emoji_setup_utils.py
+++ b/tools/setup/emoji/emoji_setup_utils.py
@@ -53,7 +53,7 @@ EMOTICON_CONVERSIONS = {
def emoji_names_for_picker(emoji_name_maps: Dict[str, Dict[str, Any]]) -> List[str]:
emoji_names: List[str] = []
- for emoji_code, name_info in emoji_name_maps.items():
+ for name_info in emoji_name_maps.values():
emoji_names.append(name_info["canonical_name"])
emoji_names.extend(name_info["aliases"])
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py
index ba804205583..e14fdec317d 100644
--- a/zerver/data_import/slack.py
+++ b/zerver/data_import/slack.py
@@ -366,7 +366,7 @@ def build_customprofile_field(
# The name of the custom profile field is not provided in the Slack data
# Hash keys of the fields are provided
# Reference: https://api.slack.com/methods/users.profile.set
- for field, value in fields.items():
+ for field in fields:
if field not in slack_custom_field_name_to_zulip_custom_field_id:
slack_custom_fields = ["phone", "skype"]
if field in slack_custom_fields:
diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py
index e18bbe4df6c..a0073a2fc3b 100644
--- a/zerver/lib/cache.py
+++ b/zerver/lib/cache.py
@@ -367,9 +367,7 @@ def generic_bulk_cached_fetch(
[cache_keys[object_id] for object_id in object_ids],
)
- cached_objects: Dict[str, CacheItemT] = {}
- for key, val in cached_objects_compressed.items():
- cached_objects[key] = extractor(cached_objects_compressed[key][0])
+ cached_objects = {key: extractor(val[0]) for key, val in cached_objects_compressed.items()}
needed_ids = [
object_id for object_id in object_ids if cache_keys[object_id] not in cached_objects
]
diff --git a/zerver/lib/rate_limiter.py b/zerver/lib/rate_limiter.py
index d3a89201811..338d07ea5a9 100644
--- a/zerver/lib/rate_limiter.py
+++ b/zerver/lib/rate_limiter.py
@@ -282,7 +282,7 @@ class TornadoInMemoryRateLimiterBackend(RateLimiterBackend):
@classmethod
def clear_history(cls, entity_key: str) -> None:
- for rule, reset_times_for_rule in cls.reset_times.items():
+ for reset_times_for_rule in cls.reset_times.values():
reset_times_for_rule.pop(entity_key, None)
cls.timestamps_blocked_until.pop(entity_key, None)
diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py
index adb81a83453..a94d2fabe39 100644
--- a/zerver/lib/streams.py
+++ b/zerver/lib/streams.py
@@ -73,7 +73,7 @@ def get_stream_permission_policy_name(
is_web_public: Optional[bool] = None,
) -> str:
policy_name = None
- for permission, permission_dict in Stream.PERMISSION_POLICIES.items():
+ for permission_dict in Stream.PERMISSION_POLICIES.values():
if (
permission_dict["invite_only"] == invite_only
and permission_dict["history_public_to_subscribers"] == history_public_to_subscribers
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index 62a3b88fd81..ec5383e0722 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -1558,7 +1558,7 @@ Output:
"""
directory = orjson.loads(self.fixture_data("directory.json", type="ldap"))
- for dn, attrs in directory.items():
+ for attrs in directory.values():
if "uid" in attrs:
# Generate a password for the LDAP account:
attrs["userPassword"] = [self.ldap_password(attrs["uid"][0])]
diff --git a/zerver/management/commands/compilemessages.py b/zerver/management/commands/compilemessages.py
index 4d92491bec9..86f15ffac12 100644
--- a/zerver/management/commands/compilemessages.py
+++ b/zerver/management/commands/compilemessages.py
@@ -145,7 +145,7 @@ class Command(compilemessages.Command):
# frontend stats
with open(self.get_json_filename(locale_path, locale), "rb") as reader:
- for key, value in orjson.loads(reader.read()).items():
+ for value in orjson.loads(reader.read()).values():
total += 1
if value == "":
not_translated += 1
diff --git a/zerver/models.py b/zerver/models.py
index f033c116b8d..efcdc0185a4 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -1064,7 +1064,7 @@ def avatar_changes_disabled(realm: Realm) -> bool:
def get_org_type_display_name(org_type: int) -> str:
- for realm_type, realm_type_details in Realm.ORG_TYPES.items():
+ for realm_type_details in Realm.ORG_TYPES.values():
if realm_type_details["id"] == org_type:
return realm_type_details["name"]
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 19a85c8aff3..ba0165dbce3 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -1959,7 +1959,7 @@ class NormalActionsTest(BaseAction):
check_user_group_add_members("events[3]", events[3])
def test_change_notification_settings(self) -> None:
- for notification_setting, v in self.user_profile.notification_setting_types.items():
+ for notification_setting in self.user_profile.notification_setting_types:
if notification_setting in [
"notification_sound",
"desktop_icon_count_display",
diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.py
index 0f766278e1e..bc1209b5766 100644
--- a/zerver/tests/test_slack_importer.py
+++ b/zerver/tests/test_slack_importer.py
@@ -1345,8 +1345,7 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(Message.objects.filter(realm=realm).count(), 82)
# All auth backends are enabled initially.
- for name, enabled in realm.authentication_methods_dict().items():
- self.assertTrue(enabled)
+ self.assertTrue(all(realm.authentication_methods_dict().values()))
Realm.objects.filter(name=test_realm_subdomain).delete()