From 8fe966ad0d4c184d03c15653a42530565bf959b1 Mon Sep 17 00:00:00 2001 From: Kate Case Date: Mon, 2 Dec 2024 15:21:42 -0500 Subject: [PATCH] Remove unnecessary casts --- src/molecule/dependency/ansible_galaxy/base.py | 2 +- src/molecule/dependency/ansible_galaxy/collections.py | 4 ++-- src/molecule/dependency/ansible_galaxy/roles.py | 4 ++-- src/molecule/provisioner/ansible.py | 6 +++--- src/molecule/types.py | 5 ++--- src/molecule/util.py | 10 ++++------ 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/molecule/dependency/ansible_galaxy/base.py b/src/molecule/dependency/ansible_galaxy/base.py index 23ab6a2c0f..04244f5bf3 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 4a2e43c2da..0fb5841170 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 ec2e67b59a..49d105c44b 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 6cfe0b082e..2a357e234f 100644 --- a/src/molecule/provisioner/ansible.py +++ b/src/molecule/provisioner/ansible.py @@ -582,13 +582,13 @@ def options(self) -> MutableMapping[str, str | bool]: # 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 884b023f24..6004f65312 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 ade8dde0a3..844c012b83 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: