Skip to content

Commit 3478863

Browse files
authored
Address issues reported by ruff check (#11043)
* Resolve E713 and E714 (not in/is tests). * Address UP018 (unnecessary str call). * UP045 requires Python 3.10+. * Address UP007 (X | Y for type annotations). * Address UP035 (import Callable from collections.abc). * Address UP006 (t.Dict -> dict). * Address UP009 (UTF-8 encoding comment). * Address UP034 (extraneous parantheses). * Address SIM910 (dict.get() with None default). * Address F401 (unused import). * Address UP020 (use builtin open). * Address B009 and B010 (getattr/setattr with constant name). * Address SIM300 (Yoda conditions). * UP029 isn't in use anyway. * Address FLY002 (static join). * Address B034 (re.sub positional args). * Address B020 (loop variable overrides input). * Address B017 (assert raise Exception). * Address SIM211 (if expression with false/true). * Address SIM113 (enumerate for loop). * Address UP036 (sys.version_info checks). * Remove unnecessary UP039. * Address SIM201 (not ==). * Address SIM212 (if expr with twisted arms). * Add changelog fragment. * Reformat.
1 parent f594320 commit 3478863

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+196
-222
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
bugfixes:
2+
- timestamp callback plugin - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
3+
- wsl connection plugin - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
4+
- json_patch filter plugin - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
5+
- to_* time filter plugins - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
6+
- linode inventory plugin - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
7+
- _filelock module utils - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
8+
- btrfs module utils - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
9+
- module_helper module utils - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
10+
- oneandone module utils - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
11+
- opennebula module utils - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
12+
- ali_instance - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
13+
- ali_instance_info - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
14+
- apt_rpm - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
15+
- btrfs_subvolume - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
16+
- consul - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
17+
- cronvar - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
18+
- dnf_versionlock - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
19+
- dnsmadeeasy - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
20+
- gitlab_issue - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
21+
- gitlab_merge_request - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
22+
- gitlab_project - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
23+
- gitlab_user - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
24+
- haproxy - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
25+
- homebrew - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
26+
- homebrew_services - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
27+
- hpilo_boot - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
28+
- ini_file - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
29+
- ipa_otptoken - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
30+
- jenkins_credential - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
31+
- jenkins_plugin - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
32+
- kea_command - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
33+
- keycloak_authz_permission - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
34+
- keycloak_clientscope_type - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
35+
- keycloak_user_execute_actions_email - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
36+
- keycloak_user_federation - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
37+
- listen_ports_facts - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
38+
- lxc_container - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
39+
- lxd_container - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
40+
- matrix - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
41+
- maven_artifact - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
42+
- monit - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
43+
- netcup_dns - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
44+
- nmcli - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
45+
- nomad_job - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
46+
- npm - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
47+
- one_host - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
48+
- one_image - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
49+
- one_template - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
50+
- one_vm - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
51+
- one_vnet - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
52+
- onepassword_info - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
53+
- pamd - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
54+
- pkgin - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
55+
- pulp_repo - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
56+
- redhat_subscription - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
57+
- rhevm - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
58+
- sensu_check - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
59+
- simpleinit_msb - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
60+
- sorcery - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
61+
- terraform - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
62+
- timezone - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
63+
- xenserver_guest - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).
64+
- zypper_repository - improve Python code (https://github.com/ansible-collections/community.general/pull/11043).

plugins/callback/timestamp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,5 @@ def set_options(self, task_keys=None, var_options=None, direct=None):
119119
tzinfo = ZoneInfo(self.get_option("timezone"))
120120

121121
# Inject options into the display object
122-
setattr(self._display, "timestamp_tzinfo", tzinfo)
123-
setattr(self._display, "timestamp_format_string", self.get_option("format_string"))
122+
self._display.timestamp_tzinfo = tzinfo
123+
self._display.timestamp_format_string = self.get_option("format_string")

plugins/connection/wsl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def _parse_proxy_command(self, port: int = 22) -> dict[str, t.Any]:
416416

417417
sock_kwarg = {}
418418
if proxy_command:
419-
replacers: t.Dict[str, str] = {
419+
replacers: dict[str, str] = {
420420
"%h": self.get_option("remote_addr"),
421421
"%p": str(port),
422422
"%r": self.get_option("remote_user"),
@@ -457,7 +457,7 @@ def _connect(self) -> Connection:
457457
paramiko_preferred_pubkeys = getattr(paramiko.Transport, "_preferred_pubkeys", ())
458458
paramiko_preferred_hostkeys = getattr(paramiko.Transport, "_preferred_keys", ())
459459
use_rsa_sha2_algorithms = self.get_option("use_rsa_sha2_algorithms")
460-
disabled_algorithms: t.Dict[str, t.Iterable[str]] = {}
460+
disabled_algorithms: dict[str, t.Iterable[str]] = {}
461461
if not use_rsa_sha2_algorithms:
462462
if paramiko_preferred_pubkeys:
463463
disabled_algorithms["pubkeys"] = tuple(a for a in paramiko_preferred_pubkeys if "rsa-sha2" in a)

plugins/filter/json_patch.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111

1212
if t.TYPE_CHECKING:
13-
from typing import Any, Callable, Union
13+
from typing import Any
14+
from collections.abc import Callable
1415

1516
JSONPATCH_IMPORT_ERROR: ImportError | None
1617
try:
@@ -60,7 +61,7 @@ def check_patch_arguments(self, filter_name: str, args: dict):
6061

6162
def json_patch(
6263
self,
63-
inp: Union[str, list, dict, bytes, bytearray],
64+
inp: str | list | dict | bytes | bytearray,
6465
op: str,
6566
path: str,
6667
value: Any = None,
@@ -105,7 +106,7 @@ def json_patch(
105106

106107
def json_patch_recipe(
107108
self,
108-
inp: Union[str, list, dict, bytes, bytearray],
109+
inp: str | list | dict | bytes | bytearray,
109110
operations: list,
110111
/,
111112
fail_test: bool = False,
@@ -141,8 +142,8 @@ def json_patch_recipe(
141142

142143
def json_diff(
143144
self,
144-
inp: Union[str, list, dict, bytes, bytearray],
145-
target: Union[str, list, dict, bytes, bytearray],
145+
inp: str | list | dict | bytes | bytearray,
146+
target: str | list | dict | bytes | bytearray,
146147
) -> list:
147148
if not HAS_LIB:
148149
raise AnsibleFilterError(

plugins/filter/time.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ def to_time_unit(human_time, unit="ms", **kwargs):
5656
unit = unit_to_short_form.get(unit.rstrip("s"), unit)
5757
if unit not in unit_factors:
5858
raise AnsibleFilterError(
59-
(
60-
f"to_time_unit() can not convert to the following unit: {unit}. Available units (singular or plural):"
61-
f"{', '.join(unit_to_short_form.keys())}. Available short units: {', '.join(unit_factors.keys())}"
62-
)
59+
f"to_time_unit() can not convert to the following unit: {unit}. Available units (singular or plural):"
60+
f"{', '.join(unit_to_short_form.keys())}. Available short units: {', '.join(unit_factors.keys())}"
6361
)
6462

6563
if "year" in kwargs:

plugins/inventory/linode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def _build_client(self, loader):
151151
access_token = self.templar.template(variable=access_token)
152152

153153
if access_token is None:
154-
raise AnsibleError(("Could not retrieve Linode access token from plugin configuration sources"))
154+
raise AnsibleError("Could not retrieve Linode access token from plugin configuration sources")
155155

156156
self.client = LinodeClient(access_token)
157157

plugins/module_utils/_filelock.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import stat
1212
import time
1313
import fcntl
14-
import sys
1514

1615
from contextlib import contextmanager
1716

@@ -59,9 +58,6 @@ def set_lock(self, path, tmpdir, lock_timeout=None):
5958
"""
6059
lock_path = os.path.join(tmpdir, f"ansible-{os.path.basename(path)}.lock")
6160
l_wait = 0.1
62-
r_exception = IOError
63-
if sys.version_info[0] == 3:
64-
r_exception = BlockingIOError
6561

6662
self.lockfd = open(lock_path, "w")
6763

@@ -77,7 +73,7 @@ def set_lock(self, path, tmpdir, lock_timeout=None):
7773
fcntl.flock(self.lockfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
7874
os.chmod(lock_path, stat.S_IWRITE | stat.S_IREAD)
7975
return True
80-
except r_exception:
76+
except BlockingIOError:
8177
time.sleep(l_wait)
8278
e_secs += l_wait
8379
continue

plugins/module_utils/btrfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def is_mounted(self):
190190
return mountpoints is not None and len(mountpoints) > 0
191191

192192
def is_filesystem_root(self):
193-
return 5 == self.__subvolume_id
193+
return self.__subvolume_id == 5
194194

195195
def is_filesystem_default(self):
196196
return self.__filesystem.default_subvolid == self.__subvolume_id

plugins/module_utils/module_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
# pylint: disable=unused-import
99

10-
from ansible_collections.community.general.plugins.module_utils.mh.module_helper import (
10+
from ansible_collections.community.general.plugins.module_utils.mh.module_helper import ( # noqa: F401
1111
ModuleHelper,
1212
StateModuleHelper,
1313
)
1414
from ansible_collections.community.general.plugins.module_utils.mh.exceptions import ModuleHelperException # noqa: F401
15-
from ansible_collections.community.general.plugins.module_utils.mh.deco import (
15+
from ansible_collections.community.general.plugins.module_utils.mh.deco import ( # noqa: F401
1616
cause_changes,
1717
module_fails_on_exception,
1818
check_mode_skip,

plugins/module_utils/oneandone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_resource(oneandone_conn, resource_type, resource_id):
3838
"vpn": oneandone_conn.get_vpn,
3939
}
4040

41-
return switcher.get(resource_type, None)(resource_id)
41+
return switcher.get(resource_type)(resource_id)
4242

4343

4444
def get_datacenter(oneandone_conn, datacenter, full_object=False):

0 commit comments

Comments
 (0)