Commits vergleichen

...

4 Commits

Autor SHA1 Nachricht Datum
144ffc72a5 some clean up of the code 2025-03-14 08:35:47 +01:00
c8d7d4e286 fixed an typing error 2025-03-14 08:35:28 +01:00
9d18ea533e removed display 2024-03-16 21:28:31 +01:00
f351bb6fb6 fixed typo 2024-03-16 21:28:18 +01:00
2 geänderte Dateien mit 9 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -23,9 +23,9 @@ def wrap_func(func, **updates):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
return func(*args, **kwargs) return func(*args, **kwargs)
attrs = frozenset( attrs = set(('__module__', '__name__', '__qualname__', '__doc__', '__annotations__', '__type_params__')).difference(
('__module__', '__name__', '__qualname__', '__doc__', '__annotations__', '__type_params__') updates.keys()
) - frozenset(updates.keys()) )
for attr in attrs: for attr in attrs:
try: try:
value = getattr(func, attr) value = getattr(func, attr)
@ -90,6 +90,7 @@ class meta(type):
class Types(metaclass=meta): class Types(metaclass=meta):
@staticmethod
def list( # type: ignore[misc] def list( # type: ignore[misc]
elements: Union[Type[object], str, AnsibleParameter], elements: Union[Type[object], str, AnsibleParameter],
required: bool = False, required: bool = False,
@ -109,7 +110,7 @@ class Types(metaclass=meta):
option["elements"] = elements["type"] option["elements"] = elements["type"]
if elements["type"] == "dict": if elements["type"] == "dict":
option["options"] = dict() option["options"] = dict()
for name, value in elements["option"].items(): for name, value in elements["options"].items():
option["options"][name] = value option["options"][name] = value
if "description" not in option["options"][name]: if "description" not in option["options"][name]:
warnings.warn( # pragma: nocover warnings.warn( # pragma: nocover
@ -120,6 +121,7 @@ class Types(metaclass=meta):
option["description"] = help.split("\n") option["description"] = help.split("\n")
return option return option
@staticmethod
def dict(required: bool = False, help: Optional[str] = None, **options: AnsibleParameter) -> AnsibleParameter: # type: ignore[misc] def dict(required: bool = False, help: Optional[str] = None, **options: AnsibleParameter) -> AnsibleParameter: # type: ignore[misc]
"""Wrapper for the Ansible dict type """Wrapper for the Ansible dict type
@ -154,6 +156,7 @@ def modspec(
supports_check_mode: bool = False, supports_check_mode: bool = False,
add_file_common_args: bool = False, add_file_common_args: bool = False,
) -> Dict[str, Any]: # pragma: nocover ) -> Dict[str, Any]: # pragma: nocover
"""Wrapper to properly Type the module specs"""
return dict( return dict(
argument_spec=argument_spec, argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive, mutually_exclusive=mutually_exclusive,

Datei anzeigen

@ -1,7 +1,6 @@
import pathlib import pathlib
from copy import deepcopy from copy import deepcopy
from typing import Any, Callable, ClassVar, Dict, NoReturn, Optional, Type, TypeVar, Union, overload, TypedDict from typing import Any, Callable, ClassVar, Dict, NoReturn, Optional, Type, TypeVar, Union, overload, TypedDict
from ansible.utils.display import Display
import ansible.module_utils.basic as basic import ansible.module_utils.basic as basic
@ -21,8 +20,8 @@ T = TypeVar("T")
class TypedDiff(TypedDict): class TypedDiff(TypedDict):
before: str before: str
after: str after: str
before_header: Optional[str] = None before_header: Optional[str]
after_header: Optional[str] = None after_header: Optional[str]
def docify(input: Union[dict, AnsibleParameter]) -> dict: def docify(input: Union[dict, AnsibleParameter]) -> dict:
@ -63,8 +62,6 @@ class AnsibleModule(object):
module_spec: ClassVar[dict] module_spec: ClassVar[dict]
#: This is set by classes that define common things for their subclasses, like behaviour of the run and check methods. This is used by `SystemdUnitModule` #: This is set by classes that define common things for their subclasses, like behaviour of the run and check methods. This is used by `SystemdUnitModule`
_common_args: ClassVar[dict[str, Any]] = dict() _common_args: ClassVar[dict[str, Any]] = dict()
#: For log messages
display: Display
@property @property
def params(self) -> Dict[str, Any]: def params(self) -> Dict[str, Any]:
@ -80,7 +77,6 @@ class AnsibleModule(object):
specs["argument_spec"].update(modspec["argument_spec"]) specs["argument_spec"].update(modspec["argument_spec"])
del modspec["argument_spec"] del modspec["argument_spec"]
specs.update(modspec) specs.update(modspec)
self.display = Display()
self.module = basic.AnsibleModule(**specs) self.module = basic.AnsibleModule(**specs)
self.tmpdir = pathlib.Path(self.module.tmpdir) self.tmpdir = pathlib.Path(self.module.tmpdir)