1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-05-02 08:22:52 +00:00

Add more type hints.

This commit is contained in:
Felix Fontein 2025-11-30 12:00:56 +01:00
parent fe478bd1bb
commit 93cd3755a0
30 changed files with 354 additions and 298 deletions

View file

@ -21,6 +21,7 @@ from ansible_collections.community.general.plugins.module_utils.datetime import
)
if t.TYPE_CHECKING:
from collections.abc import Iterable
from ansible.module_utils.basic import AnsibleModule
SCALEWAY_SECRET_IMP_ERR: str | None = None
@ -33,7 +34,7 @@ except Exception:
HAS_SCALEWAY_SECRET_PACKAGE = False
def scaleway_argument_spec():
def scaleway_argument_spec() -> dict[str, t.Any]:
return dict(
api_token=dict(
required=True,
@ -63,7 +64,7 @@ def payload_from_object(scw_object):
class ScalewayException(Exception):
def __init__(self, message):
def __init__(self, message: str) -> None:
self.message = message
@ -74,7 +75,7 @@ R_LINK_HEADER = r"""<[^>]+>;\srel="(first|previous|next|last)"
R_RELATION = r'</?(?P<target_IRI>[^>]+)>; rel="(?P<relation>first|previous|next|last)"'
def parse_pagination_link(header):
def parse_pagination_link(header: str) -> dict[str, str]:
if not re.match(R_LINK_HEADER, header, re.VERBOSE):
raise ScalewayException("Scaleway API answered with an invalid Link pagination header")
else:
@ -90,7 +91,7 @@ def parse_pagination_link(header):
return parsed_relations
def filter_sensitive_attributes(container, attributes):
def filter_sensitive_attributes(container: dict[str, t.Any], attributes: Iterable[str]) -> dict[str, t.Any]:
"""
WARNING: This function is effectively private, **do not use it**!
It will be removed or renamed once changing its name no longer triggers a pylint bug.
@ -103,7 +104,7 @@ def filter_sensitive_attributes(container, attributes):
class SecretVariables:
@staticmethod
def ensure_scaleway_secret_package(module):
def ensure_scaleway_secret_package(module: AnsibleModule) -> None:
if not HAS_SCALEWAY_SECRET_PACKAGE:
module.fail_json(
msg=missing_required_lib("passlib[argon2]", url="https://passlib.readthedocs.io/en/stable/"),
@ -228,8 +229,9 @@ class Scaleway:
return Response(resp, info)
@staticmethod
def get_user_agent_string(module):
return f"ansible {module.ansible_version} Python {sys.version.split(' ', 1)[0]}"
def get_user_agent_string(module: AnsibleModule) -> str:
ansible_version = module.ansible_version # type: ignore # For some reason this isn't documented in AnsibleModule
return f"ansible {ansible_version} Python {sys.version.split(' ', 1)[0]}"
def get(self, path, data=None, headers=None, params=None):
return self.send(method="GET", path=path, data=data, headers=headers, params=params)
@ -249,7 +251,7 @@ class Scaleway:
def update(self, path, data=None, headers=None, params=None):
return self.send(method="UPDATE", path=path, data=data, headers=headers, params=params)
def warn(self, x):
def warn(self, x) -> None:
self.module.warn(str(x))
def fetch_state(self, resource):