Skip to content

Commit

Permalink
consider-using-dict-items
Browse files Browse the repository at this point in the history
  • Loading branch information
jiasli committed Dec 4, 2024
1 parent 2c037ba commit 77c84ba
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 27 deletions.
1 change: 0 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/azure-cli-core/azure/cli/core/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/azure-cli/azure/cli/command_modules/acr/check_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/resource/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/azure-cli/azure/cli/command_modules/role/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 77c84ba

Please sign in to comment.