From b72e38c909b7de9f2a731c08b7e6a0c49fcc0942 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 12 Nov 2025 21:58:36 +0100 Subject: [PATCH] [PR #11115/58bb1e7c backport][stable-12] fix ruff case B007 (#11131) fix ruff case B007 (#11115) * fix ruff case B007 * rollback inventory/iocage * re-do the fix in inventory/iocage * add cases in tests/unit/plugins * rollback plugins/module_utils/memset.py * rollback extraneous changes in plugins/modules/xcc_redfish_command.py * add changelog frag (cherry picked from commit 58bb1e7c0409777ac1b78be2d4903ade3325d42f) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- changelogs/fragments/11115-ruff-cases-1.yml | 28 +++++++++++++++++ plugins/callback/elastic.py | 4 +-- plugins/callback/opentelemetry.py | 4 +-- plugins/connection/wsl.py | 4 +-- plugins/inventory/cobbler.py | 2 +- plugins/inventory/iocage.py | 4 +-- plugins/module_utils/_stormssh.py | 2 +- .../identity/keycloak/keycloak.py | 4 +-- plugins/module_utils/redfish_utils.py | 2 +- plugins/modules/ali_instance.py | 2 +- plugins/modules/apt_rpm.py | 2 +- plugins/modules/dnf_config_manager.py | 2 +- plugins/modules/haproxy.py | 2 +- plugins/modules/hpilo_info.py | 2 +- plugins/modules/hwc_ecs_instance.py | 14 ++++----- plugins/modules/hwc_vpc_port.py | 30 ++++++++----------- plugins/modules/influxdb_user.py | 2 +- plugins/modules/keycloak_authentication.py | 2 +- .../modules/keycloak_client_rolemapping.py | 4 +-- plugins/modules/keycloak_component.py | 6 ++-- plugins/modules/keycloak_realm_key.py | 6 ++-- plugins/modules/keycloak_realm_rolemapping.py | 4 +-- plugins/modules/keycloak_user_rolemapping.py | 4 +-- plugins/modules/keycloak_userprofile.py | 6 ++-- plugins/modules/nmcli.py | 2 +- plugins/modules/pear.py | 4 --- plugins/modules/xbps.py | 2 +- plugins/modules/xcc_redfish_command.py | 2 +- ruff.toml | 1 - tests/unit/plugins/inventory/test_iocage.py | 4 +-- tests/unit/plugins/module_utils/test_csv.py | 2 +- .../unit/plugins/modules/test_pritunl_org.py | 4 +-- 32 files changed, 90 insertions(+), 73 deletions(-) create mode 100644 changelogs/fragments/11115-ruff-cases-1.yml diff --git a/changelogs/fragments/11115-ruff-cases-1.yml b/changelogs/fragments/11115-ruff-cases-1.yml new file mode 100644 index 0000000000..77f9f63742 --- /dev/null +++ b/changelogs/fragments/11115-ruff-cases-1.yml @@ -0,0 +1,28 @@ +minor_changes: + - elastic callback plugin - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - opentelemetry callback plugin - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - wsl connection plugin - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - cobbler inventory plugin - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - iocage inventory plugin - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - _stormssh module utils - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - keycloak module utils - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - redfish_utils module utils - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - ali_instance - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - apt_rpm - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - dnf_config_manager - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - haproxy - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - hpilo_info - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - hwc_ecs_instance - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - hwc_vpc_port - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - influxdb_user - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - keycloak_authentication - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - keycloak_client_rolemapping - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - keycloak_component - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - keycloak_realm_key - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - keycloak_realm_rolemapping - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - keycloak_user_rolemapping - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - keycloak_userprofile - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - nmcli - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - pear - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - xbps - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). + - xcc_redfish_command - fix cases of unused variables in loops (https://github.com/ansible-collections/community.general/pull/11115). diff --git a/plugins/callback/elastic.py b/plugins/callback/elastic.py index c64934b06a..ad1a748c71 100644 --- a/plugins/callback/elastic.py +++ b/plugins/callback/elastic.py @@ -201,7 +201,7 @@ class ElasticSource: tasks = [] parent_start_time = None - for task_uuid, task in tasks_data.items(): + for task in tasks_data.values(): if parent_start_time is None: parent_start_time = task.start tasks.append(task) @@ -224,7 +224,7 @@ class ElasticSource: label(ansible_host_ip=self.ip_address) for task_data in tasks: - for host_uuid, host_data in task_data.host_data.items(): + for host_data in task_data.host_data.values(): self.create_span_data(apm_cli, task_data, host_data) apm_cli.end_transaction(name=__name__, result=status, duration=end_time - parent_start_time) diff --git a/plugins/callback/opentelemetry.py b/plugins/callback/opentelemetry.py index 2e318de136..ed2961b9b3 100644 --- a/plugins/callback/opentelemetry.py +++ b/plugins/callback/opentelemetry.py @@ -272,7 +272,7 @@ class OpenTelemetrySource: tasks = [] parent_start_time = None - for task_uuid, task in tasks_data.items(): + for task in tasks_data.values(): if parent_start_time is None: parent_start_time = task.start tasks.append(task) @@ -309,7 +309,7 @@ class OpenTelemetrySource: parent.set_attribute("ansible.host.ip", self.ip_address) parent.set_attribute("ansible.host.user", self.user) for task in tasks: - for host_uuid, host_data in task.host_data.items(): + for host_data in task.host_data.values(): with tracer.start_as_current_span(task.name, start_time=task.start, end_on_exit=False) as span: self.update_span_data(task, host_data, span, disable_logs, disable_attributes_in_logs) diff --git a/plugins/connection/wsl.py b/plugins/connection/wsl.py index 9a3839bf02..4a37e8c601 100644 --- a/plugins/connection/wsl.py +++ b/plugins/connection/wsl.py @@ -541,8 +541,8 @@ class Connection(ConnectionBase): return self def _any_keys_added(self) -> bool: - for hostname, keys in self.ssh._host_keys.items(): # type: ignore[attr-defined] # TODO: figure out what _host_keys is! - for keytype, key in keys.items(): + for host_keys in self.ssh._host_keys.values(): # type: ignore[attr-defined] # TODO: figure out what _host_keys is! + for key in host_keys.values(): added_this_time = getattr(key, "_added_by_ansible_this_time", False) if added_this_time: return True diff --git a/plugins/inventory/cobbler.py b/plugins/inventory/cobbler.py index 45e01aecbb..55b6d4afbf 100644 --- a/plugins/inventory/cobbler.py +++ b/plugins/inventory/cobbler.py @@ -373,7 +373,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable): ip_address_first = None ipv6_address = None ipv6_address_first = None - for iname, ivalue in interfaces.items(): + for ivalue in interfaces.values(): # Set to first interface or management interface if defined or hostname matches dns_name if ivalue["ip_address"] != "": if ip_address_first is None: diff --git a/plugins/inventory/iocage.py b/plugins/inventory/iocage.py index ae8a85db4a..18300f5e4e 100644 --- a/plugins/inventory/iocage.py +++ b/plugins/inventory/iocage.py @@ -292,7 +292,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): self.get_jails(t_stdout, results) if get_properties: - for hostname, host_vars in results["_meta"]["hostvars"].items(): + for hostname in results["_meta"]["hostvars"]: cmd_get_properties = cmd.copy() cmd_get_properties.append(self.IOCAGE) cmd_get_properties.append("get") @@ -335,7 +335,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): except Exception as e: raise AnsibleError(f"Failed to get pool: {e}") from e - for hostname, host_vars in results["_meta"]["hostvars"].items(): + for hostname in results["_meta"]["hostvars"]: iocage_hooks = [] for hook in hooks_results: path = f"/{iocage_pool}/iocage/jails/{hostname}/root{hook}" diff --git a/plugins/module_utils/_stormssh.py b/plugins/module_utils/_stormssh.py index 4e71a77019..a298b406c0 100644 --- a/plugins/module_utils/_stormssh.py +++ b/plugins/module_utils/_stormssh.py @@ -184,7 +184,7 @@ class ConfigParser: continue searchable_information = host_entry.get("host") - for key, value in host_entry.get("options").items(): + for value in host_entry.get("options").values(): if isinstance(value, list): value = " ".join(value) if isinstance(value, int): diff --git a/plugins/module_utils/identity/keycloak/keycloak.py b/plugins/module_utils/identity/keycloak/keycloak.py index 4f6360b179..60295c863c 100644 --- a/plugins/module_utils/identity/keycloak/keycloak.py +++ b/plugins/module_utils/identity/keycloak/keycloak.py @@ -2350,7 +2350,7 @@ class KeycloakAPI: """ try: if diff > 0: - for i in range(diff): + for _i in range(diff): self._request( URL_AUTHENTICATION_EXECUTION_RAISE_PRIORITY.format( url=self.baseurl, realm=realm, id=executionId @@ -2358,7 +2358,7 @@ class KeycloakAPI: method="POST", ) elif diff < 0: - for i in range(-diff): + for _i in range(-diff): self._request( URL_AUTHENTICATION_EXECUTION_LOWER_PRIORITY.format( url=self.baseurl, realm=realm, id=executionId diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index c1dbab2f85..1843635fa0 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -2913,7 +2913,7 @@ class RedfishUtils: @staticmethod def _virt_media_image_inserted(resources, image_url): - for uri, data in resources.items(): + for data in resources.values(): if data.get("Image"): if urlparse(image_url) == urlparse(data.get("Image")): if data.get("Inserted", False) and data.get("ImageName"): diff --git a/plugins/modules/ali_instance.py b/plugins/modules/ali_instance.py index aa714c456f..faedaf34b3 100644 --- a/plugins/modules/ali_instance.py +++ b/plugins/modules/ali_instance.py @@ -890,7 +890,7 @@ def main(): if state == "present": if not instance_ids: if len(instances) > count: - for i in range(0, len(instances) - count): + for _i in range(0, len(instances) - count): inst = instances[len(instances) - 1] if inst.status != "stopped" and not force: module.fail_json( diff --git a/plugins/modules/apt_rpm.py b/plugins/modules/apt_rpm.py index 2b8714859e..57c3d21d2c 100644 --- a/plugins/modules/apt_rpm.py +++ b/plugins/modules/apt_rpm.py @@ -210,7 +210,7 @@ def update_package_db(module): def dir_size(module, path): total_size = 0 - for cur_path, dirs, files in os.walk(path): + for cur_path, _dirs, files in os.walk(path): for f in files: total_size += os.path.getsize(os.path.join(cur_path, f)) return total_size diff --git a/plugins/modules/dnf_config_manager.py b/plugins/modules/dnf_config_manager.py index 9c6dd10a5a..a78961c293 100644 --- a/plugins/modules/dnf_config_manager.py +++ b/plugins/modules/dnf_config_manager.py @@ -133,7 +133,7 @@ def get_repo_states(module): repos = dict() last_repo = "" - for i, line in enumerate(out.split("\n")): + for line in out.split("\n"): m = REPO_ID_RE.match(line) if m: if len(last_repo) > 0: diff --git a/plugins/modules/haproxy.py b/plugins/modules/haproxy.py index d66dd276bf..885b0505d4 100644 --- a/plugins/modules/haproxy.py +++ b/plugins/modules/haproxy.py @@ -359,7 +359,7 @@ class HAProxy: the expected status in that time, the module will fail. If the service was not found, the module will fail. """ - for i in range(1, self.wait_retries): + for _i in range(1, self.wait_retries): state = self.get_state_for(pxname, svname) # We can assume there will only be 1 element in state because both svname and pxname are always set when we get here diff --git a/plugins/modules/hpilo_info.py b/plugins/modules/hpilo_info.py index e3d1132327..7f43ac1e2a 100644 --- a/plugins/modules/hpilo_info.py +++ b/plugins/modules/hpilo_info.py @@ -234,7 +234,7 @@ def main(): if memory_details_summary: info["hw_memory_details_summary"] = memory_details_summary info["hw_memory_total"] = 0 - for cpu, details in memory_details_summary.items(): + for details in memory_details_summary.values(): cpu_total_memory_size = details.get("total_memory_size") if cpu_total_memory_size: ram = re.search(r"(\d+)\s+(\w+)", cpu_total_memory_size) diff --git a/plugins/modules/hwc_ecs_instance.py b/plugins/modules/hwc_ecs_instance.py index 146fc4c8d2..e623ed2dd4 100644 --- a/plugins/modules/hwc_ecs_instance.py +++ b/plugins/modules/hwc_ecs_instance.py @@ -1174,16 +1174,14 @@ def expand_delete_servers(d, array_index): req = [] - n = 1 - for i in range(n): - transformed = dict() + transformed = dict() - v = expand_delete_servers_id(d, new_ai) - if not is_empty_value(v): - transformed["id"] = v + v = expand_delete_servers_id(d, new_ai) + if not is_empty_value(v): + transformed["id"] = v - if transformed: - req.append(transformed) + if transformed: + req.append(transformed) return req diff --git a/plugins/modules/hwc_vpc_port.py b/plugins/modules/hwc_vpc_port.py index 189435a547..0814eaee12 100644 --- a/plugins/modules/hwc_vpc_port.py +++ b/plugins/modules/hwc_vpc_port.py @@ -509,16 +509,14 @@ def expand_create_fixed_ips(d, array_index): req = [] - n = 1 - for i in range(n): - transformed = dict() + transformed = dict() - v = navigate_value(d, ["ip_address"], new_array_index) - if not is_empty_value(v): - transformed["ip_address"] = v + v = navigate_value(d, ["ip_address"], new_array_index) + if not is_empty_value(v): + transformed["ip_address"] = v - if transformed: - req.append(transformed) + if transformed: + req.append(transformed) return req @@ -1011,17 +1009,15 @@ def expand_list_fixed_ips(d, array_index): req = [] - n = 1 - for i in range(n): - transformed = dict() + transformed = dict() - v = navigate_value(d, ["ip_address"], new_array_index) - transformed["ip_address"] = v + v = navigate_value(d, ["ip_address"], new_array_index) + transformed["ip_address"] = v - for v in transformed.values(): - if v is not None: - req.append(transformed) - break + for v in transformed.values(): + if v is not None: + req.append(transformed) + break return req if req else None diff --git a/plugins/modules/influxdb_user.py b/plugins/modules/influxdb_user.py index 2bee172f09..fb1a9dc08b 100644 --- a/plugins/modules/influxdb_user.py +++ b/plugins/modules/influxdb_user.py @@ -175,7 +175,7 @@ def set_user_grants(module, client, user_name, grants): try: parsed_grants = [] # Fix privileges wording - for i, v in enumerate(current_grants): + for v in current_grants: if v["privilege"] != "NO PRIVILEGES": if v["privilege"] == "ALL PRIVILEGES": v["privilege"] = "ALL" diff --git a/plugins/modules/keycloak_authentication.py b/plugins/modules/keycloak_authentication.py index 72225d6182..455df642e2 100644 --- a/plugins/modules/keycloak_authentication.py +++ b/plugins/modules/keycloak_authentication.py @@ -289,7 +289,7 @@ def create_or_update_executions(kc, config, realm="master"): if exec_index != -1: # Remove key that doesn't need to be compared with existing_exec exclude_key = ["flowAlias", "subFlowType"] - for index_key, key in enumerate(new_exec, start=0): + for key in new_exec: if new_exec[key] is None: exclude_key.append(key) # Compare the executions to see if it need changes diff --git a/plugins/modules/keycloak_client_rolemapping.py b/plugins/modules/keycloak_client_rolemapping.py index cc5fc68169..e190102488 100644 --- a/plugins/modules/keycloak_client_rolemapping.py +++ b/plugins/modules/keycloak_client_rolemapping.py @@ -326,7 +326,7 @@ def main(): if roles is None: module.exit_json(msg="Nothing to do (no roles specified).") else: - for role_index, role in enumerate(roles, start=0): + for role in roles: if role["name"] is None and role["id"] is None: module.fail_json(msg="Either the `name` or `id` has to be specified on each role.") # Fetch missing role_id @@ -350,7 +350,7 @@ def main(): result["proposed"] = list(assigned_roles_before) if assigned_roles_before else [] update_roles = [] - for role_index, role in enumerate(roles, start=0): + for role in roles: # Fetch roles to assign if state present if state == "present": for available_role in available_roles_before: diff --git a/plugins/modules/keycloak_component.py b/plugins/modules/keycloak_component.py index 14d6d90bf4..52312e0c95 100644 --- a/plugins/modules/keycloak_component.py +++ b/plugins/modules/keycloak_component.py @@ -254,7 +254,7 @@ def main(): changeset_copy["id"] = component_id # Compare top-level parameters - for param, value in changeset.items(): + for param in changeset: before_component[param] = component[param] if changeset_copy[param] != component[param] and param != "config": @@ -266,8 +266,8 @@ def main(): before_component["config"][p] = component["config"][p] or [] except KeyError: before_component["config"][p] = [] - if changeset_copy["config"][p] != component["config"][p]: - changes += f"config.{p}: {component['config'][p]} -> {changeset_copy['config'][p]}, " + if v != component["config"][p]: + changes += f"config.{p}: {component['config'][p]} -> {v}, " result["changed"] = True # Check all the possible states of the resource and do what is needed to diff --git a/plugins/modules/keycloak_realm_key.py b/plugins/modules/keycloak_realm_key.py index 30ad35480a..3824c9a4ef 100644 --- a/plugins/modules/keycloak_realm_key.py +++ b/plugins/modules/keycloak_realm_key.py @@ -392,7 +392,7 @@ def main(): changeset_copy["id"] = key_id # Compare top-level parameters - for param, value in changeset.items(): + for param in changeset: before_realm_key[param] = key[param] if changeset_copy[param] != key[param] and param != "config": @@ -402,8 +402,8 @@ def main(): # Compare parameters under the "config" key for p, v in changeset_copy["config"].items(): before_realm_key["config"][p] = key["config"][p] - if changeset_copy["config"][p] != key["config"][p]: - changes += f"config.{p}: {key['config'][p]} -> {changeset_copy['config'][p]}, " + if v != key["config"][p]: + changes += f"config.{p}: {key['config'][p]} -> {v}, " result["changed"] = True # Sanitize linefeeds for the privateKey. Without this the JSON payload diff --git a/plugins/modules/keycloak_realm_rolemapping.py b/plugins/modules/keycloak_realm_rolemapping.py index c0c577e20f..c9f00e9d8d 100644 --- a/plugins/modules/keycloak_realm_rolemapping.py +++ b/plugins/modules/keycloak_realm_rolemapping.py @@ -304,7 +304,7 @@ def main(): if roles is None: module.exit_json(msg="Nothing to do (no roles specified).") else: - for role_index, role in enumerate(roles, start=0): + for role in roles: if role["name"] is None and role["id"] is None: module.fail_json(msg="Either the `name` or `id` has to be specified on each role.") # Fetch missing role_id @@ -330,7 +330,7 @@ def main(): result["proposed"] = list(assigned_roles_before) if assigned_roles_before else [] update_roles = [] - for role_index, role in enumerate(roles, start=0): + for role in roles: # Fetch roles to assign if state present if state == "present": if any(assigned == role["name"] for assigned in assigned_roles_before): diff --git a/plugins/modules/keycloak_user_rolemapping.py b/plugins/modules/keycloak_user_rolemapping.py index 7ad62aa0cb..2e5609e08a 100644 --- a/plugins/modules/keycloak_user_rolemapping.py +++ b/plugins/modules/keycloak_user_rolemapping.py @@ -333,7 +333,7 @@ def main(): if roles is None: module.exit_json(msg="Nothing to do (no roles specified).") else: - for role_index, role in enumerate(roles, start=0): + for role in roles: if role.get("name") is None and role.get("id") is None: module.fail_json(msg="Either the `name` or `id` has to be specified on each role.") # Fetch missing role_id @@ -373,7 +373,7 @@ def main(): result["proposed"] = roles update_roles = [] - for role_index, role in enumerate(roles, start=0): + for role in roles: # Fetch roles to assign if state present if state == "present": for available_role in available_roles_before: diff --git a/plugins/modules/keycloak_userprofile.py b/plugins/modules/keycloak_userprofile.py index ecff05bfbf..7664d77ea2 100644 --- a/plugins/modules/keycloak_userprofile.py +++ b/plugins/modules/keycloak_userprofile.py @@ -664,7 +664,7 @@ def main(): ) # Compare top-level parameters - for param, value in changeset.items(): + for param in changeset: before_realm_userprofile[param] = userprofile[param] if changeset_copy[param] != userprofile[param] and param != "config": @@ -674,8 +674,8 @@ def main(): # Compare parameters under the "config" userprofile for p, v in changeset_copy["config"].items(): before_realm_userprofile["config"][p] = userprofile["config"][p] - if changeset_copy["config"][p] != userprofile["config"][p]: - changes += f"config.{p}: {userprofile['config'][p]} -> {changeset_copy['config'][p]}, " + if v != userprofile["config"][p]: + changes += f"config.{p}: {userprofile['config'][p]} -> {v}, " result["changed"] = True # Check all the possible states of the resource and do what is needed to diff --git a/plugins/modules/nmcli.py b/plugins/modules/nmcli.py index 265427daf3..02800e8f6a 100644 --- a/plugins/modules/nmcli.py +++ b/plugins/modules/nmcli.py @@ -2553,7 +2553,7 @@ class Nmcli: supported_properties = self.get_supported_properties(setting) unsupported_properties = [] - for property, value in getattr(self, setting_key).items(): + for property in getattr(self, setting_key): if property not in supported_properties: unsupported_properties.append(property) diff --git a/plugins/modules/pear.py b/plugins/modules/pear.py index 2fad89ff94..df614b5ed6 100644 --- a/plugins/modules/pear.py +++ b/plugins/modules/pear.py @@ -311,10 +311,6 @@ def main(): if p["name"]: pkgs = p["name"].split(",") - pkg_files = [] - for i, pkg in enumerate(pkgs): - pkg_files.append(None) - if module.check_mode: check_packages(module, pkgs, p["state"]) diff --git a/plugins/modules/xbps.py b/plugins/modules/xbps.py index fca8995c62..619e6fccaf 100644 --- a/plugins/modules/xbps.py +++ b/plugins/modules/xbps.py @@ -283,7 +283,7 @@ def remove_packages(module, xbps_path, packages): def install_packages(module, xbps_path, state, packages): """Returns true if package install succeeds.""" toInstall = [] - for i, package in enumerate(packages): + for package in packages: """If the package is installed and state == present or state == latest and is up-to-date then skip""" installed, updated = query_package(module, xbps_path, package) diff --git a/plugins/modules/xcc_redfish_command.py b/plugins/modules/xcc_redfish_command.py index 8f25919f02..85ac5ad26f 100644 --- a/plugins/modules/xcc_redfish_command.py +++ b/plugins/modules/xcc_redfish_command.py @@ -418,7 +418,7 @@ class XCCRedfishUtils(RedfishUtils): # eject all inserted media one by one ejected_media_list = [] - for uri, data in resources.items(): + for data in resources.values(): if data.get("Image") and data.get("Inserted", True): returndict = self.virtual_media_eject_one(data.get("Image")) if not returndict["ret"]: diff --git a/ruff.toml b/ruff.toml index 00a84b2111..cc83b38257 100644 --- a/ruff.toml +++ b/ruff.toml @@ -27,7 +27,6 @@ ignore = [ "UP030", # Use implicit references for positional format fields "UP031", # Use format specifiers instead of percent format "UP041", # Replace aliased errors with `TimeoutError` - "B007", # unused-loop-control-variable "B015", # useless-comparison "B026", # star-arg-unpacking-after-keyword-arg "SIM102", # collapsible-if diff --git a/tests/unit/plugins/inventory/test_iocage.py b/tests/unit/plugins/inventory/test_iocage.py index aed960b3e2..c09b13c532 100644 --- a/tests/unit/plugins/inventory/test_iocage.py +++ b/tests/unit/plugins/inventory/test_iocage.py @@ -91,7 +91,7 @@ def test_get_jails(inventory): def test_get_properties(inventory): results = {"_meta": {"hostvars": {}}} inventory.get_jails(inventory.jails, results) - for hostname, host_vars in results["_meta"]["hostvars"].items(): + for hostname in results["_meta"]["hostvars"]: inventory.get_properties(inventory.prpts[hostname], results, hostname) assert results == inventory.ps_ok @@ -99,7 +99,7 @@ def test_get_properties(inventory): def test_populate(inventory, mocker): results = {"_meta": {"hostvars": {}}} inventory.get_jails(inventory.jails, results) - for hostname, host_vars in results["_meta"]["hostvars"].items(): + for hostname in results["_meta"]["hostvars"]: inventory.get_properties(inventory.prpts[hostname], results, hostname) inventory.get_option = mocker.MagicMock(side_effect=get_option) inventory.populate(results) diff --git a/tests/unit/plugins/module_utils/test_csv.py b/tests/unit/plugins/module_utils/test_csv.py index bbef9ee4a5..b652f61838 100644 --- a/tests/unit/plugins/module_utils/test_csv.py +++ b/tests/unit/plugins/module_utils/test_csv.py @@ -145,7 +145,7 @@ def test_invalid_csv(data, dialect, dialect_params, fieldnames): result = False try: - for row in reader: + for _row in reader: continue except csv.CSVError: result = True diff --git a/tests/unit/plugins/modules/test_pritunl_org.py b/tests/unit/plugins/modules/test_pritunl_org.py index 85c5052d10..5f788fd433 100644 --- a/tests/unit/plugins/modules/test_pritunl_org.py +++ b/tests/unit/plugins/modules/test_pritunl_org.py @@ -96,9 +96,9 @@ class TestPritunlOrg(ModuleTestCase): # except for changed which should be false the second time for k, v in idempotent_exc.items(): if k == "changed": - self.assertFalse(idempotent_exc[k]) + self.assertFalse(v) else: - self.assertEqual(create_exc[k], idempotent_exc[k]) + self.assertEqual(create_exc[k], v) def test_absent(self): """Test organization removal from Pritunl."""