Skip to content

Commit

Permalink
use a generator rather than list comprehension when using any()
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Aug 12, 2021
1 parent d8caa6a commit 2aa83e9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/465-pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- aws_ec2 - use a generator rather than list comprehension (https://github.com/ansible-collections/amazon.aws/pull/465).
- ec2_group - use a generator rather than list comprehension (https://github.com/ansible-collections/amazon.aws/pull/465).
4 changes: 2 additions & 2 deletions plugins/inventory/aws_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def _compile_values(self, obj, attr):
else:
temp_obj = obj.get(attr)

has_indexes = any([isinstance(temp_obj, list), isinstance(temp_obj, tuple)])
has_indexes = any(isinstance(temp_obj, list), isinstance(temp_obj, tuple))
if has_indexes and len(temp_obj) == 1:
return temp_obj[0]

Expand Down Expand Up @@ -470,7 +470,7 @@ def _get_instances_by_region(self, regions, filters, strict_permissions):
for connection, region in self._boto3_conn(regions):
try:
# By default find non-terminated/terminating instances
if not any([f['Name'] == 'instance-state-name' for f in filters]):
if not any(f['Name'] == 'instance-state-name' for f in filters):
filters.append({'Name': 'instance-state-name', 'Values': ['running', 'pending', 'stopping', 'stopped']})
paginator = connection.get_paginator('describe_instances')
reservations = paginator.paginate(Filters=filters).build_full_result().get('Reservations')
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ec2_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ def main():
if purge_rules:
revoke_ingress = []
for p in present_ingress:
if not any([rule_cmp(p, b) for b in named_tuple_ingress_list]):
if not any(rule_cmp(p, b) for b in named_tuple_ingress_list):
revoke_ingress.append(to_permission(p))
else:
revoke_ingress = []
Expand All @@ -1329,7 +1329,7 @@ def main():
else:
revoke_egress = []
for p in present_egress:
if not any([rule_cmp(p, b) for b in named_tuple_egress_list]):
if not any(rule_cmp(p, b) for b in named_tuple_egress_list):
revoke_egress.append(to_permission(p))
else:
revoke_egress = []
Expand Down
2 changes: 0 additions & 2 deletions tests/sanity/ignore-2.12.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
plugins/inventory/aws_ec2.py pylint:use-a-generator # (new test) Should be an easy fix but not worth blocking gating
plugins/modules/ec2_group.py pylint:use-a-generator # (new test) Should be an easy fix but not worth blocking gating
plugins/modules/ec2_tag.py validate-modules:parameter-state-invalid-choice # Deprecated choice that can't be removed until 2022
plugins/modules/ec2_vol.py validate-modules:parameter-state-invalid-choice # Deprecated choice that can't be removed until 2022
plugins/module_utils/compat/_ipaddress.py no-assert # Vendored library
Expand Down

0 comments on commit 2aa83e9

Please sign in to comment.