1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

fix ruff case SIM110 (#11215)

* fix ruff case SIM110

* Update plugins/module_utils/xenserver.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* add changelog frag

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky 2025-11-26 09:47:50 +13:00 committed by GitHub
parent d364e35423
commit 862fe79a22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 34 additions and 72 deletions

View file

@ -0,0 +1,13 @@
minor_changes:
- database module utils - improve code by using native Python construct (https://github.com/ansible-collections/community.general/pull/11215).
- hwc_utils module utils - improve code by using native Python construct (https://github.com/ansible-collections/community.general/pull/11215).
- known_hosts module utils - improve code by using native Python construct (https://github.com/ansible-collections/community.general/pull/11215).
- oci_utils module utils - improve code by using native Python construct (https://github.com/ansible-collections/community.general/pull/11215).
- utm_utils module utils - improve code by using native Python construct (https://github.com/ansible-collections/community.general/pull/11215).
- xenserver module utils - improve code by using native Python construct (https://github.com/ansible-collections/community.general/pull/11215).
- aix_filesystem - improve code by using native Python construct (https://github.com/ansible-collections/community.general/pull/11215).
- composer - improve code by using native Python construct (https://github.com/ansible-collections/community.general/pull/11215).
- flatpak - improve code by using native Python construct (https://github.com/ansible-collections/community.general/pull/11215).
- gitlab_group_members - improve code by using native Python construct (https://github.com/ansible-collections/community.general/pull/11215).
- gitlab_project_members - improve code by using native Python construct (https://github.com/ansible-collections/community.general/pull/11215).
- lxd_container - improve code by using native Python construct (https://github.com/ansible-collections/community.general/pull/11215).

View file

@ -159,11 +159,7 @@ def is_input_dangerous(string):
if not string:
return False
for pattern in (PATTERN_1, PATTERN_2, PATTERN_3):
if re.search(pattern, string):
return True
return False
return any(pattern.search(string) for pattern in (PATTERN_1, PATTERN_2, PATTERN_3))
def check_input(module, *args):

View file

@ -269,11 +269,7 @@ class _DictComparison:
if set(dict1.keys()) != set(dict2.keys()):
return False
for k in dict1:
if not self._compare_value(dict1.get(k), dict2.get(k)):
return False
return True
return all(self._compare_value(dict1[k], dict2[k]) for k in dict1)
def _compare_lists(self, list1, list2):
"""Takes in two lists and compares them."""
@ -283,11 +279,7 @@ class _DictComparison:
if len(list1) != len(list2):
return False
for i in range(len(list1)):
if not self._compare_value(list1[i], list2[i]):
return False
return True
return all(self._compare_value(l1, l2) for l1, l2 in zip(list1, list2))
def _compare_value(self, value1, value2):
"""

View file

@ -32,10 +32,7 @@ def is_ssh_url(url):
if "@" in url and "://" not in url:
return True
for scheme in "ssh://", "git+ssh://", "ssh+git://":
if url.startswith(scheme):
return True
return False
return any(url.startswith(scheme) for scheme in ("ssh://", "git+ssh://", "ssh+git://"))
def get_fqdn_and_port(repo_url):

View file

@ -507,10 +507,7 @@ def is_dictionary_subset(sub, super_dict):
:param super_dict: super dictionary, for example resources_attr_value.
:return: True if sub is contained in super.
"""
for key in sub:
if sub[key] != super_dict[key]:
return False
return True
return all(sub[key] == super_dict[key] for key in sub)
def are_lists_equal(s, t):
@ -533,10 +530,7 @@ def are_lists_equal(s, t):
# `service_id` is provided by the user in the update call.
sorted_s = sort_list_of_dictionary(s)
sorted_t = sort_list_of_dictionary(t)
for index, d in enumerate(sorted_s):
if not is_dictionary_subset(d, sorted_t[index]):
return False
return True
return all(is_dictionary_subset(d, sorted_t[index]) for index, d in enumerate(sorted_s))
else:
# Handle lists of primitive types.
try:

View file

@ -230,7 +230,4 @@ class UTM:
:param result: The result from the query
:return:
"""
for key in keys:
if module.params.get(key) != result[key]:
return True
return False
return any(module.params.get(key) != result[key] for key in keys)

View file

@ -219,11 +219,7 @@ def is_valid_ip6_addr(ip6_addr):
ip6_addr_hextet_regex = re.compile("^[0-9a-f]{1,4}$")
for ip6_addr_hextet in ip6_addr_split:
if not bool(ip6_addr_hextet_regex.match(ip6_addr_hextet)):
return False
return True
return all(ip6_addr_hextet_regex.match(ip6_addr_hextet) for ip6_addr_hextet in ip6_addr_split)
def is_valid_ip6_prefix(ip6_prefix):

View file

@ -205,11 +205,7 @@ def _check_nfs_device(module, nfs_host, device):
module.fail_json(msg=f"Failed to run showmount. Error message: {err}")
else:
showmount_data = showmount_out.splitlines()
for line in showmount_data:
if line.split(":")[1] == device:
return True
return False
return any(line.split(":")[1] == device for line in showmount_data)
def _validate_vg(module, vg):

View file

@ -150,11 +150,10 @@ def parse_out(string):
def has_changed(string):
for no_change in ["Nothing to install or update", "Nothing to install, update or remove"]:
if no_change in string:
return False
return True
return all(
no_change not in string
for no_change in ["Nothing to install or update", "Nothing to install, update or remove"]
)
def get_available_options(module, command="install"):

View file

@ -313,10 +313,7 @@ def _is_flatpak_id(part):
domain = sections[0]
if not domain.islower():
return False
for section in sections[1:]:
if not section.isalnum():
return False
return True
return all(section.isalnum() for section in sections[1:])
def _parse_flatpak_name(name):

View file

@ -202,10 +202,7 @@ class GitLabGroup:
# check if the user is a member of the group
def is_user_a_member(self, members, gitlab_user_id):
for member in members:
if member.id == gitlab_user_id:
return True
return False
return any(member.id == gitlab_user_id for member in members)
# add user to a group
def add_member_to_group(self, gitlab_user_id, gitlab_group_id, access_level):

View file

@ -205,10 +205,7 @@ class GitLabProjectMembers:
# check if the user is a member of the project
def is_user_a_member(self, members, gitlab_user_id):
for member in members:
if member.id == gitlab_user_id:
return True
return False
return any(member.id == gitlab_user_id for member in members)
# add user to a project
def add_member_to_project(self, gitlab_user_id, gitlab_project_id, access_level):

View file

@ -682,10 +682,9 @@ class LXDContainerManagement:
return self.config[key] != old_configs
def _needs_to_apply_instance_configs(self):
for param in set(CONFIG_PARAMS) - set(CONFIG_CREATION_PARAMS):
if self._needs_to_change_instance_config(param):
return True
return False
return any(
self._needs_to_change_instance_config(param) for param in set(CONFIG_PARAMS) - set(CONFIG_CREATION_PARAMS)
)
def _apply_instance_configs(self):
old_metadata = copy.deepcopy(self.old_instance_json).get("metadata", None) or {}

View file

@ -26,7 +26,6 @@ ignore = [
"UP041", # Replace aliased errors with `TimeoutError`
"B026", # star-arg-unpacking-after-keyword-arg
"SIM102", # collapsible-if
"SIM110", # reimplemented-builtin
"SIM114", # if-with-same-arms
"SIM115", # open-file-with-context-handler
"SIM116", # if-else-block-instead-of-dict-lookup

View file

@ -45,11 +45,7 @@ def xml_equal(x, y):
if len(x_children) != len(y_children):
return False
for x, y in zip(x_children, y_children):
if not xml_equal(x, y):
return False
return True
return all(xml_equal(x, y) for x, y in zip(x_children, y_children))
def assert_xml_equal(x, y):

View file

@ -188,10 +188,7 @@ def test__new_fallback_urls(mocker):
def isInList(l, i):
print(f"checking if {i} in {l}")
for item in l:
if item == i:
return True
return False
return any(item == i for item in l) # TODO: check if return `i in l` works
@patch("ansible_collections.community.general.plugins.modules.jenkins_plugin.fetch_url")