From 77c84ba039c0869102d5387057fd06c1b412db08 Mon Sep 17 00:00:00 2001 From: jiasli <4003950+jiasli@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:24:15 +0800 Subject: [PATCH] consider-using-dict-items --- pylintrc | 1 - .../azure/cli/core/commands/__init__.py | 6 +++--- .../azure/cli/command_modules/acr/check_health.py | 10 +++++----- .../cli/command_modules/appservice/_create_util.py | 4 ++-- .../cli/command_modules/containerapp/_up_utils.py | 12 ++++++------ .../azure_keyvault_securitydomain/_serialization.py | 4 ++-- .../azure/cli/command_modules/resource/custom.py | 4 ++-- .../azure/cli/command_modules/role/custom.py | 6 +++--- .../command_modules/serviceconnector/_validators.py | 6 +++--- 9 files changed, 26 insertions(+), 27 deletions(-) diff --git a/pylintrc b/pylintrc index d4fe9d3113c..147457d5e8b 100644 --- a/pylintrc +++ b/pylintrc @@ -41,7 +41,6 @@ disable= use-maxsplit-arg, arguments-renamed, consider-using-in, - consider-using-dict-items, consider-using-enumerate, # These rules were added in Pylint >= 2.12, disable them to avoid making retroactive change missing-timeout, diff --git a/src/azure-cli-core/azure/cli/core/commands/__init__.py b/src/azure-cli-core/azure/cli/core/commands/__init__.py index 80dd362115c..548926111c4 100644 --- a/src/azure-cli-core/azure/cli/core/commands/__init__.py +++ b/src/azure-cli-core/azure/cli/core/commands/__init__.py @@ -999,10 +999,10 @@ def _generate_template_progress(self, correlation_id): # pylint: disable=no-sel if deploy_values.get('timestamp', None) is None or \ event.event_timestamp > deploy_values.get('timestamp'): - for value in checked_values: - if deploy_values.get(checked_values[value], None) != value: + for k, v in checked_values.items(): + if deploy_values.get(v, None) != k: update = True - deploy_values[checked_values[value]] = value + deploy_values[v] = k deploy_values['timestamp'] = event.event_timestamp # don't want to show the timestamp diff --git a/src/azure-cli/azure/cli/command_modules/acr/check_health.py b/src/azure-cli/azure/cli/command_modules/acr/check_health.py index 13efdf9122e..2f74bb377d8 100644 --- a/src/azure-cli/azure/cli/command_modules/acr/check_health.py +++ b/src/azure-cli/azure/cli/command_modules/acr/check_health.py @@ -402,15 +402,15 @@ def _check_private_endpoint(cmd, registry_name, vnet_of_private_endpoint): # py ' Please make sure you provided correct vnet') raise CLIError(err.format(registry_name, vnet_of_private_endpoint)) - for fqdn in dns_mappings: + for k, v in dns_mappings.items(): try: - result = socket.gethostbyname(fqdn) - if result != dns_mappings[fqdn]: + result = socket.gethostbyname(k) + if result != v: err = 'DNS routing to registry "%s" through private IP is incorrect. Expect: %s, Actual: %s' - logger.warning(err, registry_name, dns_mappings[fqdn], result) + logger.warning(err, registry_name, v, result) dns_ok = False except Exception as e: # pylint: disable=broad-except - logger.warning('Error resolving DNS for %s. Ex: %s', fqdn, e) + logger.warning('Error resolving DNS for %s. Ex: %s', k, e) dns_ok = False if dns_ok: diff --git a/src/azure-cli/azure/cli/command_modules/appservice/_create_util.py b/src/azure-cli/azure/cli/command_modules/appservice/_create_util.py index 0be965693cd..857da341a36 100644 --- a/src/azure-cli/azure/cli/command_modules/appservice/_create_util.py +++ b/src/azure-cli/azure/cli/command_modules/appservice/_create_util.py @@ -632,8 +632,8 @@ def zip_dotnet_project_references(dirPath, zip_file_path): csproj_content = csproj_file.read() new_csproj_content = str(csproj_content) - for include in replace_dict: - new_csproj_content = str(new_csproj_content).replace(include, replace_dict[include]) + for k, v in replace_dict.items(): + new_csproj_content = str(new_csproj_content).replace(k, v) # Step 3: append transitive project references to .zip.tmp transitives_references = _get_dotnet_transitive_missing_references(abs_references) diff --git a/src/azure-cli/azure/cli/command_modules/containerapp/_up_utils.py b/src/azure-cli/azure/cli/command_modules/containerapp/_up_utils.py index cf41c805eb3..473e4754b05 100644 --- a/src/azure-cli/azure/cli/command_modules/containerapp/_up_utils.py +++ b/src/azure-cli/azure/cli/command_modules/containerapp/_up_utils.py @@ -450,9 +450,9 @@ def _docker_push_to_container_registry(self, image_name, forced_acr_login=False) task_command_kwargs = {"resource_type": ResourceType.MGMT_CONTAINERREGISTRY, 'operation_group': 'webhooks'} old_command_kwargs = {} - for key in task_command_kwargs: # pylint: disable=consider-using-dict-items - old_command_kwargs[key] = self.cmd.command_kwargs.get(key) - self.cmd.command_kwargs[key] = task_command_kwargs[key] + for k, v in task_command_kwargs.items(): + old_command_kwargs[k] = self.cmd.command_kwargs.get(k) + self.cmd.command_kwargs[k] = v if self.acr and self.acr.name is not None: acr_login(self.cmd, self.acr.name) for k, v in old_command_kwargs.items(): @@ -557,9 +557,9 @@ def build_container_from_source_with_acr_task(self, image_name, source): run_client = cf_acr_runs(self.cmd.cli_ctx) task_command_kwargs = {"resource_type": ResourceType.MGMT_CONTAINERREGISTRY, 'operation_group': 'webhooks'} old_command_kwargs = {} - for key in task_command_kwargs: # pylint: disable=consider-using-dict-items - old_command_kwargs[key] = self.cmd.command_kwargs.get(key) - self.cmd.command_kwargs[key] = task_command_kwargs[key] + for k, v in task_command_kwargs.items(): + old_command_kwargs[k] = self.cmd.command_kwargs.get(k) + self.cmd.command_kwargs[k] = v with NamedTemporaryFile(mode="w", delete=False) as task_file: try: diff --git a/src/azure-cli/azure/cli/command_modules/keyvault/vendored_sdks/azure_keyvault_securitydomain/_serialization.py b/src/azure-cli/azure/cli/command_modules/keyvault/vendored_sdks/azure_keyvault_securitydomain/_serialization.py index 7262dab2462..5f784a5823b 100644 --- a/src/azure-cli/azure/cli/command_modules/keyvault/vendored_sdks/azure_keyvault_securitydomain/_serialization.py +++ b/src/azure-cli/azure/cli/command_modules/keyvault/vendored_sdks/azure_keyvault_securitydomain/_serialization.py @@ -317,13 +317,13 @@ class Model: def __init__(self, **kwargs: Any) -> None: self.additional_properties: Optional[Dict[str, Any]] = {} - for k in kwargs: # pylint: disable=consider-using-dict-items + for k, v in kwargs.items(): if k not in self._attribute_map: _LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__) elif k in self._validation and self._validation[k].get("readonly", False): _LOGGER.warning("Readonly attribute %s will be ignored in class %s", k, self.__class__) else: - setattr(self, k, kwargs[k]) + setattr(self, k, v) def __eq__(self, other: Any) -> bool: """Compare objects by comparing all attributes. diff --git a/src/azure-cli/azure/cli/command_modules/resource/custom.py b/src/azure-cli/azure/cli/command_modules/resource/custom.py index 74181ca85b4..38338437497 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/custom.py @@ -1040,8 +1040,8 @@ def _parse_bicepparam_inline_params(parameters, template_obj): raise InvalidArgumentValueError(f"Unable to parse parameter: {parameter_item}. Only correctly formatted in-line parameters are allowed with a .bicepparam file") name_value_obj = {} - for param in parsed_inline_params: - name_value_obj[param] = parsed_inline_params[param]['value'] + for k, v in parsed_inline_params.items(): + name_value_obj[k] = v['value'] return name_value_obj diff --git a/src/azure-cli/azure/cli/command_modules/role/custom.py b/src/azure-cli/azure/cli/command_modules/role/custom.py index 640e230b2ed..92f1ebbb6f1 100644 --- a/src/azure-cli/azure/cli/command_modules/role/custom.py +++ b/src/azure-cli/azure/cli/command_modules/role/custom.py @@ -374,14 +374,14 @@ def list_role_assignment_change_logs(cmd, start_time=None, end_time=None): # py # Only query Role Definitions and Graph when there are events returned role_defs = {d.name: worker.get_role_property(d, 'role_name') for d in list_role_definitions(cmd)} - for op_id in start_events: - e = end_events.get(op_id, None) + for k, v in start_events.items(): + e = end_events.get(k, None) if not e: continue entry = {} if e.status.value == 'Succeeded': - s, payload = start_events[op_id], None + s, payload = v, None entry = dict.fromkeys( ['principalId', 'principalName', 'scope', 'scopeName', 'scopeType', 'roleDefinitionId', 'roleName'], None) diff --git a/src/azure-cli/azure/cli/command_modules/serviceconnector/_validators.py b/src/azure-cli/azure/cli/command_modules/serviceconnector/_validators.py index cb7a70a0f38..aea5bc8258c 100644 --- a/src/azure-cli/azure/cli/command_modules/serviceconnector/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/serviceconnector/_validators.py @@ -333,9 +333,9 @@ def intelligent_experience(cmd, namespace, missing_args): # apply local context arguments param_str = '' - for arg in context_arg_values: - option = missing_args[arg].get('options')[0] - value = context_arg_values[arg] + for k, v in context_arg_values.items(): + option = missing_args[k].get('options')[0] + value = v param_str += '{} {} '.format(option, value) if param_str: logger.warning('Apply local context arguments: %s', param_str.strip())