From e1ed44907b0cfca316cf291b22aaaeda64d800b3 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sun, 11 Dec 2022 18:39:16 -0800 Subject: [PATCH] ruff: Fix SIM118 Use `key in dict` instead of `key in dict.keys()`. Signed-off-by: Anders Kaseorg --- scripts/nagios/check-rabbitmq-consumers | 2 +- tools/setup/emoji/generate_emoji_names | 2 +- zerver/actions/users.py | 2 +- zerver/data_import/slack.py | 2 +- zerver/lib/event_schema.py | 6 +++--- zerver/lib/events.py | 2 +- zerver/lib/home.py | 2 +- zerver/lib/hotspots.py | 2 +- zerver/lib/message.py | 2 +- zerver/lib/retention.py | 2 +- zerver/lib/user_groups.py | 2 +- zerver/management/commands/fill_memcached_caches.py | 2 +- zerver/migrations/0382_create_role_based_system_groups.py | 2 +- .../0403_create_role_based_groups_for_internal_realms.py | 2 +- zerver/tests/test_auth_backends.py | 2 +- zerver/tests/test_docs.py | 6 +++--- zerver/tests/test_message_edit.py | 4 ++-- zerver/tests/test_settings.py | 2 +- zerver/tornado/event_queue.py | 2 +- zerver/webhooks/opbeat/view.py | 2 +- zerver/webhooks/sonarqube/view.py | 2 +- zerver/worker/queue_processors.py | 2 +- 22 files changed, 27 insertions(+), 27 deletions(-) diff --git a/scripts/nagios/check-rabbitmq-consumers b/scripts/nagios/check-rabbitmq-consumers index 03f346bb60..5d2c13ff19 100755 --- a/scripts/nagios/check-rabbitmq-consumers +++ b/scripts/nagios/check-rabbitmq-consumers @@ -53,7 +53,7 @@ for line in output.split("\n"): now = int(time.time()) -for queue_name in consumers.keys(): +for queue_name in consumers: state_file_path = "/var/lib/nagios_state/check-rabbitmq-consumers-" + queue_name state_file_tmp = state_file_path + "-tmp" diff --git a/tools/setup/emoji/generate_emoji_names b/tools/setup/emoji/generate_emoji_names index 2e825c2d6c..c1d626b092 100755 --- a/tools/setup/emoji/generate_emoji_names +++ b/tools/setup/emoji/generate_emoji_names @@ -179,7 +179,7 @@ def main() -> None: # If the alias was specifically specified in custom_emoji_names, then we can keep just # that one, but otherwise there's no particular emoji that is an obvious candidate # for the alias so just remove the alias for all relevant emoji. - for alias in alias_to_emoji_code.keys(): + for alias in alias_to_emoji_code: if len(alias_to_emoji_code[alias]) > 1: for emoji_code in alias_to_emoji_code[alias]: if emoji_code not in CUSTOM_EMOJI_NAME_MAPS: diff --git a/zerver/actions/users.py b/zerver/actions/users.py index e4972db150..1c78fd3e5d 100644 --- a/zerver/actions/users.py +++ b/zerver/actions/users.py @@ -356,7 +356,7 @@ def get_service_dicts_for_bots( for service in services ] elif bot_type == UserProfile.EMBEDDED_BOT: - if bot_profile_id in embedded_bot_configs.keys(): + if bot_profile_id in embedded_bot_configs: bot_config = embedded_bot_configs[bot_profile_id] service_dicts = [ { diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py index 755637ae25..0a99864694 100644 --- a/zerver/data_import/slack.py +++ b/zerver/data_import/slack.py @@ -910,7 +910,7 @@ def channel_message_to_zerver_message( message_id = NEXT_ID("message") - if "reactions" in message.keys(): + if "reactions" in message: build_reactions( reaction_list, message["reactions"], diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py index 731a5c5a12..878cb9512e 100644 --- a/zerver/lib/event_schema.py +++ b/zerver/lib/event_schema.py @@ -894,7 +894,7 @@ def check_realm_update( if prop == "plan_type": assert isinstance(value, int) - assert "extra_data" in event.keys() + assert "extra_data" in event return assert "extra_data" not in event.keys() @@ -1495,7 +1495,7 @@ def check_update_display_settings( assert isinstance(setting, setting_type) if setting_name == "default_language": - assert "language_name" in event.keys() + assert "language_name" in event else: assert "language_name" not in event.keys() @@ -1516,7 +1516,7 @@ def check_user_settings_update( assert isinstance(value, setting_type) if setting_name == "default_language": - assert "language_name" in event.keys() + assert "language_name" in event else: assert "language_name" not in event.keys() diff --git a/zerver/lib/events.py b/zerver/lib/events.py index c36a588ac6..42f6b0e73d 100644 --- a/zerver/lib/events.py +++ b/zerver/lib/events.py @@ -1011,7 +1011,7 @@ def apply_event( if permission in state: state[permission] = user_profile.has_permission(policy) - if event["property"] in policy_permission_dict.keys(): + if event["property"] in policy_permission_dict: if policy_permission_dict[event["property"]] in state: state[policy_permission_dict[event["property"]]] = user_profile.has_permission( event["property"] diff --git a/zerver/lib/home.py b/zerver/lib/home.py index 37678a79ca..59e92cdb18 100644 --- a/zerver/lib/home.py +++ b/zerver/lib/home.py @@ -210,7 +210,7 @@ def build_page_params_for_home_page_load( no_event_queue=user_profile is None, ) - for field_name in register_ret.keys(): + for field_name in register_ret: page_params[field_name] = register_ret[field_name] if narrow_stream is not None: diff --git a/zerver/lib/hotspots.py b/zerver/lib/hotspots.py index c1131f874e..1f66361edd 100644 --- a/zerver/lib/hotspots.py +++ b/zerver/lib/hotspots.py @@ -77,7 +77,7 @@ def get_next_hotspots(user: UserProfile) -> List[Dict[str, object]]: seen_hotspots = frozenset( UserHotspot.objects.filter(user=user).values_list("hotspot", flat=True) ) - for hotspot in INTRO_HOTSPOTS.keys(): + for hotspot in INTRO_HOTSPOTS: if hotspot not in seen_hotspots: return [ { diff --git a/zerver/lib/message.py b/zerver/lib/message.py index 77dbc25e85..764c032b16 100644 --- a/zerver/lib/message.py +++ b/zerver/lib/message.py @@ -1627,7 +1627,7 @@ def parse_message_content_edit_or_delete_limit( *, setting_name: str, ) -> Optional[int]: - if isinstance(value, str) and value in special_values_map.keys(): + if isinstance(value, str) and value in special_values_map: return special_values_map[value] if isinstance(value, str) or value <= 0: raise RequestVariableConversionError(setting_name, value) diff --git a/zerver/lib/retention.py b/zerver/lib/retention.py index d0e810b832..a2d1dce327 100644 --- a/zerver/lib/retention.py +++ b/zerver/lib/retention.py @@ -668,7 +668,7 @@ def parse_message_retention_days( value: Union[int, str], special_values_map: Mapping[str, Optional[int]], ) -> Optional[int]: - if isinstance(value, str) and value in special_values_map.keys(): + if isinstance(value, str) and value in special_values_map: return special_values_map[value] if isinstance(value, str) or value <= 0: raise RequestVariableConversionError("message_retention_days", value) diff --git a/zerver/lib/user_groups.py b/zerver/lib/user_groups.py index d034aa3c71..7774842b4d 100644 --- a/zerver/lib/user_groups.py +++ b/zerver/lib/user_groups.py @@ -208,7 +208,7 @@ def create_system_user_groups_for_realm(realm: Realm) -> Dict[int, UserGroup]: which is a copy of this function from when we introduced system groups. """ role_system_groups_dict: Dict[int, UserGroup] = {} - for role in UserGroup.SYSTEM_USER_GROUP_ROLE_MAP.keys(): + for role in UserGroup.SYSTEM_USER_GROUP_ROLE_MAP: user_group_params = UserGroup.SYSTEM_USER_GROUP_ROLE_MAP[role] user_group = UserGroup( name=user_group_params["name"], diff --git a/zerver/management/commands/fill_memcached_caches.py b/zerver/management/commands/fill_memcached_caches.py index 3972611a13..32fd29f65c 100644 --- a/zerver/management/commands/fill_memcached_caches.py +++ b/zerver/management/commands/fill_memcached_caches.py @@ -17,5 +17,5 @@ class Command(BaseCommand): fill_remote_cache(options["cache"]) return - for cache in cache_fillers.keys(): + for cache in cache_fillers: fill_remote_cache(cache) diff --git a/zerver/migrations/0382_create_role_based_system_groups.py b/zerver/migrations/0382_create_role_based_system_groups.py index a0a4f67639..fbf2e0515a 100644 --- a/zerver/migrations/0382_create_role_based_system_groups.py +++ b/zerver/migrations/0382_create_role_based_system_groups.py @@ -56,7 +56,7 @@ def create_role_based_system_groups( continue role_system_groups_dict = {} - for role in SYSTEM_USER_GROUP_ROLE_MAP.keys(): + for role in SYSTEM_USER_GROUP_ROLE_MAP: user_group_params = SYSTEM_USER_GROUP_ROLE_MAP[role] user_group = UserGroup( name=user_group_params["name"], diff --git a/zerver/migrations/0403_create_role_based_groups_for_internal_realms.py b/zerver/migrations/0403_create_role_based_groups_for_internal_realms.py index 4e2d7a8a83..771b879afc 100644 --- a/zerver/migrations/0403_create_role_based_groups_for_internal_realms.py +++ b/zerver/migrations/0403_create_role_based_groups_for_internal_realms.py @@ -65,7 +65,7 @@ def create_role_based_system_groups_for_internal_realms( return role_system_groups_dict = {} - for role in SYSTEM_USER_GROUP_ROLE_MAP.keys(): + for role in SYSTEM_USER_GROUP_ROLE_MAP: user_group_params = SYSTEM_USER_GROUP_ROLE_MAP[role] user_group = UserGroup( name=user_group_params["name"], diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index 244ee28a2c..6e1286e75c 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -243,7 +243,7 @@ class AuthBackendTest(ZulipTestCase): clear_supported_auth_backends_cache() # Verify auth fails if the auth backend is disabled for the realm - for backend_name in AUTH_BACKEND_NAME_MAP.keys(): + for backend_name in AUTH_BACKEND_NAME_MAP: if isinstance(backend, AUTH_BACKEND_NAME_MAP[backend_name]): break diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py index f38dd7f0c3..204bfff809 100644 --- a/zerver/tests/test_docs.py +++ b/zerver/tests/test_docs.py @@ -231,7 +231,7 @@ class DocPageTest(ZulipTestCase): ], ) - for integration in INTEGRATIONS.keys(): + for integration in INTEGRATIONS: url = f"/integrations/doc-html/{integration}" self._test(url, "", doc_html_str=True) @@ -253,9 +253,9 @@ class DocPageTest(ZulipTestCase): self._test(url, description, doc_html_str=True) # Test category pages - for category in CATEGORIES.keys(): + for category in CATEGORIES: url = f"/integrations/{category}" - if category in META_CATEGORY.keys(): + if category in META_CATEGORY: title = f"{CATEGORIES[category]} | Zulip integrations" og_title = f'' else: diff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.py index 847005a86b..bae919f86c 100644 --- a/zerver/tests/test_message_edit.py +++ b/zerver/tests/test_message_edit.py @@ -1683,11 +1683,11 @@ class EditMessageTest(EditMessageTestCase): msg3 = Message.objects.get(id=id3) msg1_edit_history = orjson.loads(assert_is_not_none(msg1.edit_history)) - self.assertTrue("prev_content" in msg1_edit_history[0].keys()) + self.assertTrue("prev_content" in msg1_edit_history[0]) for msg in [msg2, msg3]: self.assertFalse( - "prev_content" in orjson.loads(assert_is_not_none(msg.edit_history))[0].keys() + "prev_content" in orjson.loads(assert_is_not_none(msg.edit_history))[0] ) for msg in [msg1, msg2, msg3]: diff --git a/zerver/tests/test_settings.py b/zerver/tests/test_settings.py index e51e55f7fc..25da2ab209 100644 --- a/zerver/tests/test_settings.py +++ b/zerver/tests/test_settings.py @@ -403,7 +403,7 @@ class ChangeSettingsTest(ZulipTestCase): ) self.login("hamlet") - for setting_name in invalid_values_dict.keys(): + for setting_name in invalid_values_dict: invalid_value = invalid_values_dict.get(setting_name) if isinstance(invalid_value, str): invalid_value = orjson.dumps(invalid_value).decode() diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.py index 4c357ff471..f158af8ea2 100644 --- a/zerver/tornado/event_queue.py +++ b/zerver/tornado/event_queue.py @@ -1158,7 +1158,7 @@ def process_message_update_event( user_profile_id = user_data["id"] user_event = dict(event_template) # shallow copy, but deep enough for our needs - for key in user_data.keys(): + for key in user_data: if key != "id": user_event[key] = user_data[key] diff --git a/zerver/webhooks/opbeat/view.py b/zerver/webhooks/opbeat/view.py index a9b837c9a3..cf45f54f74 100644 --- a/zerver/webhooks/opbeat/view.py +++ b/zerver/webhooks/opbeat/view.py @@ -50,7 +50,7 @@ subject_types: Dict[str, List[List[str]]] = { def get_value(_obj: WildValue, key: str) -> str: for _key in key.lstrip("!").split("/"): - if _key in _obj.keys(): + if _key in _obj: _obj = _obj[_key] else: return "" diff --git a/zerver/webhooks/sonarqube/view.py b/zerver/webhooks/sonarqube/view.py index 48926851c0..1bd608205f 100644 --- a/zerver/webhooks/sonarqube/view.py +++ b/zerver/webhooks/sonarqube/view.py @@ -117,7 +117,7 @@ def api_sonarqube_webhook( ) -> HttpResponse: project = payload["project"]["name"].tame(check_string) branch = None - if "branch" in payload.keys(): + if "branch" in payload: branch = payload["branch"].get("name").tame(check_none_or(check_string)) if branch: topic = TOPIC_WITH_BRANCH.format(project, branch) diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py index 93109064fe..70103f790c 100644 --- a/zerver/worker/queue_processors.py +++ b/zerver/worker/queue_processors.py @@ -667,7 +667,7 @@ class MissedMessageWorker(QueueProcessingWorker): else: events_by_recipient[event.user_profile_id] = [entry] - for user_profile_id in events_by_recipient.keys(): + for user_profile_id in events_by_recipient: events: List[Dict[str, Any]] = events_by_recipient[user_profile_id] logging.info(