From 881a3dd0ee82470240316bf12e5a96b25df13e83 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Mon, 8 May 2023 19:21:22 +0200 Subject: [PATCH] Bulk migration to Python 3.6 f-strings (#1810) Bulk migration to Python 3.6 f-strings SUMMARY We've dropped support for Python <3.6, bulk migrate to fstrings and perform some general string cleanup A combination of black --preview flynt some manual cleanup ISSUE TYPE Feature Pull Request COMPONENT NAME plugins/ tests/ ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/de338210dc1b0bb2eecee1dc16e073163b2d1df7 --- plugins/modules/acm_certificate.py | 12 ++++++------ plugins/modules/acm_certificate_info.py | 2 +- plugins/modules/ec2_ami_copy.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/modules/acm_certificate.py b/plugins/modules/acm_certificate.py index 197124fb59e..4bf07f0321a 100644 --- a/plugins/modules/acm_certificate.py +++ b/plugins/modules/acm_certificate.py @@ -276,7 +276,7 @@ def ensure_tags(client, module, resource_arn, existing_tags, tags, purge_tags): botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError, ) as e: - module.fail_json_aws(e, "Couldn't add tags to certificate {0}".format(resource_arn)) + module.fail_json_aws(e, f"Couldn't add tags to certificate {resource_arn}") if tags_to_remove and not module.check_mode: # remove_tags_from_certificate wants a list of key, value pairs, not a list of keys. tags_list = [{"Key": key, "Value": existing_tags.get(key)} for key in tags_to_remove] @@ -289,7 +289,7 @@ def ensure_tags(client, module, resource_arn, existing_tags, tags, purge_tags): botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError, ) as e: - module.fail_json_aws(e, "Couldn't remove tags from certificate {0}".format(resource_arn)) + module.fail_json_aws(e, f"Couldn't remove tags from certificate {resource_arn}") new_tags = deepcopy(existing_tags) for key, value in tags_to_add.items(): new_tags[key] = value @@ -441,7 +441,7 @@ def ensure_certificates_present(client, module, acm, certificates, desired_tags, cert_arn = None changed = False if len(certificates) > 1: - msg = "More than one certificate with Name=%s exists in ACM in this region" % module.params["name_tag"] + msg = f"More than one certificate with Name={module.params['name_tag']} exists in ACM in this region" module.fail_json(msg=msg, certificates=certificates) elif len(certificates) == 1: # Update existing certificate that was previously imported to ACM. @@ -496,7 +496,7 @@ def main(): absent_args = ["certificate_arn", "domain_name", "name_tag"] if sum([(module.params[a] is not None) for a in absent_args]) < 1: for a in absent_args: - module.debug("%s is %s" % (a, module.params[a])) + module.debug(f"{a} is {module.params[a]}") module.fail_json( msg="If 'state' is specified as 'present' then at least one of 'name_tag', 'certificate_arn' or 'domain_name' must be specified" ) @@ -505,7 +505,7 @@ def main(): absent_args = ["certificate_arn", "domain_name", "name_tag"] if sum([(module.params[a] is not None) for a in absent_args]) != 1: for a in absent_args: - module.debug("%s is %s" % (a, module.params[a])) + module.debug(f"{a} is {module.params[a]}") module.fail_json( msg="If 'state' is specified as 'absent' then exactly one of 'name_tag', 'certificate_arn' or 'domain_name' must be specified" ) @@ -543,7 +543,7 @@ def main(): only_tags=filter_tags, ) - module.debug("Found %d corresponding certificates in ACM" % len(certificates)) + module.debug(f"Found {len(certificates)} corresponding certificates in ACM") if module.params["state"] == "present": ensure_certificates_present(client, module, acm, certificates, desired_tags, filter_tags) diff --git a/plugins/modules/acm_certificate_info.py b/plugins/modules/acm_certificate_info.py index 287e7006aef..420cd0e0f92 100644 --- a/plugins/modules/acm_certificate_info.py +++ b/plugins/modules/acm_certificate_info.py @@ -296,7 +296,7 @@ def main(): ) if module.params["certificate_arn"] and len(certificates) != 1: - module.fail_json(msg="No certificate exists in this region with ARN %s" % module.params["certificate_arn"]) + module.fail_json(msg=f"No certificate exists in this region with ARN {module.params['certificate_arn']}") module.exit_json(certificates=certificates) diff --git a/plugins/modules/ec2_ami_copy.py b/plugins/modules/ec2_ami_copy.py index 5d7e49bde90..170a564e15d 100644 --- a/plugins/modules/ec2_ami_copy.py +++ b/plugins/modules/ec2_ami_copy.py @@ -171,7 +171,7 @@ def copy_image(module, ec2): try: if module.params.get("tag_equality"): - filters = [{"Name": "tag:%s" % k, "Values": [v]} for (k, v) in module.params.get("tags").items()] + filters = [{"Name": f"tag:{k}", "Values": [v]} for (k, v) in module.params.get("tags").items()] filters.append(dict(Name="state", Values=["available", "pending"])) images = ec2.describe_images(Filters=filters) if len(images["Images"]) > 0: @@ -197,7 +197,7 @@ def copy_image(module, ec2): except (ClientError, BotoCoreError) as e: module.fail_json_aws(e, msg="Could not copy AMI") except Exception as e: - module.fail_json(msg="Unhandled exception. (%s)" % to_native(e)) + module.fail_json(msg=f"Unhandled exception. ({to_native(e)})") def main():