diff --git a/changelogs/fragments/688-pylint.yml b/changelogs/fragments/688-pylint.yml new file mode 100644 index 00000000000..6008db9cf0f --- /dev/null +++ b/changelogs/fragments/688-pylint.yml @@ -0,0 +1,10 @@ +minor_changes: +- aws_kms_info - use a generator rather than list comprehension (https://github.com/ansible-collections/community.aws/pull/688). +- aws_ses_rule_set - use a generator rather than list comprehension (https://github.com/ansible-collections/community.aws/pull/688). +- cloudwatchevent_rule - use a generator rather than list comprehension (https://github.com/ansible-collections/community.aws/pull/688). +- elb_target_group - use a generator rather than list comprehension (https://github.com/ansible-collections/community.aws/pull/688). +- iam - use a generator rather than list comprehension (https://github.com/ansible-collections/community.aws/pull/688). +- iam_group - use a generator rather than list comprehension (https://github.com/ansible-collections/community.aws/pull/688). +- iam_role - use a generator rather than list comprehension (https://github.com/ansible-collections/community.aws/pull/688). +- iam_user - use a generator rather than list comprehension (https://github.com/ansible-collections/community.aws/pull/688). +- rds_instance - use a generator rather than list comprehension (https://github.com/ansible-collections/community.aws/pull/688). diff --git a/plugins/modules/aws_kms_info.py b/plugins/modules/aws_kms_info.py index d517ac4abd5..3e606481e15 100644 --- a/plugins/modules/aws_kms_info.py +++ b/plugins/modules/aws_kms_info.py @@ -386,7 +386,7 @@ def key_matches_filters(key, filters): if not filters: return True else: - return all([key_matches_filter(key, filtr) for filtr in filters.items()]) + return all(key_matches_filter(key, filtr) for filtr in filters.items()) def get_key_details(connection, module, key_id, tokens=None): diff --git a/plugins/modules/aws_ses_rule_set.py b/plugins/modules/aws_ses_rule_set.py index 9b0b66cc30f..c87145eab5e 100644 --- a/plugins/modules/aws_ses_rule_set.py +++ b/plugins/modules/aws_ses_rule_set.py @@ -116,7 +116,7 @@ def list_rule_sets(client, module): def rule_set_in(name, rule_sets): - return any([s for s in rule_sets if s['Name'] == name]) + return any(s for s in rule_sets if s['Name'] == name) def ruleset_active(client, module, name): diff --git a/plugins/modules/cloudwatchevent_rule.py b/plugins/modules/cloudwatchevent_rule.py index e7a200dd960..d38db416864 100644 --- a/plugins/modules/cloudwatchevent_rule.py +++ b/plugins/modules/cloudwatchevent_rule.py @@ -388,10 +388,10 @@ def _rule_matches_aws(self): # The rule matches AWS only if all rule data fields are equal # to their corresponding local value defined in the task - return all([ + return all( getattr(self.rule, field) == aws_rule_data.get(field, None) for field in self.RULE_FIELDS - ]) + ) def _targets_to_put(self): """Returns a list of targets that need to be updated or added remotely""" diff --git a/plugins/modules/elb_target_group.py b/plugins/modules/elb_target_group.py index 722d7afa013..45649e7e651 100644 --- a/plugins/modules/elb_target_group.py +++ b/plugins/modules/elb_target_group.py @@ -479,7 +479,7 @@ def create_or_update_target_group(connection, module): "health_check_path", "health_check_protocol", "health_check_interval", "health_check_timeout", "healthy_threshold_count", "unhealthy_threshold_count", "successful_response_codes" ] - health_options = any([module.params[health_option_key] is not None for health_option_key in health_option_keys]) + health_options = any(module.params[health_option_key] is not None for health_option_key in health_option_keys) # Set health check if anything set if health_options: diff --git a/plugins/modules/iam.py b/plugins/modules/iam.py index 2aacd151cd1..4dd11aa0672 100644 --- a/plugins/modules/iam.py +++ b/plugins/modules/iam.py @@ -672,7 +672,7 @@ def main(): if key_state: key_state = key_state.lower() - if any([n in key_state for n in ['active', 'inactive']]) and not key_ids: + if any(n in key_state for n in ['active', 'inactive']) and not key_ids: module.fail_json(changed=False, msg="At least one access key has to be defined in order" " to use 'active' or 'inactive'") @@ -735,7 +735,7 @@ def main(): if iam_type == 'user': been_updated = False user_groups = None - user_exists = any([n in [name, new_name] for n in orig_user_list]) + user_exists = any(n in [name, new_name] for n in orig_user_list) if user_exists: current_path = iam.get_user(name).get_user_result.user['path'] if not new_path and current_path != path: diff --git a/plugins/modules/iam_group.py b/plugins/modules/iam_group.py index 7b534aa0504..5f85c4bfc8c 100644 --- a/plugins/modules/iam_group.py +++ b/plugins/modules/iam_group.py @@ -217,7 +217,7 @@ def compare_group_members(current_group_members, new_group_members): def convert_friendly_names_to_arns(connection, module, policy_names): - if not any([not policy.startswith('arn:') for policy in policy_names if policy is not None]): + if not any(not policy.startswith('arn:') for policy in policy_names if policy is not None): return policy_names allpolicies = {} paginator = connection.get_paginator('list_policies') diff --git a/plugins/modules/iam_role.py b/plugins/modules/iam_role.py index e696d9d7417..e95ed0afddf 100644 --- a/plugins/modules/iam_role.py +++ b/plugins/modules/iam_role.py @@ -221,7 +221,7 @@ def _list_policies(connection): def convert_friendly_names_to_arns(connection, module, policy_names): - if not any([not policy.startswith('arn:') for policy in policy_names]): + if not any(not policy.startswith('arn:') for policy in policy_names): return policy_names allpolicies = {} policies = _list_policies(connection) diff --git a/plugins/modules/iam_user.py b/plugins/modules/iam_user.py index b88953a6868..659eec56354 100644 --- a/plugins/modules/iam_user.py +++ b/plugins/modules/iam_user.py @@ -137,7 +137,7 @@ def convert_friendly_names_to_arns(connection, module, policy_names): # List comprehension that looks for any policy in the 'policy_names' list # that does not begin with 'arn'. If there aren't any, short circuit. # If there are, translate friendly name to the full arn - if not any([not policy.startswith('arn:') for policy in policy_names if policy is not None]): + if not any(not policy.startswith('arn:') for policy in policy_names if policy is not None): return policy_names allpolicies = {} paginator = connection.get_paginator('list_policies') diff --git a/plugins/modules/rds_instance.py b/plugins/modules/rds_instance.py index 6e894005ab9..c1f118db514 100644 --- a/plugins/modules/rds_instance.py +++ b/plugins/modules/rds_instance.py @@ -844,7 +844,7 @@ def get_parameters(client, module, parameters, method_name): parameters['TargetDBInstanceIdentifier'] = module.params['db_instance_identifier'] required_options = get_boto3_client_method_parameters(client, method_name, required=True) - if any([parameters.get(k) is None for k in required_options]): + if any(parameters.get(k) is None for k in required_options): module.fail_json(msg='To {0} requires the parameters: {1}'.format( get_rds_method_attribute(method_name, module).operation_description, required_options)) options = get_boto3_client_method_parameters(client, method_name) diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index a172764cf6b..e5bade76474 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -1,12 +1,3 @@ -plugins/modules/aws_kms_info.py pylint:use-a-generator # (new test) Should be an easy fix but not worth blocking gating -plugins/modules/aws_ses_rule_set.py pylint:use-a-generator # (new test) Should be an easy fix but not worth blocking gating plugins/modules/cloudfront_info.py pylint:unnecessary-comprehension # (new test) Should be an easy fix, but testing is a challenge - test are broken and aliases require a wildcard cert in ACM -plugins/modules/cloudwatchevent_rule.py pylint:use-a-generator # (new test) Should be an easy fix but not worth blocking gating -plugins/modules/elb_target_group.py pylint:use-a-generator # (new test) Should be an easy fix but not worth blocking gating -plugins/modules/iam_group.py pylint:use-a-generator # (new test) Should be an easy fix but not worth blocking gating -plugins/modules/iam.py pylint:use-a-generator # no tests and module is deprecated plugins/modules/iam.py pylint:unnecessary-comprehension # no tests and module is deprecated -plugins/modules/iam_role.py pylint:use-a-generator # (new test) Should be an easy fix but not worth blocking gating -plugins/modules/iam_user.py pylint:use-a-generator # (new test) Should be an easy fix but not worth blocking gating -plugins/modules/rds_instance.py pylint:use-a-generator # (new test) Should be an easy fix but not worth blocking gating plugins/modules/route53.py validate-modules:parameter-state-invalid-choice # route53_info needs improvements before we can deprecate this