diff --git a/src/molecule/dependency/ansible_galaxy/base.py b/src/molecule/dependency/ansible_galaxy/base.py index 23ab6a2c0..04244f5bf 100644 --- a/src/molecule/dependency/ansible_galaxy/base.py +++ b/src/molecule/dependency/ansible_galaxy/base.py @@ -120,7 +120,7 @@ def options(self) -> MutableMapping[str, str | bool]: Returns: Merged and filtered options for this dependency. """ - opts: MutableMapping[str, str | bool] = self._config.config["dependency"]["options"] + opts = self._config.config["dependency"]["options"] # NOTE(retr0h): Remove verbose options added by the user while in # debug. if self._config.debug: diff --git a/src/molecule/dependency/ansible_galaxy/collections.py b/src/molecule/dependency/ansible_galaxy/collections.py index 4a2e43c2d..0fb584117 100644 --- a/src/molecule/dependency/ansible_galaxy/collections.py +++ b/src/molecule/dependency/ansible_galaxy/collections.py @@ -5,7 +5,7 @@ import logging from pathlib import Path -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, cast from molecule import util from molecule.dependency.ansible_galaxy.base import AnsibleGalaxyBase @@ -58,4 +58,4 @@ def requirements_file(self) -> str: Returns: Path to the requirements file for this dependency. """ - return self.options["requirements-file"] # type: ignore[return-value] + return cast(str, self.options["requirements-file"]) diff --git a/src/molecule/dependency/ansible_galaxy/roles.py b/src/molecule/dependency/ansible_galaxy/roles.py index ec2e67b59..49d105c44 100644 --- a/src/molecule/dependency/ansible_galaxy/roles.py +++ b/src/molecule/dependency/ansible_galaxy/roles.py @@ -5,7 +5,7 @@ import logging from pathlib import Path -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, cast from molecule import util from molecule.dependency.ansible_galaxy.base import AnsibleGalaxyBase @@ -57,4 +57,4 @@ def requirements_file(self) -> str: Returns: Path to the requirements file for this dependency. """ - return self.options["role-file"] # type: ignore[return-value] + return cast(str, self.options["role-file"]) diff --git a/src/molecule/provisioner/ansible.py b/src/molecule/provisioner/ansible.py index 6cfe0b082..bbd8a0cbf 100644 --- a/src/molecule/provisioner/ansible.py +++ b/src/molecule/provisioner/ansible.py @@ -39,9 +39,10 @@ if TYPE_CHECKING: - from collections.abc import MutableMapping from typing import Any + from molecule.types import Options + Vivify = collections.defaultdict[str, Any | "Vivify"] @@ -578,17 +579,17 @@ def config_options(self) -> dict[str, Any]: ) @property - def options(self) -> MutableMapping[str, str | bool]: # noqa: D102 + def options(self) -> Options: # noqa: D102 if self._config.action in ["create", "destroy"]: return self.default_options - o: MutableMapping[str, str | bool] = self._config.config["provisioner"]["options"] + opts = self._config.config["provisioner"]["options"] # NOTE(retr0h): Remove verbose options added by the user while in # debug. if self._config.debug: - o = util.filter_verbose_permutation(o) + opts = util.filter_verbose_permutation(opts) - return util.merge_dicts(self.default_options, o) + return util.merge_dicts(self.default_options, opts) @property def env(self) -> dict[str, str]: # noqa: D102 diff --git a/src/molecule/types.py b/src/molecule/types.py index 884b023f2..6004f6531 100644 --- a/src/molecule/types.py +++ b/src/molecule/types.py @@ -2,15 +2,14 @@ from __future__ import annotations -from collections.abc import MutableMapping from typing import TYPE_CHECKING, TypedDict if TYPE_CHECKING: + from collections.abc import MutableMapping from typing import Any, Literal, TypeAlias - -Options: TypeAlias = MutableMapping[str, str | bool] + Options: TypeAlias = MutableMapping[str, str | bool] class DependencyData(TypedDict, total=False): diff --git a/src/molecule/util.py b/src/molecule/util.py index ade8dde0a..844c012b8 100644 --- a/src/molecule/util.py +++ b/src/molecule/util.py @@ -43,12 +43,12 @@ if TYPE_CHECKING: - from collections.abc import Generator, Iterable, Mapping, MutableMapping + from collections.abc import Generator, Iterable, MutableMapping from io import TextIOWrapper from typing import Any, AnyStr, NoReturn, TypeVar from warnings import WarningMessage - from molecule.types import CommandArgs, ConfigData, PlatformData + from molecule.types import CommandArgs, ConfigData, Options, PlatformData NestedDict = MutableMapping[str, Any] _T = TypeVar("_T", bound=NestedDict) @@ -355,7 +355,7 @@ def instance_with_scenario_name(instance_name: str, scenario_name: str) -> str: return f"{instance_name}-{scenario_name}" -def verbose_flag(options: MutableMapping[str, str | bool]) -> list[str]: +def verbose_flag(options: Options) -> list[str]: """Return computed verbosity flag. Args: @@ -378,9 +378,7 @@ def verbose_flag(options: MutableMapping[str, str | bool]) -> list[str]: return flags -def filter_verbose_permutation( - options: Mapping[str, str | bool], -) -> MutableMapping[str, str | bool]: +def filter_verbose_permutation(options: Options) -> Options: """Clean verbose information. Args: