made some typehints that even work with pyright

Dieser Commit ist enthalten in:
Sebastian Tobie 2025-03-14 19:05:37 +01:00
Ursprung 144ffc72a5
Commit 59400d158f
2 geänderte Dateien mit 115 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,110 @@
from typing import Any, Optional, Sequence, Dict, Tuple, Union
from pathlib import PosixPath
__all__ = [
'Types',
'SYSTEMD_SERVICE_CONFIG',
'SYSTEMD_NETWORK_CONFIG',
'SYSTEMD_CONFIG_ROOT',
'systemdbool',
'AnsibleParameter',
]
SYSTEMD_CONFIG_ROOT: PosixPath
SYSTEMD_NETWORK_CONFIG: PosixPath
SYSTEMD_SERVICE_CONFIG: PosixPath
AnsibleParameter = dict[str, Any]
class meta(type):
def __new__(cls, clsname, bases, attrs): ...
class Types(metaclass=meta):
@staticmethod
def str(
required: bool = False,
help: Optional[str] = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def bool(
required: bool = False,
help: Optional[str] = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def int(
required: bool = False,
help: Optional[str] = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def float(
required: bool = False,
help: Optional[str] = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def path(
required: bool = False,
help: Optional[str] = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def raw(
required: bool = False,
help: Optional[str] = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def jsonarg(
required: bool = False,
help: Optional[str] = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def json(
required: bool = False,
help: Optional[str] = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def bytes(
required: bool = False,
help: Optional[str] = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def bits(
required: bool = False,
help: Optional[str] = None,
choices: Optional[Sequence] = None,
default: Optional[Any] = None,
): ...
@staticmethod
def list(
elements: type[object] | str | AnsibleParameter, required: bool = False, help: str | None = None
) -> AnsibleParameter: ...
@staticmethod
def dict(required: bool = False, help: str | None = None, **options: AnsibleParameter) -> AnsibleParameter: ...
def systemdbool(b: bool | str) -> str: ...
def joindict(*items: dict) -> dict: ...
def modspec(
argument_spec: Dict[str, Dict[str, Any]],
mutually_exclusive: Sequence[Tuple[str, ...]] = (),
required_together: Sequence[Tuple[str, ...]] = (),
required_one_of: Sequence[Tuple[str, ...]] = (),
required_if: Sequence[Union[Tuple[str, Any, Tuple[str, ...]], Tuple[str, Any, Tuple[str, ...], bool]]] = (),
required_by: Dict[str, Union[str, Tuple[str, ...]]] = {},
supports_check_mode: bool = False,
add_file_common_args: bool = False,
) -> Dict[str, Any]: ...

Datei anzeigen

@ -197,11 +197,11 @@ class AnsibleModule(object):
)
)
def fail(self, message: str) -> NoReturn:
def fail(self, message: str) -> NoReturn: # type: ignore[reportReturnType]
"""Wrapper for AnsibleModule.fail_json"""
self.module.fail_json(message, **self.result)
def exit(self) -> NoReturn:
def exit(self) -> NoReturn: # type: ignore[reportReturnType]
"""Wrapper for AnsibleModule.exit_json"""
self.module.exit_json(**self.result)
@ -289,7 +289,7 @@ class SystemdUnitModule(AnsibleModule):
self.module.set_group_if_different(path.as_posix(), "root", False)
self.module.set_mode_if_different(path.as_posix(), "0644", False)
if self.unitfile.exists():
diff: dict[str, str] = dict()
diff = TypedDiff() # type:ignore[reportCallIssue]
self.changed = self.changed | self.module.set_owner_if_different(
self.unitfile.as_posix(),
"root",
@ -297,7 +297,7 @@ class SystemdUnitModule(AnsibleModule):
diff,
)
self.diff(diff)
diff = dict()
diff = TypedDiff() # type:ignore[reportCallIssue]
self.changed = self.changed | self.module.set_group_if_different(
self.unitfile.as_posix(),
"root",
@ -305,7 +305,7 @@ class SystemdUnitModule(AnsibleModule):
diff,
)
self.diff(diff)
diff = dict()
diff = TypedDiff() # type:ignore[reportCallIssue]
self.changed = self.changed | self.module.set_mode_if_different(
self.unitfile.as_posix(),
"0644",