1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-27 05:58:50 +00:00

CI: add type checking (#10997)

* Set up type checking with mypy.

* Make mypy pass.

* Use list() instead of sorted().
This commit is contained in:
Felix Fontein 2025-10-29 18:13:38 +01:00 committed by GitHub
parent 831787619a
commit 6088b0cff5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
73 changed files with 442 additions and 175 deletions

View file

@ -129,6 +129,7 @@ from ansible.module_utils.basic import (
)
from ansible.module_utils.common.text.converters import to_native
RPM_PYTHON_IMPORT_ERROR: str | None
try:
import rpm
except ImportError:

View file

@ -114,14 +114,7 @@ EXAMPLES = r"""
msg: Task completed ... with feeling.
"""
try:
from html import escape as html_escape
except ImportError:
# Python-3.2 or later
import cgi
def html_escape(text, quote=True):
return cgi.escape(text, quote)
from html import escape as html_escape
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url

View file

@ -166,10 +166,11 @@ def main():
class Crypttab(object):
_lines = []
_lines: list[str]
def __init__(self, path):
self.path = path
self._lines = []
if not os.path.exists(path):
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))

View file

@ -201,16 +201,16 @@ class Device(object):
class Filesystem(object):
MKFS = None
MKFS_FORCE_FLAGS = []
MKFS_SET_UUID_OPTIONS = None
MKFS_SET_UUID_EXTRA_OPTIONS = []
INFO = None
GROW = None
GROW_MAX_SPACE_FLAGS = []
MKFS: str | None = None
MKFS_FORCE_FLAGS: list[str] | None = []
MKFS_SET_UUID_OPTIONS: list[str] | None = None
MKFS_SET_UUID_EXTRA_OPTIONS: list[str] | None = []
INFO: str | None = None
GROW: str | None = None
GROW_MAX_SPACE_FLAGS: list[str] | None = []
GROW_MOUNTPOINT_ONLY = False
CHANGE_UUID = None
CHANGE_UUID_OPTION = None
CHANGE_UUID: str | None = None
CHANGE_UUID_OPTION: str | None = None
CHANGE_UUID_OPTION_HAS_ARG = True
LANG_ENV = {'LANG': 'C', 'LC_ALL': 'C', 'LC_MESSAGES': 'C'}

View file

@ -273,6 +273,7 @@ from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.basic import jsonify
from ansible.module_utils.common.text.formatters import human_to_bytes
CRYPT_IMPORT_ERROR: str | None
try:
import crypt
except ImportError:
@ -282,6 +283,7 @@ else:
HAS_CRYPT = True
CRYPT_IMPORT_ERROR = None
LEGACYCRYPT_IMPORT_ERROR: str | None
try:
import legacycrypt
if not HAS_CRYPT:

View file

@ -112,7 +112,9 @@ from ansible.module_utils.common.text.converters import to_native
with deps.declare("passlib"):
from passlib.apache import HtpasswdFile, htpasswd_context
# Apparently the type infos don't know htpasswd_context, which *does* exist
# (but isn't mentioned in the documentation for some reason)
from passlib.apache import HtpasswdFile, htpasswd_context # type: ignore[attr-defined]
from passlib.context import CryptContext

View file

@ -164,7 +164,7 @@ IS_PYTHON_2 = sys.version_info[0] <= 2
class JenkinsNode:
def __init__(self, module):
def __init__(self, module: AnsibleModule) -> None:
self.module = module
self.name = module.params['name']
@ -174,7 +174,7 @@ class JenkinsNode:
self.url = module.params['url']
self.num_executors = module.params['num_executors']
self.labels = module.params['labels']
self.offline_message = module.params['offline_message'] # type: str | None
self.offline_message: str | None = module.params['offline_message']
if self.offline_message is not None:
self.offline_message = self.offline_message.strip()

View file

@ -74,7 +74,7 @@ class PacemakerInfo(ModuleHelper):
"constraint_info": "constraint",
"property_info": "property"
}
output_params = info_vars.keys()
output_params = list(info_vars.keys())
def __init_module__(self):
self.runner = pacemaker_runner(self.module)

View file

@ -209,6 +209,7 @@ import re
import traceback
from ansible.module_utils.basic import AnsibleModule, missing_required_lib, human_to_bytes
XMLTODICT_LIBRARY_IMPORT_ERROR: str | None
try:
import xmltodict
except ImportError:

View file

@ -347,7 +347,7 @@ RHEV_UNAVAILABLE = 2
RHEV_TYPE_OPTS = ['desktop', 'host', 'server']
STATE_OPTS = ['absent', 'cd', 'down', 'info', 'ping', 'present', 'restart', 'up']
msg = []
msg: list[str] = []
changed = False
failed = False
@ -1258,7 +1258,7 @@ def setChanged():
changed = True
def setMsg(message):
def setMsg(message: str) -> None:
msg.append(message)

View file

@ -328,6 +328,7 @@ from ansible_collections.community.general.plugins.module_utils.univention_umc i
base_dn,
)
CRYPT_IMPORT_ERROR: str | None
try:
import crypt
except ImportError:
@ -337,6 +338,7 @@ else:
HAS_CRYPT = True
CRYPT_IMPORT_ERROR = None
LEGACYCRYPT_IMPORT_ERROR: str | None
try:
import legacycrypt
if not HAS_CRYPT: