diff --git a/changelogs/fragments/10712-python-idioms-2.yml b/changelogs/fragments/10712-python-idioms-2.yml new file mode 100644 index 0000000000..8d49f1f86f --- /dev/null +++ b/changelogs/fragments/10712-python-idioms-2.yml @@ -0,0 +1,7 @@ +minor_changes: + - iocage inventory plugin - minor refactor to improve readability (https://github.com/ansible-collections/community.general/pull/10712). + - manageiq - minor refactor to improve readability (https://github.com/ansible-collections/community.general/pull/10712). + - android_sdk - minor refactor to improve readability (https://github.com/ansible-collections/community.general/pull/10712). + - elasticsearch_plugin - minor refactor to improve readability (https://github.com/ansible-collections/community.general/pull/10712). + - manageiq_alert_profiles - minor refactor to improve readability (https://github.com/ansible-collections/community.general/pull/10712). + - one_vm - minor refactor to improve readability (https://github.com/ansible-collections/community.general/pull/10712). diff --git a/plugins/inventory/iocage.py b/plugins/inventory/iocage.py index 603003d617..1ba139420f 100644 --- a/plugins/inventory/iocage.py +++ b/plugins/inventory/iocage.py @@ -404,7 +404,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): results['_meta']['hostvars'][iocage_name]['iocage_basejail'] = jail[9] def get_properties(self, t_stdout, results, hostname): - properties = dict([x.split(':', 1) for x in t_stdout.splitlines()]) + properties = dict(x.split(':', 1) for x in t_stdout.splitlines()) results['_meta']['hostvars'][hostname]['iocage_properties'] = properties def populate(self, results): diff --git a/plugins/module_utils/manageiq.py b/plugins/module_utils/manageiq.py index cbce05b8ec..d88c746c3a 100644 --- a/plugins/module_utils/manageiq.py +++ b/plugins/module_utils/manageiq.py @@ -297,7 +297,7 @@ class ManageIQPolicies(object): # make a list of assigned full profile names strings # e.g. ['openscap profile', ...] - assigned_profiles_set = set([profile['profile_name'] for profile in assigned_profiles]) + assigned_profiles_set = set(profile['profile_name'] for profile in assigned_profiles) for profile in profiles: assigned = profile.get('name') in assigned_profiles_set @@ -424,7 +424,7 @@ class ManageIQTags(object): # make a list of assigned full tag names strings # e.g. ['/managed/environment/prod', ...] - assigned_tags_set = set([tag['full_name'] for tag in assigned_tags]) + assigned_tags_set = set(tag['full_name'] for tag in assigned_tags) for tag in tags: assigned = self.full_tag_name(tag) in assigned_tags_set diff --git a/plugins/modules/android_sdk.py b/plugins/modules/android_sdk.py index a9bffa50ea..0e2296666b 100644 --- a/plugins/modules/android_sdk.py +++ b/plugins/modules/android_sdk.py @@ -160,7 +160,7 @@ class AndroidSdk(StateModuleHelper): arg_pkgs = set(self.vars.package) if len(arg_pkgs) < len(self.vars.package): self.do_raise("Packages may not repeat") - return set([Package(p) for p in arg_pkgs]) + return set(Package(p) for p in arg_pkgs) def state_present(self): packages = self._parse_packages() diff --git a/plugins/modules/elasticsearch_plugin.py b/plugins/modules/elasticsearch_plugin.py index 8552b55ccd..5d14aaa848 100644 --- a/plugins/modules/elasticsearch_plugin.py +++ b/plugins/modules/elasticsearch_plugin.py @@ -238,8 +238,8 @@ def get_plugin_bin(module, plugin_bin=None): # Get separate lists of dirs and binary names from the full paths to the # plugin binaries. - plugin_dirs = list(set([os.path.dirname(x) for x in bin_paths])) - plugin_bins = list(set([os.path.basename(x) for x in bin_paths])) + plugin_dirs = list(set(os.path.dirname(x) for x in bin_paths)) + plugin_bins = list(set(os.path.basename(x) for x in bin_paths)) # Check for the binary names in the default system paths as well as the path # specified in the module arguments. diff --git a/plugins/modules/manageiq_alert_profiles.py b/plugins/modules/manageiq_alert_profiles.py index fff9552a6c..8061b73bc5 100644 --- a/plugins/modules/manageiq_alert_profiles.py +++ b/plugins/modules/manageiq_alert_profiles.py @@ -201,7 +201,7 @@ class ManageIQAlertProfiles(object): # alert which currently exist in the profile if 'alert_definitions' in old_profile: # we use get_alert_href to have a direct href to the alert - existing_alerts = set([self.get_alert_href(alert) for alert in old_profile['alert_definitions']]) + existing_alerts = set(self.get_alert_href(alert) for alert in old_profile['alert_definitions']) else: # no alerts in this profile existing_alerts = set() diff --git a/plugins/modules/one_vm.py b/plugins/modules/one_vm.py index 3d23efa036..6d2e6f0b05 100644 --- a/plugins/modules/one_vm.py +++ b/plugins/modules/one_vm.py @@ -1146,7 +1146,7 @@ def create_count_of_vms(module, client, base_name = vm_name[:len(vm_name) - num_sign_cnt] vm_name = base_name # Make list which contains used indexes in format ['000', '001',...] - vm_filled_indexes_list = list((vm.NAME[len(base_name):].zfill(num_sign_cnt)) for vm in vm_list) + vm_filled_indexes_list = [vm.NAME[len(base_name):].zfill(num_sign_cnt) for vm in vm_list] while count > 0: new_vm_name = vm_name diff --git a/tests/unit/plugins/inventory/test_opennebula.py b/tests/unit/plugins/inventory/test_opennebula.py index 87ec4314de..827063121a 100644 --- a/tests/unit/plugins/inventory/test_opennebula.py +++ b/tests/unit/plugins/inventory/test_opennebula.py @@ -316,7 +316,7 @@ keyed_groups: # note the vm_pool (and json data file) has four hosts, # but the options above asks ansible to filter one out assert len(get_vm_pool_json().VM) == 4 - assert set([vm.NAME for vm in get_vm_pool_json().VM]) == set([ + assert set(vm.NAME for vm in get_vm_pool_json().VM) == set([ 'terraform_demo_00', 'terraform_demo_01', 'terraform_demo_srv_00',