mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
[PR #11215/862fe79a backport][stable-12] fix ruff case SIM110 (#11217)
fix ruff case SIM110 (#11215)
* fix ruff case SIM110
* Update plugins/module_utils/xenserver.py
* add changelog frag
---------
(cherry picked from commit 862fe79a22)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
e741e22ec4
commit
8930d03c7c
16 changed files with 34 additions and 72 deletions
13
changelogs/fragments/11215-ruff-cases-8.yml
Normal file
13
changelogs/fragments/11215-ruff-cases-8.yml
Normal 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).
|
||||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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"):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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 {}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue