From 1c678f5c0728618b6223cb0701171d5a838a2b7a Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Sun, 23 Nov 2025 20:37:41 +1300 Subject: [PATCH] fix ruff case UP030 (#11189) * fix ruff case UP030 * add changelog frag * formatting * suggestion from review --- changelogs/fragments/11189-ruff-cases-6.yml | 4 ++++ plugins/lookup/dependent.py | 4 +++- plugins/module_utils/oracle/oci_utils.py | 6 +++--- plugins/modules/snap.py | 7 ++----- ruff.toml | 1 - 5 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/11189-ruff-cases-6.yml diff --git a/changelogs/fragments/11189-ruff-cases-6.yml b/changelogs/fragments/11189-ruff-cases-6.yml new file mode 100644 index 0000000000..8cad240630 --- /dev/null +++ b/changelogs/fragments/11189-ruff-cases-6.yml @@ -0,0 +1,4 @@ +minor_changes: + - dependent lookup plugin - improve templating of strings (https://github.com/ansible-collections/community.general/pull/11189). + - oci_utils module utils - improve templating of strings (https://github.com/ansible-collections/community.general/pull/11189). + - snap - improve templating of strings (https://github.com/ansible-collections/community.general/pull/11189). diff --git a/plugins/lookup/dependent.py b/plugins/lookup/dependent.py index 0168719801..10decf191c 100644 --- a/plugins/lookup/dependent.py +++ b/plugins/lookup/dependent.py @@ -145,7 +145,9 @@ class LookupModule(LookupBase): ``variables`` are the variables to use. """ templar.available_variables = variables or {} - quoted_expression = "{0}{1}{2}".format("{{", expression, "}}") + open_br = "{{" + close_br = "}}" + quoted_expression = f"{open_br}{expression}{close_br}" if hasattr(templar, "evaluate_expression"): # This is available since the Data Tagging PR has been merged return templar.evaluate_expression(_make_safe(expression)) diff --git a/plugins/module_utils/oracle/oci_utils.py b/plugins/module_utils/oracle/oci_utils.py index b3c0f9f1f5..37ffe885d7 100644 --- a/plugins/module_utils/oracle/oci_utils.py +++ b/plugins/module_utils/oracle/oci_utils.py @@ -231,12 +231,12 @@ def get_oci_config(module, service_client_class=None): "OCI_IDENTITY_DO_NOT_REDIRECT_TO_HOME_REGION" ) if service_client_class == IdentityClient and not do_not_redirect: - _debug("Region passed for module invocation - {0} ".format(config["region"])) + _debug(f"Region passed for module invocation - {config['region']} ") identity_client = IdentityClient(config) region_subscriptions = identity_client.list_region_subscriptions(config["tenancy"]).data # Replace the region in the config with the home region. [config["region"]] = [rs.region_name for rs in region_subscriptions if rs.is_home_region is True] - _debug("Setting region in the config to home region - {0} ".format(config["region"])) + _debug(f"Setting region in the config to home region - {config['region']} ") return config @@ -1282,7 +1282,7 @@ def wait_for_resource_lifecycle_state( _debug(f"Waiting for resource to reach READY state. get_args: {kwargs_get}") response_get = call_with_backoff(get_fn, **kwargs_get) else: - _debug("Waiting for resource with id {0} to reach READY state.".format(resource["id"])) + _debug(f"Waiting for resource with id {resource['id']} to reach READY state.") response_get = call_with_backoff(get_fn, **{get_param: resource["id"]}) if states is None: states = module.params.get("wait_until") or DEFAULT_READY_STATES diff --git a/plugins/modules/snap.py b/plugins/modules/snap.py index 6499a47f89..9dee335109 100644 --- a/plugins/modules/snap.py +++ b/plugins/modules/snap.py @@ -338,11 +338,8 @@ class Snap(StateModuleHelper): process_ = process_many if "warning: no snap found" in check_error: - self.do_raise( - "Snaps not found: {0}.".format( - [x.split()[-1] for x in out.split("\n") if x.startswith("warning: no snap found")] - ) - ) + snaps_not_found = [x.split()[-1] for x in out.split("\n") if x.startswith("warning: no snap found")] + self.do_raise(f"Snaps not found: {snaps_not_found}.") return process_(rc, out, err) names = [] diff --git a/ruff.toml b/ruff.toml index a69359d815..50abc3d78c 100644 --- a/ruff.toml +++ b/ruff.toml @@ -22,7 +22,6 @@ ignore = [ "UP045", # Use `X | None` for type annotations - needs Python 3.10+ # To fix: "UP024", # Replace aliased errors with `OSError` - "UP030", # Use implicit references for positional format fields "UP031", # Use format specifiers instead of percent format "UP041", # Replace aliased errors with `TimeoutError` "B026", # star-arg-unpacking-after-keyword-arg