From 818142fbc97977bea1bb677a29f2b720e0042844 Mon Sep 17 00:00:00 2001 From: Jiashuo Li <4003950+jiasli@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:20:24 +0800 Subject: [PATCH] {Pylint} Fix consider-using-enumerate (#30343) --- pylintrc | 1 - .../command_modules/acs/addonconfiguration.py | 4 ++-- .../command_modules/backup/custom_common.py | 4 ++-- .../cli/command_modules/cdn/custom/custom.py | 24 +++++++++---------- .../command_modules/storage/azcopy/util.py | 6 ++--- .../cli/command_modules/vm/_validators.py | 6 ++--- .../vm/azure_stack/_validators.py | 6 ++--- .../command_modules/vm/azure_stack/custom.py | 14 +++++------ .../azure/cli/command_modules/vm/custom.py | 14 +++++------ 9 files changed, 39 insertions(+), 40 deletions(-) diff --git a/pylintrc b/pylintrc index bb4952224d..1db71b778f 100644 --- a/pylintrc +++ b/pylintrc @@ -39,7 +39,6 @@ disable= consider-using-f-string, unspecified-encoding, consider-using-in, - consider-using-enumerate, # These rules were added in Pylint >= 2.12, disable them to avoid making retroactive change missing-timeout, # These rules were added in Pylint >= 3.2 diff --git a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py index 44d113b9c2..2114c1dcb2 100644 --- a/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py +++ b/src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py @@ -500,8 +500,8 @@ def ensure_container_insights_for_monitoring( extensionSettings["dataCollectionSettings"] = dataCollectionSettings if enable_high_log_scale_mode: - for i in range(len(cistreams)): - if cistreams[i] == "Microsoft-ContainerLogV2": + for i, v in enumerate(cistreams): + if v == "Microsoft-ContainerLogV2": cistreams[i] = "Microsoft-ContainerLogV2-HighScale" # create the DCR dcr_creation_body_without_syslog = json.dumps( diff --git a/src/azure-cli/azure/cli/command_modules/backup/custom_common.py b/src/azure-cli/azure/cli/command_modules/backup/custom_common.py index e306b4e7c6..f4295d120e 100644 --- a/src/azure-cli/azure/cli/command_modules/backup/custom_common.py +++ b/src/azure-cli/azure/cli/command_modules/backup/custom_common.py @@ -209,8 +209,8 @@ def fetch_tier_for_rp(rp): setattr(rp, "tier_type", None) return - for i in range(len(rp.properties.recovery_point_tier_details)): - currRpTierDetails = rp.properties.recovery_point_tier_details[i] + for v in rp.properties.recovery_point_tier_details: + currRpTierDetails = v if (currRpTierDetails.type == RecoveryPointTierType.ARCHIVED_RP and currRpTierDetails.status == RecoveryPointTierStatus.REHYDRATED): isRehydrated = True diff --git a/src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py b/src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py index ff7a19195d..5276ca1a47 100644 --- a/src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py +++ b/src/azure-cli/azure/cli/command_modules/cdn/custom/custom.py @@ -564,9 +564,9 @@ def add_condition(client, resource_group_name, profile_name, endpoint_name, endpoint = client.endpoints.get(resource_group_name, profile_name, endpoint_name) policy = endpoint.delivery_policy condition = create_condition(match_variable, operator, match_values, selector, negate_condition, transform) - for i in range(0, len(policy.rules)): - if policy.rules[i].name == rule_name: - policy.rules[i].conditions.append(condition) + for v in policy.rules: + if v.name == rule_name: + v.conditions.append(condition) params = EndpointUpdateParameters( delivery_policy=policy @@ -589,9 +589,9 @@ def add_action(cmd, client, resource_group_name, profile_name, endpoint_name, redirect_protocol, custom_hostname, custom_path, custom_querystring, custom_fragment, source_pattern, destination, preserve_unmatched_path, cmd, resource_group_name, profile_name, endpoint_name, origin_group) - for i in range(0, len(policy.rules)): - if policy.rules[i].name == rule_name: - policy.rules[i].actions.append(action) + for v in policy.rules: + if v.name == rule_name: + v.actions.append(action) params = EndpointUpdateParameters( delivery_policy=policy @@ -645,9 +645,9 @@ def remove_condition(client, resource_group_name, profile_name, endpoint_name, r endpoint = client.endpoints.get(resource_group_name, profile_name, endpoint_name) policy = endpoint.delivery_policy if policy is not None: - for i in range(0, len(policy.rules)): - if policy.rules[i].name == rule_name: - policy.rules[i].conditions.pop(index) + for v in policy.rules: + if v.name == rule_name: + v.conditions.pop(index) else: logger.warning("rule cannot be found. This command will be skipped. Please check the rule name") @@ -663,9 +663,9 @@ def remove_action(client, resource_group_name, profile_name, endpoint_name, rule endpoint = client.endpoints.get(resource_group_name, profile_name, endpoint_name) policy = endpoint.delivery_policy if policy is not None: - for i in range(0, len(policy.rules)): - if policy.rules[i].name == rule_name: - policy.rules[i].actions.pop(index) + for v in policy.rules: + if v.name == rule_name: + v.actions.pop(index) else: logger.warning("rule cannot be found. This command will be skipped. Please check the rule name") diff --git a/src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py b/src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py index d7be927efe..d39940196b 100644 --- a/src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py +++ b/src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py @@ -92,9 +92,9 @@ class AzCopy: def run_command(self, args): args = [self.executable] + args args_hides = args.copy() - for i in range(len(args_hides)): - if args_hides[i].find('sig') > 0: - args_hides[i] = args_hides[i][0:args_hides[i].index('sig') + 4] + for i, v in enumerate(args_hides): + if v.find('sig') > 0: + args_hides[i] = v[0:v.index('sig') + 4] logger.warning("Azcopy command: %s", args_hides) env_kwargs = {} if self.creds and self.creds.tenant_id: diff --git a/src/azure-cli/azure/cli/command_modules/vm/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/_validators.py index 640938125f..5ebe4888ea 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_validators.py @@ -2176,9 +2176,9 @@ def process_assign_identity_namespace(cmd, namespace): def process_remove_identity_namespace(cmd, namespace): if namespace.identities: from ._vm_utils import MSI_LOCAL_ID - for i in range(len(namespace.identities)): - if namespace.identities[i] != MSI_LOCAL_ID: - namespace.identities[i] = _get_resource_id(cmd.cli_ctx, namespace.identities[i], + for i, identity in enumerate(namespace.identities): + if identity != MSI_LOCAL_ID: + namespace.identities[i] = _get_resource_id(cmd.cli_ctx, identity, namespace.resource_group_name, 'userAssignedIdentities', 'Microsoft.ManagedIdentity') diff --git a/src/azure-cli/azure/cli/command_modules/vm/azure_stack/_validators.py b/src/azure-cli/azure/cli/command_modules/vm/azure_stack/_validators.py index 32f9f5ba88..e63eece65d 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/azure_stack/_validators.py +++ b/src/azure-cli/azure/cli/command_modules/vm/azure_stack/_validators.py @@ -2194,9 +2194,9 @@ def process_assign_identity_namespace(cmd, namespace): def process_remove_identity_namespace(cmd, namespace): if namespace.identities: from ._vm_utils import MSI_LOCAL_ID - for i in range(len(namespace.identities)): - if namespace.identities[i] != MSI_LOCAL_ID: - namespace.identities[i] = _get_resource_id(cmd.cli_ctx, namespace.identities[i], + for i, identity in enumerate(namespace.identities): + if identity != MSI_LOCAL_ID: + namespace.identities[i] = _get_resource_id(cmd.cli_ctx, identity, namespace.resource_group_name, 'userAssignedIdentities', 'Microsoft.ManagedIdentity') diff --git a/src/azure-cli/azure/cli/command_modules/vm/azure_stack/custom.py b/src/azure-cli/azure/cli/command_modules/vm/azure_stack/custom.py index 3354c3c230..58e41134a3 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/azure_stack/custom.py +++ b/src/azure-cli/azure/cli/command_modules/vm/azure_stack/custom.py @@ -5046,9 +5046,9 @@ def get_image_version_to_update(cmd, resource_group_name, gallery_name, gallery_ if version.storage_profile.os_disk_image and version.storage_profile.os_disk_image.source: version.storage_profile.os_disk_image.source = None if version.storage_profile.data_disk_images: - for i in range(len(version.storage_profile.data_disk_images)): - if version.storage_profile.data_disk_images[i].source: - version.storage_profile.data_disk_images[i].source = None + for v in version.storage_profile.data_disk_images: + if v.source: + v.source = None return version @@ -5914,10 +5914,10 @@ def restore_point_create(client, raise ArgumentUsageError( 'Length of --source-data-disk-resource, --data-disk-restore-point-encryption-type must be same.') - for i in range(len(source_data_disk_resource)): + for i, v in enumerate(source_data_disk_resource): data_disks.append({ 'managedDisk': { - 'id': source_data_disk_resource[i] + 'id': v }, 'diskRestorePoint': { 'encryption': { @@ -5977,11 +5977,11 @@ def restore_point_create(client, raise ArgumentUsageError( 'Length of --source-data-disk-resource, --data-disk-restore-point-encryption-type must be same.') - for i in range(len(source_data_disk_resource)): + for i, v in enumerate(source_data_disk_resource): data_disks.append({ 'diskRestorePoint': { 'sourceDiskRestorePoint': { - 'id': source_data_disk_resource[i] + 'id': v }, 'encryption': { 'disk_encryption_set': { diff --git a/src/azure-cli/azure/cli/command_modules/vm/custom.py b/src/azure-cli/azure/cli/command_modules/vm/custom.py index 26abe84754..98a5097003 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/custom.py +++ b/src/azure-cli/azure/cli/command_modules/vm/custom.py @@ -5002,9 +5002,9 @@ def get_image_version_to_update(cmd, resource_group_name, gallery_name, gallery_ if version.storage_profile.os_disk_image and version.storage_profile.os_disk_image.source: version.storage_profile.os_disk_image.source = None if version.storage_profile.data_disk_images: - for i in range(len(version.storage_profile.data_disk_images)): - if version.storage_profile.data_disk_images[i].source: - version.storage_profile.data_disk_images[i].source = None + for v in version.storage_profile.data_disk_images: + if v.source: + v.source = None return version @@ -5835,10 +5835,10 @@ def restore_point_create(client, if data_disk_restore_point_encryption_type is not None and (len(source_data_disk_resource) != len(data_disk_restore_point_encryption_type)): raise ArgumentUsageError('Length of --source-data-disk-resource, --data-disk-restore-point-encryption-type must be same.') - for i in range(len(source_data_disk_resource)): + for i, v in enumerate(source_data_disk_resource): data_disks.append({ 'managedDisk': { - 'id': source_data_disk_resource[i] + 'id': v }, 'diskRestorePoint': { 'encryption': { @@ -5890,11 +5890,11 @@ def restore_point_create(client, if data_disk_restore_point_encryption_type is not None and (len(source_data_disk_resource) != len(data_disk_restore_point_encryption_type)): raise ArgumentUsageError('Length of --source-data-disk-resource, --data-disk-restore-point-encryption-type must be same.') - for i in range(len(source_data_disk_resource)): + for i, v in enumerate(source_data_disk_resource): data_disks.append({ 'diskRestorePoint': { 'sourceDiskRestorePoint': { - 'id': source_data_disk_resource[i] + 'id': v }, 'encryption': { 'disk_encryption_set': {